Merge branch 'master' into new-php-pa

This commit is contained in:
Bill Zimmerman 2017-11-16 02:28:59 +01:00 committed by GitHub
commit 6dc944603c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 652 additions and 68 deletions

10
CONTRIBUTING.md Normal file
View File

@ -0,0 +1,10 @@
## How to contribute
1. File an issue in the repository, using the bug tracker, describing the
contribution you'd like to make. This will help us to get you started on the
right foot.
2. Fork the project in your account and create a new branch:
`your-great-feature`.
3. Commit your changes in that branch.
4. Open a pull request, and reference the initial issue in the pull request
message.

View File

@ -1,14 +1,16 @@
![](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)
A simple, responsive web interface t:o control wifi, hostapd and related services on the Raspberry Pi.
# `$ raspap-webgui` [![Release 1.3.0](https://img.shields.io/badge/Release-1.3.0-green.svg)](https://github.com/billz/raspap-webgui/releases)
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. Since then, the project has evolved to include greater control over many aspects of a networked RPi, better security, authentication, support for themes and more.
We'd be curious to hear about how you use this with your own Pi-powered access points. Ping us on Twitter ([**@billzimmerman**](https://twitter.com/billzimmerman), [**@jrmhaig**](https://twitter.com/jrmhaig) and [**@SirLagz**](https://twitter.com/SirLagz)). Until then, here are some screenshots:
![](https://i.imgur.com/l4Vgd5G.png)
![](https://i.imgur.com/mRPtEnC.png)
![](https://i.imgur.com/FFdKoML.png)
![](https://i.imgur.com/0f27nen.png)
![](https://i.imgur.com/jFDMEy6.png)
![](https://i.imgur.com/ck0XS8P.png)
![](https://i.imgur.com/Vaej8Xv.png)
![](https://i.imgur.com/iNuMMip.png)
## Contents
- [Prerequisites](#prerequisites)
@ -78,7 +80,7 @@ www-data ALL=(ALL) NOPASSWD:/sbin/reboot
```
Once those modifications are done, git clone the files to `/var/www/html`.
**Note,** for older versions of Raspbian (before Jessie, May 2016) use
**Note:** for older versions of Raspbian (before Jessie, May 2016) use
`/var/www` instead.
```sh
sudo rm -rf /var/www/html
@ -124,3 +126,4 @@ Please note that these are only UI's for now. If there's enough interest I'll co
## License
See the [LICENSE](./LICENSE) file.

View File

@ -0,0 +1,42 @@
<?php
session_start();
include_once('../../includes/config.php');
include_once('../../includes/functions.php');
if(isset($_POST['generate']) && isset($_POST['csrf_token']) && CSRFValidate()) {
$cnfNetworking = array_diff(scandir(RASPI_CONFIG_NETWORKING, 1),array('..','.'));
$cnfNetworking = array_combine($cnfNetworking,$cnfNetworking);
$strConfFile = "";
foreach($cnfNetworking as $index=>$file) {
if($index != "defaults") {
$cnfFile = parse_ini_file(RASPI_CONFIG_NETWORKING.'/'.$file);
if($cnfFile['static'] === 'true') {
$strConfFile .= "interface ".$cnfFile['interface']."\n";
$strConfFile .= "static ip_address=".$cnfFile['ip_address']."\n";
$strConfFile .= "static routers=".$cnfFile['routers']."\n";
$strConfFile .= "static domain_name_servers=".$cnfFile['domain_name_server']."\n";
} elseif($cnfFile['static'] === 'false' && $cnfFile['failover'] === 'true') {
$strConfFile .= "profile static_".$cnfFile['interface']."\n";
$strConfFile .= "static ip_address=".$cnfFile['ip_address']."\n";
$strConfFile .= "static routers=".$cnfFile['routers']."\n";
$strConfFile .= "static domain_name_servers=".$cnfFile['domain_name_server']."\n\n";
$strConfFile .= "interface ".$cnfFile['interface']."\n";
$strConfFile .= "fallback static_".$cnfFile['interface']."\n\n";
} else {
$strConfFile .= "#DHCP configured for ".$cnfFile['interface']."\n\n";
}
} else {
$strConfFile .= file_get_contents(RASPI_CONFIG_NETWORKING.'/'.$index)."\n\n";
}
}
if(file_put_contents(RASPI_CONFIG_NETWORKING.'/dhcpcd.conf',$strConfFile)) {
exec('sudo /bin/cp /etc/raspap/networking/dhcpcd.conf /etc/dhcpcd.conf');
$output = ['return'=>0,'output'=>'Settings successfully applied'];
} else {
$output = ['return'=>2,'output'=>'Unable to write to apply settings'];
}
echo json_encode($output);
}
?>

View File

@ -0,0 +1,4 @@
<?php
exec("ls /sys/class/net | grep -v lo", $interfaces);
echo json_encode($interfaces);
?>

View File

@ -0,0 +1,24 @@
<?php
session_start();
include_once('../../includes/config.php');
include_once('../../includes/functions.php');
if(isset($_POST['interface']) && isset($_POST['csrf_token']) && CSRFValidate()) {
$int = $_POST['interface'];
if(!file_exists(RASPI_CONFIG_NETWORKING.'/'.$int.'.ini')) {
touch(RASPI_CONFIG_NETWORKING.'/'.$int.'.ini');
}
$intConfig = parse_ini_file(RASPI_CONFIG_NETWORKING.'/'.$int.'.ini');
$jsonData = ['return'=>1,'output'=>['intConfig'=>$intConfig]];
echo json_encode($jsonData);
// Todo - get dhcp lease information from `dhcpcd -U eth0` ? maybe ?
} else {
$jsonData = ['return'=>2,'output'=>['Error getting data']];
echo json_encode($jsonData);
}
?>

View File

@ -0,0 +1,15 @@
<?php
session_start();
include_once('../../includes/functions.php');
if(isset($_POST['interface']) && isset($_POST['csrf_token']) && CSRFValidate()) {
$int = preg_replace('/[^a-z0-9]/','',$_POST['interface']);
exec('ip a s '.$int,$intOutput,$intResult);
$jsonData = ['return'=>$intResult,'output'=>$intOutput];
echo json_encode($jsonData);
} else {
$jsonData = ['return'=>2,'output'=>['Error getting data']];
echo json_encode($jsonData);
}
?>

View File

@ -0,0 +1,31 @@
<?php
session_start();
include_once('../../includes/config.php');
include_once('../../includes/functions.php');
if(isset($_POST['interface']) && isset($_POST['csrf_token']) && CSRFValidate()) {
$int = $_POST['interface'];
$cfg = [];
$file = $int.".ini";
$ip = $_POST[$int.'-ipaddress'];
$netmask = mask2cidr($_POST[$int.'-netmask']);
$dns1 = $_POST[$int.'-dnssvr'];
$dns2 = $_POST[$int.'-dnssvralt'];
$cfg['interface'] = $int;
$cfg['routers'] = $_POST[$int.'-gateway'];
$cfg['ip_address'] = $ip."/".$netmask;
$cfg['domain_name_server'] = $dns1." ".$dns2;
$cfg['static'] = $_POST[$int.'-static'];
$cfg['failover'] = $_POST[$int.'-failover'];
if(write_php_ini($cfg,RASPI_CONFIG_NETWORKING.'/'.$file)) {
$jsonData = ['return'=>0,'output'=>['Successfully Updated Network Configuration']];
} else {
$jsonData = ['return'=>1,'output'=>['Error saving network configuration to file']];
}
} else {
$jsonData = ['return'=>2,'output'=>'Unable to detect interface'];
}
echo json_encode($jsonData);
?>

View File

@ -1,24 +0,0 @@
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
printf "My IP address is %s\n" "$_IP"
fi
# Set up IP forwarding and NAT routing
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -j MASQUERADE
exit 0

6
dist/css/custom.css vendored
View File

@ -37,6 +37,7 @@
.webconsole {
width:100%;
height:100%;
border:1px solid;
}
#console {
@ -47,3 +48,8 @@
height:100%;
min-height:500px;
}
.logoutput {
width:100%;
height:300px;
}

View File

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

65
dist/css/terminal.css vendored
View File

@ -66,7 +66,7 @@ a:focus, a:hover {
border-color: #33ff00;
}
.panel-primary>.panel-heading {
.panel-primary>.panel-heading, .panel-default>.panel-heading {
border-color: #33ff00;
background-color: #33ff00;
color: #000;
@ -81,6 +81,11 @@ a:focus, a:hover {
margin-bottom: 20px;
border: 1px solid #33ff00;
border-radius: 0px;
background-color: #000;
}
hr {
border-top: 1px solid #33ff00;
}
.page-header {
@ -135,6 +140,28 @@ a:focus, a:hover {
color: #33ff00;
}
label.btn.btn-primary {
color: #33ff00;
}
label.btn.btn-primary.active, label.btn.btn-warning.active {
background-color: #33ff00;
border-color: #33ff00;
color: #000;
}
.label-warning {
background-color: #33ff00;
}
span.label.label-warning {
color: #000;
}
.btn.btn-primary {
border-color: #33ff00;
}
.table>tbody>tr>td, .table>tbody>tr>th, .table>tfoot>tr>td, .table>tfoot>tr>th, .table>thead>tr>td, .table>thead>tr>th {
background-color: #000;
border-top: 1px solid #000;
@ -160,7 +187,7 @@ a:focus, a:hover {
border-radius: 0px;
}
.alert-success,.alert-warning,.alert-ifo,.alert-dismissable {
.alert-success,.alert-warning,.alert-ifo,.alert-dismissable,.alert-danger {
color: #33ff00;
background-color: #000;
border-color: #33ff00;
@ -182,6 +209,16 @@ a:focus, a:hover {
transition: unset;
}
input[type="text"]{
color: #33ff00 !important
}
.form-control::-webkit-input-placeholder { color: #33ff00; }
.form-control:-moz-placeholder { color: #33ff00; }
.form-control::-moz-placeholder { color: #33ff00; }
.form-control:-ms-input-placeholder { color: #33ff00; }
.form-control::-ms-input-placeholder { color: #33ff00; }
.progress {
background-color: #000;
border-radius: 0px;
@ -196,4 +233,28 @@ a:focus, a:hover {
float: left;
}
.logoutput {
width: 100%;
height: 300px;
background-color: #000;
border-color: #33ff00;
}
.webconsole {
width: 100%;
height: 100%;
border-color: #33ff00;
border-bottom: 1px solid;
border-left: 1px solid;
border-top: 0px;
border-right: 1px solid;
}
#console {
height: 500px;
}
.systemtabcontent {
height: 100%;
min-height: 500px;
}

23
includes/config.php Normal file
View File

@ -0,0 +1,23 @@
<?php
define('RASPI_CONFIG', '/etc/raspap');
define('RASPI_CONFIG_NETWORKING',RASPI_CONFIG.'/networking');
define('RASPI_ADMIN_DETAILS', RASPI_CONFIG.'/raspap.auth');
// Constants for configuration file paths.
// These are typical for default RPi installs. Modify if needed.
define('RASPI_DNSMASQ_CONFIG', '/etc/dnsmasq.conf');
define('RASPI_DNSMASQ_LEASES', '/var/lib/misc/dnsmasq.leases');
define('RASPI_HOSTAPD_CONFIG', '/etc/hostapd/hostapd.conf');
define('RASPI_WPA_SUPPLICANT_CONFIG', '/etc/wpa_supplicant/wpa_supplicant.conf');
define('RASPI_HOSTAPD_CTRL_INTERFACE', '/var/run/hostapd');
define('RASPI_WPA_CTRL_INTERFACE', '/var/run/wpa_supplicant');
define('RASPI_OPENVPN_CLIENT_CONFIG', '/etc/openvpn/client.conf');
define('RASPI_OPENVPN_SERVER_CONFIG', '/etc/openvpn/server.conf');
define('RASPI_TORPROXY_CONFIG', '/etc/tor/torrc');
// Optional services, set to true to enable.
define('RASPI_OPENVPN_ENABLED', false );
define('RASPI_TORPROXY_ENABLED', false );
?>

View File

@ -149,11 +149,11 @@ function DisplayDHCPConfig() {
</div>
<div class="row">
<div class="form-group col-xs-2 col-sm-2">
<div class="form-group col-xs-4 col-sm-2">
<label for="code">Lease Time</label>
<input type="text" class="form-control" name="RangeLeaseTime" value="<?php echo $arrRangeLeaseTime[1]; ?>" />
</div>
<div class="col-xs-2 col-sm-2">
<div class="col-xs-4 col-sm-2">
<label for="code">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></select>
</div>

View File

@ -1,4 +1,52 @@
<?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;
}
}
/**
*
@ -7,7 +55,7 @@
*/
function CSRFToken() {
?>
<input type="hidden" name="csrf_token" value="<?php echo $_SESSION['csrf_token']; ?>" />
<input id="csrf_token" type="hidden" name="csrf_token" value="<?php echo $_SESSION['csrf_token']; ?>" />
<?php
}

View File

@ -10,6 +10,8 @@ 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');
@ -74,6 +76,7 @@ function DisplayHostAPDConfig(){
<li class="active"><a href="#basic" data-toggle="tab">Basic</a></li>
<li><a href="#security" data-toggle="tab">Security</a></li>
<li><a href="#advanced" data-toggle="tab">Advanced</a></li>
<li><a href="#logoutput" data-toggle="tab">Logfile Output</a></li>
</ul>
<!-- Tab panes -->
@ -130,8 +133,33 @@ function DisplayHostAPDConfig(){
</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">
<h4>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="form-group col-md-4">
<label for="code">Country Code</label>
@ -431,6 +459,26 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $status)
$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
if (strlen($_POST['ssid']) == 0 || strlen($_POST['ssid']) > 32) {
// Not sure of all the restrictions of SSID

125
includes/networking.php Normal file
View File

@ -0,0 +1,125 @@
<?php
include_once( 'includes/status_messages.php' );
/**
*
*
*/
function DisplayNetworkingConfig(){
$status = new StatusMessages();
exec("ls /sys/class/net | grep -v lo", $interfaces);
foreach($interfaces as $interface) {
exec("ip a show $interface",$$interface);
}
CSRFToken();
?>
<div class="row">
<div class="col-lg-12">
<div class="panel panel-primary">
<div class="panel panel-heading">
<i class="fa fa-sitemap fa-fw"></i> Configure Networking
</div>
<div class="panel-body">
<div id="msgNetworking"></div>
<ul class="nav nav-tabs">
<li role="presentation" class="active"><a href="#summary" aria-controls="summary" role="tab" data-toggle="tab">Summary</a></li>
<?php
foreach($interfaces as $interface) {
echo '<li role="presentation"><a href="#'.$interface.'" aria-controls="'.$interface.'" role="tab" data-toggle="tab">'.$interface.'</a></li>';
}
?>
</ul>
<div class="tab-content">
<div role="tabpanel" class="tab-pane active" id="summary">
<h4>Current Settings</h4>
<div class="row">
<?php
foreach($interfaces as $interface) {
echo '<div class="col-md-6">
<div class="panel panel-default">
<div class="panel-heading">'.$interface.'</div>
<div class="panel-body" id="'.$interface.'-summary"></div>
</div>
</div>';
}
?>
</div><!-- /.row -->
<div class="col-lg-12">
<div class="row">
<a href="#" class="btn btn-outline btn-primary" id="btnSummaryRefresh"><i class="fa fa-refresh"></i> Refresh</a>
</div><!-- /.row -->
</div><!-- /.col-lg-12 -->
</div><!-- /.tab-pane -->
<?php
foreach($interfaces as $interface) {
echo '
<div role="tabpanel" class="tab-pane fade in" id="'.$interface.'">
<div class="row">
<div class="col-lg-6">
<form id="frm-'.$interface.'">
<div class="form-group">
<h4>Adapter IP Address Settings</h4>
<div class="btn-group" data-toggle="buttons">
<label class="btn btn-primary">
<input type="radio" name="'.$interface.'-addresstype" id="'.$interface.'-dhcp" autocomplete="off">DHCP
</label>
<label class="btn btn-primary">
<input type="radio" name="'.$interface.'-addresstype" id="'.$interface.'-static" autocomplete="off">Static IP
</label>
</div><!-- /.btn-group -->
<h4>Enable Fallback to Static Option</h4>
<div class="btn-group" data-toggle="buttons">
<label class="btn btn-primary">
<input type="radio" name="'.$interface.'-dhcpfailover" id="'.$interface.'-failover" autocomplete="off">Enabled
</label>
<label class="btn btn-warning">
<input type="radio" name="'.$interface.'-dhcpfailover" id="'.$interface.'-nofailover" autocomplete="off">Disabled
</label>
</div><!-- /.btn-group -->
</div><!-- /.form-group -->
<hr />
<h4>Static IP Options</h4>
<div class="form-group">
<label for="'.$interface.'-ipaddress">IP Address</label>
<input type="text" class="form-control" id="'.$interface.'-ipaddress" placeholder="0.0.0.0">
</div>
<div class="form-group">
<label for="'.$interface.'-netmask">Subnet Mask</label>
<input type="text" class="form-control" id="'.$interface.'-netmask" placeholder="255.255.255.0">
</div>
<div class="form-group">
<label for="'.$interface.'-gateway">Default Gateway</label>
<input type="text" class="form-control" id="'.$interface.'-gateway" placeholder="0.0.0.0">
</div>
<div class="form-group">
<label for="'.$interface.'-dnssvr">DNS Server</label>
<input type="text" class="form-control" id="'.$interface.'-dnssvr" placeholder="0.0.0.0">
</div>
<div class="form-group">
<label for="'.$interface.'-dnssvralt">Alternate DNS Server</label>
<input type="text" class="form-control" id="'.$interface.'-dnssvralt" placeholder="0.0.0.0">
</div>
<a href="#" class="btn btn-outline btn-primary intsave" data-int="'.$interface.'">Save Settings</a>
<a href="#" class="btn btn-warning intapply" data-int="'.$interface.'">Apply Settings</a>
</form>
</div>
</div><!-- /.tab-panel -->
</div>';
}
?>
</div><!-- /.tab-content -->
</div><!-- /.panel-body -->
<div class="panel-footer">Information provided by /sys/class/net</div>
</div><!-- /.panel-primary -->
</div><!-- /.col-lg-12 -->
</div>
<?php
}
?>

View File

@ -13,36 +13,12 @@
* @author Lawrence Yau <sirlagz@gmail.com>
* @author Bill Zimmerman <billzimmerman@gmail.com>
* @license GNU General Public License, version 3 (GPL-3.0)
* @version 1.2.2
* @version 1.3.0
* @link https://github.com/billz/raspap-webgui
* @see http://sirlagz.net/2013/02/08/raspap-webgui/
*/
define('RASPI_CONFIG', '/etc/raspap');
define('RASPI_ADMIN_DETAILS', RASPI_CONFIG.'/raspap.auth');
//if(file_exists(RASPI_CONFIG.'/raspap.auth')) {
// define('RASPI_ADMIN_DETAILS', RASPI_CONFIG.'/raspap.auth');
//} else {
// define('RASPI_ADMIN_DETAILS','');
//}
// Constants for configuration file paths.
// These are typical for default RPi installs. Modify if needed.
define('RASPI_DNSMASQ_CONFIG', '/etc/dnsmasq.conf');
define('RASPI_DNSMASQ_LEASES', '/var/lib/misc/dnsmasq.leases');
define('RASPI_HOSTAPD_CONFIG', '/etc/hostapd/hostapd.conf');
define('RASPI_WPA_SUPPLICANT_CONFIG', '/etc/wpa_supplicant/wpa_supplicant.conf');
define('RASPI_HOSTAPD_CTRL_INTERFACE', '/var/run/hostapd');
define('RASPI_WPA_CTRL_INTERFACE', '/var/run/wpa_supplicant');
define('RASPI_OPENVPN_CLIENT_CONFIG', '/etc/openvpn/client.conf');
define('RASPI_OPENVPN_SERVER_CONFIG', '/etc/openvpn/server.conf');
define('RASPI_TORPROXY_CONFIG', '/etc/tor/torrc');
// Optional services, set to true to enable.
define('RASPI_OPENVPN_ENABLED', false );
define('RASPI_TORPROXY_ENABLED', false );
include_once( 'includes/config.php' );
include_once( RASPI_CONFIG.'/raspap.php' );
include_once( 'includes/functions.php' );
include_once( 'includes/dashboard.php' );
@ -52,6 +28,7 @@ include_once( 'includes/dhcp.php' );
include_once( 'includes/hostapd.php' );
include_once( 'includes/system.php' );
include_once( 'includes/configure_client.php' );
include_once( 'includes/networking.php' );
include_once( 'includes/themes.php' );
$output = $return = 0;
@ -127,7 +104,7 @@ $theme_url = 'dist/css/' . $theme;
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="index.php">RaspAP Wifi Portal v1.2.2</a>
<a class="navbar-brand" href="index.php">RaspAP Wifi Portal v1.3.0</a>
</div>
<!-- /.navbar-header -->
@ -139,11 +116,14 @@ $theme_url = 'dist/css/' . $theme;
<a href="index.php?page=wlan0_info"><i class="fa fa-dashboard fa-fw"></i> Dashboard</a>
</li>
<li>
<a href="index.php?page=wpa_conf"><i class="fa fa-signal fa-fw"></i> Configure client</a>
<a href="index.php?page=wpa_conf"><i class="fa fa-signal fa-fw"></i> Configure WiFi Client</a>
</li>
<li>
<a href="index.php?page=hostapd_conf"><i class="fa fa-dot-circle-o fa-fw"></i> Configure hotspot</a>
<a href="index.php?page=hostapd_conf"><i class="fa fa-dot-circle-o fa-fw"></i> Configure Hotspot</a>
</li>
<li>
<a href="index.php?page=network_conf"><i class="fa fa-sitemap fa-fw"></i> Configure Networking</a>
</li>
<li>
<a href="index.php?page=dhcpd_conf"><i class="fa fa-exchange fa-fw"></i> Configure DHCP Server</a>
</li>
@ -194,6 +174,9 @@ $theme_url = 'dist/css/' . $theme;
case "wpa_conf":
DisplayWPAConfig();
break;
case "network_conf":
DisplayNetworkingConfig();
break;
case "hostapd_conf":
DisplayHostAPDConfig();
break;
@ -241,5 +224,8 @@ $theme_url = 'dist/css/' . $theme;
<!-- Custom Theme JavaScript -->
<script src="dist/js/sb-admin-2.js"></script>
<!-- Custom RaspAP JS -->
<script src="js/custom.js"></script>
</body>
</html>

View File

@ -78,8 +78,7 @@ function install_dependencies() {
function enable_php_lighttpd() {
install_log "Enabling PHP for lighttpd"
sudo lighttpd-enable-mod fastcgi-php
sudo lighttpd-enable-mod fastcgi-php
sudo service lighttpd force-reload
sudo /etc/init.d/lighttpd restart || install_error "Unable to restart lighttpd"
}
@ -101,6 +100,14 @@ function create_raspap_directories() {
cat /etc/dhcpcd.conf | sudo tee -a /etc/raspap/networking/defaults
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/raspap/hostapd
}
# Generate logging enable/disable files for hostapd
@ -186,7 +193,7 @@ function default_configuration() {
'echo 1 > /proc/sys/net/ipv4/ip_forward #RASPAP'
'iptables -t nat -A POSTROUTING -j MASQUERADE #RASPAP'
)
for line in "${lines[@]}"; do
if grep "$line" /etc/rc.local > /dev/null; then
echo "$line: Line already added"

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

View File

@ -63,10 +63,23 @@ function check_for_backups() {
fi
if [ -f "$raspap_dir/backups/dhcpcd.conf" ]; then
echo -n "Restore the last dhcpcd.conf file? [y/N]: "
read answer
if [[ $answer -eq 'y' ]]; then
sudo cp "$raspap_dir/backups/dhcpcd.conf" /etc/dhcpcd.conf
fi
fi
if [ -f "$raspap_dir/backups/rc.local" ]; then
echo -n "Restore the last rc.local file? [y/N]: "
read answer
if [[ $answer -eq 'y' ]]; then
sudo cp "$raspap_dir/backups/rc.local" /etc/rc.local
else
echo -n "Remove RaspAP Lines from /etc/rc.local? [Y/n]: "
if $answer -ne 'n' ]]; then
sed -i '/#RASPAP/d' /etc/rc.local
fi
fi
fi
fi
}

152
js/custom.js Normal file
View File

@ -0,0 +1,152 @@
function msgShow(retcode,msg) {
if(retcode == 0) {
var alertType = 'success';
} else if(retcode == 2 || retcode == 1) {
var alertType = 'danger';
}
var htmlMsg = '<div class="alert alert-'+alertType+' alert-dismissible" role="alert"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>'+msg+'</div>';
return htmlMsg;
}
function createNetmaskAddr(bitCount) {
var mask=[];
for(i=0;i<4;i++) {
var n = Math.min(bitCount, 8);
mask.push(256 - Math.pow(2, 8-n));
bitCount -= n;
}
return mask.join('.');
}
function loadSummary(strInterface) {
$.post('/ajax/networking/get_ip_summary.php',{interface:strInterface,csrf_token:csrf},function(data){
jsonData = JSON.parse(data);
console.log(jsonData);
if(jsonData['return'] == 0) {
$('#'+strInterface+'-summary').html(jsonData['output'].join('<br />'));
} else if(jsonData['return'] == 2) {
$('#'+strInterface+'-summary').append('<div class="alert alert-danger alert-dismissible" role="alert"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>'+jsonData['output'].join('<br />')+'</div>');
}
});
}
function getAllInterfaces() {
$.get('/ajax/networking/get_all_interfaces.php',function(data){
jsonData = JSON.parse(data);
$.each(jsonData,function(ind,value){
loadSummary(value)
});
});
}
function setupTabs() {
$('a[data-toggle="tab"]').on('shown.bs.tab',function(e){
var target = $(e.target).attr('href');
if(!target.match('summary')) {
var int = target.replace("#","");
loadCurrentSettings(int);
}
});
}
function loadCurrentSettings(strInterface) {
$.post('/ajax/networking/get_int_config.php',{interface:strInterface,csrf_token:csrf},function(data){
jsonData = JSON.parse(data);
$.each(jsonData['output'],function(i,v) {
var int = v['interface'];
$.each(v,function(i2,v2) {
switch(i2) {
case "static":
if(v2 == 'true') {
$('#'+int+'-static').click();
$('#'+int+'-nofailover').click();
} else {
$('#'+int+'-dhcp').click();
}
break;
case "failover":
if(v2 === 'true') {
$('#'+int+'-failover').click();
} else {
$('#'+int+'-nofailover').click();
}
break;
case "ip_address":
var arrIPNetmask = v2.split('/');
$('#'+int+'-ipaddress').val(arrIPNetmask[0]);
$('#'+int+'-netmask').val(createNetmaskAddr(arrIPNetmask[1]));
break;
case "routers":
$('#'+int+'-gateway').val(v2);
break;
case "domain_name_server":
svrsDNS = v2.split(" ");
$('#'+int+'-dnssvr').val(svrsDNS[0]);
$('#'+int+'-dnssvralt').val(svrsDNS[1]);
break;
}
});
});
});
}
function saveNetworkSettings(int) {
var frmInt = $('#frm-'+int).find(':input');
var arrFormData = {};
$.each(frmInt,function(i3,v3){
if($(v3).attr('type') == 'radio') {
arrFormData[$(v3).attr('id')] = $(v3).prop('checked');
} else {
arrFormData[$(v3).attr('id')] = $(v3).val();
}
});
arrFormData['interface'] = int;
arrFormData['csrf_token'] = csrf;
$.post('/ajax/networking/save_int_config.php',arrFormData,function(data){
//console.log(data);
var jsonData = JSON.parse(data);
$('#msgNetworking').html(msgShow(jsonData['return'],jsonData['output']));
});
}
function applyNetworkSettings() {
var int = $(this).data('int');
arrFormData = {};
arrFormData['csrf_token'] = csrf;
arrFormData['generate'] = '';
$.post('/ajax/networking/gen_int_config.php',arrFormData,function(data){
console.log(data);
var jsonData = JSON.parse(data);
$('#msgNetworking').html(msgShow(jsonData['return'],jsonData['output']));
});
}
function setupBtns() {
$('#btnSummaryRefresh').click(function(){getAllInterfaces();});
$('.intsave').click(function(){
var int = $(this).data('int');
saveNetworkSettings(int);
});
$('.intapply').click(function(){
applyNetworkSettings();
});
}
$().ready(function(){
csrf = $('#csrf_token').val();
pageCurrent = window.location.href.split("?")[1].split("=")[1];
pageCurrent = pageCurrent.replace("#","");
$('#side-menu').metisMenu();
switch(pageCurrent) {
case "network_conf":
getAllInterfaces();
setupTabs();
setupBtns();
break;
}
});