Stable, before fixing nav css

This commit is contained in:
Bill Zimmerman 2015-02-25 14:06:48 +01:00
parent 4b69104df5
commit cb37f12f56
7 changed files with 169 additions and 6999 deletions

6331
assets/css/bootstrap.css vendored

File diff suppressed because it is too large Load Diff

View File

@ -1,116 +0,0 @@
body {
font-family:Arial;
}
.red {
color:red;
}
.green {
color:green;
}
.network {
border:1px solid;
padding-top:5px;
padding-left:5px;
}
.tableft {
text-align:right;
width:50px;
display:inline-block;
}
.menu {
float:left;
width:9%;
height:100%;
text-align:center;
}
.content {
border:1px solid;
float:left;
width:90%;
height:100%;
padding:3px;
}
.header {
float:left;
width:99%;
text-align:center;
}
textarea {
width:699px;
height:499px;
}
input.button {
width:80%;
border:1px solid;
}
.footer {
text-align:center;
width:100%;
float:left;
}
input[type=text],input[type=password] {
border:1px solid;
}
input[type=button],input[type=submit] {
border:1px solid;
border-radius:15px;
}
input[type=button]:hover {
font-weight:bold;
}
input[type=submit]:hover {
font-weight:bold;
}
.infoheader {
font-size:18px;
font-weight:bold;
width:100%;
text-align:center;
margin-top:10px;
border-bottom:1px solid;
}
.infobox {
width:100%;
}
#intinfo {
width:48%;
padding-left:10px;
border-right:1px solid;
float:left;
}
#wifiinfo {
width:48%;
padding-left:10px;
float:left;
}
.intheader {
font-size:14px;
text-align:center;
font-weight:bold;
width:100%;
}
.intfooter {
width:100%;
border-top:1px solid;
float:left;
text-align:center;
}

File diff suppressed because one or more lines are too long

View File

@ -1,72 +0,0 @@
function WiFiDown() {
var down = confirm("Take down wlan0 ?");
if(down) {
} else {
alert("Action cancelled");
}
}
function UpdateNetworks() {
var existing = document.getElementById("networkbox").getElementsByTagName('div').length;
document.getElementById("Networks").value = existing;
}
function AddNetwork() {
// existing = document.getElementById("networkbox").getElementsByTagName('div').length;
// existing++;
var Networks = document.getElementById('Networks').value;
document.getElementById('networkbox').innerHTML += '<div id="Networkbox'+Networks+'" class="Networkboxes">Network '+Networks+'<input type="button" value="Delete" onClick="DeleteNetwork('+Networks+')" /><br /> \
<span class="tableft">SSID :</span><input type="text" name="ssid'+Networks+'" onkeyup="CheckSSID(this)"><br> \
<span class="tableft">PSK :</span><input type="password" name="psk'+Networks+'" onkeyup="CheckPSK(this)"></div>';
Networks++;
document.getElementById('Networks').value=Networks;
}
function AddScanned(network) {
// var RegEx = new RegExp("[\s\t]+");
// networkname = network.split(RegEx)[4];
// alert(networkname);
existing = document.getElementById("networkbox").getElementsByTagName('div').length;
var Networks = document.getElementById('Networks').value;
if(existing != 0) {
Networks++;
}
document.getElementById('Networks').value=Networks;
document.getElementById('networkbox').innerHTML += '<div id="Networkbox'+Networks+'" class="Networkboxes">Network '+Networks+'<input type="button" value="Delete" /><br /> \
<span class="tableft">SSID :</span><input type="text" name="ssid'+Networks+'" id="ssid'+Networks+'" onkeyup="CheckSSID(this)"><br> \
<span class="tableft">PSK :</span><input type="password" name="psk'+Networks+'" onkeyup="CheckPSK(this)"></div>';
document.getElementById('ssid'+Networks).value = network;
if(existing == 0) {
Networks++
document.getElementById('Networks').value = Networks;
}
}
function CheckSSID(ssid) {
if(ssid.value.length>31) {
ssid.style.background='#FFD0D0';
document.getElementById('Save').disabled = true;
} else {
ssid.style.background='#D0FFD0'
document.getElementById('Save').disabled = false;
}
}
function CheckPSK(psk) {
if(psk.value.length < 8) {
psk.style.background='#FFD0D0';
document.getElementById('Save').disabled = true;
} else {
psk.style.background='#D0FFD0';
document.getElementById('Save').disabled = false;
}
}
function DeleteNetwork(network) {
element = document.getElementById('Networkbox'+network);
element.parentNode.removeChild(element);
var Networks = document.getElementById('Networks').value;
Networks--
document.getElementById('Networks').value = Networks;
}

