1
0
mirror of https://github.com/billz/raspap-webgui.git synced 2023-10-10 13:37:24 +02:00

Merge branch 'master' into i18n

This commit is contained in:
Bill Zimmerman 2017-11-02 23:41:33 +01:00 committed by GitHub
commit ef9dcbe06c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 135 additions and 3 deletions

View File

@ -1,6 +1,6 @@
![](http://i.imgur.com/xeKD93p.png) ![](http://i.imgur.com/xeKD93p.png)
# `$ raspap-webgui` [![Release 1.2.1](https://img.shields.io/badge/Release-1.2.1-green.svg)](https://github.com/billz/raspap-webgui/releases) # `$ raspap-webgui` [![Release 1.2.1](https://img.shields.io/badge/Release-1.2.1-green.svg)](https://github.com/billz/raspap-webgui/releases)
A simple, responsive web interface t:o control wifi, hostapd and related services on the Raspberry Pi. 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. 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.

5
dist/css/custom.css vendored
View File

@ -48,3 +48,8 @@
height:100%; height:100%;
min-height:500px; min-height:500px;
} }
.logoutput {
width:100%;
height:300px;
}

View File

@ -76,3 +76,8 @@ h4 {
width: 140px; width: 140px;
float: left; float: left;
} }
.logoutput {
width: 100%;
height: 300px;
}

View File

@ -196,4 +196,9 @@ a:focus, a:hover {
float: left; float: left;
} }
.logoutput {
width: 100%;
height: 300px;
background-color: #000;
border-color: #33ff00;
}

View File

