Skip to content

Commit

Permalink
Adding support for device-specific options be displayed only for devi…
Browse files Browse the repository at this point in the history
…ces they belong to
  • Loading branch information
twoln committed Dec 29, 2023
1 parent 94c9881 commit 0349ba0
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 10 deletions.
16 changes: 16 additions & 0 deletions devices/Devices-template.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ class Devices extends \core\common\Entity {
* The default is unset, so it is not listed in the Options array.
* - 'hs20' - if defined and equal to 1 will mark the device as potentially supporting
* Hotspot 2.0.
* - 'device_options' - this is an array of strings pointing to device-sepecific options,
* for instance possible strings are 'geteduroam' or 'geantlink'. If the corresponding
* option, like device-specific:geteduroam has the flag set to 'SPECIFIC'
* then the options selection in the admin interface will only show such an
* option if the selected device has the option 'device_options' set
* and containing value lile 'geteduroam'.
*
* @var array
*/
Expand Down Expand Up @@ -151,6 +157,8 @@ public static function listDevices($profile = 0, $orAlways = 0) {
'clientcert' => Devices::SUPPORT_EMBEDDED_ECDSA,
'mime' => 'application/x-dosexec',
'hs20' => 1,
'device_options' => ['geantlink',
],
],
],
'w8' => [
Expand All @@ -167,6 +175,8 @@ public static function listDevices($profile = 0, $orAlways = 0) {
'mime' => 'application/x-dosexec',
'hs20' => 0,
'hidden' => 2,
'device_options' => ['geantlink',
],
],
],
'w7' => [
Expand All @@ -180,6 +190,8 @@ public static function listDevices($profile = 0, $orAlways = 0) {
'sign' => 1,
'device_id' => 'W7',
'mime' => 'application/x-dosexec',
'device_options' => ['geantlink',
],
],
],
'vista' => [
Expand Down Expand Up @@ -421,6 +433,8 @@ public static function listDevices($profile = 0, $orAlways = 0) {
'mime' => 'application/eap-config',
'hs20' => 1,
'message_only' => 0,
'device_options' => ['geteduroam',
],
'message' => sprintf(_("Before you proceed with installation on Android systems, please make sure that you have installed the %s application. This application is available from these sites: %s and will use the configuration file downloaded from CAT to create all necessary settings."),
"geteduroam",
"<a target='_blank' href='https://play.google.com/store/apps/details?id=app.eduroam.geteduroam'>Google Play</a>, <a target='_blank' href='geteduroam-stable.apk'>" . _("as local download") . "</a>"),
Expand Down Expand Up @@ -464,6 +478,8 @@ public static function listDevices($profile = 0, $orAlways = 0) {
'options' => [
'mime' => 'application/eap-config',
'message_only' => 0,
'device_options' => ['geteduroam',
],
'message' => sprintf(_("Before you proceed with installation on Android systems, please make sure that you have installed the %s application. This application is available from these sites: %s and will use the configuration file downloaded from CAT to create all necessary settings."),
"eduroamCAT",
"<a target='_blank' href='https://play.google.com/store/apps/details?id=uk.ac.swansea.eduroamcat'>Google Play</a>, <a target='_blank' href='https://www.amazon.com/dp/B01EACCX0S/'>Amazon Appstore</a>, <a target='_blank' href='eduroamCAT-stable.apk'>" . _("as local download") . "</a>"),
Expand Down
8 changes: 6 additions & 2 deletions web/admin/inc/option_xhr.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
require_once dirname(dirname(dirname(dirname(__FILE__)))) . "/config/_config.php";

\core\CAT::sessionStart();
$validator = new \web\lib\common\InputValidation();

if (!isset($_GET["class"] )) {
throw new Exception("Unknown type of option!");
Expand All @@ -30,15 +31,18 @@
if (!isset($_GET["fedid"])) {
throw new Exception("Unknown federation context!");
}

$validator->existingFederation($_GET["fedid"]);
if (isset($_GET["device"]) && $_GET["device"] != "") {
$validator->existingDevice($_GET["device"]);
}

// XHR call: language isn't set yet ... so do it
$languageInstance = new \core\common\Language();
$languageInstance->setTextDomain("web_admin");

// add one option of the specified class

$list = web\lib\admin\OptionDisplay::enumerateOptionsToDisplay($_GET["class"], $_GET['fedid']);
$list = web\lib\admin\OptionDisplay::enumerateOptionsToDisplay($_GET["class"], $_GET['fedid'], $_GET["device"]);

$optionDisplay = new \web\lib\admin\OptionDisplay($list);
echo $optionDisplay->optiontext(array_values($list));
6 changes: 4 additions & 2 deletions web/admin/inc/toggleRedirect.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
$validator = new \web\lib\common\InputValidation();
$languageInstance = new \core\common\Language();
$uiElements = new web\lib\admin\UIElements();
$loggerInstance = new \core\common\Logging();

$auth->authenticate();
$languageInstance->setTextDomain("web_admin");
Expand Down Expand Up @@ -100,6 +101,7 @@
$captiontext = sprintf(_("device <strong>%s</strong>"), $device['display']);
$keyword = "device-specific";
$extrainput = "<input type='hidden' name='device' value='" . $device_key . "'/>";
$dev = $device_key;
} elseif ($eaptype !== NULL) {
foreach ($my_profile->getAttributes() as $attrib) {
if (isset($attrib['eapmethod']) && $attrib['eapmethod'] == $eaptype->getArrayRep()) {
Expand All @@ -110,6 +112,7 @@
$captiontext = sprintf(_("EAP-Type <strong>%s</strong>"), $eaptype->getPrintableRep());
$keyword = "eap-specific";
$extrainput = "<input type='hidden' name='eaptype' value='" . $eaptype->getIntegerRep() . "'>";
$dev = '';
} else {
throw new Exception("previous type checks make it impossible to reach this code path.");
}
Expand All @@ -121,7 +124,6 @@
<?php
// see if we already have any attributes; if so, display these
$interesting_attribs = [];

foreach ($attribs as $attrib) {
if ($attrib['level'] == \core\Options::LEVEL_METHOD && preg_match('/^' . $keyword . ':/', $attrib['name'])) {
$interesting_attribs[] = $attrib;
Expand All @@ -131,7 +133,7 @@
echo $optionDisplay->prefilledOptionTable($keyword, $my_inst->federation);
if (\config\Master::DB['INST']['readonly'] === FALSE) {
?>
<button type='button' class='newoption' onclick='getXML("<?php echo $keyword;?>", "<?php echo $my_inst->federation;?>")'><?php echo _("Add new option"); ?></button>
<button type='button' class='newoption' onclick='getXML("<?php echo $keyword;?>", "<?php echo $my_inst->federation;?>", "<?php echo $dev;?>")'><?php echo _("Add new option"); ?></button>
<br/>
<hr/>
<button type='submit' name='submitbutton' id='submitbutton' value='<?php echo web\lib\common\FormElements::BUTTON_SAVE; ?>'><?php echo _("Save data"); ?></button>
Expand Down
5 changes: 3 additions & 2 deletions web/admin/js/option_expand.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@

/* General function for doing HTTP XML GET requests. */

function getXML(attribute_class, fedid) {
function getXML(attribute_class, fedid, device) {
console.log("Device="+device);
var client = new XMLHttpRequest();
client.attribute_class = attribute_class;
client.onreadystatechange = addOption;
client.open("GET", "inc/option_xhr.inc.php?class=" + attribute_class + "&fedid="+ fedid + "&etype=XML");
client.open("GET", "inc/option_xhr.inc.php?class=" + attribute_class + "&fedid="+ fedid + "&etype=XML&device="+device);
client.send();
}

Expand Down
24 changes: 20 additions & 4 deletions web/lib/admin/OptionDisplay.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,15 @@ private function addOptionEdit(string $class, array $prepopulate = [])
// we expect the variable $class to contain the class of options
$retval = "";
$optioninfo = \core\Options::instance();
$loggerInstance = new \core\common\Logging();

$blackListOnPrefill = "user:fedadmin|managedsp:vlan|managedsp:operatorname";
if (\config\Master::FUNCTIONALITY_LOCATIONS['CONFASSISTANT_SILVERBULLET'] == "LOCAL" && \config\Master::FUNCTIONALITY_LOCATIONS['CONFASSISTANT_RADIUS'] != "LOCAL") {
$blackListOnPrefill .= "|fed:silverbullet";
}
foreach ($prepopulate as $option) {
if (preg_match("/^$class:/", $option['name']) && !preg_match("/($blackListOnPrefill)/", $option['name'])) {
$optiontypearray = $optioninfo->optionType($option['name']);
$loggerInstance = new \core\common\Logging();
$loggerInstance->debug(5, "About to execute optiontext with PREFILL!\n");
$retval .= $this->optiontext([$option['name']], ($optiontypearray["type"] == "file" ? 'ROWID-' . $option['level'] . '-' . $option['row_id'] : $option['value']), $option['lang']);
}
Expand All @@ -169,12 +170,11 @@ private function addOptionEdit(string $class, array $prepopulate = [])
* @param string $fed the federation TLD, to determine fed ops preference context
* @return array the list of options to display
*/
public static function enumerateOptionsToDisplay($class, $fed)
public static function enumerateOptionsToDisplay($class, $fed, $device='')
{
$optioninfo = \core\Options::instance();

$loggerInstance = new \core\common\Logging();
$list = $optioninfo->availableOptions($class);

// use federation context to delete more options, if the feds don't like
// a particular one
$fedInstance = new \core\Federation($fed);
Expand Down Expand Up @@ -203,6 +203,22 @@ public static function enumerateOptionsToDisplay($class, $fed)
unset($list[array_search("media:openroaming", $list)]);
}
break;
case "device-specific":
if ($device != '') {
$factory = new \core\DeviceFactory($device);
$dev = $factory->device;
foreach ($list as $l) {
$optFlag = $optioninfo->optionType($l)['flag'];
if ($optFlag == "SPECIFIC") {
$opt = str_replace('device-specific:', '', $l);
if (!isset($dev->options['device_options']) || !in_array($opt, $dev->options['device_options'])) {
$loggerInstance->debug(5, $l, "removing option: ", "\n");
unset($list[array_search($l, $list)]);
}
}
}
}
break;
default:
break;
}
Expand Down

0 comments on commit 0349ba0

Please sign in to comment.