From 457da910083f13ec754bf8ee4bb9667b92105bc5 Mon Sep 17 00:00:00 2001 From: billz Date: Sat, 15 Feb 2020 17:57:46 +0000 Subject: [PATCH] Processed with phpcbf --- ajax/bandwidth/get_bandwidth.php | 22 +- ajax/bandwidth/get_bandwidth_hourly.php | 132 +-- ajax/networking/gen_int_config.php | 6 +- ajax/networking/get_all_interfaces.php | 2 +- ajax/networking/get_channel.php | 6 +- ajax/networking/get_int_config.php | 6 +- ajax/networking/get_ip_summary.php | 4 +- ajax/networking/save_int_config.php | 6 +- ajax/networking/wifi_stations.php | 10 +- includes/about.php | 2 - includes/admin.php | 2 +- includes/configure_client.php | 10 +- includes/csrf.php | 4 +- includes/dashboard.php | 48 +- includes/defaults.php | 8 +- includes/dhcp.php | 91 +- includes/functions.php | 89 +- includes/hostapd.php | 58 +- includes/locale.php | 131 ++- includes/networking.php | 8 +- includes/openvpn.php | 55 +- includes/sysstats.php | 2 +- includes/system.php | 6 +- includes/themes.php | 6 +- includes/torproxy.php | 26 +- includes/webconsole.php | 1087 ++++++++++++----------- includes/wifi_functions.php | 56 +- index.php | 148 +-- 28 files changed, 1062 insertions(+), 969 deletions(-) diff --git a/ajax/bandwidth/get_bandwidth.php b/ajax/bandwidth/get_bandwidth.php index 37d4adc9..db9ebfe8 100644 --- a/ajax/bandwidth/get_bandwidth.php +++ b/ajax/bandwidth/get_bandwidth.php @@ -1,6 +1,6 @@ IFNAMSIZ) { require_once './get_bandwidth_hourly.php'; -exec(sprintf('vnstat -i %s --json ', escapeshellarg($interface)), $jsonstdoutvnstat, - $exitcodedaily); +exec( + sprintf('vnstat -i %s --json ', escapeshellarg($interface)), $jsonstdoutvnstat, + $exitcodedaily +); if ($exitcodedaily !== 0) { - exit('vnstat error'); + exit('vnstat error'); } $jsonobj = json_decode($jsonstdoutvnstat[0], true); @@ -53,12 +55,16 @@ echo '[ '; $firstelm = true; for ($i = count($jsonData) - 1; $i >= 0; --$i) { if ($timeunits === 'm') { - $dt = DateTime::createFromFormat('Y n', $jsonData[$i]['date']['year'].' '. - $jsonData[$i]['date']['month']); + $dt = DateTime::createFromFormat( + 'Y n', $jsonData[$i]['date']['year'].' '. + $jsonData[$i]['date']['month'] + ); } else { - $dt = DateTime::createFromFormat('Y n j', $jsonData[$i]['date']['year'].' '. + $dt = DateTime::createFromFormat( + 'Y n j', $jsonData[$i]['date']['year'].' '. $jsonData[$i]['date']['month'].' '. - $jsonData[$i]['date']['day']); + $jsonData[$i]['date']['day'] + ); } if ($firstelm) { diff --git a/ajax/bandwidth/get_bandwidth_hourly.php b/ajax/bandwidth/get_bandwidth_hourly.php index 482b6c6f..bc1c48b5 100644 --- a/ajax/bandwidth/get_bandwidth_hourly.php +++ b/ajax/bandwidth/get_bandwidth_hourly.php @@ -1,66 +1,66 @@ - array('date' => '00:00', 'rx' => 0, 'tx' => 0), - 1 => array('date' => '01:00', 'rx' => 0, 'tx' => 0), - 2 => array('date' => '02:00', 'rx' => 0, 'tx' => 0), - 3 => array('date' => '03:00', 'rx' => 0, 'tx' => 0), - 4 => array('date' => '04:00', 'rx' => 0, 'tx' => 0), - 5 => array('date' => '05:00', 'rx' => 0, 'tx' => 0), - 6 => array('date' => '06:00', 'rx' => 0, 'tx' => 0), - 7 => array('date' => '07:00', 'rx' => 0, 'tx' => 0), - 8 => array('date' => '08:00', 'rx' => 0, 'tx' => 0), - 9 => array('date' => '09:00', 'rx' => 0, 'tx' => 0), - 10 => array('date' => '10:00', 'rx' => 0, 'tx' => 0), - 11 => array('date' => '11:00', 'rx' => 0, 'tx' => 0), - 12 => array('date' => '12:00', 'rx' => 0, 'tx' => 0), - 13 => array('date' => '13:00', 'rx' => 0, 'tx' => 0), - 14 => array('date' => '14:00', 'rx' => 0, 'tx' => 0), - 15 => array('date' => '15:00', 'rx' => 0, 'tx' => 0), - 16 => array('date' => '16:00', 'rx' => 0, 'tx' => 0), - 17 => array('date' => '17:00', 'rx' => 0, 'tx' => 0), - 18 => array('date' => '18:00', 'rx' => 0, 'tx' => 0), - 19 => array('date' => '19:00', 'rx' => 0, 'tx' => 0), - 20 => array('date' => '20:00', 'rx' => 0, 'tx' => 0), - 21 => array('date' => '21:00', 'rx' => 0, 'tx' => 0), - 22 => array('date' => '22:00', 'rx' => 0, 'tx' => 0), - 23 => array('date' => '23:00', 'rx' => 0, 'tx' => 0) - ); - - - - - exec(sprintf('vnstat -i %s --json h', escapeshellarg($interface)), $jsonstdoutvnstat, $exitcodedaily); - if ($exitcodedaily !== 0) { - exit('vnstat error'); - } - - $jsonobj = json_decode($jsonstdoutvnstat[0], true)['interfaces'][0]; - $jsonData = $jsonobj['traffic']['hours']; - for ($i = count($jsonData) - 1; $i >= 0; --$i) { - $data_template[$jsonData[$i]['id']]['rx'] = round($jsonData[$i]['rx'] / 1024, 0); - $data_template[$jsonData[$i]['id']]['tx'] = round($jsonData[$i]['tx'] / 1024, 0); - } - - $data = array(); - $hour = $jsonobj['updated']['time']['hour']; - foreach ($data_template as $key => $value) { - if ($key > $hour) { - array_push($data, $value); - } - } - foreach ($data_template as $key => $value) { - if ($key <= $hour) { - array_push($data, $value); - } - } - echo json_encode($data); - exit(0); -} + array('date' => '00:00', 'rx' => 0, 'tx' => 0), + 1 => array('date' => '01:00', 'rx' => 0, 'tx' => 0), + 2 => array('date' => '02:00', 'rx' => 0, 'tx' => 0), + 3 => array('date' => '03:00', 'rx' => 0, 'tx' => 0), + 4 => array('date' => '04:00', 'rx' => 0, 'tx' => 0), + 5 => array('date' => '05:00', 'rx' => 0, 'tx' => 0), + 6 => array('date' => '06:00', 'rx' => 0, 'tx' => 0), + 7 => array('date' => '07:00', 'rx' => 0, 'tx' => 0), + 8 => array('date' => '08:00', 'rx' => 0, 'tx' => 0), + 9 => array('date' => '09:00', 'rx' => 0, 'tx' => 0), + 10 => array('date' => '10:00', 'rx' => 0, 'tx' => 0), + 11 => array('date' => '11:00', 'rx' => 0, 'tx' => 0), + 12 => array('date' => '12:00', 'rx' => 0, 'tx' => 0), + 13 => array('date' => '13:00', 'rx' => 0, 'tx' => 0), + 14 => array('date' => '14:00', 'rx' => 0, 'tx' => 0), + 15 => array('date' => '15:00', 'rx' => 0, 'tx' => 0), + 16 => array('date' => '16:00', 'rx' => 0, 'tx' => 0), + 17 => array('date' => '17:00', 'rx' => 0, 'tx' => 0), + 18 => array('date' => '18:00', 'rx' => 0, 'tx' => 0), + 19 => array('date' => '19:00', 'rx' => 0, 'tx' => 0), + 20 => array('date' => '20:00', 'rx' => 0, 'tx' => 0), + 21 => array('date' => '21:00', 'rx' => 0, 'tx' => 0), + 22 => array('date' => '22:00', 'rx' => 0, 'tx' => 0), + 23 => array('date' => '23:00', 'rx' => 0, 'tx' => 0) + ); + + + + + exec(sprintf('vnstat -i %s --json h', escapeshellarg($interface)), $jsonstdoutvnstat, $exitcodedaily); + if ($exitcodedaily !== 0) { + exit('vnstat error'); + } + + $jsonobj = json_decode($jsonstdoutvnstat[0], true)['interfaces'][0]; + $jsonData = $jsonobj['traffic']['hours']; + for ($i = count($jsonData) - 1; $i >= 0; --$i) { + $data_template[$jsonData[$i]['id']]['rx'] = round($jsonData[$i]['rx'] / 1024, 0); + $data_template[$jsonData[$i]['id']]['tx'] = round($jsonData[$i]['tx'] / 1024, 0); + } + + $data = array(); + $hour = $jsonobj['updated']['time']['hour']; + foreach ($data_template as $key => $value) { + if ($key > $hour) { + array_push($data, $value); + } + } + foreach ($data_template as $key => $value) { + if ($key <= $hour) { + array_push($data, $value); + } + } + echo json_encode($data); + exit(0); +} diff --git a/ajax/networking/gen_int_config.php b/ajax/networking/gen_int_config.php index c166c529..f49d1fa0 100644 --- a/ajax/networking/gen_int_config.php +++ b/ajax/networking/gen_int_config.php @@ -1,9 +1,9 @@ 'app/js/dashboardchart.js', 'defer'=>false); } @@ -205,8 +207,8 @@ function DisplayDashboard(&$extraFooterScripts) /** * Get a human readable data size string from a number of bytes. * - * @param long $numbytes The number of bytes. - * @param int $precision The number of numbers to round to after the dot/comma. + * @param long $numbytes The number of bytes. + * @param int $precision The number of numbers to round to after the dot/comma. * @return string Data size in units: PB, TB, GB, MB or KB otherwise an empty string. */ function getHumanReadableDatasize($numbytes, $precision = 2) diff --git a/includes/defaults.php b/includes/defaults.php index db71718b..4efbe056 100755 --- a/includes/defaults.php +++ b/includes/defaults.php @@ -1,7 +1,7 @@ $value) { - if (!defined($setting)) { - define($setting, $value); - } + if (!defined($setting)) { + define($setting, $value); + } } unset($defaults); diff --git a/includes/dhcp.php b/includes/dhcp.php index 7ccc292d..d4525297 100755 --- a/includes/dhcp.php +++ b/includes/dhcp.php @@ -1,13 +1,11 @@ = IFNAMSIZ) { + if (!preg_match('/^[a-zA-Z0-9]+$/', $_POST['interface']) + || strlen($_POST['interface']) >= 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 ? + 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 ? + 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; } @@ -58,9 +59,9 @@ function DisplayDHCPConfig() } } - if ($_POST['DNS1']){ + if ($_POST['DNS1']) { $config .= "dhcp-option=6," . $_POST['DNS1']; - if ($_POST['DNS2']){ + if ($_POST['DNS2']) { $config .= ','.$_POST['DNS2']; } $config .= PHP_EOL; @@ -126,13 +127,13 @@ function DisplayDHCPConfig() $DNS1 = ''; $DNS2 = ''; - if (isset($conf['dhcp-option'])){ + if (isset($conf['dhcp-option'])) { $arrDns = explode(",", $conf['dhcp-option']); - if ($arrDns[0] == '6'){ - if (count($arrDns) > 1){ + if ($arrDns[0] == '6') { + if (count($arrDns) > 1) { $DNS1 = $arrDns[1]; } - if (count($arrDns) > 2){ + if (count($arrDns) > 2) { $DNS2 = $arrDns[2]; } } @@ -147,37 +148,39 @@ function DisplayDHCPConfig() $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; + case 'h': + $hselected = ' selected="selected"'; + break; + case 'm': + $mselected = ' selected="selected"'; + break; + case 'd': + $dselected = ' selected="selected"'; + break; } } exec("ip -o link show | awk -F': ' '{print $2}'", $interfaces); exec('cat ' . RASPI_DNSMASQ_LEASES, $leases); - echo renderTemplate("dhcp", compact( - "status", - "serviceStatus", - "RangeStart", - "RangeEnd", - "DNS1", - "DNS2", - "arrRangeLeaseTime", - "mselected", - "hselected", - "dselected", - "infiniteselected", - "dnsmasq_state", - "conf", - "dhcpHost", - "interfaces", - "leases" - )); + echo renderTemplate( + "dhcp", compact( + "status", + "serviceStatus", + "RangeStart", + "RangeEnd", + "DNS1", + "DNS2", + "arrRangeLeaseTime", + "mselected", + "hselected", + "dselected", + "infiniteselected", + "dnsmasq_state", + "conf", + "dhcpHost", + "interfaces", + "leases" + ) + ); } diff --git a/includes/functions.php b/includes/functions.php index d43c7b89..81fed816 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -55,8 +55,8 @@ function safefilerewrite($fileName, $dataToSave) } /** -* Saves a CSRF token in the session -*/ + * Saves a CSRF token in the session + */ function ensureCSRFSessionToken() { if (empty($_SESSION['csrf_token'])) { @@ -65,10 +65,8 @@ function ensureCSRFSessionToken() } /** -* -* Add CSRF Token to form -* -*/ + * Add CSRF Token to form + */ function CSRFTokenFieldTag() { $token = htmlspecialchars($_SESSION['csrf_token']); @@ -76,8 +74,8 @@ function CSRFTokenFieldTag() } /** -* Retuns a CSRF meta tag (for use with xhr, for example) -*/ + * Retuns a CSRF meta tag (for use with xhr, for example) + */ function CSRFMetaTag() { $token = htmlspecialchars($_SESSION['csrf_token']); @@ -85,10 +83,8 @@ function CSRFMetaTag() } /** -* -* Validate CSRF Token -* -*/ + * Validate CSRF Token + */ function CSRFValidate() { $post_token = $_POST['csrf_token']; @@ -112,8 +108,8 @@ function CSRFValidate() } /** -* Should the request be CSRF-validated? -*/ + * Should the request be CSRF-validated? + */ function csrfValidateRequest() { $request_method = strtolower($_SERVER['REQUEST_METHOD']); @@ -121,8 +117,8 @@ function csrfValidateRequest() } /** -* Handle invalid CSRF -*/ + * Handle invalid CSRF + */ function handleInvalidCSRFToken() { header('HTTP/1.1 500 Internal Server Error'); @@ -132,23 +128,23 @@ function handleInvalidCSRFToken() } /** -* Test whether array is associative -*/ + * Test whether array is associative + */ function isAssoc($arr) { return array_keys($arr) !== range(0, count($arr) - 1); } /** -* -* Display a selector field for a form. Arguments are: -* @param string $name: Field name -* @param array $options: Array of options -* @param string $selected: Selected option (optional) -* @param string $id: $options is an associative array this should be the key -* @param string $event: onChange event (optional) -* @param string $disabled (optional) -*/ + * Display a selector field for a form. Arguments are: + * + * @param string $name: Field name + * @param array $options: Array of options + * @param string $selected: Selected option (optional) + * @param string $id: $options is an associative array this should be the key + * @param string $event: onChange event (optional) + * @param string $disabled (optional) + */ function SelectorOptions($name, $options, $selected = null, $id = null, $event = null, $disabled = null) { echo '