Skip to content

Commit

Permalink
Implement SSID hiding option
Browse files Browse the repository at this point in the history
- Display of current hiding setting implemented.
- Moodle form updated.
- See issue #56.
  • Loading branch information
martignoni committed Nov 11, 2018
1 parent 2460a1d commit b0e459e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
8 changes: 8 additions & 0 deletions forms.php
Expand Up @@ -118,6 +118,7 @@ class wifisettings_form extends moodleform {
*/
public function definition() {
global $currentwifissid;
global $currentwifissidhiddenstate;
global $currentwifichannel;
global $currentwifipassword;
global $currentwificountry;
Expand All @@ -131,6 +132,13 @@ public function definition() {
$mform->setDefault('wifissid', $currentwifissid);
$mform->addHelpButton('wifissid', 'wifissid', 'tool_moodlebox');

// SSID hiding setting.
$mform->addElement('checkbox', 'wifissidhiddenstate', get_string('wifissidhiddenstate', 'tool_moodlebox'),
' ' . get_string('wifissidhidden', 'tool_moodlebox'));
$mform->setDefault('wifissidhiddenstate', ($currentwifissidhiddenstate == 0) ? 0 : 1);
$mform->setType('wifissidhiddenstate', PARAM_INT);
$mform->addHelpButton('wifissidhiddenstate', 'wifissidhiddenstate', 'tool_moodlebox');

// Channel setting.
if ($currentwificountry == 'US' or $currentwificountry == 'CA') {
$wifichannelrange = range(1, 11);
Expand Down
15 changes: 15 additions & 0 deletions index.php
Expand Up @@ -137,6 +137,14 @@
}
$currentwifipassword = array_key_exists('wpa_passphrase', $wifiinfo) ? $wifiinfo['wpa_passphrase'] : null;
$currentwificountry = $wifiinfo['country_code'];
$currentwifissidhiddenstate = array_key_exists('ignore_broadcast_ssid', $wifiinfo) ? $wifiinfo['ignore_broadcast_ssid'] : '0';
if ( $currentwifissidhiddenstate === '0') {
// SSID is visible.
$currentwifissidhiddenstate = 0;
} else {
// SSID is hidden.
$currentwifissidhiddenstate = 1;
}

// System information section.
print_collapsible_region_start('systeminfo', 'systeminfo',
Expand All @@ -162,6 +170,9 @@
$table->add_data(array(get_string('uptime', 'tool_moodlebox'), $uptime));
$table->add_data(array(get_string('wifisettings', 'tool_moodlebox'), ''));
$table->add_data(array(get_string('wifissid', 'tool_moodlebox'), $currentwifissid), 'subinfo');
$table->add_data(array(get_string('wifissidhiddenstate', 'tool_moodlebox'),
($currentwifissidhiddenstate == 0) ?
get_string('visible', 'tool_moodlebox') : get_string('hidden', 'tool_moodlebox')), 'subinfo');
$table->add_data(array(get_string('wifichannel', 'tool_moodlebox'), $currentwifichannel), 'subinfo');
$table->add_data(array(get_string('wificountry', 'tool_moodlebox'), $currentwificountry), 'subinfo');
$table->add_data(array(get_string('wifipassword', 'tool_moodlebox'), $currentwifipassword), 'subinfo');
Expand Down Expand Up @@ -256,13 +267,17 @@
if (!isset($data->wifipassword)) {
$data->wifipassword = null;
}
if (!isset($data->wifissidhiddenstate)) {
$data->wifissidhiddenstate = 0;
}
// Convert $data->wifissid to hex. See https://stackoverflow.com/a/46344675.
$data->wifissid = implode(unpack("H*", $data->wifissid));
file_put_contents($wifisettingstriggerfilename,
"channel=" . $data->wifichannel . "\n" .
"country=" . $data->wificountry . "\n" .
"password=" . $data->wifipassword . "\n" .
"ssid=" . $data->wifissid . "\n" .
"ssidhiddenstate=" . $data->wifissidhiddenstate . "\n" .
"passwordprotected=" . $data->wifipasswordon . "\n");
\core\notification::warning(get_string('wifisettingsmessage', 'tool_moodlebox'));
}
Expand Down

0 comments on commit b0e459e

Please sign in to comment.