1
0
mirror of https://github.com/billz/raspap-webgui.git synced 2023-10-10 13:37:24 +02:00
This commit is contained in:
Bill Zimmerman 2018-10-14 11:25:23 +02:00
commit 3a7de3d734
5 changed files with 155 additions and 66 deletions

View File

@ -1,3 +1,6 @@
### Before submitting an issue
The [FAQs](https://github.com/billz/raspap-webgui/wiki/FAQs) have answers to many common issues. Please check this before creating a new issue.
### Subject of the issue
Describe your issue here.

View File

@ -1,5 +1,6 @@
![](http://i.imgur.com/xeKD93p.png)
# `$ raspap-webgui` [![Release 1.3.1](https://img.shields.io/badge/Release-1.3.1-green.svg)](https://github.com/billz/raspap-webgui/releases) [![Awesome](https://awesome.re/badge.svg)](https://github.com/thibmaek/awesome-raspberry-pi)
# `$ raspap-webgui` [![Release 1.3.1](https://img.shields.io/badge/Release-1.3.1-green.svg)](https://github.com/billz/raspap-webgui/releases) [![Awesome](https://awesome.re/badge.svg)](https://github.com/thibmaek/awesome-raspberry-pi) [![Beerpay](https://img.shields.io/beerpay/hashdog/scrapfy-chrome-extension.svg)](https://beerpay.io/billz/raspap-webgui)
A simple, responsive web interface to control wifi, hostapd and related services on the Raspberry Pi.
This project was inspired by a [**blog post**](http://sirlagz.net/2013/02/06/script-web-configuration-page-for-raspberry-pi/) by SirLagz about using a web page rather than ssh to configure wifi and hostapd settings on the Raspberry Pi. I mostly just prettified the UI by wrapping it in [**SB Admin 2**](https://github.com/BlackrockDigital/startbootstrap-sb-admin-2), a Bootstrap based admin theme. Since then, the project has evolved to include greater control over many aspects of a networked RPi, better security, authentication, a Quick Installer, support for themes and more. RaspAP has been featured on sites such as [Instructables](http://www.instructables.com/id/Raspberry-Pi-As-Completely-Wireless-Router/), [Adafruit](https://blog.adafruit.com/2016/06/24/raspap-wifi-configuration-portal-piday-raspberrypi-raspberry_pi/), [Raspberry Pi Weekly](https://www.raspberrypi.org/weekly/commander/) and [Awesome Raspberry Pi](https://project-awesome.org/thibmaek/awesome-raspberry-pi) and implemented in countless projects.

View File

@ -29,7 +29,7 @@ function DisplayDHCPConfig() {
$errors .= _('Invalid DHCP range end.').'<br />'.PHP_EOL;
}
if (!ctype_digit($_POST['RangeLeaseTime'])) {
if (!ctype_digit($_POST['RangeLeaseTime']) && $_POST['RangeLeaseTimeUnits'] !== 'infinite') {
$errors .= _('Invalid DHCP lease time, not a number.').'<br />'.PHP_EOL;
}
@ -41,7 +41,12 @@ function DisplayDHCPConfig() {
if (empty($errors)) {
$config = 'interface='.$_POST['interface'].PHP_EOL.
'dhcp-range='.$_POST['RangeStart'].','.$_POST['RangeEnd'].
',255.255.255.0,'.$_POST['RangeLeaseTime'].$_POST['RangeLeaseTimeUnits'];
',255.255.255.0,';
if ($_POST['RangeLeaseTimeUnits'] !== 'infinite') {
$config .= $_POST['RangeLeaseTime'];
}
$config .= $_POST['RangeLeaseTimeUnits'];
exec('echo "'.$config.'" > /tmp/dhcpddata', $temp);
system('sudo cp /tmp/dhcpddata '.RASPI_DNSMASQ_CONFIG, $return);
} else {
@ -107,25 +112,30 @@ function DisplayDHCPConfig() {
$RangeStart = $arrRange[0];
$RangeEnd = $arrRange[1];
$RangeMask = $arrRange[2];
preg_match( '/([0-9]*)([a-z])/i', $arrRange[3], $arrRangeLeaseTime );
$leaseTime = $arrRange[3];
$hselected = '';
$mselected = '';
$dselected = '';
switch( $arrRangeLeaseTime[2] ) {
case 'h':
$hselected = ' selected="selected"';
break;
case 'm':
$mselected = ' selected="selected"';
break;
case 'd':
$dselected = ' selected="selected"';
break;
$infiniteselected = '';
preg_match( '/([0-9]*)([a-z])/i', $leaseTime, $arrRangeLeaseTime );
if ($leaseTime === 'infinite') {
$infiniteselected = ' selected="selected"';
} else {
switch( $arrRangeLeaseTime[2] ) {
case 'h':
$hselected = ' selected="selected"';
break;
case 'm':
$mselected = ' selected="selected"';
break;
case 'd':
$dselected = ' selected="selected"';
break;
}
}
?>
?>
<div class="row">
<div class="col-lg-12">
<div class="panel panel-primary">
@ -156,7 +166,7 @@ function DisplayDHCPConfig() {
foreach( $interfaces as $inet ) {
$select = '';
if( $inet === $conf['interface'] ) {
$select = ' selected="selected"'; // FIXED use xhtml valid attribute
$select = ' selected="selected"';
}
echo ' <option value="'.htmlspecialchars($inet, ENT_QUOTES).'"'.
@ -188,10 +198,10 @@ function DisplayDHCPConfig() {
<div class="col-xs-2 col-sm-2">
<label for="code"><?php echo _("Interval"); ?></label>
<select name="RangeLeaseTimeUnits" class="form-control" >
<option value="m" <?php echo $mselected; ?>>Minute(s)</option>
<option value="h" <?php echo $hselected; ?>>Hour(s)</option>
<option value="d" <?php echo $dselected; ?>>Day(s)</option>
<option value="infinite">Infinite</option>
<option value="m"<?php echo $mselected; ?>><?php echo _("Minute(s)"); ?></option>
<option value="h"<?php echo $hselected; ?>><?php echo _("Hour(s)"); ?></option>
<option value="d"<?php echo $dselected; ?>><?php echo _("Day(s)"); ?></option>
<option value="infinite"<?php echo $infiniteselected; ?>><?php echo _("Infinite"); ?></option>
</select>
</div>
</div>

View File

@ -89,8 +89,13 @@ function isAssoc($arr) {
* If $options is an associative array this should be the key
*
*/
function SelectorOptions($name, $options, $selected = null) {
echo '<select class="form-control" name="'.htmlspecialchars($name, ENT_QUOTES).'">' , PHP_EOL;
function SelectorOptions($name, $options, $selected = null, $id = null) {
echo '<select class="form-control" name="'.htmlspecialchars($name, ENT_QUOTES).'"';
if (isset($id)) {
echo ' id="' . htmlspecialchars($id, ENT_QUOTES) .'"';
}
echo '>' , PHP_EOL;
foreach ( $options as $opt => $label) {
$select = '';
$key = isAssoc($options) ? $opt : $label;

View File

@ -6,22 +6,21 @@ include_once( 'includes/status_messages.php' );
*
*
*/
function DisplayHostAPDConfig(){
function DisplayHostAPDConfig()
{
$status = new StatusMessages();
$arrHostapdConf = parse_ini_file('/etc/raspap/hostapd.ini');
$arrConfig = array();
$arrChannel = array('a','b','g');
$arrSecurity = array( 1 => 'WPA', 2 => 'WPA2',3=> 'WPA+WPA2');
$arr80211Standard = array('a','b','g','n');
$arrSecurity = array(1 => 'WPA', 2 => 'WPA2', 3 => 'WPA+WPA2', 'none' => _("None"));
$arrEncType = array('TKIP' => 'TKIP', 'CCMP' => 'CCMP', 'TKIP CCMP' => 'TKIP+CCMP');
exec("ip -o link show | awk -F': ' '{print $2}'", $interfaces);
if( isset($_POST['SaveHostAPDSettings']) ) {
if (CSRFValidate()) {
SaveHostAPDConfig($arrSecurity, $arrEncType, $arrChannel, $interfaces, $status);
SaveHostAPDConfig($arrSecurity, $arrEncType, $arr80211Standard, $interfaces, $status);
} else {
error_log('CSRF violation');
}
@ -47,7 +46,7 @@ function DisplayHostAPDConfig(){
}
}
exec( 'cat '. RASPI_HOSTAPD_CONFIG, $return );
exec( 'cat '. RASPI_HOSTAPD_CONFIG, $hostapdconfig );
exec( 'pidof hostapd | wc -l', $hostapdstatus);
if( $hostapdstatus[0] == 0 ) {
@ -56,9 +55,13 @@ function DisplayHostAPDConfig(){
$status->addMessage('HostAPD is running', 'success');
}
foreach( $return as $a ) {
if( $a[0] != "#" ) {
$arrLine = explode( "=",$a) ;
foreach( $hostapdconfig as $hostapdconfigline ) {
if (strlen($hostapdconfigline) === 0) {
continue;
}
if ($hostapdconfigline[0] != "#" ) {
$arrLine = explode("=", $hostapdconfigline) ;
$arrConfig[$arrLine[0]]=$arrLine[1];
}
};
@ -88,28 +91,55 @@ function DisplayHostAPDConfig(){
<?php CSRFToken() ?>
<div class="row">
<div class="form-group col-md-4">
<label for="code"><?php echo _("Interface") ;?></label>
<label for="cbxinterface"><?php echo _("Interface") ;?></label>
<?php
SelectorOptions('interface', $interfaces, $arrConfig['interface']);
SelectorOptions('interface', $interfaces, $arrConfig['interface'], 'cbxinterface');
?>
</div>
</div>
<div class="row">
<div class="form-group col-md-4">
<label for="code"><?php echo _("SSID"); ?></label>
<input type="text" class="form-control" name="ssid" value="<?php echo htmlspecialchars($arrConfig['ssid'], ENT_QUOTES); ?>" />
<label for="txtssid"><?php echo _("SSID"); ?></label>
<input type="text" id="txtssid" class="form-control" name="ssid" value="<?php echo htmlspecialchars($arrConfig['ssid'], ENT_QUOTES); ?>" />
</div>
</div>
<div class="row">
<div class="form-group col-md-4">
<label for="code"><?php echo _("Wireless Mode") ;?></label>
<?php SelectorOptions('hw_mode', $arrChannel, $arrConfig['hw_mode']); ?>
<label for="cbxhwmode"><?php echo _("Wireless Mode") ;?></label>
<?php
$selectedHwMode = $arrConfig['hw_mode'];
if (isset($arrConfig['ieee80211n'])) {
if (strval($arrConfig['ieee80211n']) === '1') {
$selectedHwMode = 'n';
}
}
SelectorOptions('hw_mode', $arr80211Standard, $selectedHwMode, 'cbxhwmode'); ?>
</div>
</div>
<div class="row">
<div class="form-group col-md-4">
<label for="code"><?php echo _("Channel"); ?></label>
<?php SelectorOptions('channel', range(1, 14), intval($arrConfig['channel'])) ?>
<label for="cbxchannel"><?php echo _("Channel"); ?></label>
<?php
$selectablechannels = range(1, 13);
$countries_2_4Ghz_max11ch = array('AG', 'BS', 'BB', 'BZ', 'CR', 'CU', 'DM', 'DO', 'SV', 'GD', 'GT',
'HT', 'HN', 'JM', 'MX', 'NI', 'PA', 'KN', 'LC', 'VC', 'TT',
'US', 'CA', 'UZ', 'CO');
$countries_2_4Ghz_max14ch = array('JA');
if (in_array($arrConfig['country_code'], $countries_max11channels)) {
// In North America till channel 11 is the maximum allowed wi-fi 2.4Ghz channel.
// Except for the US that allows channel 12 & 13 in low power mode with additional restrictions.
// Canada that allows channel 12 in low power mode. Because it's unsure if low powered mode
// can be supported the channels are not selectable for those countries.
// source: https://en.wikipedia.org/wiki/List_of_WLAN_channels#Interference_concerns
// Also Uzbekistan and Colombia allow to select till channel 11 as maximum channel on the 2.4Ghz wi-fi band.
$selectablechannels = range(1, 11);
} elseif (in_array($arrConfig['country_code'], $countries_2_4Ghz_max14ch)) {
if ($arrConfig['hw_mode'] === 'b') {
$selectablechannels = range(1, 14);
}
}
SelectorOptions('channel', $selectablechannels, intval($arrConfig['channel']), 'cbxchannel'); ?>
</div>
</div>
</div>
@ -117,20 +147,20 @@ function DisplayHostAPDConfig(){
<h4><?php echo _("Security settings"); ?></h4>
<div class="row">
<div class="form-group col-md-4">
<label for="code"><?php echo _("Security type"); ?></label>
<?php SelectorOptions('wpa', $arrSecurity, $arrConfig['wpa']); ?>
<label for="cbxwpa"><?php echo _("Security type"); ?></label>
<?php SelectorOptions('wpa', $arrSecurity, $arrConfig['wpa'], 'cbxwpa'); ?>
</div>
</div>
<div class="row">
<div class="form-group col-md-4">
<label for="code"><?php echo _("Encryption Type"); ?></label>
<?php SelectorOptions('wpa_pairwise', $arrEncType, $arrConfig['wpa_pairwise']); ?>
<label for="cbxwpapairwise"><?php echo _("Encryption Type"); ?></label>
<?php SelectorOptions('wpa_pairwise', $arrEncType, $arrConfig['wpa_pairwise'], 'cbxwpapairwise'); ?>
</div>
</div>
<div class="row">
<div class="form-group col-md-4">
<label for="code"><?php echo _("PSK"); ?></label>
<input type="text" class="form-control" name="wpa_passphrase" value="<?php echo htmlspecialchars($arrConfig['wpa_passphrase'], ENT_QUOTES); ?>" />
<label for="txtwpapassphrase"><?php echo _("PSK"); ?></label>
<input type="text" class="form-control" id="txtwpapassphrase" name="wpa_passphrase" value="<?php echo htmlspecialchars($arrConfig['wpa_passphrase'], ENT_QUOTES); ?>" />
</div>
</div>
</div>
@ -153,25 +183,38 @@ function DisplayHostAPDConfig(){
<h4><?php echo _("Advanced settings"); ?></h4>
<div class="row">
<div class="col-md-4">
<div class="form-check">
<label class="form-check-label">
<?php echo _("Enable logging");
$checked = '';
<div class="form-check">
<label class="form-check-label" for="chxlogenable"><?php echo _("Enable logging");
$checkedLogEnabled = '';
if ($arrHostapdConf['LogEnable'] == 1) {
$checked = ' checked="checked"';
$checkedLogEnabled = ' checked="checked"';
}
?>
<input id="logEnable" name ="logEnable" type="checkbox" class="form-check-input" value="1"<?php echo $checked; ?> />
</label>
</label>
<input id="chxlogenable" name="logEnable" type="checkbox" class="form-check-input" value="1"<?php echo $checkedLogEnabled; ?> />
</div>
</div>
</div>
<div class="row">
<div class="col-md-4">
<div class="form-check">
<label class="form-check-label" for="chxhiddenssid"><?php echo _("Hide SSID in broadcast");
$checkedHiddenSSID = '';
if ($arrConfig['ignore_broadcast_ssid'] == 1 || $arrConfig['ignore_broadcast_ssid'] == 2) {
$checkedHiddenSSID = ' checked="checked"';
}
?> </label>
<input id="chxhiddenssid" name="hiddenSSID" type="checkbox" class="form-check-input" value="1"<?php echo $checkedHiddenSSID; ?> />
</div>
</div>
</div>
<div class="row">
<div class="form-group col-md-4">
<label for="code"><?php echo _("Country Code"); ?></label>
<label for="cbxcountries"><?php echo _("Country Code"); ?></label>
<input type="hidden" id="selected_country" value="<?php echo htmlspecialchars($arrConfig['country_code'], ENT_QUOTES); ?>">
<select class="form-control" id="countries" name="country_code">
<select class="form-control" id="cbxcountries" name="country_code">
<option value="AF">Afghanistan</option>
<option value="AX">Åland Islands</option>
<option value="AL">Albania</option>
@ -424,7 +467,7 @@ if ($arrHostapdConf['LogEnable'] == 1) {
</select>
<script type="text/javascript">
var country = document.getElementById("selected_country").value;
var countries = document.getElementById("countries");
var countries = document.getElementById("cbxcountries");
var ops = countries.getElementsByTagName("option");
for (var i = 0; i < ops.length; ++i) {
if(ops[i].value == country){
@ -463,10 +506,13 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $status)
return false;
}
if ((!filter_var($_POST['channel'], FILTER_VALIDATE_INT)) ||
intval($_POST['channel']) < 1 ||
intval($_POST['channel']) > 14) {
error_log("Attempting to set channel to '".$_POST['channel']."'"); // FIXME: log injection
if (!filter_var($_POST['channel'], FILTER_VALIDATE_INT)) {
error_log("Attempting to set channel to invalid number.");
return false;
}
if (intval($_POST['channel']) < 1 || intval($_POST['channel']) > 14) {
error_log("Attempting to set channel to '".$_POST['channel']."'");
return false;
}
@ -500,15 +546,30 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $status)
$good_input = false;
}
if (strlen($_POST['wpa_passphrase']) < 8 || strlen($_POST['wpa_passphrase']) > 63) {
if ($_POST['wpa'] !== 'none' &&
(strlen($_POST['wpa_passphrase']) < 8 || strlen($_POST['wpa_passphrase']) > 63)) {
$status->addMessage('WPA passphrase must be between 8 and 63 characters', 'danger');
$good_input = false;
}
if (isset($_POST['hiddenSSID'])) {
if (!is_int((int)$_POST['hiddenSSID'])) {
$status->addMessage('Parameter hiddenSSID not a number.', 'danger');
$good_input = false;
} elseif ((int)$_POST['hiddenSSID'] < 0 || (int)$_POST['hiddenSSID'] >= 3) {
$status->addMessage('Parameter hiddenSSID contains invalid configuratie value.', 'danger');
$good_input = false;
} else {
$ignore_broadcast_ssid = $_POST['hiddenSSID'];
}
} else {
$ignore_broadcast_ssid = '0';
}
if (! in_array($_POST['interface'], $interfaces)) {
// The user is probably up to something here but it may also be a
// genuine error.
$status->addMessage('Unknown interface '.$_POST['interface'], 'danger');
$status->addMessage('Unknown interface '.htmlspecialchars($_POST['interface'], ENT_QUOTES), 'danger');
$good_input = false;
}
@ -523,19 +584,28 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $status)
fwrite($tmp_file, 'driver=nl80211'.PHP_EOL);
fwrite($tmp_file, 'ctrl_interface='.RASPI_HOSTAPD_CTRL_INTERFACE.PHP_EOL);
fwrite($tmp_file, 'ctrl_interface_group=0'.PHP_EOL);
fwrite($tmp_file, 'beacon_int=100'.PHP_EOL);
fwrite($tmp_file, 'auth_algs=1'.PHP_EOL);
fwrite($tmp_file, 'wpa_key_mgmt=WPA-PSK'.PHP_EOL);
fwrite($tmp_file, 'beacon_int=100'.PHP_EOL);
// TODO: deal with ini file value escaping. E.g. ssid=E=mc2 becomes ssid=E\=mc2
fwrite($tmp_file, 'ssid='.$_POST['ssid'].PHP_EOL);
fwrite($tmp_file, 'channel='.$_POST['channel'].PHP_EOL);
fwrite($tmp_file, 'hw_mode='.$_POST['hw_mode'].PHP_EOL);
if ($_POST['hw_mode'] === 'n') {
fwrite($tmp_file, 'hw_mode=g'.PHP_EOL);
fwrite($tmp_file, 'ieee80211n=1'.PHP_EOL);
// Enable basic Quality of service
fwrite($tmp_file, 'wme_enabled=1'.PHP_EOL);
} else {
fwrite($tmp_file, 'hw_mode='.$_POST['hw_mode'].PHP_EOL);
fwrite($tmp_file, 'ieee80211n=0'.PHP_EOL);
}
fwrite($tmp_file, 'wpa_passphrase='.$_POST['wpa_passphrase'].PHP_EOL);
fwrite($tmp_file, 'interface='.$_POST['interface'].PHP_EOL);
fwrite($tmp_file, 'wpa='.$_POST['wpa'].PHP_EOL);
fwrite($tmp_file, 'wpa_pairwise='.$_POST['wpa_pairwise'].PHP_EOL);
fwrite($tmp_file, 'country_code='.$_POST['country_code'].PHP_EOL);
fwrite($tmp_file, 'ignore_broadcast_ssid='.$ignore_broadcast_ssid.PHP_EOL);
fclose($tmp_file);
system( "sudo cp /tmp/hostapddata " . RASPI_HOSTAPD_CONFIG, $return );