Processed with phpcbf

This commit is contained in:
billz 2020-02-15 17:57:46 +00:00
parent c0af41a53b
commit 457da91008
28 changed files with 1062 additions and 969 deletions

View File

@ -1,6 +1,6 @@
<?php
require('../../includes/csrf.php');
require '../../includes/csrf.php';
require_once '../../includes/config.php';
require_once RASPI_CONFIG.'/raspap.php';
@ -30,10 +30,12 @@ if (strlen($interface) > 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) {

View File

@ -1,66 +1,66 @@
<?php
require('../../includes/csrf.php');
if (filter_input(INPUT_GET, 'tu') == 'h') {
header('X-Content-Type-Options: nosniff');
header('Content-Type: application/json');
$data_template = array(
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);
}
<?php
require '../../includes/csrf.php';
if (filter_input(INPUT_GET, 'tu') == 'h') {
header('X-Content-Type-Options: nosniff');
header('Content-Type: application/json');
$data_template = array(
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);
}

View File

@ -1,9 +1,9 @@
<?php
require('../../includes/csrf.php');
require '../../includes/csrf.php';
include_once('../../includes/config.php');
include_once('../../includes/functions.php');
require_once '../../includes/config.php';
require_once '../../includes/functions.php';
if (isset($_POST['generate'])) {
$cnfNetworking = array_diff(scandir(RASPI_CONFIG_NETWORKING, 1), array('..','.','dhcpcd.conf'));

View File

@ -1,6 +1,6 @@
<?php
require('../../includes/csrf.php');
require '../../includes/csrf.php';
exec("ls /sys/class/net | grep -v lo", $interfaces);
echo json_encode($interfaces);

View File

@ -1,7 +1,7 @@
<?php
require('../../includes/csrf.php');
include_once('../../includes/config.php');
require '../../includes/csrf.php';
require_once '../../includes/config.php';
exec('cat '. RASPI_HOSTAPD_CONFIG, $hostapdconfig);
$arrConfig = array();
@ -10,7 +10,7 @@ foreach ($hostapdconfig as $hostapdconfigline) {
if (strlen($hostapdconfigline) === 0) {
continue;
}
$arrLine = explode("=", $hostapdconfigline) ;
$arrLine = explode("=", $hostapdconfigline);
$arrConfig[$arrLine[0]]=$arrLine[1];
};
$channel = intval($arrConfig['channel']);

View File

@ -1,9 +1,9 @@
<?php
require('../../includes/csrf.php');
require '../../includes/csrf.php';
include_once('../../includes/config.php');
include_once('../../includes/functions.php');
require_once '../../includes/config.php';
require_once '../../includes/functions.php';
if (isset($_POST['interface'])) {

View File

@ -1,8 +1,8 @@
<?php
require('../../includes/csrf.php');
require '../../includes/csrf.php';
include_once('../../includes/functions.php');
require_once '../../includes/functions.php';
if (isset($_POST['interface'])) {
$int = preg_replace('/[^a-z0-9]/', '', $_POST['interface']);

View File

@ -1,9 +1,9 @@
<?php
require('../../includes/csrf.php');
require '../../includes/csrf.php';
include_once('../../includes/config.php');
include_once('../../includes/functions.php');
require_once '../../includes/config.php';
require_once '../../includes/functions.php';
if (isset($_POST['interface'])) {
$int = $_POST['interface'];

View File

@ -1,10 +1,10 @@
<?php
require('../../includes/csrf.php');
include_once('../../includes/config.php');
include_once('../../includes/defaults.php');
include_once('../../includes/functions.php');
include_once('../../includes/wifi_functions.php');
require '../../includes/csrf.php';
require_once '../../includes/config.php';
require_once '../../includes/defaults.php';
require_once '../../includes/functions.php';
require_once '../../includes/wifi_functions.php';
$networks = [];
$network = null;

View File

@ -1,9 +1,7 @@
<?php
/**
*
* Displays info about the RaspAP project
*
*/
function DisplayAbout()
{

View File

@ -1,6 +1,6 @@
<?php
include_once('includes/status_messages.php');
require_once 'includes/status_messages.php';
function DisplayAuthConfig($username, $password)
{

View File

@ -1,12 +1,12 @@
<?php
include_once('includes/status_messages.php');
include_once('includes/wifi_functions.php');
require_once 'includes/status_messages.php';
require_once 'includes/wifi_functions.php';
/**
*
*
*/
*
*
*/
function DisplayWPAConfig()
{
$status = new StatusMessages();

View File

@ -1,7 +1,7 @@
<?php
include_once('functions.php');
include_once('session.php');
require_once 'functions.php';
require_once 'session.php';
if (csrfValidateRequest() && !CSRFValidate()) {
handleInvalidCSRFToken();

View File

@ -3,8 +3,8 @@
require_once 'config.php';
/**
* Show dashboard page.
*/
* Show dashboard page.
*/
function DisplayDashboard(&$extraFooterScripts)
{
@ -179,25 +179,27 @@ function DisplayDashboard(&$extraFooterScripts)
}
}
echo renderTemplate("dashboard", compact(
"status",
"ipv4Addrs",
"ipv4Netmasks",
"ipv6Addrs",
"macAddr",
"strRxPackets",
"strRxBytes",
"strTxPackets",
"strTxBytes",
"connectedSSID",
"connectedBSSID",
"bitrate",
"signalLevel",
"txPower",
"frequency",
"strLinkQuality",
"wlan0up"
));
echo renderTemplate(
"dashboard", compact(
"status",
"ipv4Addrs",
"ipv4Netmasks",
"ipv6Addrs",
"macAddr",
"strRxPackets",
"strRxBytes",
"strTxPackets",
"strTxBytes",
"connectedSSID",
"connectedBSSID",
"bitrate",
"signalLevel",
"txPower",
"frequency",
"strLinkQuality",
"wlan0up"
)
);
$extraFooterScripts[] = array('src'=>'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)

View File

@ -1,7 +1,7 @@
<?php
if (!defined('RASPI_CONFIG')) {
define('RASPI_CONFIG', '/etc/raspap');
define('RASPI_CONFIG', '/etc/raspap');
}
$defaults = [
@ -45,9 +45,9 @@ $defaults = [
];
foreach ($defaults as $setting => $value) {
if (!defined($setting)) {
define($setting, $value);
}
if (!defined($setting)) {
define($setting, $value);
}
}
unset($defaults);

View File

@ -1,13 +1,11 @@
<?php
include_once('includes/status_messages.php');
require_once 'includes/status_messages.php';
require_once 'config.php';
/**
*
* Manage DHCP configuration
*
*/
* Manage DHCP configuration
*/
function DisplayDHCPConfig()
{
@ -16,18 +14,21 @@ function DisplayDHCPConfig()
if (isset($_POST['savedhcpdsettings'])) {
$errors = '';
define('IFNAMSIZ', 16);
if (!preg_match('/^[a-zA-Z0-9]+$/', $_POST['interface']) ||
strlen($_POST['interface']) >= IFNAMSIZ) {
if (!preg_match('/^[a-zA-Z0-9]+$/', $_POST['interface'])
|| strlen($_POST['interface']) >= IFNAMSIZ
) {
$errors .= _('Invalid interface name.').'<br />'.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.').'<br />'.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.').'<br />'.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"
)
);
}

View File

@ -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 '<select class="form-control" name="'.htmlspecialchars($name, ENT_QUOTES).'"';
@ -176,13 +172,13 @@ function SelectorOptions($name, $options, $selected = null, $id = null, $event =
}
/**
*
* @param string $input
* @param string $string
* @param int $offset
* @param string $separator
* @return $string
*/
*
* @param string $input
* @param string $string
* @param int $offset
* @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));
@ -190,10 +186,10 @@ function GetDistString($input, $string, $offset, $separator)
}
/**
*
* @param array $arrConfig
* @return $config
*/
*
* @param array $arrConfig
* @return $config
*/
function ParseConfig($arrConfig)
{
$config = array();
@ -218,10 +214,10 @@ function ParseConfig($arrConfig)
}
/**
*
* @param string $freq
* @return $channel
*/
*
* @param string $freq
* @return $channel
*/
function ConvertToChannel($freq)
{
if ($freq >= 2412 && $freq <= 2484) {
@ -241,10 +237,11 @@ function ConvertToChannel($freq)
}
/**
* Converts WPA security string to readable format
* @param string $security
* @return string
*/
* Converts WPA security string to readable format
*
* @param string $security
* @return string
*/
function ConvertToSecurity($security)
{
$options = array();

View File

@ -1,17 +1,17 @@
<?php
include_once('includes/status_messages.php');
include_once('app/lib/system.php');
require_once 'includes/status_messages.php';
require_once 'app/lib/system.php';
require_once 'config.php';
/**
*
*
*/
*
*
*/
function DisplayHostAPDConfig()
{
$status = new StatusMessages();
$system = new System();
$system = new System();
$arrHostapdConf = parse_ini_file('/etc/raspap/hostapd.ini');
$arrConfig = array();
$arr80211Standard = [
@ -20,7 +20,7 @@ function DisplayHostAPDConfig()
'g' => '802.11g - 2.4 GHz',
'n' => '802.11n - 2.4 GHz',
'ac' => '802.11.ac - 5 GHz'
];
];
$arrSecurity = array(1 => 'WPA', 2 => 'WPA2', 3 => 'WPA+WPA2', 'none' => _("None"));
$arrEncType = array('TKIP' => 'TKIP', 'CCMP' => 'CCMP', 'TKIP CCMP' => 'TKIP+CCMP');
$managedModeEnabled = false;
@ -50,7 +50,7 @@ function DisplayHostAPDConfig()
exec('cat '. RASPI_HOSTAPD_CONFIG, $hostapdconfig);
exec('iwgetid '. RASPI_WIFI_CLIENT_INTERFACE. ' -r', $wifiNetworkID);
if ( !empty($wifiNetworkID[0])) {
if (!empty($wifiNetworkID[0])) {
$managedModeEnabled = true;
}
$hostapdstatus = $system->hostapdStatus();
@ -62,33 +62,36 @@ function DisplayHostAPDConfig()
}
if ($hostapdconfigline[0] != "#") {
$arrLine = explode("=", $hostapdconfigline) ;
$arrLine = explode("=", $hostapdconfigline);
$arrConfig[$arrLine[0]]=$arrLine[1];
}
};
echo renderTemplate("hostapd", compact(
"status",
"serviceStatus",
"hostapdstatus",
"managedModeEnabled",
"interfaces",
"arrConfig",
"arr80211Standard",
"selectedHwMode",
"arrSecurity",
"arrEncType",
"arrHostapdConf"
));
echo renderTemplate(
"hostapd", compact(
"status",
"serviceStatus",
"hostapdstatus",
"managedModeEnabled",
"interfaces",
"arrConfig",
"arr80211Standard",
"selectedHwMode",
"arrSecurity",
"arrEncType",
"arrHostapdConf"
)
);
}
function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $status)
{
// It should not be possible to send bad data for these fields so clearly
// someone is up to something if they fail. Fail silently.
if (!(array_key_exists($_POST['wpa'], $wpa_array) &&
array_key_exists($_POST['wpa_pairwise'], $enc_types) &&
array_key_exists($_POST['hw_mode'], $modes))) {
if (!(array_key_exists($_POST['wpa'], $wpa_array)
&& array_key_exists($_POST['wpa_pairwise'], $enc_types)
&& array_key_exists($_POST['hw_mode'], $modes))
) {
error_log("Attempting to set hostapd config with wpa='".$_POST['wpa']."', wpa_pairwise='".$_POST['wpa_pairwise']."' and hw_mode='".$_POST['hw_mode']."'"); // FIXME: log injection
return false;
}
@ -147,8 +150,9 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $status)
$good_input = false;
}
if ($_POST['wpa'] !== 'none' &&
(strlen($_POST['wpa_passphrase']) < 8 || strlen($_POST['wpa_passphrase']) > 63)) {
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;
}

View File

@ -1,77 +1,76 @@
<?php
/**
* Sets locale information for i18n support
*
*/
* Sets locale information for i18n support
*/
/**
* Rudimentary language detection via the browser.
* Accept-Language returns a list of weighted values with a quality (or 'q') parameter.
* A better method would parse the list of preferred languages and match this with
* the languages supported by our platform.
*
* Refer to: https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.4
* Rudimentary language detection via the browser.
* Accept-Language returns a list of weighted values with a quality (or 'q') parameter.
* A better method would parse the list of preferred languages and match this with
* the languages supported by our platform.
*
* Refer to: https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.4
*/
if (empty($_SESSION['locale']) && strlen($_SERVER['HTTP_ACCEPT_LANGUAGE']) >= 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;
case "tr":
$locale = "tr_TR.UTF-8";
break;
case "id":
$locale = "id_ID.UTF-8";
break;
case "ko":
$locale = "ko_KR.UTF-8";
break;
case "ja":
$locale = "ja_JP.UTF-8";
break;
case "vi":
$locale = "vi_VN.UTF-8";
break;
case "el":
$locale = "el_GR.UTF-8";
break;
default:
$locale = "en_GB.UTF-8";
break;
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;
case "tr":
$locale = "tr_TR.UTF-8";
break;
case "id":
$locale = "id_ID.UTF-8";
break;
case "ko":
$locale = "ko_KR.UTF-8";
break;
case "ja":
$locale = "ja_JP.UTF-8";
break;
case "vi":
$locale = "vi_VN.UTF-8";
break;
case "el":
$locale = "el_GR.UTF-8";
break;
default:
$locale = "en_GB.UTF-8";
break;
}
$_SESSION['locale'] = $locale;

View File

@ -1,11 +1,11 @@
<?php
include_once('includes/status_messages.php');
require_once 'includes/status_messages.php';
/**
*
*
*/
*
*
*/
function DisplayNetworkingConfig()
{

View File

@ -1,12 +1,10 @@
<?php
include_once('includes/status_messages.php');
require_once 'includes/status_messages.php';
require_once 'config.php';
/**
*
* Manage OpenVPN configuration
*
*/
function DisplayOpenVPNConfig()
{
@ -48,26 +46,27 @@ function DisplayOpenVPNConfig()
$authPassword = $auth[1];
}
echo renderTemplate("openvpn", compact(
"status",
"serviceStatus",
"openvpnstatus",
"public_ip",
"authUser",
"authPassword"
));
echo renderTemplate(
"openvpn", compact(
"status",
"serviceStatus",
"openvpnstatus",
"public_ip",
"authUser",
"authPassword"
)
);
}
/**
*
* Validates uploaded .ovpn file, adds auth-user-pass and
* stores auth credentials in login.conf. Copies files from
* tmp to OpenVPN
*
* @param object $status
* @param object $file
* @param string $authUser
* @param string $authPassword
* @param object $status
* @param object $file
* @param string $authUser
* @param string $authPassword
* @return object $status
*/
function SaveOpenVPNConfig($status, $file, $authUser, $authPassword)
@ -84,15 +83,15 @@ function SaveOpenVPNConfig($status, $file, $authUser, $authPassword)
// Parse returned errors
switch ($file['error']) {
case UPLOAD_ERR_OK:
break;
case UPLOAD_ERR_NO_FILE:
throw new RuntimeException('OpenVPN configuration file not sent');
case UPLOAD_ERR_INI_SIZE:
case UPLOAD_ERR_FORM_SIZE:
throw new RuntimeException('Exceeded filesize limit');
default:
throw new RuntimeException('Unknown errors');
case UPLOAD_ERR_OK:
break;
case UPLOAD_ERR_NO_FILE:
throw new RuntimeException('OpenVPN configuration file not sent');
case UPLOAD_ERR_INI_SIZE:
case UPLOAD_ERR_FORM_SIZE:
throw new RuntimeException('Exceeded filesize limit');
default:
throw new RuntimeException('Unknown errors');
}
// Validate extension
@ -109,7 +108,8 @@ function SaveOpenVPNConfig($status, $file, $authUser, $authPassword)
'ovpn' => 'text/plain'
),
true
)) {
)
) {
throw new RuntimeException('Invalid file format');
}
@ -127,7 +127,8 @@ function SaveOpenVPNConfig($status, $file, $authUser, $authPassword)
'ovpnclient',
$ext
)
)) {
)
) {
throw new RuntimeException('Unable to move uploaded file');
}
// Good file upload, update auth credentials if present

