From ee39d6ee361dec5d4ef084c0b79c3b638d041206 Mon Sep 17 00:00:00 2001 From: Nicolas Martignoni Date: Sun, 18 Sep 2016 18:11:33 +0200 Subject: [PATCH] New option to set Wi-Fi network password --- README.md | 2 ++ bin/setwifipassword.sh | 34 ++++++++++++++++++++++++++++++++ index.php | 40 ++++++++++++++++++++++++++++++++++++++ lang/en/tool_moodlebox.php | 6 ++++++ lang/fr/tool_moodlebox.php | 6 ++++++ version.php | 4 ++-- 6 files changed, 90 insertions(+), 2 deletions(-) create mode 100644 bin/setwifipassword.sh diff --git a/README.md b/README.md index 656577a..eab3857 100755 --- a/README.md +++ b/README.md @@ -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 @@ -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 diff --git a/bin/setwifipassword.sh b/bin/setwifipassword.sh new file mode 100644 index 0000000..1bb63e7 --- /dev/null +++ b/bin/setwifipassword.sh @@ -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 . +# +# 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 \ No newline at end of file diff --git a/index.php b/index.php index 1398078..22139b6 100644 --- a/index.php +++ b/index.php @@ -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() { @@ -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; @@ -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'); diff --git a/lang/en/tool_moodlebox.php b/lang/en/tool_moodlebox.php index c344f1c..f9850d3 100644 --- a/lang/en/tool_moodlebox.php +++ b/lang/en/tool_moodlebox.php @@ -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.

Warning! The password of the Admin user of the Moodle was not changed. 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'; @@ -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'; @@ -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'; \ No newline at end of file diff --git a/lang/fr/tool_moodlebox.php b/lang/fr/tool_moodlebox.php index b65b5ad..27f737b 100644 --- a/lang/fr/tool_moodlebox.php +++ b/lang/fr/tool_moodlebox.php @@ -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.

Attention ! Le mot de passe de l\'utilisateur Admin du Moodle n\'a pas été modifié. 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'; @@ -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'; @@ -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'; \ No newline at end of file diff --git a/version.php b/version.php index 5fb6d4e..6829776 100755 --- a/version.php +++ b/version.php @@ -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';