@ -1,4 +1,52 @@
<?php <?php
/* Functions for Networking */
function mask2cidr($mask){
$long = ip2long($mask);
$base = ip2long('255.255.255.255');
return 32-log(($long ^ $base)+1,2);
}
/* Functions to write ini files */
function write_php_ini($array, $file) {
$res = array();
foreach($array as $key => $val) {
if(is_array($val)) {
$res[] = "[$key]";
foreach($val as $skey => $sval) $res[] = "$skey = ".(is_numeric($sval) ? $sval : '"'.$sval.'"');
}
else $res[] = "$key = ".(is_numeric($val) ? $val : '"'.$val.'"');
}
if(safefilerewrite($file, implode("\r\n", $res))) {
return true;
} else {
return false;
}
}
function safefilerewrite($fileName, $dataToSave) {
if ($fp = fopen($fileName, 'w')) {
$startTime = microtime(TRUE);
do {
$canWrite = flock($fp, LOCK_EX);
// If lock not obtained sleep for 0 - 100 milliseconds, to avoid collision and CPU load
if(!$canWrite) usleep(round(rand(0, 100)*1000));
} while ((!$canWrite)and((microtime(TRUE)-$startTime) < 5));
//file was locked so now we can store information
if ($canWrite) {
fwrite($fp, $dataToSave);
flock($fp, LOCK_UN);
}
fclose($fp);
return true;
} else {
return false;
}
}
/** /**
* *

View File

@ -10,6 +10,8 @@ function DisplayHostAPDConfig(){
$status = new StatusMessages(); $status = new StatusMessages();
$arrHostapdConf = parse_ini_file('/etc/raspap/hostapd.ini');
$arrConfig = array(); $arrConfig = array();
$arrChannel = array('a','b','g'); $arrChannel = array('a','b','g');
$arrSecurity = array( 1 => 'WPA', 2 => 'WPA2',3=> 'WPA+WPA2'); $arrSecurity = array( 1 => 'WPA', 2 => 'WPA2',3=> 'WPA+WPA2');
@ -74,6 +76,7 @@ function DisplayHostAPDConfig(){
<li class="active"><a href="#basic" data-toggle="tab"><?php echo _("Basic"); ?></a></li> <li class="active"><a href="#basic" data-toggle="tab"><?php echo _("Basic"); ?></a></li>
<li><a href="#security" data-toggle="tab"><?php echo _("Security"); ?></a></li> <li><a href="#security" data-toggle="tab"><?php echo _("Security"); ?></a></li>
<li><a href="#advanced" data-toggle="tab"><?php echo _("Advanced"); ?></a></li> <li><a href="#advanced" data-toggle="tab"><?php echo _("Advanced"); ?></a></li>
<li><a href="#logoutput" data-toggle="tab"><?php echo _("Logfile Output"); ?></a></li>
</ul> </ul>
<!-- Tab panes --> <!-- Tab panes -->
@ -130,8 +133,33 @@ function DisplayHostAPDConfig(){
</div> </div>
</div> </div>
</div> </div>
<div class="tab-pane fade" id="logoutput">
<h4>Logfile output</h4>
<div class="row">
<div class="form-group col-md-8">
<?php
if($arrHostapdConf['LogEnable'] == 1) {
$log = file_get_contents('/tmp/hostapd.log');
echo '<br /><textarea class="logoutput">'.$log.'</textarea>';
} else {
echo "<br />Logfile output not enabled";
}
?>
</div>
</div>
</div>
<div class="tab-pane fade" id="advanced"> <div class="tab-pane fade" id="advanced">
<h4><?php echo _("Advanced settings"); ?></h4> <h4><?php echo _("Advanced settings"); ?></h4>
<div class="row">
<div class="col-md-4">
<div class="form-check">
<label class="form-check-label">
Enable Logging <?php $checked = ''; if($arrHostapdConf['LogEnable'] == 1) { $checked = 'checked'; } ?>
<input id="logEnable" name ="logEnable" type="checkbox" class="form-check-input" value="1" <?php echo $checked; ?> />
</label>
</div>
</div>
</div>
<div class="row"> <div class="row">
<div class="form-group col-md-4"> <div class="form-group col-md-4">
<label for="code"><?php echo _("Country Code"); ?></label> <label for="code"><?php echo _("Country Code"); ?></label>
@ -431,6 +459,26 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $status)
$good_input = true; $good_input = true;
// Check for Logging Checkbox
$logEnable = 0;
if($arrHostapdConf['LogEnable'] == 0) {
if(isset($_POST['logEnable'])) {
// Need code to enable logfile logging here
$logEnable = 1;
exec('sudo /etc/raspap/hostapd/enablelog.sh');
} else {
exec('sudo /etc/raspap/hostapd/disablelog.sh');
}
} else {
if(isset($_POST['logEnable'])) {
$logEnable = 1;
exec('sudo /etc/raspap/hostapd/enablelog.sh');
} else {
exec('sudo /etc/raspap/hostapd/disablelog.sh');
}
}
write_php_ini(["LogEnable" => $logEnable],'/etc/raspap/hostapd.ini');
// Verify input // Verify input
if (strlen($_POST['ssid']) == 0 || strlen($_POST['ssid']) > 32) { if (strlen($_POST['ssid']) == 0 || strlen($_POST['ssid']) > 32) {
// Not sure of all the restrictions of SSID // Not sure of all the restrictions of SSID

View File

@ -73,7 +73,14 @@ function enable_php_lighttpd() {
install_log "Enabling PHP for lighttpd" install_log "Enabling PHP for lighttpd"
sudo lighty-enable-mod fastcgi-php sudo lighty-enable-mod fastcgi-php
if [ $? -eq 2 ]; then echo already enabled; else install_error "Cannot enable fastcgi-php for lighttpd"; fi ERR=$?
if [ $ERR -eq 2 ]
then
echo ' [already enabled]'
elif [ $ERR -ne 0 ]
then
install_error "Cannot enable fastcgi-php for lighttpd"
fi
sudo /etc/init.d/lighttpd restart || install_error "Unable to restart lighttpd" sudo /etc/init.d/lighttpd restart || install_error "Unable to restart lighttpd"
} }
@ -90,6 +97,12 @@ function create_raspap_directories() {
sudo chown -R $raspap_user:$raspap_user "$raspap_dir" || install_error "Unable to change file ownership for '$raspap_dir'" sudo chown -R $raspap_user:$raspap_user "$raspap_dir" || install_error "Unable to change file ownership for '$raspap_dir'"
} }
# Generate logging enable/disable files for hostapd
function create_logging_scripts() {
sudo mkdir /etc/raspap/hostapd
sudo mv /var/www/html/installers/*log.sh /etc/rasp/hostapd
}
# Fetches latest files from github to webroot # Fetches latest files from github to webroot
function download_latest_files() { function download_latest_files() {
if [ -d "$webroot_dir" ]; then if [ -d "$webroot_dir" ]; then
@ -207,6 +220,8 @@ function patch_system_files() {
'/sbin/ip link set wlan0 down' '/sbin/ip link set wlan0 down'
'/sbin/ip link set wlan0 up' '/sbin/ip link set wlan0 up'
'/sbin/ip -s a f label wlan0' '/sbin/ip -s a f label wlan0'
'/etc/raspap/hostapd/enablelog.sh'
'/etc/raspap/hostapd/disablelog.sh'
) )
# Check if sudoers needs patchin # Check if sudoers needs patchin
@ -243,6 +258,7 @@ function install_raspap() {
install_dependencies install_dependencies
enable_php_lighttpd enable_php_lighttpd
create_raspap_directories create_raspap_directories
create_logging_scripts
check_for_old_configs check_for_old_configs
download_latest_files download_latest_files
change_file_ownership change_file_ownership

3
installers/disablelog.sh Executable file
View File

@ -0,0 +1,3 @@
#!/bin/bash
/bin/sed -i 's|DAEMON_OPTS=" -f /tmp/hostapd.log"|#DAEMON_OPTS=""|' /etc/default/hostapd

2
installers/enablelog.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/bash
/bin/sed -i 's|#DAEMON_OPTS=""|DAEMON_OPTS=" -f /tmp/hostapd.log"|' /etc/default/hostapd