View File

@ -1,6 +1,6 @@
<?php
include_once('app/lib/system.php');
require_once 'app/lib/system.php';
$system = new System();

View File

@ -1,13 +1,11 @@
<?php
include_once('includes/status_messages.php');
require_once 'includes/status_messages.php';
require_once 'config.php';
/**
*
* Find the version of the Raspberry Pi
* Currently only used for the system information page but may useful elsewhere
*
*/
function RPiVersion()
@ -98,7 +96,7 @@ function DisplaySystem()
}
if (isset($_POST['RestartLighttpd'])) {
$status->addMessage('Restarting lighttpd in 3 seconds...','info');
$status->addMessage('Restarting lighttpd in 3 seconds...', 'info');
exec('sudo /etc/raspap/lighttpd/configport.sh --restart');
}
exec('cat '. RASPI_LIGHTTPD_CONFIG, $return);

View File

@ -1,8 +1,8 @@
<?php
/**
*
*
*/
*
*
*/
function DisplayThemeConfig()
{
$themes = [

View File

@ -1,12 +1,10 @@
<?php
include_once('includes/status_messages.php');
require_once 'includes/status_messages.php';
/**
*
* Manage Tor Proxy configuration
*
*/
* Manage Tor Proxy configuration
*/
function DisplayTorProxyConfig()
{
@ -16,21 +14,23 @@ function DisplayTorProxyConfig()
$arrConfig = array();
foreach ($return as $a) {
if ($a[0] != "#") {
$arrLine = explode(" ", $a) ;
$arrLine = explode(" ", $a);
$arrConfig[$arrLine[0]]=$arrLine[1];
}
}
echo renderTemplate("torproxy", compact(
"status",
"torproxystatus"
));
echo renderTemplate(
"torproxy", compact(
"status",
"torproxystatus"
)
);
}
/**
*
*
*/
*
*
*/
function SaveTORAndVPNConfig()
{
if (isset($_POST['SaveTORProxySettings'])) {

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
<?php
include_once('functions.php');
require_once 'functions.php';
function knownWifiStations(&$networks)
{
@ -16,26 +16,26 @@ function knownWifiStations(&$networks)
$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], '"');
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;
}
}
}
@ -51,15 +51,17 @@ function nearbyWifiStations(&$networks, $cached = true)
deleteCache($cacheKey);
}
$scan_results = cache($cacheKey, function () {
exec('sudo wpa_cli -i ' . RASPI_WIFI_CLIENT_INTERFACE . ' scan');
sleep(3);
$scan_results = cache(
$cacheKey, function () {
exec('sudo wpa_cli -i ' . RASPI_WIFI_CLIENT_INTERFACE . ' scan');
sleep(3);
exec('sudo wpa_cli -i ' . RASPI_WIFI_CLIENT_INTERFACE . ' scan_results', $stdout);
array_shift($stdout);
exec('sudo wpa_cli -i ' . RASPI_WIFI_CLIENT_INTERFACE . ' scan_results', $stdout);
array_shift($stdout);
return implode("\n", $stdout);
});
return implode("\n", $stdout);
}
);
foreach (explode("\n", $scan_results) as $network) {
$arrNetwork = preg_split("/[\t]+/", $network); // split result into array

148
index.php
View File

@ -10,36 +10,36 @@
* php-cgi (I have version 7.1.20-1+b2 installed via apt)
* along with their supporting packages, php7.1 will also need to be enabled.
*
* @author Lawrence Yau <sirlagz@gmail.com>
* @author Bill Zimmerman <billzimmerman@gmail.com>
* @license GNU General Public License, version 3 (GPL-3.0)
* @version 2.2
* @link https://github.com/billz/raspap-webgui
* @see http://sirlagz.net/2013/02/08/raspap-webgui/
* @author Lawrence Yau <sirlagz@gmail.com>
* @author Bill Zimmerman <billzimmerman@gmail.com>
* @license GNU General Public License, version 3 (GPL-3.0)
* @version 2.2
* @link https://github.com/billz/raspap-webgui
* @see http://sirlagz.net/2013/02/08/raspap-webgui/
*/
require('includes/csrf.php');
require 'includes/csrf.php';
ensureCSRFSessionToken();
include_once('includes/config.php');
include_once('includes/defaults.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/sysstats.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/openvpn.php');
include_once('includes/torproxy.php');
require_once 'includes/config.php';
require_once 'includes/defaults.php';
require_once RASPI_CONFIG.'/raspap.php';
require_once 'includes/locale.php';
require_once 'includes/functions.php';
require_once 'includes/dashboard.php';
require_once 'includes/authenticate.php';
require_once 'includes/admin.php';
require_once 'includes/dhcp.php';
require_once 'includes/hostapd.php';
require_once 'includes/system.php';
require_once 'includes/sysstats.php';
require_once 'includes/configure_client.php';
require_once 'includes/networking.php';
require_once 'includes/themes.php';
require_once 'includes/data_usage.php';
require_once 'includes/about.php';
require_once 'includes/openvpn.php';
require_once 'includes/torproxy.php';
$output = $return = 0;
$page = $_GET['page'];
@ -131,7 +131,7 @@ if ($_COOKIE['sidebarToggled'] == 'true' ) {
<li class="nav-item">
<a class="nav-link" href="index.php?page=wpa_conf"><i class="fas fa-wifi fa-fw mr-2"></i><span class="nav-label"><?php echo _("Configure WiFi client"); ?></span></a>
</li>
<?php endif; ?>
<?php endif; ?>
<?php if (RASPI_HOTSPOT_ENABLED) : ?>
<li class="nav-item">
<a class="nav-link" href="index.php?page=hostapd_conf"><i class="far fa-dot-circle fa-fw mr-2"></i><span class="nav-label"><?php echo _("Configure hotspot"); ?></a>
@ -219,52 +219,52 @@ if ($_COOKIE['sidebarToggled'] == 'true' ) {
<!-- Begin Page Content -->
<div class="container-fluid">
<?php
$extraFooterScripts = array();
// handle page actions
switch ($page) {
case "wlan0_info":
DisplayDashboard($extraFooterScripts);
break;
case "dhcpd_conf":
DisplayDHCPConfig();
break;
case "wpa_conf":
DisplayWPAConfig();
break;
case "network_conf":
DisplayNetworkingConfig();
break;
case "hostapd_conf":
DisplayHostAPDConfig();
break;
case "openvpn_conf":
DisplayOpenVPNConfig();
break;
case "torproxy_conf":
DisplayTorProxyConfig();
break;
case "auth_conf":
DisplayAuthConfig($config['admin_user'], $config['admin_pass']);
break;
case "save_hostapd_conf":
SaveTORAndVPNConfig();
break;
case "theme_conf":
DisplayThemeConfig();
break;
case "data_use":
DisplayDataUsage($extraFooterScripts);
break;
case "system_info":
DisplaySystem();
break;
case "about":
DisplayAbout();
break;
default:
DisplayDashboard($extraFooterScripts);
}
?>
$extraFooterScripts = array();
// handle page actions
switch ($page) {
case "wlan0_info":
DisplayDashboard($extraFooterScripts);
break;
case "dhcpd_conf":
DisplayDHCPConfig();
break;
case "wpa_conf":
DisplayWPAConfig();
break;
case "network_conf":
DisplayNetworkingConfig();
break;
case "hostapd_conf":
DisplayHostAPDConfig();
break;
case "openvpn_conf":
DisplayOpenVPNConfig();
break;
case "torproxy_conf":
DisplayTorProxyConfig();
break;
case "auth_conf":
DisplayAuthConfig($config['admin_user'], $config['admin_pass']);
break;
case "save_hostapd_conf":
SaveTORAndVPNConfig();
break;
case "theme_conf":
DisplayThemeConfig();
break;
case "data_use":
DisplayDataUsage($extraFooterScripts);
break;
case "system_info":
DisplaySystem();
break;
case "about":
DisplayAbout();
break;
default:
DisplayDashboard($extraFooterScripts);
}
?>
</div><!-- /.container-fluid -->
</div><!-- End of Main Content -->
<!-- Footer -->
@ -317,6 +317,6 @@ if ($_COOKIE['sidebarToggled'] == 'true' ) {
}
echo '></script>' , PHP_EOL;
}
?>
?>
</body>
</html>