mirror of
https://github.com/billz/raspap-webgui.git
synced 2023-10-10 13:37:24 +02:00
Initial setup of project
This commit is contained in:
commit
4b69104df5
6331
assets/css/bootstrap.css
vendored
Normal file
6331
assets/css/bootstrap.css
vendored
Normal file
File diff suppressed because it is too large
Load Diff
116
assets/css/styles.css
Executable file
116
assets/css/styles.css
Executable file
@ -0,0 +1,116 @@
|
|||||||
|
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;
|
||||||
|
}
|
7
assets/js/bootstrap.min.js
vendored
Normal file
7
assets/js/bootstrap.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
72
assets/js/functions.js
Executable file
72
assets/js/functions.js
Executable file
@ -0,0 +1,72 @@
|
|||||||
|
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;
|
||||||
|
}
|
6
assets/js/jquery.min.js
vendored
Normal file
6
assets/js/jquery.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
415
index.php
Executable file
415
index.php
Executable file
@ -0,0 +1,415 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
include('phpincs.php');
|
||||||
|
$output = $return = 0;
|
||||||
|
$page = $_GET['page'];
|
||||||
|
|
||||||
|
|
||||||
|
echo '<html>
|
||||||
|
<head>
|
||||||
|
|
||||||
|
<!-- Bootstrap core CSS -->
|
||||||
|
<link href="assets/css/bootstrap.css" rel="stylesheet">
|
||||||
|
|
||||||
|
<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>
|
||||||
|
</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>';
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isset($_POST['startdhcpd'])) {
|
||||||
|
$line = system('sudo /etc/init.d/dnsmasq start',$return);
|
||||||
|
echo "Attempting to start dnsmasq";
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isset($_POST['stopdhcpd'])) {
|
||||||
|
$line = system('sudo /etc/init.d/dnsmasq stop',$return);
|
||||||
|
echo "Stopping dnsmasq";
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
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>';
|
||||||
|
|
||||||
|
echo $output;
|
||||||
|
echo '<script type="text/Javascript">UpdateNetworks()</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>
|
||||||
|
</body>
|
||||||
|
</html>';
|
||||||
|
?>
|
73
phpincs.php
Executable file
73
phpincs.php
Executable file
@ -0,0 +1,73 @@
|
|||||||
|
<?
|
||||||
|
|
||||||
|
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
|
||||||
|
*/
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user