File diff suppressed because one or more lines are too long

563
index.php
View File

@ -1,415 +1,190 @@
<?php
include('phpincs.php');
/**
* Raspbian WiFi Configuration Portal
*
* Enables use of simple web interface rather than SSH to control wifi and hostapd on the Raspberry Pi.
* Recommended distribution is Raspbian Server Edition. Specific instructions to install the supported software are
* in the README and original post by @SirLagz. For a quick run through, the packages required for the WebGUI are:
* lighttpd (I have version 1.4.31-2 installed via apt)
* php5-cgi (I have version 5.4.4-12 installed via apt)
* along with their supporting packages, php5 will also need to be enabled.
*
* LICENSE: TODO
*
* @author Lawrence Yau <sirlagz@gmail.comm>
* @author Bill Zimmerman <billzimmerman@gmail.com>
* @license TBD
* @version 1.0
* @link https://github.com/
* @see http://sirlagz.net/2013/02/08/raspap-webgui/
*/
// 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 false to disable.
define('RASPI_OPENVPN_ENABLED', true );
define('RASPI_TORPROXY_ENABLED', true );
include_once( 'includes/functions.php' );
$output = $return = 0;
$page = $_GET['page'];
?>
echo '<html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<!-- Bootstrap core CSS -->
<link href="assets/css/bootstrap.css" rel="stylesheet">
<title>Raspbian WiFi Configuration Portal</title>
<link href="assets/css/styles.css" rel="stylesheet" type="text/css"></link>
<script type="text/Javascript" src="assets/js/functions.js"></script>
<title>Raspbian WiFi Configuration Portal</title>
<!-- Bootstrap Core CSS -->
<link href="bower_components/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
<!-- MetisMenu CSS -->
<link href="bower_components/metisMenu/dist/metisMenu.min.css" rel="stylesheet">
<!-- Timeline CSS -->
<link href="dist/css/timeline.css" rel="stylesheet">
<!-- Custom CSS -->
<link href="dist/css/sb-admin-2.css" rel="stylesheet">
<!-- Morris Charts CSS -->
<link href="bower_components/morrisjs/morris.css" rel="stylesheet">
<!-- Custom Fonts -->
<link href="bower_components/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
<!-- Custom CSS -->
<link href="dist/css/custom.css" rel="stylesheet">
<link rel="shortcut icon" type="image/png" href="../img/favicon.png?v=2.0">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="header">
<h2>Raspbian WiFi Configuration Portal</h2>
</div>
<div class="menu">
<input class="button" type="button" value="WiFi
Info" name="wlan0_info" onclick="document.location=\'?page=\'+this.name" />
<input class="button" type="button" value="Configure
Client" name="wpa_conf" onclick="document.location=\'?page=\'+this.name" />
<input class="button" type="button" value="Configure
Hotspot" name="hostapd_conf" onclick="document.location=\'?page=\'+this.name" />
<input class="button" type="button" value="Configure
DHCP Server" name="dhcpd_conf" onclick="document.location=\'?page=\'+this.name" />
</div>
<div class="content">';
switch($page) {
case "dhcpd_conf":
exec('cat /etc/dnsmasq.conf',$return);
$conf = ParseConfig($return);
$arrRange = explode(",",$conf['dhcp-range']);
$RangeStart = $arrRange[0];
$RangeEnd = $arrRange[1];
$RangeMask = $arrRange[2];
preg_match('/([0-9]*)([a-z])/i',$arrRange[3],$arrRangeLeaseTime);
switch($arrRangeLeaseTime[2]) {
case "h":
$hselected = " selected";
break;
case "m":
$mselected = " selected";
break;
case "d":
$dselected = " selected";
break;
}
exec('pidof dnsmasq | wc -l',$dnsmasq);
if($dnsmasq[0] == 0) {
$status = '<span class="red">dnsmasq not running</span>';
} else {
$status = '<span class="green">dnsmasq is running</span>';
}
echo 'DHCP Server Options<br />
<span id="dnsmasqstatus">Status : '.$status.'</span>
<form method="POST" action="?page=dhcpd_conf">
Interface : <select name="interface">';
exec("cat /proc/net/dev | tail -n -3 | awk -F :\ ' { print $1 } ' | tr -d ' '",$interfaces);
foreach($interfaces as $int) {
$select = '';
if($int == $conf['interface']) {
$select = " selected";
}
echo '<option value="'.$int.'"'.$select.'>'.$int.'</option>';
}
<div id="wrapper">
<nav class="navbar navbar-default navbar-static-top" role="navigation" style="margin-bottom: 0">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<!-- /.navbar-header -->
echo'</select><br />
Starting IP Address : <input type="text" name="RangeStart" value="'.$RangeStart.'" /> <br />
Ending IP Address : <input type="text" name="RangeEnd" value="'.$RangeEnd.'" /><br />
Lease Time <input type="text" name="RangeLeaseTime" value="'.$arrRangeLeaseTime[1].'" /><select name="RangeLeaseTimeUnits"><option value="m"'.$mselected.'>Minutes</option><option value="h"'.$hselected.'>Hours</option><option value="d"'.$dselected.'>Days</option><option value="infinite">Infinite</option>
</select> <br />
<input type="submit" value="Save" name="savedhcpdsettings" />';
if($dnsmasq[0] == 0) {
echo'<input type="submit" value="Start dnsmasq" name="startdhcpd" />';
} else {
echo '<input type="submit" value="Stop dnsmasq" name="stopdhcpd" />';
}
echo'
</form>
<hr>
Client list<br />
';
exec('cat /var/lib/misc/dnsmasq.leases',$leases);
foreach($leases as $lease) {
echo $lease;
}
<!-- Navigation -->
<div class="navbar-default sidebar" role="navigation">
<div class="sidebar-nav navbar-collapse">
<ul class="nav" id="side-menu">
<li>
<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>
</li>
<li>
<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=dhcpd_conf"><i class="fa fa-exchange fa-fw"></i> Configure DHCP</a>
</li>
<?php if ( RASPI_OPENVPN_ENABLED ) : ?>
<li>
<a href="index.php?page=openvpn_conf"><i class="fa fa-lock fa-fw"></i> Configure OpenVPN</a>
</li>
<?php endif; ?>
<?php if ( RASPI_TORPROXY_ENABLED ) : ?>
<li>
<a href="index.php?page=torproxy_conf"><i class="fa fa-eye-slash fa-fw"></i> Configure TOR proxy</a>
</li>
<?php endif; ?>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.navbar-default -->
</nav>
<div id="page-wrapper">
if(isset($_POST['savedhcpdsettings'])) {
$config = 'interface='.$_POST['interface'].'
dhcp-range='.$_POST['RangeStart'].','.$_POST['RangeEnd'].',255.255.255.0,'.$_POST['RangeLeaseTime'].''.$_POST['RangeLeaseTimeUnits'];
exec('echo "'.$config.'" > /tmp/dhcpddata',$temp);
system('sudo cp /tmp/dhcpddata /etc/dnsmasq.conf',$return);
if($return == 0) {
echo "dnsmasq configuration updated successfully";
} else {
echo "Dnsmasq configuration failed to be updated";
}
}
<!-- Page Heading -->
<div class="row">
<div class="col-lg-12">
<h1 class="page-header">
<img class="logo" src="img/Raspi-PBG001.png" width="45" height="45">Raspbian <small>WiFi Configuration Portal</small>
</h1>
</div>
</div><!-- /.row -->
if(isset($_POST['startdhcpd'])) {
$line = system('sudo /etc/init.d/dnsmasq start',$return);
echo "Attempting to start dnsmasq";
}
<?php
// handle page actions
switch( $page ) {
case "wlan0_info":
DisplayDashboard();
break;
case "dhcpd_conf":
DisplayDHCPConfig();
break;
case "wpa_conf":
DisplayWPAConfig();
break;
case "hostapd_conf":
DisplayHostAPDConfig();
break;
case "openvpn_conf":
DisplayOpenVPNConfig();
break;
case "torproxy_conf":
DisplayTorProxyConfig();
break;
case "save_hostapd_conf":
SaveHostAPDConfig();
break;
default:
DisplayDashboard();
}
?>
</div><!-- /#page-wrapper -->
</div><!-- /#wrapper -->
if(isset($_POST['stopdhcpd'])) {
$line = system('sudo /etc/init.d/dnsmasq stop',$return);
echo "Stopping dnsmasq";
}
break;
<!-- jQuery -->
<script src="bower_components/jquery/dist/jquery.min.js"></script>
case "wlan0_info":
exec('ifconfig wlan0',$return);
exec('iwconfig wlan0',$return);
$strWlan0 = implode(" ",$return);
$strWlan0 = preg_replace('/\s\s+/', ' ', $strWlan0);
preg_match('/HWaddr ([0-9a-f:]+)/i',$strWlan0,$result);
$strHWAddress = $result[1];
preg_match('/inet addr:([0-9.]+)/i',$strWlan0,$result);
$strIPAddress = $result[1];
preg_match('/Mask:([0-9.]+)/i',$strWlan0,$result);
$strNetMask = $result[1];
preg_match('/RX packets:(\d+)/',$strWlan0,$result);
$strRxPackets = $result[1];
preg_match('/TX packets:(\d+)/',$strWlan0,$result);
$strTxPackets = $result[1];
preg_match('/RX Bytes:(\d+ \(\d+.\d+ MiB\))/i',$strWlan0,$result);
$strRxBytes = $result[1];
preg_match('/TX Bytes:(\d+ \(\d+.\d+ [K|M|G]iB\))/i',$strWlan0,$result);
$strTxBytes = $result[1];
preg_match('/ESSID:\"([a-zA-Z0-9\s]+)\"/i',$strWlan0,$result);
$strSSID = str_replace('"','',$result[1]);
preg_match('/Access Point: ([0-9a-f:]+)/i',$strWlan0,$result);
$strBSSID = $result[1];
preg_match('/Bit Rate=([0-9]+ Mb\/s)/i',$strWlan0,$result);
$strBitrate = $result[1];
preg_match('/Tx-Power=([0-9]+ dBm)/i',$strWlan0,$result);
$strTxPower = $result[1];
preg_match('/Link Quality=([0-9]+\/[0-9]+)/i',$strWlan0,$result);
$strLinkQuality = $result[1];
preg_match('/Signal Level=(-[0-9]+ dBm)/i',$strWlan0,$result);
$strSignalLevel = $result[1];
if(strpos($strWlan0, "UP") !== false && strpos($strWlan0, "RUNNING") !== false) {
$strStatus = '<span style="color:green">Interface is up</span>';
} else {
$strStatus = '<span style="color:red">Interface is down</span>';
}
if(isset($_POST['ifdown_wlan0'])) {
exec('ifconfig wlan0 | grep -i running | wc -l',$test);
if($test[0] == 1) {
exec('sudo ifdown wlan0',$return);
} else {
echo 'Interface already down';
}
} elseif(isset($_POST['ifup_wlan0'])) {
exec('ifconfig wlan0 | grep -i running | wc -l',$test);
if($test[0] == 0) {
exec('sudo ifup wlan0',$return);
} else {
echo 'Interface already up';
}
}
echo '<div class="infobox">
<form action="/?page=wlan0_info" method="POST">
<input type="submit" value="ifdown wlan0" name="ifdown_wlan0" />
<input type="submit" value="ifup wlan0" name="ifup_wlan0" />
<input type="button" value="Refresh" onclick="document.location.reload(true)" />
</form>
<div class="infoheader">Wireless Information and Statistics</div>
<div id="intinfo"><div class="intheader">Interface Information</div>
Interface Name : wlan0<br />
Interface Status : ' . $strStatus . '<br />
IP Address : ' . $strIPAddress . '<br />
Subnet Mask : ' . $strNetMask . '<br />
Mac Address : ' . $strHWAddress . '<br />
<div class="intheader">Interface Statistics</div>
Received Packets : ' . $strRxPackets . '<br />
Received Bytes : ' . $strRxBytes . '<br /><br />
Transferred Packets : ' . $strTxPackets . '<br />
Transferred Bytes : ' . $strTxBytes . '<br />
</div>
<div id="wifiinfo">
<div class="intheader">Wireless Information</div>
Connected To : ' . $strSSID . '<br />
AP Mac Address : ' . $strBSSID . '<br />
Bitrate : ' . $strBitrate . '<br />
Transmit Power : ' . $strTxPower .'<br />
Link Quality : ' . $strLinkQuality . '<br />
Signal Level : ' . $strSignalLevel . '<br />
</div>
</div>
<div class="intfooter">Information provided by ifconfig and iwconfig</div>';
break;
<!-- Bootstrap Core JavaScript -->
<script src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
case "wpa_conf":
exec('sudo cat /etc/wpa_supplicant/wpa_supplicant.conf',$return);
$ssid = array();
$psk = array();
foreach($return as $a) {
if(preg_match('/SSID/i',$a)) {
$arrssid = explode("=",$a);
$ssid[] = str_replace('"','',$arrssid[1]);
}
if(preg_match('/\#psk/i',$a)) {
$arrpsk = explode("=",$a);
$psk[] = str_replace('"','',$arrpsk[1]);
}
}
$numSSIDs = count($ssid);
$output = '<form method="POST" action="/?page=wpa_conf" id="wpa_conf_form"><input type="hidden" id="Networks" name="Networks" /><div class="network" id="networkbox">';
for($ssids = 0; $ssids < $numSSIDs; $ssids++) {
$output .= '<div id="Networkbox'.$ssids.'" class="NetworkBoxes">Network '.$ssids.' <input type="button" value="Delete" onClick="DeleteNetwork('.$ssids.')" /></span><br />
<span class="tableft" id="lssid0">SSID :</span><input type="text" id="ssid0" name="ssid'.$ssids.'" value="'.$ssid[$ssids].'" onkeyup="CheckSSID(this)" /><br />
<span class="tableft" id="lpsk0">PSK :</span><input type="password" id="psk0" name="psk'.$ssids.'" value="'.$psk[$ssids].'" onkeyup="CheckPSK(this)" /></div>';
}
$output .= '</div><input type="submit" value="Scan for Networks" name="Scan" /><input type="button" value="Add Network" onClick="AddNetwork();" /><input type="submit" value="Save" name="SaveWPAPSKSettings" onmouseover="UpdateNetworks(this)" id="Save" disabled />
</form>';
<!-- Metis Menu Plugin JavaScript -->
<script src="bower_components/metisMenu/dist/metisMenu.min.js"></script>
echo $output;
echo '<script type="text/Javascript">UpdateNetworks()</script>';
<!-- Morris Charts JavaScript -->
<!--script src="bower_components/raphael/raphael-min.js"></script-->
<!--script src="bower_components/morrisjs/morris.min.js"></script-->
<!--script src="js/morris-data.js"></script-->
if(isset($_POST['SaveWPAPSKSettings'])) {
$config = 'ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
';
$networks = $_POST['Networks'];
for($x = 0; $x < $networks; $x++) {
$network = '';
$ssid = escapeshellarg($_POST['ssid'.$x]);
$psk = escapeshellarg($_POST['psk'.$x]);
exec('wpa_passphrase '.$ssid. ' ' . $psk,$network);
foreach($network as $b) {
$config .= "$b
";
}
}
exec("echo '$config' > /tmp/wifidata",$return);
system('sudo cp /tmp/wifidata /etc/wpa_supplicant/wpa_supplicant.conf',$returnval);
if($returnval == 0) {
echo "Wifi Settings Updated Successfully";
} else {
echo "Wifi settings failed to be updated";
}
} elseif(isset($_POST['Scan'])) {
$return = '';
exec('sudo wpa_cli scan',$return);
sleep(5);
exec('sudo wpa_cli scan_results',$return);
for($shift = 0; $shift < 4; $shift++ ) {
array_shift($return);
}
echo "Networks found : <br />";
foreach($return as $network) {
$arrNetwork = preg_split("/[\t]+/",$network);
$bssid = $arrNetwork[0];
$channel = ConvertToChannel($arrNetwork[1]);
$signal = $arrNetwork[2] . " dBm";
$security = $arrNetwork[3];
$ssid = $arrNetwork[4];
echo '<input type="button" value="Connect to This network" onClick="AddScanned(\''.$ssid.'\')" />' . $ssid . " on channel " . $channel . " with " . $signal . "(".ConvertToSecurity($security)." Security)<br />";
}
}
break;
case "hostapd_conf":
exec('cat /etc/hostapd/hostapd.conf',$return);
exec('pidof hostapd | wc -l',$hostapdstatus);
if($hostapdstatus[0] == 0) {
$status = '<span class="red">hostapd is not running</span>';
} else {
$status = '<span class="green">hostapd is running</span>';
}
$arrConfig = array();
$arrChannel = array('a','b','g');
$arrSecurity = array( 1 => 'WPA', 2 => 'WPA2',3=> 'WPA+WPA2');
$arrEncType = array('TKIP' => 'TKIP', 'CCMP' => 'CCMP', 'TKIP CCMP' => 'TKIP+CCMP');
foreach($return as $a) {
if($a[0] != "#") {
$arrLine = explode("=",$a);
$arrConfig[$arrLine[0]]=$arrLine[1];
}
}
echo '<form action="/?page=save_hostapd_conf" method="POST">
HostAPD status : ' . $status . '<br />
Interface : <select name="interface">';
exec("cat /proc/net/dev | tail -n -3 | awk -F :\ ' { print $1 } ' | tr -d ' '",$interfaces);
foreach($interfaces as $int) {
$select = '';
if($int == $arrConfig['interface']) {
$select = " selected";
}
echo '<option value="'.$int.'"'.$select.'>'.$int.'</option>';
}
echo'</select><br />
SSID : <input type="text" name="ssid" value="'.$arrConfig['ssid'].'" /><br />
Wireless Mode : <select name="hw_mode">';
foreach($arrChannel as $Mode) {
$select = '';
if($arrConfig['hw_mode'] == $Mode) {
$select = ' selected';
}
echo '<option value="'.$Mode.'"'.$select.'>'.$Mode.'</option>';
}
echo '</select><br />
Channel : <select name="channel">';
for($channel = 1; $channel < 14; $channel++) {
$select = '';
if($channel == $arrConfig['channel']) {
$select = " selected";
}
echo '<option value="'.$channel.'"'.$select.'>'.$channel.'</option>';
}
echo '</select><br />
Security type : <select name="wpa">';
foreach($arrSecurity as $SecVal => $SecMode) {
$select = '';
if($SecVal == $arrConfig['wpa']) {
$select = ' selected';
}
echo '<option value="'.$SecVal.'"'.$select.'>'.$SecMode.'</option>';
}
echo'</select><br />
Encryption Type : <select name="wpa_pairwise">';
foreach($arrEncType as $EncConf => $Enc) {
$select = '';
if($Enc == $arrConfig['wpa_pairwise']) {
$select = ' selected';
}
echo '<option value="'.$EncConf.'"'.$select.'>'.$Enc.'</option>';
}
echo'</select><br />
PSK : <input type="text" name="wpa_passphrase" value="'.$arrConfig['wpa_passphrase'].'" /> <br />
<input type="submit" name="SaveHostAPDSettings" value="Save Hostapd settings" /> ';
if($hostapdstatus[0] == 0) {
echo '<input type="submit" name="StartHotspot" value="Start Hotspot" />';
} else {
echo '<input type="submit" name="StopHotspot" value="Stop hotspot" />';
}
echo'<hr>
Advanced Settings<br />
Country Code : <input type="text" name="country_code" value="'.$arrConfig['country_code'].'" />
</form>';
break;
case "save_hostapd_conf":
if(isset($_POST['SaveHostAPDSettings'])) {
$config = 'driver=nl80211
ctrl_interface=/var/run/hostapd
ctrl_interface_group=0
beacon_int=100
auth_algs=1
wpa_key_mgmt=WPA-PSK
';
$config .= "interface=".$_POST['interface']."
";
$config .= "ssid=".$_POST['ssid']."
";
$config .= "hw_mode=".$_POST['hw_mode']."
";
$config .= "channel=".$_POST['channel']."
";
$config .= "wpa=".$_POST['wpa']."
";
$config .='wpa_passphrase='.$_POST['wpa_passphrase'].'
';
$config .="wpa_pairwise=".$_POST['wpa_pairwise']."
";
$config .="country_code=".$_POST['country_code'];
exec("echo '$config' > /tmp/hostapddata",$return);
system("sudo cp /tmp/hostapddata /etc/hostapd/hostapd.conf",$return);
if($return == 0) {
echo "Wifi Hotspot settings saved";
} else {
echo "Wifi Hotspot settings failed to be saved";
}
} elseif(isset($_POST['StartHotspot'])) {
echo "Attempting to start hotspot";
exec('sudo /etc/init.d/hostapd start',$return);
foreach($return as $line) {
echo $line."<br />";
}
} elseif(isset($_POST['StopHotspot'])) {
echo "Attempting to stop hotspot";
exec('sudo /etc/init.d/hostapd stop',$return);
foreach($return as $line) {
echo $line."<br />";
}
}
break;
}
echo '
</div>
<div class="footer">
</div>
<!-- Bootstrap core JavaScript -->
<script src="assets/js/jquery.min.js"></script>
<script src="assets/js/bootstrap.min.js"></script>
<!-- Custom Theme JavaScript -->
<script src="dist/js/sb-admin-2.js"></script>
</body>
</html>';
?>
</html>

