Skip to content

Commit

Permalink
New option to set Wi-Fi network password
Browse files Browse the repository at this point in the history
  • Loading branch information
martignoni committed Sep 18, 2016
1 parent 6bf0137 commit ee39d6e
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ The code is available at [https://github.com/martignoni/moodlebox](https://githu

### Release notes

* 2016-09-18, version 1.4: new option enabling to change the MoodleBox Wi-Fi network password
* 2016-09-10, version 1.3: new option enabling to change the MoodleBox password
* 2016-08-09, version 1.2: changed to admin tool plugin (from local plugin)
* 2016-08-06, version 1.1: added display of free space on SD card
Expand All @@ -27,6 +28,7 @@ The MoodleBox plugin must be installed in the Moodle tree of the MoodleBox, in t
* Info about the MoodleBox (kernel version, Raspbian version, free space on SD card, CPU load, CPU temperature, CPU frequency, uptime, DHCP clients).
* GUI to set the MoodleBox date and time.
* GUI to set the MoodleBox password.
* GUI to set the MoodleBox Wi-Fi network password.
* GUI to restart and shutdown the MoodleBox.

## License
Expand Down
34 changes: 34 additions & 0 deletions bin/setwifipassword.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash
# This script is part of MoodleBox plugin for moodlebox
# Copyright (C) 2016 onwards Nicolas Martignoni
#
# This script is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This script is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this script. If not, see <http://www.gnu.org/licenses/>.
#
# This script MUST be run as root
[[ $EUID -ne 0 ]] && { echo "This script must be run as root"; exit 1; }
#
# Configuration
# get directory of this script
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# path of file containing the new password (plain text)
FILE=${DIR%/*}/.wifipassword
# newpassword
NEWPASSWORD="$(head -n 1 $FILE | sed 's/ *$//g' | sed 's/^ *//g')"
#
# Script
# set new password
sed -i "/wpa_passphrase/c\wpa_passphrase=$NEWPASSWORD" /etc/hostapd/hostapd.conf
# reload hostapd service
service hostapd reload
# the end
40 changes: 40 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@
$sdcardfreespace = disk_free_space('/');
$moodleboxversion = $plugin->release . ' (' . $plugin->version . ')';
$currentwifipassword = exec('grep "wpa_passphrase" /etc/hostapd/hostapd.conf | cut -d= -f2');
if ( $currentwifipassword === '' ) {
$currentwifipassword = get_string('nopassworddefined', 'tool_moodlebox');
}

class datetimeset_form extends moodleform {
function definition() {
Expand Down Expand Up @@ -122,6 +125,26 @@ function validation($data, $files) {
}
}

class wifipassword_form extends moodleform {

function definition() {
global $currentwifipassword;
$mform = $this->_form;

$mform->addElement('static', 'currentwifipassword', get_string('currentwifipassword', 'tool_moodlebox'), $currentwifipassword);
$mform->addElement('text', 'wifipassword', get_string('newwifipassword', 'tool_moodlebox'));
$mform->addRule('wifipassword', get_string('wifipassworderror', 'tool_moodlebox'), 'rangelength', array(8, 63), 'client');
$mform->setType('wifipassword', PARAM_RAW);
if ( $currentwifipassword === get_string('nopassworddefined', 'tool_moodlebox') ) {
$currentwifipassword = '';
}
$mform->setDefault('wifipassword', $currentwifipassword);

$this->add_action_buttons(false, get_string('changewifipassword', 'tool_moodlebox'));
}

}

class restartshutdown_form extends moodleform {
function definition() {
$mform = $this->_form;
Expand Down Expand Up @@ -205,6 +228,23 @@ function definition() {

echo $OUTPUT->box_end();

// Wi-Fi password section
echo $OUTPUT->heading(get_string('wifipasswordsetting', 'tool_moodlebox'));
echo $OUTPUT->box_start('generalbox');

$wifipasswordform = new wifipassword_form();
$wifipasswordform->display();

if ($data = $wifipasswordform->get_data()) {
if (!empty($data->submitbutton)) {
// print_r($data);
file_put_contents(".wifipassword", $data->wifipassword);
\core\notification::warning(get_string('wifipasswordmessage', 'tool_moodlebox'));
}
}

echo $OUTPUT->box_end();

// Restart-shutdown section
echo $OUTPUT->heading(get_string('restartstop', 'tool_moodlebox'));
echo $OUTPUT->box_start('generalbox');
Expand Down
6 changes: 6 additions & 0 deletions lang/en/tool_moodlebox.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
$string['changepassworderror'] = 'The MoodleBox password was not changed. The passwords given don\'t match.';
$string['changepasswordmessage'] = 'The main password of the MoodleBox (Unix account) was changed.<br /><br />Warning! The password of the Admin user of the Moodle <b>was not changed</b>. To change it, please use the preferences page of this user.';
$string['changepasswordsetting'] = 'MoodleBox password change';
$string['changewifipassword'] = 'Change Wi-Fi password';
$string['cpufrequency'] = 'CPU frequency';
$string['cpuload'] = 'CPU load';
$string['cputemperature'] = 'CPU temperature';
Expand All @@ -40,6 +41,8 @@
$string['information'] = 'Information';
$string['kernelversion'] = 'Kernel version';
$string['moodleboxpluginversion'] = 'MoodleBox plugin version';
$string['newwifipassword'] = 'New Wi-Fi password';
$string['nopassworddefined'] = 'No Wi-Fi password defined';
$string['parameter'] = 'Parameter';
$string['pluginname'] = 'MoodleBox';
$string['raspberryhardware'] = 'Raspberry Pi model';
Expand All @@ -56,3 +59,6 @@
$string['systeminfo'] = 'System information';
$string['unsupportedhardware'] = 'Unsupported server hardware detected ! This plugin does only work on Raspberry Pi';
$string['uptime'] = 'System uptime';
$string['wifipassworderror'] = 'The Wi-Fi network password must have between 8 and 63 characters, or be empty.';
$string['wifipasswordmessage'] = 'The Wi-Fi network password was changed. Don\'t forget to communicate it to your students.';
$string['wifipasswordsetting'] = 'Wi-Fi network password change';
6 changes: 6 additions & 0 deletions lang/fr/tool_moodlebox.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
$string['changepassworderror'] = 'Le mot de passe de la MoodleBox n\'a pas été modifié. Les mots de passe donnés ne concordent pas.';
$string['changepasswordmessage'] = 'Le mot de passe principal de la Moodlebox (compte Unix), de la base de données et de phpMyAdmin ont été modifiés.<br /><br />Attention ! Le mot de passe de l\'utilisateur Admin du Moodle <b>n\'a pas été modifié</b>. Pour le modifier, veuillez passer par la page des préférences de cet utilisateur.';
$string['changepasswordsetting'] = 'Changement du mot de passe de la MoodleBox';
$string['changewifipassword'] = 'Changer le mot de passe Wi-Fi';
$string['cpufrequency'] = 'Fréquence du processeur';
$string['cpuload'] = 'Charge du processeur';
$string['cputemperature'] = 'Température du processeur';
Expand All @@ -40,6 +41,8 @@
$string['information'] = 'Information';
$string['kernelversion'] = 'Version du noyau';
$string['moodleboxpluginversion'] = 'Version du plugin MoodleBox';
$string['newwifipassword'] = 'Nouveau mot de passe Wi-Fi';
$string['nopassworddefined'] = 'Pas de mot de passe Wi-Fi défini';
$string['parameter'] = 'Paramètre';
$string['pluginname'] = 'MoodleBox';
$string['raspberryhardware'] = 'Modèle Raspberry Pi';
Expand All @@ -56,3 +59,6 @@
$string['systeminfo'] = 'Informations système';
$string['unsupportedhardware'] = 'Matériel serveur non compatible détecté ! Ce plugin ne fonctionne que sur Raspberry Pi';
$string['uptime'] = 'Durée de fonctionnement du système';
$string['wifipassworderror'] = 'Le mot de passe du réseau Wi-Fi doit comporter entre 8 et 63 caratères, ou alors être vide.';
$string['wifipasswordmessage'] = 'Le mot de passe du réseau Wi-Fi a été modifié. N\'oubliez pas de le communiquer à vos étudiants.';
$string['wifipasswordsetting'] = 'Changement du mot de passe du réseau Wi-Fi';
4 changes: 2 additions & 2 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@

defined('MOODLE_INTERNAL') || die;

$plugin->version = 2016091000;
$plugin->release = '1.3';
$plugin->version = 2016181000;
$plugin->release = '1.4';
$plugin->requires = 2015051103;
$plugin->maturity = MATURITY_STABLE;
$plugin->component = 'tool_moodlebox';

0 comments on commit ee39d6e

Please sign in to comment.