diff --git a/includes/about.php b/includes/about.php old mode 100644 new mode 100755 index 1b3e24e7..8e085994 --- a/includes/about.php +++ b/includes/about.php @@ -1,8 +1,9 @@ addMessage('New passwords do not match', 'danger'); - } else if ($new_username == '') { - $status->addMessage('Username must not be empty', 'danger'); +function DisplayAuthConfig($username, $password) +{ + $status = new StatusMessages(); + if (isset($_POST['UpdateAdminPassword'])) { + if (CSRFValidate()) { + if (password_verify($_POST['oldpass'], $password)) { + $new_username=trim($_POST['username']); + if ($_POST['newpass'] !== $_POST['newpassagain']) { + $status->addMessage('New passwords do not match', 'danger'); + } elseif ($new_username == '') { + $status->addMessage('Username must not be empty', 'danger'); + } else { + if (!file_exists(RASPI_ADMIN_DETAILS)) { + $tmpauth = fopen(RASPI_ADMIN_DETAILS, 'w'); + fclose($tmpauth); + } + + if ($auth_file = fopen(RASPI_ADMIN_DETAILS, 'w')) { + fwrite($auth_file, $new_username.PHP_EOL); + fwrite($auth_file, password_hash($_POST['newpass'], PASSWORD_BCRYPT).PHP_EOL); + fclose($auth_file); + $username = $new_username; + $status->addMessage('Admin password updated'); + } else { + $status->addMessage('Failed to update admin password', 'danger'); + } + } + } else { + $status->addMessage('Old password does not match', 'danger'); + } } else { - if (!file_exists(RASPI_ADMIN_DETAILS)) { - $tmpauth = fopen(RASPI_ADMIN_DETAILS, 'w'); - fclose($tmpauth); - } - - if ($auth_file = fopen(RASPI_ADMIN_DETAILS, 'w')) { - fwrite($auth_file, $new_username.PHP_EOL); - fwrite($auth_file, password_hash($_POST['newpass'], PASSWORD_BCRYPT).PHP_EOL); - fclose($auth_file); - $username = $new_username; - $status->addMessage('Admin password updated'); - } else { - $status->addMessage('Failed to update admin password', 'danger'); - } + error_log('CSRF violation'); } - } else { - $status->addMessage('Old password does not match', 'danger'); - } - } else { - error_log('CSRF violation'); } - } ?>
@@ -74,6 +75,6 @@ function DisplayAuthConfig($username, $password){
- false, 'configured' => true, 'connected' => false); - } elseif ($network !== null) { - if (preg_match('/^\s*}\s*$/', $line)) { - $networks[$ssid] = $network; - $network = null; - $ssid = null; - } elseif ($lineArr = preg_split('/\s*=\s*/', trim($line))) { - switch(strtolower($lineArr[0])) { - case 'ssid': - $ssid = trim($lineArr[1], '"'); - break; - case 'psk': - if (array_key_exists('passphrase', $network)) { - break; - } - case '#psk': - $network['protocol'] = 'WPA'; - case 'wep_key0': // Untested - $network['passphrase'] = trim($lineArr[1], '"'); - break; - case 'key_mgmt': - if (! array_key_exists('passphrase', $network) && $lineArr[1] === 'NONE') { - $network['protocol'] = 'Open'; - } - break; - case 'priority': - $network['priority'] = trim($lineArr[1], '"'); - break; - } - } - } - } - - if ( isset($_POST['connect']) ) { - $result = 0; - exec ( 'sudo wpa_cli -i ' . RASPI_WPA_CTRL_INTERFACE . ' select_network '.strval($_POST['connect'] )); - } - else if ( isset($_POST['client_settings']) && CSRFValidate() ) { - $tmp_networks = $networks; - if ($wpa_file = fopen('/tmp/wifidata', 'w')) { - fwrite($wpa_file, 'ctrl_interface=DIR=' . RASPI_WPA_CTRL_INTERFACE . ' GROUP=netdev' . PHP_EOL); - fwrite($wpa_file, 'update_config=1' . PHP_EOL); - - foreach(array_keys($_POST) as $post) { - if (preg_match('/delete(\d+)/', $post, $post_match)) { - unset($tmp_networks[$_POST['ssid' . $post_match[1]]]); - } elseif (preg_match('/update(\d+)/', $post, $post_match)) { - // NB, at the moment, the value of protocol from the form may - // contain HTML line breaks - $tmp_networks[$_POST['ssid' . $post_match[1]]] = array( - 'protocol' => ( $_POST['protocol' . $post_match[1]] === 'Open' ? 'Open' : 'WPA' ), - 'passphrase' => $_POST['passphrase' . $post_match[1]], - 'configured' => true - ); - if (array_key_exists('priority' . $post_match[1], $_POST)) { - $tmp_networks[$_POST['ssid' . $post_match[1]]]['priority'] = $_POST['priority' . $post_match[1]]; - } - } - } - - $ok = true; - foreach($tmp_networks as $ssid => $network) { - if ($network['protocol'] === 'Open') { - fwrite($wpa_file, "network={".PHP_EOL); - fwrite($wpa_file, "\tssid=\"".$ssid."\"".PHP_EOL); - fwrite($wpa_file, "\tkey_mgmt=NONE".PHP_EOL); - if (array_key_exists('priority', $network)) { - fwrite($wpa_file, "\tpriority=".$network['priority'].PHP_EOL); - } - fwrite($wpa_file, "}".PHP_EOL); - } else { - if (strlen($network['passphrase']) >=8 && strlen($network['passphrase']) <= 63) { - unset($wpa_passphrase); - unset($line); - exec( 'wpa_passphrase '.escapeshellarg($ssid). ' ' . escapeshellarg($network['passphrase']),$wpa_passphrase ); - foreach($wpa_passphrase as $line) { - if (preg_match('/^\s*}\s*$/', $line)) { - if (array_key_exists('priority', $network)) { - fwrite($wpa_file, "\tpriority=".$network['priority'].PHP_EOL); + foreach ($known_return as $line) { + if (preg_match('/network\s*=/', $line)) { + $network = array('visible' => false, 'configured' => true, 'connected' => false); + } elseif ($network !== null) { + if (preg_match('/^\s*}\s*$/', $line)) { + $networks[$ssid] = $network; + $network = null; + $ssid = null; + } elseif ($lineArr = preg_split('/\s*=\s*/', trim($line))) { + switch (strtolower($lineArr[0])) { + case 'ssid': + $ssid = trim($lineArr[1], '"'); + break; + case 'psk': + if (array_key_exists('passphrase', $network)) { + break; + } + case '#psk': + $network['protocol'] = 'WPA'; + case 'wep_key0': // Untested + $network['passphrase'] = trim($lineArr[1], '"'); + break; + case 'key_mgmt': + if (! array_key_exists('passphrase', $network) && $lineArr[1] === 'NONE') { + $network['protocol'] = 'Open'; + } + break; + case 'priority': + $network['priority'] = trim($lineArr[1], '"'); + break; } - fwrite($wpa_file, $line.PHP_EOL); - } else { - fwrite($wpa_file, $line.PHP_EOL); - } } - } else { - $status->addMessage('WPA passphrase must be between 8 and 63 characters', 'danger'); - $ok = false; - } } - } + } - if ($ok) { - system( 'sudo cp /tmp/wifidata ' . RASPI_WPA_SUPPLICANT_CONFIG, $returnval ); - if( $returnval == 0 ) { - exec('sudo wpa_cli -i ' . RASPI_WIFI_CLIENT_INTERFACE . ' reconfigure', $reconfigure_out, $reconfigure_return ); - if ($reconfigure_return == 0) { - $status->addMessage('Wifi settings updated successfully', 'success'); - $networks = $tmp_networks; - } else { - $status->addMessage('Wifi settings updated but cannot restart (cannot execute "wpa_cli reconfigure")', 'danger'); - } + if (isset($_POST['connect'])) { + $result = 0; + exec('sudo wpa_cli -i ' . RASPI_WPA_CTRL_INTERFACE . ' select_network '.strval($_POST['connect'])); + } elseif (isset($_POST['client_settings']) && CSRFValidate()) { + $tmp_networks = $networks; + if ($wpa_file = fopen('/tmp/wifidata', 'w')) { + fwrite($wpa_file, 'ctrl_interface=DIR=' . RASPI_WPA_CTRL_INTERFACE . ' GROUP=netdev' . PHP_EOL); + fwrite($wpa_file, 'update_config=1' . PHP_EOL); + + foreach (array_keys($_POST) as $post) { + if (preg_match('/delete(\d+)/', $post, $post_match)) { + unset($tmp_networks[$_POST['ssid' . $post_match[1]]]); + } elseif (preg_match('/update(\d+)/', $post, $post_match)) { + // NB, at the moment, the value of protocol from the form may + // contain HTML line breaks + $tmp_networks[$_POST['ssid' . $post_match[1]]] = array( + 'protocol' => ( $_POST['protocol' . $post_match[1]] === 'Open' ? 'Open' : 'WPA' ), + 'passphrase' => $_POST['passphrase' . $post_match[1]], + 'configured' => true + ); + if (array_key_exists('priority' . $post_match[1], $_POST)) { + $tmp_networks[$_POST['ssid' . $post_match[1]]]['priority'] = $_POST['priority' . $post_match[1]]; + } + } + } + + $ok = true; + foreach ($tmp_networks as $ssid => $network) { + if ($network['protocol'] === 'Open') { + fwrite($wpa_file, "network={".PHP_EOL); + fwrite($wpa_file, "\tssid=\"".$ssid."\"".PHP_EOL); + fwrite($wpa_file, "\tkey_mgmt=NONE".PHP_EOL); + if (array_key_exists('priority', $network)) { + fwrite($wpa_file, "\tpriority=".$network['priority'].PHP_EOL); + } + fwrite($wpa_file, "}".PHP_EOL); + } else { + if (strlen($network['passphrase']) >=8 && strlen($network['passphrase']) <= 63) { + unset($wpa_passphrase); + unset($line); + exec('wpa_passphrase '.escapeshellarg($ssid). ' ' . escapeshellarg($network['passphrase']), $wpa_passphrase); + foreach ($wpa_passphrase as $line) { + if (preg_match('/^\s*}\s*$/', $line)) { + if (array_key_exists('priority', $network)) { + fwrite($wpa_file, "\tpriority=".$network['priority'].PHP_EOL); + } + fwrite($wpa_file, $line.PHP_EOL); + } else { + fwrite($wpa_file, $line.PHP_EOL); + } + } + } else { + $status->addMessage('WPA passphrase must be between 8 and 63 characters', 'danger'); + $ok = false; + } + } + } + + if ($ok) { + system('sudo cp /tmp/wifidata ' . RASPI_WPA_SUPPLICANT_CONFIG, $returnval); + if ($returnval == 0) { + exec('sudo wpa_cli -i ' . RASPI_WIFI_CLIENT_INTERFACE . ' reconfigure', $reconfigure_out, $reconfigure_return); + if ($reconfigure_return == 0) { + $status->addMessage('Wifi settings updated successfully', 'success'); + $networks = $tmp_networks; + } else { + $status->addMessage('Wifi settings updated but cannot restart (cannot execute "wpa_cli reconfigure")', 'danger'); + } + } else { + $status->addMessage('Wifi settings failed to be updated', 'danger'); + } + } } else { - $status->addMessage('Wifi settings failed to be updated', 'danger'); + $status->addMessage('Failed to update wifi settings', 'danger'); } - } - } else { - $status->addMessage('Failed to update wifi settings', 'danger'); - } - } - - exec( 'sudo wpa_cli -i ' . RASPI_WIFI_CLIENT_INTERFACE . ' scan' ); - sleep(3); - exec( 'sudo wpa_cli -i ' . RASPI_WIFI_CLIENT_INTERFACE . ' scan_results',$scan_return ); - - array_shift($scan_return); - - // display output - foreach( $scan_return as $network ) { - $arrNetwork = preg_split("/[\t]+/",$network); // split result into array - - // Save RSSI - if (array_key_exists(4, $arrNetwork)) { - $networks[$arrNetwork[4]]['RSSI'] = $arrNetwork[2]; } - // If network is saved - if (array_key_exists(4, $arrNetwork) && array_key_exists($arrNetwork[4], $networks)) { - $networks[$arrNetwork[4]]['visible'] = true; - $networks[$arrNetwork[4]]['channel'] = ConvertToChannel($arrNetwork[1]); - // TODO What if the security has changed? - } else { - $networks[$arrNetwork[4]] = array( - 'configured' => false, - 'protocol' => ConvertToSecurity($arrNetwork[3]), - 'channel' => ConvertToChannel($arrNetwork[1]), - 'passphrase' => '', - 'visible' => true, - 'connected' => false - ); - } - } + exec('sudo wpa_cli -i ' . RASPI_WIFI_CLIENT_INTERFACE . ' scan'); + sleep(3); + exec('sudo wpa_cli -i ' . RASPI_WIFI_CLIENT_INTERFACE . ' scan_results', $scan_return); - exec( 'iwconfig ' . RASPI_WIFI_CLIENT_INTERFACE, $iwconfig_return ); - foreach ($iwconfig_return as $line) { - if (preg_match( '/ESSID:\"([^"]+)\"/i',$line,$iwconfig_ssid )) { - $networks[$iwconfig_ssid[1]]['connected'] = true; + array_shift($scan_return); + + // display output + foreach ($scan_return as $network) { + $arrNetwork = preg_split("/[\t]+/", $network); // split result into array + + // Save RSSI + if (array_key_exists(4, $arrNetwork)) { + $networks[$arrNetwork[4]]['RSSI'] = $arrNetwork[2]; + } + + // If network is saved + if (array_key_exists(4, $arrNetwork) && array_key_exists($arrNetwork[4], $networks)) { + $networks[$arrNetwork[4]]['visible'] = true; + $networks[$arrNetwork[4]]['channel'] = ConvertToChannel($arrNetwork[1]); + // TODO What if the security has changed? + } else { + $networks[$arrNetwork[4]] = array( + 'configured' => false, + 'protocol' => ConvertToSecurity($arrNetwork[3]), + 'channel' => ConvertToChannel($arrNetwork[1]), + 'passphrase' => '', + 'visible' => true, + 'connected' => false + ); + } + } + + exec('iwconfig ' . RASPI_WIFI_CLIENT_INTERFACE, $iwconfig_return); + foreach ($iwconfig_return as $line) { + if (preg_match('/ESSID:\"([^"]+)\"/i', $line, $iwconfig_ssid)) { + $networks[$iwconfig_ssid[1]]['connected'] = true; + } } - } ?>
@@ -176,11 +176,11 @@ function DisplayWPAConfig(){

showMessages(); ?>

- -
+ +
- + - - $network) { ?> + + $network) { ?>
@@ -206,23 +206,23 @@ function DisplayWPAConfig(){
Status
- + - - + + - +
Channel
- - - + + + X - +
@@ -231,17 +231,21 @@ function DisplayWPAConfig(){
= -50) { echo 100; } - else if($network['RSSI'] <= -100) { echo 0;} - else {echo 2*($network['RSSI'] + 100); } + if ($network['RSSI'] >= -50) { + echo 100; + } elseif ($network['RSSI'] <= -100) { + echo 0; + } else { + echo 2*($network['RSSI'] + 100); + } echo "%)"; ?>
- + - +
@@ -252,14 +256,14 @@ function DisplayWPAConfig(){
Passphrase - + --- - + - +
@@ -282,7 +286,7 @@ function DisplayWPAConfig(){
- +
diff --git a/includes/dashboard.php b/includes/dashboard.php index 4e5c58f9..7b215446 100755 --- a/includes/dashboard.php +++ b/includes/dashboard.php @@ -3,179 +3,180 @@ /** * Show dashboard page. */ -function DisplayDashboard(){ +function DisplayDashboard() +{ - $status = new StatusMessages(); - // Need this check interface name for proper shell execution. - if (!preg_match('/^([a-zA-Z0-9]+)$/', RASPI_WIFI_CLIENT_INTERFACE)) { - $status->addMessage(_('Interface name invalid.'), 'danger'); - $status->showMessages(); - return; - } - - if (!function_exists('exec')) { - $status->addMessage(_('Required exec function is disabled. Check if exec is not added to php disable_functions.'), 'danger'); - $status->showMessages(); - return; - } - - exec('ip a show '.RASPI_WIFI_CLIENT_INTERFACE, $stdoutIp); - $stdoutIpAllLinesGlued = implode(" ", $stdoutIp); - $stdoutIpWRepeatedSpaces = preg_replace('/\s\s+/', ' ', $stdoutIpAllLinesGlued); - - preg_match('/link\/ether ([0-9a-f:]+)/i', $stdoutIpWRepeatedSpaces, $matchesMacAddr ) || $matchesMacAddr[1] = _('No MAC Address Found'); - $macAddr = $matchesMacAddr[1]; - - $ipv4Addrs = ''; - $ipv4Netmasks = ''; - if (!preg_match_all('/inet (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\/([0-3][0-9])/i', $stdoutIpWRepeatedSpaces, $matchesIpv4AddrAndSubnet)) { - $ipv4Addrs = _('No IPv4 Address Found'); - } else { - $numMatchesIpv4AddrAndSubnet = count($matchesIpv4AddrAndSubnet); - for ($i = 1; $i < $numMatchesIpv4AddrAndSubnet; $i += 2) { - if ($i > 2) { - $ipv4Netmasks .= ' '; - $ipv4Addrs .= ' '; - } - - $ipv4Addrs .= $matchesIpv4AddrAndSubnet[$i][0]; - $ipv4Netmasks .= long2ip(-1 << (32 -(int)$matchesIpv4AddrAndSubnet[$i+1][0])); + $status = new StatusMessages(); + // Need this check interface name for proper shell execution. + if (!preg_match('/^([a-zA-Z0-9]+)$/', RASPI_WIFI_CLIENT_INTERFACE)) { + $status->addMessage(_('Interface name invalid.'), 'danger'); + $status->showMessages(); + return; } - } - $ipv6Addrs = ''; - if (!preg_match_all('/inet6 ([a-f0-9:]+)/i', $stdoutIpWRepeatedSpaces, $matchesIpv6Addr)) { - $ipv6Addrs = _('No IPv6 Address Found'); - } else { - $numMatchesIpv6Addr = count($matchesIpv6Addr); - for ($i = 1; $i < $numMatchesIpv6Addr; ++$i) { - if ($i > 1) { - $ipv6Addrs .= ' '; - } - - $ipv6Addrs .= $matchesIpv6Addr[$i]; + if (!function_exists('exec')) { + $status->addMessage(_('Required exec function is disabled. Check if exec is not added to php disable_functions.'), 'danger'); + $status->showMessages(); + return; } - } - preg_match('/state (UP|DOWN)/i', $stdoutIpWRepeatedSpaces, $matchesState ) || $matchesState[1] = 'unknown'; - $interfaceState = $matchesState[1]; + exec('ip a show '.RASPI_WIFI_CLIENT_INTERFACE, $stdoutIp); + $stdoutIpAllLinesGlued = implode(" ", $stdoutIp); + $stdoutIpWRepeatedSpaces = preg_replace('/\s\s+/', ' ', $stdoutIpAllLinesGlued); - // Because of table layout used in the ip output we get the interface statistics directly from - // the system. One advantage of this is that it could work when interface is disable. - exec('cat /sys/class/net/'.RASPI_WIFI_CLIENT_INTERFACE.'/statistics/rx_packets ', $stdoutCatRxPackets); - $strRxPackets = _('No data'); - if (ctype_digit($stdoutCatRxPackets[0])) { - $strRxPackets = $stdoutCatRxPackets[0]; - } + preg_match('/link\/ether ([0-9a-f:]+)/i', $stdoutIpWRepeatedSpaces, $matchesMacAddr) || $matchesMacAddr[1] = _('No MAC Address Found'); + $macAddr = $matchesMacAddr[1]; - exec('cat /sys/class/net/'.RASPI_WIFI_CLIENT_INTERFACE.'/statistics/tx_packets ', $stdoutCatTxPackets); - $strTxPackets = _('No data'); - if (ctype_digit($stdoutCatTxPackets[0])) { - $strTxPackets = $stdoutCatTxPackets[0]; - } + $ipv4Addrs = ''; + $ipv4Netmasks = ''; + if (!preg_match_all('/inet (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\/([0-3][0-9])/i', $stdoutIpWRepeatedSpaces, $matchesIpv4AddrAndSubnet)) { + $ipv4Addrs = _('No IPv4 Address Found'); + } else { + $numMatchesIpv4AddrAndSubnet = count($matchesIpv4AddrAndSubnet); + for ($i = 1; $i < $numMatchesIpv4AddrAndSubnet; $i += 2) { + if ($i > 2) { + $ipv4Netmasks .= ' '; + $ipv4Addrs .= ' '; + } - exec('cat /sys/class/net/'.RASPI_WIFI_CLIENT_INTERFACE.'/statistics/rx_bytes ', $stdoutCatRxBytes); - $strRxBytes = _('No data'); - if (ctype_digit($stdoutCatRxBytes[0])) { - $strRxBytes = $stdoutCatRxBytes[0]; - $strRxBytes .= getHumanReadableDatasize($strRxBytes); - } + $ipv4Addrs .= $matchesIpv4AddrAndSubnet[$i][0]; + $ipv4Netmasks .= long2ip(-1 << (32 -(int)$matchesIpv4AddrAndSubnet[$i+1][0])); + } + } - exec('cat /sys/class/net/'.RASPI_WIFI_CLIENT_INTERFACE.'/statistics/tx_bytes ', $stdoutCatTxBytes); - $strTxBytes = _('No data'); - if (ctype_digit($stdoutCatTxBytes[0])) { - $strTxBytes = $stdoutCatTxBytes[0]; - $strTxBytes .= getHumanReadableDatasize($strTxBytes); - } + $ipv6Addrs = ''; + if (!preg_match_all('/inet6 ([a-f0-9:]+)/i', $stdoutIpWRepeatedSpaces, $matchesIpv6Addr)) { + $ipv6Addrs = _('No IPv6 Address Found'); + } else { + $numMatchesIpv6Addr = count($matchesIpv6Addr); + for ($i = 1; $i < $numMatchesIpv6Addr; ++$i) { + if ($i > 1) { + $ipv6Addrs .= ' '; + } - define('SSIDMAXLEN', 32); - // Warning iw comes with: "Do NOT screenscrape this tool, we don't consider its output stable." - exec('iw dev '.RASPI_WIFI_CLIENT_INTERFACE.' link ', $stdoutIw); - $stdoutIwAllLinesGlued = implode(' ', $stdoutIw); - $stdoutIwWRepSpaces = preg_replace('/\s\s+/', ' ', $stdoutIwAllLinesGlued); + $ipv6Addrs .= $matchesIpv6Addr[$i]; + } + } - preg_match('/Connected to (([0-9A-Fa-f]{2}:){5}([0-9A-Fa-f]{2}))/', $stdoutIwWRepSpaces, $matchesBSSID) || $matchesBSSID[1] = ''; - $connectedBSSID = $matchesBSSID[1]; + preg_match('/state (UP|DOWN)/i', $stdoutIpWRepeatedSpaces, $matchesState) || $matchesState[1] = 'unknown'; + $interfaceState = $matchesState[1]; - $wlanHasLink = false; - if ($interfaceState === 'UP') { - $wlanHasLink = true; - } + // Because of table layout used in the ip output we get the interface statistics directly from + // the system. One advantage of this is that it could work when interface is disable. + exec('cat /sys/class/net/'.RASPI_WIFI_CLIENT_INTERFACE.'/statistics/rx_packets ', $stdoutCatRxPackets); + $strRxPackets = _('No data'); + if (ctype_digit($stdoutCatRxPackets[0])) { + $strRxPackets = $stdoutCatRxPackets[0]; + } + + exec('cat /sys/class/net/'.RASPI_WIFI_CLIENT_INTERFACE.'/statistics/tx_packets ', $stdoutCatTxPackets); + $strTxPackets = _('No data'); + if (ctype_digit($stdoutCatTxPackets[0])) { + $strTxPackets = $stdoutCatTxPackets[0]; + } + + exec('cat /sys/class/net/'.RASPI_WIFI_CLIENT_INTERFACE.'/statistics/rx_bytes ', $stdoutCatRxBytes); + $strRxBytes = _('No data'); + if (ctype_digit($stdoutCatRxBytes[0])) { + $strRxBytes = $stdoutCatRxBytes[0]; + $strRxBytes .= getHumanReadableDatasize($strRxBytes); + } + + exec('cat /sys/class/net/'.RASPI_WIFI_CLIENT_INTERFACE.'/statistics/tx_bytes ', $stdoutCatTxBytes); + $strTxBytes = _('No data'); + if (ctype_digit($stdoutCatTxBytes[0])) { + $strTxBytes = $stdoutCatTxBytes[0]; + $strTxBytes .= getHumanReadableDatasize($strTxBytes); + } + + define('SSIDMAXLEN', 32); + // Warning iw comes with: "Do NOT screenscrape this tool, we don't consider its output stable." + exec('iw dev '.RASPI_WIFI_CLIENT_INTERFACE.' link ', $stdoutIw); + $stdoutIwAllLinesGlued = implode(' ', $stdoutIw); + $stdoutIwWRepSpaces = preg_replace('/\s\s+/', ' ', $stdoutIwAllLinesGlued); + + preg_match('/Connected to (([0-9A-Fa-f]{2}:){5}([0-9A-Fa-f]{2}))/', $stdoutIwWRepSpaces, $matchesBSSID) || $matchesBSSID[1] = ''; + $connectedBSSID = $matchesBSSID[1]; - if (!preg_match('/SSID: ([^ ]{1,'.SSIDMAXLEN.'})/', $stdoutIwWRepSpaces, $matchesSSID)) { $wlanHasLink = false; - $matchesSSID[1] = 'Not connected'; - } - - $connectedSSID = $matchesSSID[1]; - - preg_match('/freq: (\d+)/i', $stdoutIwWRepSpaces, $matchesFrequency) || $matchesFrequency[1] = ''; - $frequency = $matchesFrequency[1].' MHz'; - - preg_match('/signal: (-?[0-9]+ dBm)/i', $stdoutIwWRepSpaces, $matchesSignal) || $matchesSignal[1] = ''; - $signalLevel = $matchesSignal[1]; - - preg_match('/tx bitrate: ([0-9\.]+ [KMGT]?Bit\/s)/', $stdoutIwWRepSpaces, $matchesBitrate) || $matchesBitrate[1] = ''; - $bitrate = $matchesBitrate[1]; - - // txpower is now displayed on iw dev(..) info command, not on link command. - exec('iw dev '.RASPI_WIFI_CLIENT_INTERFACE.' info ', $stdoutIwInfo); - $stdoutIwInfoAllLinesGlued = implode(' ', $stdoutIwInfo); - $stdoutIpInfoWRepSpaces = preg_replace('/\s\s+/', ' ', $stdoutIwInfoAllLinesGlued); - - preg_match('/txpower ([0-9\.]+ dBm)/i', $stdoutIpInfoWRepSpaces, $matchesTxPower ) || $matchesTxPower[1] = ''; - $txPower = $matchesTxPower[1]; - - // iw does not have the "Link Quality". This is a is an aggregate value, - // and depends on the driver and hardware. - // Display link quality as signal quality for now. - $strLinkQuality = 0; - if ($signalLevel > -100 && $wlanHasLink) { - if ($signalLevel >= 0) { - $strLinkQuality = 100; - } else { - $strLinkQuality = 100 + $signalLevel; - } - } - - $wlan0up = false; - $classMsgDevicestatus = 'warning'; - if ($interfaceState === 'UP') { - $wlan0up = true; - $classMsgDevicestatus = 'success'; - } - - - if (isset($_POST['ifdown_wlan0'])) { - // Pressed stop button if ($interfaceState === 'UP') { - $status->addMessage(sprintf(_('Interface is going %s.'), _('down')), 'warning'); - exec( 'sudo ip link set '.RASPI_WIFI_CLIENT_INTERFACE.' down' ); - $wlan0up = false; - $status->addMessage(sprintf(_('Interface is now %s.'), _('down')), 'success'); - } elseif ($interfaceState === 'unknown') { - $status->addMessage(_('Interface state unknown.'), 'danger'); - } else { - $status->addMessage(sprintf(_('Interface already %s.'), _('down')), 'warning'); + $wlanHasLink = true; } - } elseif( isset($_POST['ifup_wlan0']) ) { - // Pressed start button - if ($interfaceState === 'DOWN') { - $status->addMessage(sprintf(_('Interface is going %s.'), _('up')), 'warning'); - exec('sudo ip link set ' . RASPI_WIFI_CLIENT_INTERFACE . ' up'); - exec('sudo ip -s a f label ' . RASPI_WIFI_CLIENT_INTERFACE); - $wlan0up = true; - $status->addMessage(sprintf(_('Interface is now %s.'), _('up')), 'success'); - } elseif ($interfaceState === 'unknown') { - $status->addMessage(_('Interface state unknown.'), 'danger'); - } else { - $status->addMessage(sprintf(_('Interface already %s.'), _('up')), 'warning'); + + if (!preg_match('/SSID: ([^ ]{1,'.SSIDMAXLEN.'})/', $stdoutIwWRepSpaces, $matchesSSID)) { + $wlanHasLink = false; + $matchesSSID[1] = 'Not connected'; } - } else { - $status->addMessage(sprintf(_('Interface is %s.'), strtolower($interfaceState)), $classMsgDevicestatus); - } - ?> -
+ + $connectedSSID = $matchesSSID[1]; + + preg_match('/freq: (\d+)/i', $stdoutIwWRepSpaces, $matchesFrequency) || $matchesFrequency[1] = ''; + $frequency = $matchesFrequency[1].' MHz'; + + preg_match('/signal: (-?[0-9]+ dBm)/i', $stdoutIwWRepSpaces, $matchesSignal) || $matchesSignal[1] = ''; + $signalLevel = $matchesSignal[1]; + + preg_match('/tx bitrate: ([0-9\.]+ [KMGT]?Bit\/s)/', $stdoutIwWRepSpaces, $matchesBitrate) || $matchesBitrate[1] = ''; + $bitrate = $matchesBitrate[1]; + + // txpower is now displayed on iw dev(..) info command, not on link command. + exec('iw dev '.RASPI_WIFI_CLIENT_INTERFACE.' info ', $stdoutIwInfo); + $stdoutIwInfoAllLinesGlued = implode(' ', $stdoutIwInfo); + $stdoutIpInfoWRepSpaces = preg_replace('/\s\s+/', ' ', $stdoutIwInfoAllLinesGlued); + + preg_match('/txpower ([0-9\.]+ dBm)/i', $stdoutIpInfoWRepSpaces, $matchesTxPower) || $matchesTxPower[1] = ''; + $txPower = $matchesTxPower[1]; + + // iw does not have the "Link Quality". This is a is an aggregate value, + // and depends on the driver and hardware. + // Display link quality as signal quality for now. + $strLinkQuality = 0; + if ($signalLevel > -100 && $wlanHasLink) { + if ($signalLevel >= 0) { + $strLinkQuality = 100; + } else { + $strLinkQuality = 100 + $signalLevel; + } + } + + $wlan0up = false; + $classMsgDevicestatus = 'warning'; + if ($interfaceState === 'UP') { + $wlan0up = true; + $classMsgDevicestatus = 'success'; + } + + + if (isset($_POST['ifdown_wlan0'])) { + // Pressed stop button + if ($interfaceState === 'UP') { + $status->addMessage(sprintf(_('Interface is going %s.'), _('down')), 'warning'); + exec('sudo ip link set '.RASPI_WIFI_CLIENT_INTERFACE.' down'); + $wlan0up = false; + $status->addMessage(sprintf(_('Interface is now %s.'), _('down')), 'success'); + } elseif ($interfaceState === 'unknown') { + $status->addMessage(_('Interface state unknown.'), 'danger'); + } else { + $status->addMessage(sprintf(_('Interface already %s.'), _('down')), 'warning'); + } + } elseif (isset($_POST['ifup_wlan0'])) { + // Pressed start button + if ($interfaceState === 'DOWN') { + $status->addMessage(sprintf(_('Interface is going %s.'), _('up')), 'warning'); + exec('sudo ip link set ' . RASPI_WIFI_CLIENT_INTERFACE . ' up'); + exec('sudo ip -s a f label ' . RASPI_WIFI_CLIENT_INTERFACE); + $wlan0up = true; + $status->addMessage(sprintf(_('Interface is now %s.'), _('up')), 'success'); + } elseif ($interfaceState === 'unknown') { + $status->addMessage(_('Interface state unknown.'), 'danger'); + } else { + $status->addMessage(sprintf(_('Interface already %s.'), _('up')), 'warning'); + } + } else { + $status->addMessage(sprintf(_('Interface is %s.'), strtolower($interfaceState)), $classMsgDevicestatus); + } + ?> +
@@ -238,7 +239,7 @@ function DisplayDashboard(){ '.PHP_EOL; echo ''.htmlspecialchars($client_items[3], ENT_QUOTES).''.PHP_EOL; @@ -258,12 +259,12 @@ foreach( $clients as $client ) {
- '; - } else { - echo ''; - } - ?> + '; +} else { + echo ''; +} + ?> " onclick="document.location.reload(true)" />
@@ -274,7 +275,7 @@ foreach( $clients as $client ) {
- = $pib) { - $humanDatasize = ' ('.round($numbytes / $pib, $precision).' PB)'; - } elseif ($numbytes >= $tib) { - $humanDatasize = ' ('.round($numbytes / $tib, $precision).' TB)'; - } elseif ($numbytes >= $gib) { - $humanDatasize = ' ('.round($numbytes / $gib, $precision).' GB)'; - } elseif ($numbytes >= $mib) { - $humanDatasize = ' ('.round($numbytes / $mib, $precision).' MB)'; - } elseif ($numbytes >= $kib) { - $humanDatasize = ' ('.round($numbytes / $kib, $precision).' KB)'; - } + $humanDatasize = ''; + $kib = 1024; + $mib = $kib * 1024; + $gib = $mib * 1024; + $tib = $gib * 1024; + $pib = $tib * 1024; + if ($numbytes >= $pib) { + $humanDatasize = ' ('.round($numbytes / $pib, $precision).' PB)'; + } elseif ($numbytes >= $tib) { + $humanDatasize = ' ('.round($numbytes / $tib, $precision).' TB)'; + } elseif ($numbytes >= $gib) { + $humanDatasize = ' ('.round($numbytes / $gib, $precision).' GB)'; + } elseif ($numbytes >= $mib) { + $humanDatasize = ' ('.round($numbytes / $mib, $precision).' MB)'; + } elseif ($numbytes >= $kib) { + $humanDatasize = ' ('.round($numbytes / $kib, $precision).' KB)'; + } - return $humanDatasize; + return $humanDatasize; } diff --git a/includes/data_usage.php b/includes/data_usage.php index 6436dc3f..a6d0ae8c 100755 --- a/includes/data_usage.php +++ b/includes/data_usage.php @@ -5,7 +5,7 @@ */ function DisplayDataUsage(&$extraFooterScripts) { -exec("ip -o link show | awk -F ': ' '{print $2}' | grep -v lo ", $interfacesWlo); + exec("ip -o link show | awk -F ': ' '{print $2}' | grep -v lo ", $interfacesWlo); ?>
diff --git a/includes/dhcp.php b/includes/dhcp.php index a4fd107a..60793029 100755 --- a/includes/dhcp.php +++ b/includes/dhcp.php @@ -1,139 +1,140 @@ = IFNAMSIZ) { - $errors .= _('Invalid interface name.').'
'.PHP_EOL; - } - - if (!preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\z/', $_POST['RangeStart']) && - !empty($_POST['RangeStart'])) { // allow ''/null ? - $errors .= _('Invalid DHCP range start.').'
'.PHP_EOL; - } - - if (!preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\z/', $_POST['RangeEnd']) && - !empty($_POST['RangeEnd'])) { // allow ''/null ? - $errors .= _('Invalid DHCP range end.').'
'.PHP_EOL; - } - - if (!ctype_digit($_POST['RangeLeaseTime']) && $_POST['RangeLeaseTimeUnits'] !== 'infinite') { - $errors .= _('Invalid DHCP lease time, not a number.').'
'.PHP_EOL; - } - - if (!in_array($_POST['RangeLeaseTimeUnits'], array('m', 'h', 'd', 'infinite'))) { - $errors .= _('Unknown DHCP lease time unit.').'
'.PHP_EOL; - } - - $return = 1; - if (empty($errors)) { - $config = 'interface='.$_POST['interface'].PHP_EOL. - 'dhcp-range='.$_POST['RangeStart'].','.$_POST['RangeEnd']. - ',255.255.255.0,'; - if ($_POST['RangeLeaseTimeUnits'] !== 'infinite') { - $config .= $_POST['RangeLeaseTime']; + $errors .= _('Invalid interface name.').'
'.PHP_EOL; } - $config .= $_POST['RangeLeaseTimeUnits']; - exec('echo "'.$config.'" > /tmp/dhcpddata', $temp); - system('sudo cp /tmp/dhcpddata '.RASPI_DNSMASQ_CONFIG, $return); - } else { - $status->addMessage($errors, 'danger'); - } + if (!preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\z/', $_POST['RangeStart']) && + !empty($_POST['RangeStart'])) { // allow ''/null ? + $errors .= _('Invalid DHCP range start.').'
'.PHP_EOL; + } - if ($return == 0) { - $status->addMessage('Dnsmasq configuration updated successfully', 'success'); + if (!preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\z/', $_POST['RangeEnd']) && + !empty($_POST['RangeEnd'])) { // allow ''/null ? + $errors .= _('Invalid DHCP range end.').'
'.PHP_EOL; + } + + if (!ctype_digit($_POST['RangeLeaseTime']) && $_POST['RangeLeaseTimeUnits'] !== 'infinite') { + $errors .= _('Invalid DHCP lease time, not a number.').'
'.PHP_EOL; + } + + if (!in_array($_POST['RangeLeaseTimeUnits'], array('m', 'h', 'd', 'infinite'))) { + $errors .= _('Unknown DHCP lease time unit.').'
'.PHP_EOL; + } + + $return = 1; + if (empty($errors)) { + $config = 'interface='.$_POST['interface'].PHP_EOL. + 'dhcp-range='.$_POST['RangeStart'].','.$_POST['RangeEnd']. + ',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 { + $status->addMessage($errors, 'danger'); + } + + if ($return == 0) { + $status->addMessage('Dnsmasq configuration updated successfully', 'success'); + } else { + $status->addMessage('Dnsmasq configuration failed to be updated.', 'danger'); + } } else { - $status->addMessage('Dnsmasq configuration failed to be updated.', 'danger'); + error_log('CSRF violation'); + } + } + + exec('pidof dnsmasq | wc -l', $dnsmasq); + $dnsmasq_state = ($dnsmasq[0] > 0); + + if (isset($_POST['startdhcpd'])) { + if (CSRFValidate()) { + if ($dnsmasq_state) { + $status->addMessage('dnsmasq already running', 'info'); + } else { + exec('sudo /etc/init.d/dnsmasq start', $dnsmasq, $return); + if ($return == 0) { + $status->addMessage('Successfully started dnsmasq', 'success'); + $dnsmasq_state = true; + } else { + $status->addMessage('Failed to start dnsmasq', 'danger'); + } + } + } else { + error_log('CSRF violation'); + } + } elseif (isset($_POST['stopdhcpd'])) { + if (CSRFValidate()) { + if ($dnsmasq_state) { + exec('sudo /etc/init.d/dnsmasq stop', $dnsmasq, $return); + if ($return == 0) { + $status->addMessage('Successfully stopped dnsmasq', 'success'); + $dnsmasq_state = false; + } else { + $status->addMessage('Failed to stop dnsmasq', 'danger'); + } + } else { + $status->addMessage('dnsmasq already stopped', 'info'); + } + } else { + error_log('CSRF violation'); } } else { - error_log('CSRF violation'); - } - } - - exec( 'pidof dnsmasq | wc -l',$dnsmasq ); - $dnsmasq_state = ($dnsmasq[0] > 0); - - if( isset( $_POST['startdhcpd'] ) ) { - if (CSRFValidate()) { - if ($dnsmasq_state) { - $status->addMessage('dnsmasq already running', 'info'); - } else { - exec('sudo /etc/init.d/dnsmasq start', $dnsmasq, $return); - if ($return == 0) { - $status->addMessage('Successfully started dnsmasq', 'success'); - $dnsmasq_state = true; + if ($dnsmasq_state) { + $status->addMessage('Dnsmasq is running', 'success'); } else { - $status->addMessage('Failed to start dnsmasq', 'danger'); + $status->addMessage('Dnsmasq is not running', 'warning'); } - } - } else { - error_log('CSRF violation'); } - } elseif( isset($_POST['stopdhcpd'] ) ) { - if (CSRFValidate()) { - if ($dnsmasq_state) { - exec('sudo /etc/init.d/dnsmasq stop', $dnsmasq, $return); - if ($return == 0) { - $status->addMessage('Successfully stopped dnsmasq', 'success'); - $dnsmasq_state = false; - } else { - $status->addMessage('Failed to stop dnsmasq', 'danger'); + + exec('cat '. RASPI_DNSMASQ_CONFIG, $return); + $conf = ParseConfig($return); + $arrRange = explode(",", $conf['dhcp-range']); + $RangeStart = $arrRange[0]; + $RangeEnd = $arrRange[1]; + $RangeMask = $arrRange[2]; + $leaseTime = $arrRange[3]; + + $hselected = ''; + $mselected = ''; + $dselected = ''; + $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; } - } else { - $status->addMessage('dnsmasq already stopped', 'info'); - } - } else { - error_log('CSRF violation'); } - } else { - if( $dnsmasq_state ) { - $status->addMessage('Dnsmasq is running', 'success'); - } else { - $status->addMessage('Dnsmasq is not running', 'warning'); - } - } - - exec( 'cat '. RASPI_DNSMASQ_CONFIG, $return ); - $conf = ParseConfig($return); - $arrRange = explode( ",", $conf['dhcp-range'] ); - $RangeStart = $arrRange[0]; - $RangeEnd = $arrRange[1]; - $RangeMask = $arrRange[2]; - $leaseTime = $arrRange[3]; - - $hselected = ''; - $mselected = ''; - $dselected = ''; - $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; - } - } ?>
@@ -160,18 +161,18 @@ function DisplayDHCPConfig() {
@@ -209,12 +210,12 @@ function DisplayDHCPConfig() { " name="savedhcpdsettings" /> '; + if ($dnsmasq_state) { + echo ''; } else { - echo''; + echo''; } -?> + ?>
@@ -238,11 +239,11 @@ function DisplayDHCPConfig() { '.PHP_EOL; $lease_items = explode(' ', $lease); - foreach( $lease_items as $lease_item ) { + foreach ($lease_items as $lease_item) { echo ' '.htmlspecialchars($lease_item, ENT_QUOTES).''.PHP_EOL; } echo ' '.PHP_EOL; diff --git a/includes/functions.php b/includes/functions.php index 8e4050f5..035a8848 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -1,38 +1,46 @@ $val) { - if(is_array($val)) { + foreach ($array as $key => $val) { + if (is_array($val)) { $res[] = "[$key]"; - foreach($val as $skey => $sval) $res[] = "$skey = ".(is_numeric($sval) ? $sval : '"'.$sval.'"'); + foreach ($val as $skey => $sval) { + $res[] = "$skey = ".(is_numeric($sval) ? $sval : '"'.$sval.'"'); + } + } else { + $res[] = "$key = ".(is_numeric($val) ? $val : '"'.$val.'"'); } - else $res[] = "$key = ".(is_numeric($val) ? $val : '"'.$val.'"'); } - if(safefilerewrite($file, implode("\r\n", $res))) { + if (safefilerewrite($file, implode("\r\n", $res))) { return true; } else { return false; } } -function safefilerewrite($fileName, $dataToSave) { +function safefilerewrite($fileName, $dataToSave) +{ if ($fp = fopen($fileName, 'w')) { - $startTime = microtime(TRUE); + $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)); + 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) { @@ -46,16 +54,16 @@ function safefilerewrite($fileName, $dataToSave) { } } - - /** * * Add CSRF Token to form * */ -function CSRFToken() { +function CSRFToken() +{ ?> - + ' , PHP_EOL; - foreach ( $options as $opt => $label) { - $select = ''; - $key = isAssoc($options) ? $opt : $label; - if( $key == $selected ) { - $select = ' selected="selected"'; +function SelectorOptions($name, $options, $selected = null, $id = null) +{ + echo '' , PHP_EOL; + echo '' , PHP_EOL; + } + + echo '' , PHP_EOL; } /** @@ -118,9 +129,10 @@ function SelectorOptions($name, $options, $selected = null, $id = null) { * @param string $separator * @return $string */ -function GetDistString( $input,$string,$offset,$separator ) { - $string = substr( $input,strpos( $input,$string )+$offset,strpos( substr( $input,strpos( $input,$string )+$offset ), $separator ) ); - return $string; +function GetDistString($input, $string, $offset, $separator) +{ + $string = substr($input, strpos($input, $string)+$offset, strpos(substr($input, strpos($input, $string)+$offset), $separator)); + return $string; } /** @@ -128,16 +140,17 @@ function GetDistString( $input,$string,$offset,$separator ) { * @param array $arrConfig * @return $config */ -function ParseConfig( $arrConfig ) { - $config = array(); - foreach( $arrConfig as $line ) { - $line = trim($line); - if( $line != "" && $line[0] != "#" ) { - $arrLine = explode( "=",$line ); - $config[$arrLine[0]] = ( count($arrLine) > 1 ? $arrLine[1] : true ); - } - } - return $config; +function ParseConfig($arrConfig) +{ + $config = array(); + foreach ($arrConfig as $line) { + $line = trim($line); + if ($line != "" && $line[0] != "#") { + $arrLine = explode("=", $line); + $config[$arrLine[0]] = ( count($arrLine) > 1 ? $arrLine[1] : true ); + } + } + return $config; } /** @@ -145,21 +158,22 @@ function ParseConfig( $arrConfig ) { * @param string $freq * @return $channel */ -function ConvertToChannel( $freq ) { - if ($freq >= 2412 && $freq <= 2484) { - $channel = ($freq - 2407)/5; - } elseif ($freq >= 4915 && $freq <= 4980) { - $channel = ($freq - 4910)/5 + 182; - } elseif ($freq >= 5035 && $freq <= 5865) { - $channel = ($freq - 5030)/5 + 6; - } else { - $channel = -1; - } - if ($channel >= 1 && $channel <= 196) { - return $channel; - } else { - return 'Invalid Channel'; - } +function ConvertToChannel($freq) +{ + if ($freq >= 2412 && $freq <= 2484) { + $channel = ($freq - 2407)/5; + } elseif ($freq >= 4915 && $freq <= 4980) { + $channel = ($freq - 4910)/5 + 182; + } elseif ($freq >= 5035 && $freq <= 5865) { + $channel = ($freq - 5030)/5 + 6; + } else { + $channel = -1; + } + if ($channel >= 1 && $channel <= 196) { + return $channel; + } else { + return 'Invalid Channel'; + } } /** @@ -167,154 +181,156 @@ function ConvertToChannel( $freq ) { * @param string $security * @return string */ -function ConvertToSecurity( $security ) { - $options = array(); - preg_match_all('/\[([^\]]+)\]/s', $security, $matches); - foreach($matches[1] as $match) { - if (preg_match('/^(WPA\d?)/', $match, $protocol_match)) { - $protocol = $protocol_match[1]; - $matchArr = explode('-', $match); - if (count($matchArr) > 2) { - $options[] = htmlspecialchars($protocol . ' ('. $matchArr[2] .')', ENT_QUOTES); - } else { - $options[] = htmlspecialchars($protocol, ENT_QUOTES); - } +function ConvertToSecurity($security) +{ + $options = array(); + preg_match_all('/\[([^\]]+)\]/s', $security, $matches); + foreach ($matches[1] as $match) { + if (preg_match('/^(WPA\d?)/', $match, $protocol_match)) { + $protocol = $protocol_match[1]; + $matchArr = explode('-', $match); + if (count($matchArr) > 2) { + $options[] = htmlspecialchars($protocol . ' ('. $matchArr[2] .')', ENT_QUOTES); + } else { + $options[] = htmlspecialchars($protocol, ENT_QUOTES); + } + } } - } - if (count($options) === 0) { - // This could also be WEP but wpa_supplicant doesn't have a way to determine - // this. - // And you shouldn't be using WEP these days anyway. - return 'Open'; - } else { - return implode('
', $options); - } + if (count($options) === 0) { + // This could also be WEP but wpa_supplicant doesn't have a way to determine + // this. + // And you shouldn't be using WEP these days anyway. + return 'Open'; + } else { + return implode('
', $options); + } } /** * * */ -function DisplayOpenVPNConfig() { +function DisplayOpenVPNConfig() +{ - exec( 'cat '. RASPI_OPENVPN_CLIENT_CONFIG, $returnClient ); - exec( 'cat '. RASPI_OPENVPN_SERVER_CONFIG, $returnServer ); - exec( 'pidof openvpn | wc -l', $openvpnstatus); + exec('cat '. RASPI_OPENVPN_CLIENT_CONFIG, $returnClient); + exec('cat '. RASPI_OPENVPN_SERVER_CONFIG, $returnServer); + exec('pidof openvpn | wc -l', $openvpnstatus); - if( $openvpnstatus[0] == 0 ) { - $status = '
OpenVPN is not running + if ($openvpnstatus[0] == 0) { + $status = '
OpenVPN is not running
'; - } else { - $status = '
OpenVPN is running + } else { + $status = '
OpenVPN is running
'; - } + } - // parse client settings - foreach( $returnClient as $a ) { - if( $a[0] != "#" ) { - $arrLine = explode( " ",$a) ; - $arrClientConfig[$arrLine[0]]=$arrLine[1]; - } - } + // parse client settings + foreach ($returnClient as $a) { + if ($a[0] != "#") { + $arrLine = explode(" ", $a) ; + $arrClientConfig[$arrLine[0]]=$arrLine[1]; + } + } - // parse server settings - foreach( $returnServer as $a ) { - if( $a[0] != "#" ) { - $arrLine = explode( " ",$a) ; - $arrServerConfig[$arrLine[0]]=$arrLine[1]; - } - } - ?> -
-
-
-
Configure OpenVPN
- -
- - - -
-

-
+ // parse server settings + foreach ($returnServer as $a) { + if ($a[0] != "#") { + $arrLine = explode(" ", $a) ; + $arrServerConfig[$arrLine[0]]=$arrLine[1]; + } + } + ?> +
+
+
+
Configure OpenVPN
+ +
+ + + +
+

+
-

Client settings

-
+

Client settings

+ -
-
- - -
-
-
-
- - -
-
-
-
-

Server settings

-
-
- - -
-
-
-
- - -
-
-
-
- - -
-
-
-
- - -
-
-
-
- - -
-
-
-
- - -
-
-
-
- - -
-
-
- - ' , PHP_EOL; - } else { - echo '' , PHP_EOL; - } +
+
+ + +
+
+
+
+ + +
+
+
+
+

Server settings

+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+
+ + ' , PHP_EOL; + } else { + echo '' , PHP_EOL; + } ?> - -
-
- + +
+
+
TOR is not running + if ($torproxystatus[0] == 0) { + $status = '
TOR is not running
'; - } else { - $status = '
TOR is running + } else { + $status = '
TOR is running
'; - } + } - $arrConfig = array(); - foreach( $return as $a ) { - if( $a[0] != "#" ) { - $arrLine = explode( " ",$a) ; - $arrConfig[$arrLine[0]]=$arrLine[1]; - } - } + $arrConfig = array(); + foreach ($return as $a) { + if ($a[0] != "#") { + $arrLine = explode(" ", $a) ; + $arrConfig[$arrLine[0]]=$arrLine[1]; + } + } ?> -
-
-
-
Configure TOR proxy
+
+
+
+
Configure TOR proxy
- + -
-

+
+

-
-

Basic settings

-
-
-
- - -
-
-
-
- - -
-
-
-
- - -
-
-
-
- - -
-
-
-
- - -
-
-
-
- - -
-
-
-
-

Relay settings

-
-
- - -
-
-
-
- - -
-
-
-
- - -
-
-
-
- - -
-
-
-
- - -
-
-
-
- - -
-
-
+
+

Basic settings

+ +
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+

Relay settings

+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+
- - ' , PHP_EOL; - } else { - echo '' , PHP_EOL; - }; - ?> - -
-
- + + ' , PHP_EOL; + } else { + echo '' , PHP_EOL; + }; + ?> + +
+
+
-' , PHP_EOL; +function SaveTORAndVPNConfig() +{ + if (isset($_POST['SaveOpenVPNSettings'])) { + // TODO + } elseif (isset($_POST['SaveTORProxySettings'])) { + // TODO + } elseif (isset($_POST['StartOpenVPN'])) { + echo "Attempting to start openvpn"; + exec('sudo /etc/init.d/openvpn start', $return); + foreach ($return as $line) { + echo htmlspecialchars($line, ENT_QUOTES).'
' , PHP_EOL; + } + } elseif (isset($_POST['StopOpenVPN'])) { + echo "Attempting to stop openvpn"; + exec('sudo /etc/init.d/openvpn stop', $return); + foreach ($return as $line) { + echo htmlspecialchars($line, ENT_QUOTES).'
' , PHP_EOL; + } + } elseif (isset($_POST['StartTOR'])) { + echo "Attempting to start TOR"; + exec('sudo /etc/init.d/tor start', $return); + foreach ($return as $line) { + echo htmlspecialchars($line, ENT_QUOTES).'
' , PHP_EOL; + } + } elseif (isset($_POST['StopTOR'])) { + echo "Attempting to stop TOR"; + exec('sudo /etc/init.d/tor stop', $return); + foreach ($return as $line) { + echo htmlspecialchars($line, ENT_QUOTES).'
' , PHP_EOL; + } } - } elseif( isset($_POST['StopOpenVPN']) ) { - echo "Attempting to stop openvpn"; - exec( 'sudo /etc/init.d/openvpn stop', $return ); - foreach( $return as $line ) { - echo htmlspecialchars($line, ENT_QUOTES).'
' , PHP_EOL; - } - } elseif( isset($_POST['StartTOR']) ) { - echo "Attempting to start TOR"; - exec( 'sudo /etc/init.d/tor start', $return ); - foreach( $return as $line ) { - echo htmlspecialchars($line, ENT_QUOTES).'
' , PHP_EOL; - } - } elseif( isset($_POST['StopTOR']) ) { - echo "Attempting to stop TOR"; - exec( 'sudo /etc/init.d/tor stop', $return ); - foreach( $return as $line ) { - echo htmlspecialchars($line, ENT_QUOTES).'
' , PHP_EOL; - } - } } diff --git a/includes/hostapd.php b/includes/hostapd.php index 92192165..84d84cb4 100755 --- a/includes/hostapd.php +++ b/includes/hostapd.php @@ -1,6 +1,6 @@ '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); - $arrHostapdConf = parse_ini_file('/etc/raspap/hostapd.ini'); + if (isset($_POST['SaveHostAPDSettings'])) { + if (CSRFValidate()) { + SaveHostAPDConfig($arrSecurity, $arrEncType, $arr80211Standard, $interfaces, $status); + } else { + error_log('CSRF violation'); + } + } elseif (isset($_POST['StartHotspot'])) { + if (CSRFValidate()) { + $status->addMessage('Attempting to start hotspot', 'info'); + if ($arrHostapdConf['WifiAPEnable'] == 1) { + exec('sudo /etc/raspap/hostapd/servicestart.sh --interface uap0 --seconds 5', $return); + } else { + exec('sudo /etc/raspap/hostapd/servicestart.sh --seconds 5', $return); + } + foreach ($return as $line) { + $status->addMessage($line, 'info'); + } + } else { + error_log('CSRF violation'); + } + } elseif (isset($_POST['StopHotspot'])) { + if (CSRFValidate()) { + $status->addMessage('Attempting to stop hotspot', 'info'); + exec('sudo /etc/init.d/hostapd stop', $return); + foreach ($return as $line) { + $status->addMessage($line, 'info'); + } + } else { + error_log('CSRF violation'); + } + } - $arrConfig = array(); - $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); + exec('cat '. RASPI_HOSTAPD_CONFIG, $hostapdconfig); + exec('pidof hostapd | wc -l', $hostapdstatus); - if( isset($_POST['SaveHostAPDSettings']) ) { - if (CSRFValidate()) { - SaveHostAPDConfig($arrSecurity, $arrEncType, $arr80211Standard, $interfaces, $status); + if ($hostapdstatus[0] == 0) { + $status->addMessage('HostAPD is not running', 'warning'); } else { - error_log('CSRF violation'); - } - } elseif( isset($_POST['StartHotspot']) ) { - if (CSRFValidate()) { - $status->addMessage('Attempting to start hotspot', 'info'); - if ($arrHostapdConf['WifiAPEnable'] == 1) { - exec('sudo /etc/raspap/hostapd/servicestart.sh --interface uap0 --seconds 5', $return ); - } else { - exec( 'sudo /etc/raspap/hostapd/servicestart.sh --seconds 5', $return ); - } - foreach( $return as $line ) { - $status->addMessage($line, 'info'); - } - } else { - error_log('CSRF violation'); - } - } elseif( isset($_POST['StopHotspot']) ) { - if (CSRFValidate()) { - $status->addMessage('Attempting to stop hotspot', 'info'); - exec( 'sudo /etc/init.d/hostapd stop', $return ); - foreach( $return as $line ) { - $status->addMessage($line, 'info'); - } - } else { - error_log('CSRF violation'); - } - } - - exec( 'cat '. RASPI_HOSTAPD_CONFIG, $hostapdconfig ); - exec( 'pidof hostapd | wc -l', $hostapdstatus); - - if( $hostapdstatus[0] == 0 ) { - $status->addMessage('HostAPD is not running', 'warning'); - } else { - $status->addMessage('HostAPD is running', 'success'); - } - - foreach( $hostapdconfig as $hostapdconfigline ) { - if (strlen($hostapdconfigline) === 0) { - continue; + $status->addMessage('HostAPD is running', 'success'); } - if ($hostapdconfigline[0] != "#" ) { - $arrLine = explode("=", $hostapdconfigline) ; - $arrConfig[$arrLine[0]]=$arrLine[1]; - } - }; + foreach ($hostapdconfig as $hostapdconfigline) { + if (strlen($hostapdconfigline) === 0) { + continue; + } + + if ($hostapdconfigline[0] != "#") { + $arrLine = explode("=", $hostapdconfigline) ; + $arrConfig[$arrLine[0]]=$arrLine[1]; + } + }; ?>
@@ -77,7 +75,7 @@ function DisplayHostAPDConfig()
-

showMessages(); ?>

+

showMessages(); ?>

@@ -169,61 +167,61 @@ if (in_array($arrConfig['country_code'], $countries_max11channels)) {
-

+

- '; - } else { - echo "
Logfile output not enabled"; - } - ?> + '; + } else { + echo "
Logfile output not enabled"; + } + ?>
-

+

-
- + - /> - + /> +
-
- + - /> - + /> +
-
+
- /> - + /> +
@@ -487,10 +485,10 @@ var country = document.getElementById("selected_country").value; var countries = document.getElementById("cbxcountries"); var ops = countries.getElementsByTagName("option"); for (var i = 0; i < ops.length; ++i) { - if(ops[i].value == country){ - ops[i].selected=true; - break; - } + if(ops[i].value == country){ + ops[i].selected=true; + break; + } } @@ -499,203 +497,204 @@ for (var i = 0; i < ops.length; ++i) {
" /> ' , PHP_EOL; - } else { + } else { echo '' , PHP_EOL; - }; + }; ?>
- 14) { - error_log("Attempting to set channel to '".$_POST['channel']."'"); - return false; - } + if (intval($_POST['channel']) < 1 || intval($_POST['channel']) > 14) { + error_log("Attempting to set channel to '".$_POST['channel']."'"); + return false; + } - $good_input = true; + $good_input = true; - // Check for WiFi client AP mode checkbox - $wifiAPEnable = 0; - if($arrHostapdConf['WifiAPEnable'] == 0) { - if(isset($_POST['wifiAPEnable'])) { - $wifiAPEnable = 1; - } - } else { - if(isset($_POST['wifiAPEnable'])) { - $wifiAPEnable = 1; - } - } + // Check for WiFi client AP mode checkbox + $wifiAPEnable = 0; + if ($arrHostapdConf['WifiAPEnable'] == 0) { + if (isset($_POST['wifiAPEnable'])) { + $wifiAPEnable = 1; + } + } else { + if (isset($_POST['wifiAPEnable'])) { + $wifiAPEnable = 1; + } + } - // Check for Logfile output checkbox - $logEnable = 0; - if($arrHostapdConf['LogEnable'] == 0) { - if(isset($_POST['logEnable'])) { - $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'); - } - } - $cfg = []; - $cfg['LogEnable'] = $logEnable; - $cfg['WifiAPEnable'] = $wifiAPEnable; - write_php_ini($cfg,'/etc/raspap/hostapd.ini'); + // Check for Logfile output checkbox + $logEnable = 0; + if ($arrHostapdConf['LogEnable'] == 0) { + if (isset($_POST['logEnable'])) { + $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'); + } + } + $cfg = []; + $cfg['LogEnable'] = $logEnable; + $cfg['WifiAPEnable'] = $wifiAPEnable; + write_php_ini($cfg, '/etc/raspap/hostapd.ini'); - // Verify input - if (empty($_POST['ssid']) || strlen($_POST['ssid']) > 32) { - // Not sure of all the restrictions of SSID - $status->addMessage('SSID must be between 1 and 32 characters', 'danger'); - $good_input = false; - } + // Verify input + if (empty($_POST['ssid']) || strlen($_POST['ssid']) > 32) { + // Not sure of all the restrictions of SSID + $status->addMessage('SSID must be between 1 and 32 characters', 'danger'); + $good_input = false; + } - if ($_POST['wpa'] !== 'none' && + 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; - } + $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; + 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 = $_POST['hiddenSSID']; + $ignore_broadcast_ssid = '0'; } - } 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 '.htmlspecialchars($_POST['interface'], ENT_QUOTES), 'danger'); - $good_input = false; - } + 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 '.htmlspecialchars($_POST['interface'], ENT_QUOTES), 'danger'); + $good_input = false; + } - if (strlen($_POST['country_code']) !== 0 && strlen($_POST['country_code']) != 2) { - $status->addMessage('Country code must be blank or two characters', 'danger'); - $good_input = false; - } + if (strlen($_POST['country_code']) !== 0 && strlen($_POST['country_code']) != 2) { + $status->addMessage('Country code must be blank or two characters', 'danger'); + $good_input = false; + } - if ($good_input) { - // Fixed values - $config = 'driver=nl80211'.PHP_EOL; - $config.= 'ctrl_interface='.RASPI_HOSTAPD_CTRL_INTERFACE.PHP_EOL; - $config.= 'ctrl_interface_group=0'.PHP_EOL; - $config.= 'auth_algs=1'.PHP_EOL; - $config.= 'wpa_key_mgmt=WPA-PSK'.PHP_EOL; - $config.= 'beacon_int=100'.PHP_EOL; - $config.= 'ssid='.$_POST['ssid'].PHP_EOL; - $config.= 'channel='.$_POST['channel'].PHP_EOL; - if ($_POST['hw_mode'] === 'n') { - $config.= 'hw_mode=g'.PHP_EOL; - $config.= 'ieee80211n=1'.PHP_EOL; - // Enable basic Quality of service - $config.= 'wme_enabled=1'.PHP_EOL; + if ($good_input) { + // Fixed values + $config = 'driver=nl80211'.PHP_EOL; + $config.= 'ctrl_interface='.RASPI_HOSTAPD_CTRL_INTERFACE.PHP_EOL; + $config.= 'ctrl_interface_group=0'.PHP_EOL; + $config.= 'auth_algs=1'.PHP_EOL; + $config.= 'wpa_key_mgmt=WPA-PSK'.PHP_EOL; + $config.= 'beacon_int=100'.PHP_EOL; + $config.= 'ssid='.$_POST['ssid'].PHP_EOL; + $config.= 'channel='.$_POST['channel'].PHP_EOL; + if ($_POST['hw_mode'] === 'n') { + $config.= 'hw_mode=g'.PHP_EOL; + $config.= 'ieee80211n=1'.PHP_EOL; + // Enable basic Quality of service + $config.= 'wme_enabled=1'.PHP_EOL; + } else { + $config.= 'hw_mode='.$_POST['hw_mode'].PHP_EOL; + $config.= 'ieee80211n=0'.PHP_EOL; + } + $config.= 'wpa_passphrase='.$_POST['wpa_passphrase'].PHP_EOL; + if ($wifiAPEnable == 1) { + $config.= 'interface=uap0'.PHP_EOL; + } else { + $config.= 'interface='.$_POST['interface'].PHP_EOL; + } + $config.= 'wpa='.$_POST['wpa'].PHP_EOL; + $config.= 'wpa_pairwise='.$_POST['wpa_pairwise'].PHP_EOL; + $config.= 'country_code='.$_POST['country_code'].PHP_EOL; + $config.= 'ignore_broadcast_ssid='.$ignore_broadcast_ssid.PHP_EOL; + + exec('echo "'.$config.'" > /tmp/hostapddata', $temp); + system("sudo cp /tmp/hostapddata " . RASPI_HOSTAPD_CONFIG, $return); + + if ($wifiAPEnable == 1) { + // Enable uap0 configuration in dnsmasq for Wifi client AP mode + $config = 'interface=lo,uap0 # Enable uap0 interface for wireless client AP mode'.PHP_EOL; + $config.= 'bind-interfaces # Bind to the interfaces'.PHP_EOL; + $config.= 'server=8.8.8.8 # Forward DNS requests to Google DNS'.PHP_EOL; + $config.= 'domain-needed # Don\'t forward short names'.PHP_EOL; + $config.= 'bogus-priv # Never forward addresses in the non-routed address spaces'.PHP_EOL; + $config.= 'dhcp-range=192.168.50.50,192.168.50.150,12h'.PHP_EOL; + } else { + // Fallback to default config + $config = 'domain-needed'.PHP_EOL; + $config.= 'interface='.$_POST['interface'].PHP_EOL; + $config.= 'dhcp-range=10.3.141.50,10.3.141.255,255.255.255.0,12h'.PHP_EOL; + } + exec('echo "'.$config.'" > /tmp/dhcpddata', $temp); + system('sudo cp /tmp/dhcpddata '.RASPI_DNSMASQ_CONFIG, $return); + + if ($wifiAPEnable == 1) { + // Enable uap0 configuration in dhcpcd for Wifi client AP mode + $config = PHP_EOL.'# RaspAP uap0 configuration'.PHP_EOL; + $config.= 'interface uap0'.PHP_EOL; + $config.= 'static ip_address=192.168.50.1/24'.PHP_EOL; + $config.= 'nohook wpa_supplicant'.PHP_EOL; + } else { + // Default config + $config = '# RaspAP wlan0 configuration'.PHP_EOL; + $config.= 'hostname'.PHP_EOL; + $config.= 'clientid'.PHP_EOL; + $config.= 'persistent'.PHP_EOL; + $config.= 'option rapid_commit'.PHP_EOL; + $config.= 'option domain_name_servers, domain_name, domain_search, host_name'.PHP_EOL; + $config.= 'option classless_static_routes'.PHP_EOL; + $config.= 'option ntp_servers'.PHP_EOL; + $config.= 'require dhcp_server_identifier'.PHP_EOL; + $config.= 'slaac private'.PHP_EOL; + $config.= 'nohook lookup-hostname'.PHP_EOL; + $config.= 'interface '.RASPI_WIFI_CLIENT_INTERFACE.PHP_EOL; + $config.= 'static ip_address=10.3.141.1/24'.PHP_EOL; + $config.= 'static routers=10.3.141.1'.PHP_EOL; + $config.= 'static domain_name_server=1.1.1.1 8.8.8.8'.PHP_EOL; + } + exec('echo "'.$config.'" > /tmp/dhcpddata', $temp); + system('sudo cp /tmp/dhcpddata '.RASPI_DHCPCD_CONFIG, $return); + + + if ($return == 0) { + $status->addMessage('Wifi Hotspot settings saved', 'success'); + } else { + $status->addMessage('Unable to save wifi hotspot settings', 'danger'); + } } else { - $config.= 'hw_mode='.$_POST['hw_mode'].PHP_EOL; - $config.= 'ieee80211n=0'.PHP_EOL; + $status->addMessage('Unable to save wifi hotspot settings', 'danger'); + return false; } - $config.= 'wpa_passphrase='.$_POST['wpa_passphrase'].PHP_EOL; - if ($wifiAPEnable == 1) { - $config.= 'interface=uap0'.PHP_EOL; - } else { - $config.= 'interface='.$_POST['interface'].PHP_EOL; - } - $config.= 'wpa='.$_POST['wpa'].PHP_EOL; - $config.= 'wpa_pairwise='.$_POST['wpa_pairwise'].PHP_EOL; - $config.= 'country_code='.$_POST['country_code'].PHP_EOL; - $config.= 'ignore_broadcast_ssid='.$ignore_broadcast_ssid.PHP_EOL; - exec('echo "'.$config.'" > /tmp/hostapddata', $temp); - system( "sudo cp /tmp/hostapddata " . RASPI_HOSTAPD_CONFIG, $return ); - - if ($wifiAPEnable == 1) { - // Enable uap0 configuration in dnsmasq for Wifi client AP mode - $config = 'interface=lo,uap0 # Enable uap0 interface for wireless client AP mode'.PHP_EOL; - $config.= 'bind-interfaces # Bind to the interfaces'.PHP_EOL; - $config.= 'server=8.8.8.8 # Forward DNS requests to Google DNS'.PHP_EOL; - $config.= 'domain-needed # Don\'t forward short names'.PHP_EOL; - $config.= 'bogus-priv # Never forward addresses in the non-routed address spaces'.PHP_EOL; - $config.= 'dhcp-range=192.168.50.50,192.168.50.150,12h'.PHP_EOL; - } else { - // Fallback to default config - $config = 'domain-needed'.PHP_EOL; - $config.= 'interface='.$_POST['interface'].PHP_EOL; - $config.= 'dhcp-range=10.3.141.50,10.3.141.255,255.255.255.0,12h'.PHP_EOL; - } - exec('echo "'.$config.'" > /tmp/dhcpddata', $temp); - system('sudo cp /tmp/dhcpddata '.RASPI_DNSMASQ_CONFIG, $return); - - if ($wifiAPEnable == 1) { - // Enable uap0 configuration in dhcpcd for Wifi client AP mode - $config = PHP_EOL.'# RaspAP uap0 configuration'.PHP_EOL; - $config.= 'interface uap0'.PHP_EOL; - $config.= 'static ip_address=192.168.50.1/24'.PHP_EOL; - $config.= 'nohook wpa_supplicant'.PHP_EOL; - } else { - // Default config - $config = '# RaspAP wlan0 configuration'.PHP_EOL; - $config.= 'hostname'.PHP_EOL; - $config.= 'clientid'.PHP_EOL; - $config.= 'persistent'.PHP_EOL; - $config.= 'option rapid_commit'.PHP_EOL; - $config.= 'option domain_name_servers, domain_name, domain_search, host_name'.PHP_EOL; - $config.= 'option classless_static_routes'.PHP_EOL; - $config.= 'option ntp_servers'.PHP_EOL; - $config.= 'require dhcp_server_identifier'.PHP_EOL; - $config.= 'slaac private'.PHP_EOL; - $config.= 'nohook lookup-hostname'.PHP_EOL; - $config.= 'interface '.RASPI_WIFI_CLIENT_INTERFACE.PHP_EOL; - $config.= 'static ip_address=10.3.141.1/24'.PHP_EOL; - $config.= 'static routers=10.3.141.1'.PHP_EOL; - $config.= 'static domain_name_server=1.1.1.1 8.8.8.8'.PHP_EOL; - } - exec('echo "'.$config.'" > /tmp/dhcpddata', $temp); - system('sudo cp /tmp/dhcpddata '.RASPI_DHCPCD_CONFIG, $return); - - - if( $return == 0 ) { - $status->addMessage('Wifi Hotspot settings saved', 'success'); - } else { - $status->addMessage('Unable to save wifi hotspot settings', 'danger'); - } - } else { - $status->addMessage('Unable to save wifi hotspot settings', 'danger'); - return false; - } - - return true; + return true; } diff --git a/includes/locale.php b/includes/locale.php index 4efe07ac..ac07f8da 100755 --- a/includes/locale.php +++ b/includes/locale.php @@ -1,64 +1,62 @@ = 2) { - $lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2); - switch ($lang){ - case "de": - $locale = "de_DE.UTF-8"; - break; - case "fr": - $locale = "fr_FR.UTF-8"; - break; - case "it": - $locale = "it_IT.UTF-8"; - break; - case "pt": - $locale = "pt_BR.UTF-8"; - break; - case "sv": - $locale = "sv_SE.UTF-8"; - break; - case "nl": - $locale = "nl_NL.UTF-8"; - break; - case "zh": - $locale = "zh_CN.UTF-8"; - break; - case "cs": - $locale = "cs_CZ.UTF-8"; - break; - case "ru": - $locale = "ru_RU.UTF-8"; - break; - case "es": - $locale = "es_MX.UTF-8"; - break; - case "fi": - $locale = "fi_FI.UTF-8"; - break; - case "si": - $locale = "si_LK.UTF-8"; - break; - default: - $locale = "en_GB.UTF-8"; - break; - } + $lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2); + switch ($lang) { + case "de": + $locale = "de_DE.UTF-8"; + break; + case "fr": + $locale = "fr_FR.UTF-8"; + break; + case "it": + $locale = "it_IT.UTF-8"; + break; + case "pt": + $locale = "pt_BR.UTF-8"; + break; + case "sv": + $locale = "sv_SE.UTF-8"; + break; + case "nl": + $locale = "nl_NL.UTF-8"; + break; + case "zh": + $locale = "zh_CN.UTF-8"; + break; + case "cs": + $locale = "cs_CZ.UTF-8"; + break; + case "ru": + $locale = "ru_RU.UTF-8"; + break; + case "es": + $locale = "es_MX.UTF-8"; + break; + case "fi": + $locale = "fi_FI.UTF-8"; + break; + case "si": + $locale = "si_LK.UTF-8"; + break; + default: + $locale = "en_GB.UTF-8"; + break; + } - $_SESSION['locale'] = $locale; + $_SESSION['locale'] = $locale; } // Note: the associated locale must be installed on the RPi @@ -72,4 +70,3 @@ bindtextdomain(LOCALE_DOMAIN, LOCALE_ROOT); bind_textdomain_codeset(LOCALE_DOMAIN, 'UTF-8'); textdomain(LOCALE_DOMAIN); - diff --git a/includes/networking.php b/includes/networking.php index 25a40542..364e3e35 100755 --- a/includes/networking.php +++ b/includes/networking.php @@ -1,63 +1,64 @@
-
+
-

+

- +
'.htmlspecialchars($interface, ENT_QUOTES).'
'; } - ?> + ?>
- +
@@ -110,11 +111,11 @@ function DisplayNetworkingConfig(){
'; - } +} ?>
- +
diff --git a/includes/status_messages.php b/includes/status_messages.php index 5452baf9..8f639699 100755 --- a/includes/status_messages.php +++ b/includes/status_messages.php @@ -1,22 +1,30 @@ '. _($message); - if ($dismissable) $status .= ''; - $status .= '
'; + public function addMessage($message, $level = 'success', $dismissable = true) + { + $status = '
'. _($message); + if ($dismissable) { + $status .= ''; + } + $status .= '
'; - array_push($this->messages, $status); - } - - public function showMessages($clear = true) { - foreach($this->messages as $message) { - echo $message; + array_push($this->messages, $status); + } + + public function showMessages($clear = true) + { + foreach ($this->messages as $message) { + echo $message; + } + if ($clear) { + $this->messages = array(); + } } - if ( $clear ) $this->messages = array(); - } } -?> diff --git a/includes/system.php b/includes/system.php index f5b23eca..0f4f0c2c 100755 --- a/includes/system.php +++ b/includes/system.php @@ -1,6 +1,6 @@ 'Model B Revision 1.0', '0003' => 'Model B Revision 1.0 + ECN0001', '0004' => 'Model B Revision 2.0 (256 MB)', @@ -40,39 +41,40 @@ function RPiVersion() { 'a220a0' => 'Compute Module 3', 'a020a0' => 'Compute Module 3', 'a02100' => 'Compute Module 3+', - ); + ); - $cpuinfo_array = ''; - exec('cat /proc/cpuinfo', $cpuinfo_array); - $rev = trim(array_pop(explode(':',array_pop(preg_grep("/^Revision/", $cpuinfo_array))))); - if (array_key_exists($rev, $revisions)) { - return $revisions[$rev]; - } else { - return 'Unknown Pi'; - } + $cpuinfo_array = ''; + exec('cat /proc/cpuinfo', $cpuinfo_array); + $rev = trim(array_pop(explode(':', array_pop(preg_grep("/^Revision/", $cpuinfo_array))))); + if (array_key_exists($rev, $revisions)) { + return $revisions[$rev]; + } else { + return 'Unknown Pi'; + } } /** * * */ -function DisplaySystem(){ +function DisplaySystem() +{ - $status = new StatusMessages(); + $status = new StatusMessages(); - if( isset($_POST['SaveLanguage']) ) { - if (CSRFValidate()) { - if(isset($_POST['locale'])) { - $_SESSION['locale'] = $_POST['locale']; - $status->addMessage('Language setting saved', 'success'); - } - } else { - error_log('CSRF violation'); + if (isset($_POST['SaveLanguage'])) { + if (CSRFValidate()) { + if (isset($_POST['locale'])) { + $_SESSION['locale'] = $_POST['locale']; + $status->addMessage('Language setting saved', 'success'); + } + } else { + error_log('CSRF violation'); + } } - } - // define locales - $arrLocales = array( + // define locales + $arrLocales = array( 'en_GB.UTF-8' => 'English', 'de_DE.UTF-8' => 'Deutsch', 'fr_FR.UTF-8' => 'Français', @@ -86,40 +88,54 @@ function DisplaySystem(){ 'es_MX.UTF-8' => 'Español', 'fi_FI.UTF-8' => 'Finnish', 'si_LK.UTF-8' => 'Sinhala' - ); + ); - // hostname - exec("hostname -f", $hostarray); - $hostname = $hostarray[0]; + // hostname + exec("hostname -f", $hostarray); + $hostname = $hostarray[0]; - // uptime - $uparray = explode(" ", exec("cat /proc/uptime")); - $seconds = round($uparray[0], 0); - $minutes = $seconds / 60; - $hours = $minutes / 60; - $days = floor($hours / 24); - $hours = floor($hours - ($days * 24)); - $minutes = floor($minutes - ($days * 24 * 60) - ($hours * 60)); - $uptime= ''; - if ($days != 0) { $uptime .= $days . ' day' . (($days > 1)? 's ':' '); } - if ($hours != 0) { $uptime .= $hours . ' hour' . (($hours > 1)? 's ':' '); } - if ($minutes != 0) { $uptime .= $minutes . ' minute' . (($minutes > 1)? 's ':' '); } + // uptime + $uparray = explode(" ", exec("cat /proc/uptime")); + $seconds = round($uparray[0], 0); + $minutes = $seconds / 60; + $hours = $minutes / 60; + $days = floor($hours / 24); + $hours = floor($hours - ($days * 24)); + $minutes = floor($minutes - ($days * 24 * 60) - ($hours * 60)); + $uptime= ''; + if ($days != 0) { + $uptime .= $days . ' day' . (($days > 1)? 's ':' '); + } + if ($hours != 0) { + $uptime .= $hours . ' hour' . (($hours > 1)? 's ':' '); + } + if ($minutes != 0) { + $uptime .= $minutes . ' minute' . (($minutes > 1)? 's ':' '); + } - // mem used - $memused_status = "primary"; - exec("free -m | awk '/Mem:/ { total=$2 ; used=$3 } END { print used/total*100}'", $memarray); - $memused = floor($memarray[0]); - if ($memused > 90) { $memused_status = "danger"; } - elseif ($memused > 75) { $memused_status = "warning"; } - elseif ($memused > 0) { $memused_status = "success"; } + // mem used + $memused_status = "primary"; + exec("free -m | awk '/Mem:/ { total=$2 ; used=$3 } END { print used/total*100}'", $memarray); + $memused = floor($memarray[0]); + if ($memused > 90) { + $memused_status = "danger"; + } elseif ($memused > 75) { + $memused_status = "warning"; + } elseif ($memused > 0) { + $memused_status = "success"; + } - // cpu load - $cores = exec("grep -c ^processor /proc/cpuinfo"); - $loadavg = exec("awk '{print $1}' /proc/loadavg"); - $cpuload = floor(($loadavg * 100) / $cores); - if ($cpuload > 90) { $cpuload_status = "danger"; } - elseif ($cpuload > 75) { $cpuload_status = "warning"; } - elseif ($cpuload > 0) { $cpuload_status = "success"; } + // cpu load + $cores = exec("grep -c ^processor /proc/cpuinfo"); + $loadavg = exec("awk '{print $1}' /proc/loadavg"); + $cpuload = floor(($loadavg * 100) / $cores); + if ($cpuload > 90) { + $cpuload_status = "danger"; + } elseif ($cpuload > 75) { + $cpuload_status = "warning"; + } elseif ($cpuload > 0) { + $cpuload_status = "success"; + } ?>
@@ -129,14 +145,14 @@ function DisplaySystem(){
' . _("System Rebooting Now!") . '
'; $result = shell_exec("sudo /sbin/reboot"); - } - if (isset($_POST['system_shutdown'])) { +} +if (isset($_POST['system_shutdown'])) { echo '
' . _("System Shutting Down Now!") . '
'; $result = shell_exec("sudo /sbin/shutdown -h now"); - } +} ?>
@@ -187,7 +203,7 @@ function DisplaySystem(){

- +
diff --git a/includes/themes.php b/includes/themes.php index fded5bd3..dac35e18 100755 --- a/includes/themes.php +++ b/includes/themes.php @@ -3,25 +3,26 @@ * * */ -function DisplayThemeConfig(){ +function DisplayThemeConfig() +{ - $cselected = ''; - $hselected = ''; - $tselected = ''; + $cselected = ''; + $hselected = ''; + $tselected = ''; - switch( $_COOKIE['theme'] ) { - case "custom.css": - $cselected = ' selected="selected"'; - break; - case "hackernews.css": - $hselected = ' selected="selected"'; - break; - case "terminal.css": - $tselected = ' selected="selected"'; - break; - } + switch ($_COOKIE['theme']) { + case "custom.css": + $cselected = ' selected="selected"'; + break; + case "hackernews.css": + $hselected = ' selected="selected"'; + break; + case "terminal.css": + $tselected = ' selected="selected"'; + break; + } - ?> +?>
@@ -57,6 +58,6 @@ function DisplayThemeConfig(){
- * @author Bill Zimmerman * @license GNU General Public License, version 3 (GPL-3.0) @@ -20,21 +20,21 @@ session_start(); -include_once( 'includes/config.php' ); -include_once( RASPI_CONFIG.'/raspap.php' ); -include_once( 'includes/locale.php'); -include_once( 'includes/functions.php' ); -include_once( 'includes/dashboard.php' ); -include_once( 'includes/authenticate.php' ); -include_once( 'includes/admin.php' ); -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' ); -include_once( 'includes/data_usage.php' ); -include_once( 'includes/about.php' ); +include_once('includes/config.php'); +include_once(RASPI_CONFIG.'/raspap.php'); +include_once('includes/locale.php'); +include_once('includes/functions.php'); +include_once('includes/dashboard.php'); +include_once('includes/authenticate.php'); +include_once('includes/admin.php'); +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'); +include_once('includes/data_usage.php'); +include_once('includes/about.php'); $output = $return = 0; $page = $_GET['page']; @@ -48,7 +48,7 @@ if (empty($_SESSION['csrf_token'])) { } $csrf_token = $_SESSION['csrf_token']; -if(!isset($_COOKIE['theme'])) { +if (!isset($_COOKIE['theme'])) { $theme = "custom.css"; } else { $theme = $_COOKIE['theme']; @@ -111,7 +111,7 @@ $theme_url = 'dist/css/'.htmlspecialchars($theme, ENT_QUOTES); - v + v
@@ -122,51 +122,51 @@ $theme_url = 'dist/css/'.htmlspecialchars($theme, ENT_QUOTES);
  • - +
  • -
  • - - + + +
  • - - + +
  • - +
  • - - + +
  • - - + +
  • - - + +
  • - - + +
  • - - + +
  • - - + +
  • - +
  • @@ -189,51 +189,51 @@ $theme_url = 'dist/css/'.htmlspecialchars($theme, ENT_QUOTES);
    - diff --git a/raspap.php b/raspap.php index 3ec743da..9487720c 100755 --- a/raspap.php +++ b/raspap.php @@ -1,15 +1,14 @@ 'admin', - 'admin_pass' => '$2y$10$YKIyWAmnQLtiJAy6QgHQ.eCpY4m.HCEbiHaTgN6.acNC6bDElzt.i' + 'admin_user' => 'admin', + 'admin_pass' => '$2y$10$YKIyWAmnQLtiJAy6QgHQ.eCpY4m.HCEbiHaTgN6.acNC6bDElzt.i' ); -if(file_exists(RASPI_CONFIG.'/raspap.auth')) { - if ( $auth_details = fopen(RASPI_CONFIG.'/raspap.auth', 'r') ) { - $config['admin_user'] = trim(fgets($auth_details)); - $config['admin_pass'] = trim(fgets($auth_details)); - fclose($auth_details); +if (file_exists(RASPI_CONFIG.'/raspap.auth')) { + if ($auth_details = fopen(RASPI_CONFIG.'/raspap.auth', 'r')) { + $config['admin_user'] = trim(fgets($auth_details)); + $config['admin_pass'] = trim(fgets($auth_details)); + fclose($auth_details); } } -?>