View File

@ -1,73 +0,0 @@
<?
function GetDistString($input,$string,$offset,$separator) {
$string = substr($input,strpos($input,$string)+$offset,strpos(substr($input,strpos($input,$string)+$offset),$separator));
return $string;
}
function ParseConfig($arrConfig) {
$config = array();
foreach($arrConfig as $line) {
if($line[0] != "#") {
$arrLine = explode("=",$line);
$config[$arrLine[0]] = $arrLine[1];
}
}
return $config;
}
function ConvertToChannel($freq) {
$base = 2412;
$channel = 1;
for($x = 0; $x < 13; $x++) {
if($freq != $base) {
$base = $base + 5;
$channel++;
} else {
return $channel;
}
}
return "Invalid Channel";
}
function ConvertToSecurity($security) {
switch($security) {
case "[WPA2-PSK-CCMP][ESS]":
return "WPA2-PSK (AES)";
break;
case "[WPA2-PSK-TKIP][ESS]":
return "WPA2-PSK (TKIP)";
break;
case "[WPA-PSK-TKIP+CCMP][WPS][ESS]":
return "WPA-PSK (TKIP/AES) with WPS";
break;
case "[WPA-PSK-TKIP+CCMP][WPA2-PSK-TKIP+CCMP][ESS]":
return "WPA/WPA2-PSK (TKIP/AES)";
break;
case "[WPA-PSK-TKIP][ESS]":
return "WPA-PSK (TKIP)";
break;
case "[WEP][ESS]":
return "WEP";
break;
}
}
/*
1* 2412 Yes Yes YesD
2 2417 Yes Yes YesD
3 2422 Yes Yes YesD
4 2427 Yes Yes YesD
5* 2432 Yes Yes Yes
6 2437 Yes Yes Yes
7 2442 Yes Yes Yes
8 2447 Yes Yes Yes
9* 2452 Yes Yes Yes
10 2457 Yes Yes Yes
11 2462 Yes Yes Yes
12 2467 NoB Yes Yes
13* 2472 NoB Yes Yes
*/
?>