Changed routing system to use the more common path approach instead of query strings.

This commit is contained in:
Mark Pointing 2020-12-15 13:48:51 +00:00 committed by billz
parent 557cd260e6
commit 6966bc7f3a
18 changed files with 117 additions and 50 deletions

View file

@ -145,8 +145,11 @@ function setCSRFTokenHeader(event, xhr, settings) {
}
function contentLoaded() {
pageCurrent = window.location.href.split("?")[1].split("=")[1];
pageCurrent = pageCurrent.replace("#","");
//pageCurrent = window.location.href.split("?")[1].split("=")[1];
//pageCurrent = pageCurrent.replace("#","");
pageCurrent = window.location.href.split("/").pop();
switch(pageCurrent) {
case "network_conf":
getAllInterfaces();

View file

@ -0,0 +1,9 @@
server.modules += (
"mod_rewrite",
)
$HTTP["url"] =~ "^/(?!(dist|app|ajax)).*" {
url.rewrite-once = (
"^/[^\?]*(\?.*)?" => "/index.php$1"
)
}

View file

@ -48,7 +48,8 @@ require_once 'includes/openvpn.php';
require_once 'includes/torproxy.php';
$output = $return = 0;
$page = $_GET['page'];
//$page = $_GET['page'];
$page = $_SERVER['REQUEST_URI'];
$theme_url = getThemeOpt();
$toggleState = getSidebarState();
@ -107,7 +108,7 @@ $bridgedEnabled = getBridgedState();
<!-- Sidebar -->
<ul class="navbar-nav sidebar sidebar-light d-none d-md-block accordion <?php echo (isset($toggleState)) ? $toggleState : null ; ?>" id="accordionSidebar">
<!-- Sidebar - Brand -->
<a class="sidebar-brand d-flex align-items-center justify-content-center" href="index.php?page=wlan0_info">
<a class="sidebar-brand d-flex align-items-center justify-content-center" href="wlan0_info">
<div class="sidebar-brand-text ml-1"><?php echo RASPI_BRAND_TEXT; ?></div>
</a>
<!-- Divider -->
@ -130,65 +131,65 @@ $bridgedEnabled = getBridgedState();
</div>
</div>
<li class="nav-item">
<a class="nav-link" href="index.php?page=wlan0_info"><i class="fas fa-tachometer-alt fa-fw mr-2"></i><span class="nav-label"><?php echo _("Dashboard"); ?></span></a>
<a class="nav-link" href="wlan0_info"><i class="fas fa-tachometer-alt fa-fw mr-2"></i><span class="nav-label"><?php echo _("Dashboard"); ?></span></a>
</li>
<?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 _("Hotspot"); ?></a>
<a class="nav-link" href="hostapd_conf"><i class="far fa-dot-circle fa-fw mr-2"></i><span class="nav-label"><?php echo _("Hotspot"); ?></a>
</li>
<?php endif; ?>
<?php if (RASPI_DHCP_ENABLED && !$bridgedEnabled) : ?>
<li class="nav-item">
<a class="nav-link" href="index.php?page=dhcpd_conf"><i class="fas fa-exchange-alt fa-fw mr-2"></i><span class="nav-label"><?php echo _("DHCP Server"); ?></a>
<a class="nav-link" href="dhcpd_conf"><i class="fas fa-exchange-alt fa-fw mr-2"></i><span class="nav-label"><?php echo _("DHCP Server"); ?></a>
</li>
<?php endif; ?>
<?php if (RASPI_ADBLOCK_ENABLED && !$bridgedEnabled) : ?>
<li class="nav-item">
<a class="nav-link" href="index.php?page=adblock_conf"><i class="far fa-hand-paper fa-fw mr-2"></i><span class="nav-label"><?php echo _("Ad Blocking"); ?></a>
<a class="nav-link" href="adblock_conf"><i class="far fa-hand-paper fa-fw mr-2"></i><span class="nav-label"><?php echo _("Ad Blocking"); ?></a>
</li>
<?php endif; ?>
<?php if (RASPI_NETWORK_ENABLED) : ?>
<li class="nav-item">
<a class="nav-link" href="index.php?page=network_conf"><i class="fas fa-network-wired fa-fw mr-2"></i><span class="nav-label"><?php echo _("Networking"); ?></a>
<a class="nav-link" href="network_conf"><i class="fas fa-network-wired fa-fw mr-2"></i><span class="nav-label"><?php echo _("Networking"); ?></a>
</li>
<?php endif; ?>
<?php if (RASPI_WIFICLIENT_ENABLED && !$bridgedEnabled) : ?>
<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 _("WiFi client"); ?></span></a>
<a class="nav-link" href="wpa_conf"><i class="fas fa-wifi fa-fw mr-2"></i><span class="nav-label"><?php echo _("WiFi client"); ?></span></a>
</li>
<?php endif; ?>
<?php if (RASPI_OPENVPN_ENABLED) : ?>
<li class="nav-item">
<a class="nav-link" href="index.php?page=openvpn_conf"><i class="fas fa-key fa-fw mr-2"></i><span class="nav-label"><?php echo _("OpenVPN"); ?></a>
<a class="nav-link" href="openvpn_conf"><i class="fas fa-key fa-fw mr-2"></i><span class="nav-label"><?php echo _("OpenVPN"); ?></a>
</li>
<?php endif; ?>
<?php if (RASPI_TORPROXY_ENABLED) : ?>
<li class="nav-item">
<a class="nav-link" href="index.php?page=torproxy_conf"><i class="fas fa-eye-slash fa-fw mr-2"></i><span class="nav-label"><?php echo _("TOR proxy"); ?></a>
<a class="nav-link" href="torproxy_conf"><i class="fas fa-eye-slash fa-fw mr-2"></i><span class="nav-label"><?php echo _("TOR proxy"); ?></a>
</li>
<?php endif; ?>
<?php if (RASPI_CONFAUTH_ENABLED) : ?>
<li class="nav-item">
<a class="nav-link" href="index.php?page=auth_conf"><i class="fas fa-user-lock fa-fw mr-2"></i><span class="nav-label"><?php echo _("Authentication"); ?></a>
<a class="nav-link" href="auth_conf"><i class="fas fa-user-lock fa-fw mr-2"></i><span class="nav-label"><?php echo _("Authentication"); ?></a>
</li>
<?php endif; ?>
<?php if (RASPI_CHANGETHEME_ENABLED) : ?>
<li class="nav-item">
<a class="nav-link" href="index.php?page=theme_conf"><i class="fas fa-paint-brush fa-fw mr-2"></i><span class="nav-label"><?php echo _("Change Theme"); ?></a>
<a class="nav-link" href="theme_conf"><i class="fas fa-paint-brush fa-fw mr-2"></i><span class="nav-label"><?php echo _("Change Theme"); ?></a>
</li>
<?php endif; ?>
<?php if (RASPI_VNSTAT_ENABLED) : ?>
<li class="nav-item">
<a class="nav-link" href="index.php?page=data_use"><i class="fas fa-chart-bar fa-fw mr-2"></i><span class="nav-label"><?php echo _("Data usage"); ?></a>
<a class="nav-link" href="data_use"><i class="fas fa-chart-bar fa-fw mr-2"></i><span class="nav-label"><?php echo _("Data usage"); ?></a>
</li>
<?php endif; ?>
<?php if (RASPI_SYSTEM_ENABLED) : ?>
<li class="nav-item">
<a class="nav-link" href="index.php?page=system_info"><i class="fas fa-cube fa-fw mr-2"></i><span class="nav-label"><?php echo _("System"); ?></a>
<a class="nav-link" href="system_info"><i class="fas fa-cube fa-fw mr-2"></i><span class="nav-label"><?php echo _("System"); ?></a>
</li>
<?php endif; ?>
<li class="nav-item">
<a class="nav-link" href="index.php?page=about"><i class="fas fa-info-circle fa-fw mr-2"></i><span class="nav-label"><?php echo _("About RaspAP"); ?></a>
<a class="nav-link" href="about"><i class="fas fa-info-circle fa-fw mr-2"></i><span class="nav-label"><?php echo _("About RaspAP"); ?></a>
</li>
<!-- Divider -->
<hr class="sidebar-divider d-none d-md-block">
@ -218,7 +219,7 @@ $bridgedEnabled = getBridgedState();
<div class="topbar-divider d-none d-sm-block"></div>
<!-- Nav Item - User -->
<li class="nav-item dropdown no-arrow">
<a class="nav-link" href="index.php?page=auth_conf">
<a class="nav-link" href="auth_conf">
<span class="mr-2 d-none d-lg-inline small"><?php echo htmlspecialchars($config['admin_user'], ENT_QUOTES); ?></span>
<i class="fas fa-user-circle fa-3x"></i>
</a>
@ -232,46 +233,46 @@ $bridgedEnabled = getBridgedState();
$extraFooterScripts = array();
// handle page actions
switch ($page) {
case "wlan0_info":
case "/wlan0_info":
DisplayDashboard($extraFooterScripts);
break;
case "dhcpd_conf":
case "/dhcpd_conf":
DisplayDHCPConfig();
break;
case "wpa_conf":
case "/wpa_conf":
DisplayWPAConfig();
break;
case "network_conf":
case "/network_conf":
DisplayNetworkingConfig();
break;
case "hostapd_conf":
case "/hostapd_conf":
DisplayHostAPDConfig();
break;
case "adblock_conf":
case "/adblock_conf":
DisplayAdBlockConfig();
break;
case "openvpn_conf":
case "/openvpn_conf":
DisplayOpenVPNConfig();
break;
case "torproxy_conf":
case "/torproxy_conf":
DisplayTorProxyConfig();
break;
case "auth_conf":
case "/auth_conf":
DisplayAuthConfig($config['admin_user'], $config['admin_pass']);
break;
case "save_hostapd_conf":
case "/save_hostapd_conf":
SaveTORAndVPNConfig();
break;
case "theme_conf":
case "/theme_conf":
DisplayThemeConfig($extraFooterScripts);
break;
case "data_use":
case "/data_use":
DisplayDataUsage($extraFooterScripts);
break;
case "system_info":
case "/system_info":
DisplaySystem();
break;
case "about":
case "/about":
DisplayAbout();
break;
default:

View file

@ -169,7 +169,15 @@ function _create_raspap_directories() {
# Create a directory to store networking configs
echo "Creating $raspap_dir/networking"
sudo mkdir -p "$raspap_dir/networking"
<<<<<<< HEAD
=======
# Copy existing dhcpcd.conf to use as base config
echo "Adding /etc/dhcpcd.conf as base configuration"
cat /etc/dhcpcd.conf | sudo tee -a "$raspap_dir/networking/defaults" > /dev/null
echo "Changing file ownership of $raspap_dir"
sudo chown -R $raspap_user:$raspap_user "$raspap_dir" || _install_status 1 "Unable to change file ownership for '$raspap_dir'"
>>>>>>> 26d0dbfe... Changed routing system to use the more common path approach instead of query strings.
}
# Generate hostapd logging and service control scripts
@ -202,6 +210,20 @@ function _create_lighttpd_scripts() {
_install_status 0
}
# Copy extra config files required to configure lighthttpd
function _install_lighttpd_configs() {
_install_log "Copying lighttpd extra config files"
# Copy config files
echo "Copying 50-raspap-router.conf to /etc/lighttpd/conf-available"
sudo cp "$webroot_dir/config/50-raspap-router.conf" "/etc/lighttpd/conf-available" || _install_status 1 "Unable to copy lighttpd config file."
# link into conf-enabled
echo "Creating link to /etc/lighttpd/conf-enabled"|| _install_status 1 "Unable to copy lighthttpd config file."
sudo ln -s "/etc/lighttpd/conf-available/50-raspap-router.conf" "/etc/lighttpd/conf-enabled/50-raspap-router.conf" || _install_status 1 "Unable to symlink lighttpd config file."
sudo systemctl restart lighttpd.service || _install_status 1 "Unable to restart lighttpd"
_install_status 0
}
# Prompt to install ad blocking
function _prompt_install_adblock() {
_install_log "Configure ad blocking (Beta)"
@ -578,3 +600,28 @@ function _install_complete() {
fi
}
<<<<<<< HEAD
=======
function _install_raspap() {
_display_welcome
_config_installation
_update_system_packages
_install_dependencies
_enable_php_lighttpd
_create_raspap_directories
_optimize_php
_check_for_old_configs
_download_latest_files
_change_file_ownership
_create_hostapd_scripts
_create_lighttpd_scripts
_install_lighttpd_configs
_move_config_file
_default_configuration
_configure_networking
_prompt_install_adblock
_prompt_install_openvpn
_patch_system_files
_install_complete
}
>>>>>>> 26d0dbfe... Changed routing system to use the more common path approach instead of query strings.

View file

@ -219,6 +219,12 @@ function _remove_sudoers() {
echo "Done."
}
function _remove_lighttpd_config() {
echo "Removing ${raspap_sudoers}"
sudo rm "/etc/lighttpd/conf-available/50-raspap-router.conf" "/etc/lighttpd/conf-enabled/50-raspap-router.conf" || _install_error "Unable to remove lighttpd config"
echo "Done."
}
function _uninstall_complete() {
_install_log "Uninstall completed"
echo "It is recommended that you reboot your system as a final step."
@ -230,6 +236,7 @@ function _remove_raspap() {
_remove_raspap_service
_restore_networking
_remove_raspap_directories
_remove_lighttpd_config
_remove_installed_packages
_remove_sudoers
_uninstall_complete

View file

@ -27,7 +27,7 @@
</div><!-- /.card-header -->
<div class="card-body">
<?php $status->showMessages(); ?>
<form role="form" action="?page=adblock_conf" enctype="multipart/form-data" method="POST">
<form role="form" action="adblock_conf" enctype="multipart/form-data" method="POST">
<?php echo CSRFTokenFieldTag() ?>
<!-- Nav tabs -->
<ul class="nav nav-tabs">

View file

@ -11,7 +11,7 @@
<div class="card-body">
<?php $status->showMessages(); ?>
<h4><?php echo _("Authentication settings") ;?></h4>
<form role="form" action="?page=auth_conf" method="POST">
<form role="form" action="auth_conf" method="POST">
<?php echo CSRFTokenFieldTag() ?>
<div class="row">
<div class="form-group col-md-6">

View file

@ -34,7 +34,7 @@ $ifaceStatus = strtolower($matchesState[1]) ? "up" : "down";
<button type="button" class="btn btn-info btn-block float-right js-reload-wifi-stations"><?php echo _("Rescan"); ?></button>
</div>
</div>
<form method="POST" action="?page=wpa_conf" name="wpa_conf_form" class="row">
<form method="POST" action="wpa_conf" name="wpa_conf_form" class="row">
<?php echo CSRFTokenFieldTag() ?>
<input type="hidden" name="client_settings" ?>
<div class="row js-wifi-stations w-100 loading-spinner"></div>

View file

@ -6,10 +6,10 @@ $client_interface = $_SESSION['wifi_client_interface'];
$ap_iface = $_SESSION['ap_interface'];
$MACPattern = '"([[:xdigit:]]{2}:){5}[[:xdigit:]]{2}"';
if ($arrHostapdConf['BridgedEnable'] == 1) {
$moreLink = "index.php?page=hostapd_conf";
$moreLink = "hostapd_conf";
exec('iw dev '.$ap_iface.' station dump | grep -oE '.$MACPattern, $clients);
} else {
$moreLink = "index.php?page=dhcpd_conf";
$moreLink = "dhcpd_conf";
exec('cat '.RASPI_DNSMASQ_LEASES.'| grep -E $(iw dev '.$ap_iface.' station dump | grep -oE '.$MACPattern.' | paste -sd "|")', $clients);
}
$ifaceStatus = $wlan0up ? "up" : "down";
@ -122,7 +122,7 @@ $ifaceStatus = $wlan0up ? "up" : "down";
<div class="col-lg-12 mt-3">
<div class="row">
<form action="?page=wlan0_info" method="POST">
<form action="wlan0_info" method="POST">
<?php echo CSRFTokenFieldTag() ?>
<?php if (!RASPI_MONITOR_ENABLED) : ?>
<?php if (!$wlan0up) : ?>
@ -131,7 +131,7 @@ $ifaceStatus = $wlan0up ? "up" : "down";
<input type="submit" class="btn btn-warning" value="<?php echo _("Stop").' '.$client_interface ?>" name="ifdown_wlan0" />
<?php endif ?>
<?php endif ?>
<a href="?page=<?php echo $_GET['page'] ?>" class="btn btn-outline btn-primary"><i class="fas fa-sync-alt"></i> <?php echo _("Refresh") ?></a>
<a href="<?php echo $_GET['page'] ?>" class="btn btn-outline btn-primary"><i class="fas fa-sync-alt"></i> <?php echo _("Refresh") ?></a>
</form>
</div>
</div>

View file

@ -29,7 +29,7 @@
<div class="card-body">
<?php $status->showMessages(); ?>
<form method="POST" action="?page=dhcpd_conf" class="js-dhcp-settings-form">
<form method="POST" action="dhcpd_conf" class="js-dhcp-settings-form">
<?php echo CSRFTokenFieldTag() ?>
<!-- Nav tabs -->

View file

@ -49,7 +49,7 @@
<div class="card-body">
<?php $status->showMessages(); ?>
<form role="form" action="?page=hostapd_conf" method="POST">
<form role="form" action="hostapd_conf" method="POST">
<?php echo CSRFTokenFieldTag() ?>
<!-- Nav tabs -->

View file

@ -16,7 +16,7 @@
</div><!-- /.card-header -->
<div class="card-body">
<?php $status->showMessages(); ?>
<form role="form" action="?page=openvpn_conf" enctype="multipart/form-data" method="POST">
<form role="form" action="openvpn_conf" enctype="multipart/form-data" method="POST">
<?php echo CSRFTokenFieldTag() ?>
<!-- Nav tabs -->
<ul class="nav nav-tabs">

View file

@ -10,7 +10,7 @@
</div><!-- /.card-header -->
<div class="card-body">
<?php $status->showMessages(); ?>
<form role="form" action="?page=system_info" method="POST">
<form role="form" action="system_info" method="POST">
<?php echo CSRFTokenFieldTag() ?>
<ul class="nav nav-tabs" role="tablist">
<li role="presentation" class="nav-item"><a class="nav-link active" id="basictab" href="#basic" aria-controls="basic" role="tab" data-toggle="tab"><?php echo _("Basic"); ?></a></li>

View file

@ -2,7 +2,7 @@
<div role="tabpanel" class="tab-pane" id="advanced">
<h4 class="mt-3"><?php echo _("Advanced settings") ;?></h4>
<?php if (!RASPI_MONITOR_ENABLED) : ?>
<form action="?page=system_info" method="POST">
<form action="system_info" method="POST">
<?php echo CSRFTokenFieldTag() ?>
<div class="row">
<div class="form-group col-md-6">

View file

@ -33,9 +33,9 @@ include('includes/sysstats.php');
</div>
</div>
<form action="?page=system_info" method="POST">
<form action="system_info" method="POST">
<?php echo CSRFTokenFieldTag() ?>
<a href="?page=<?php echo $_GET['page'] ?>" class="btn btn-outline btn-primary"><i class="fas fa-sync-alt"></i> <?php echo _("Refresh") ?></a>
<a href="<?php echo $_GET['page'] ?>" class="btn btn-outline btn-primary"><i class="fas fa-sync-alt"></i> <?php echo _("Refresh") ?></a>
<?php if (!RASPI_MONITOR_ENABLED) : ?>
<input type="submit" class="btn btn-warning" name="system_reboot" value="<?php echo _("Reboot"); ?>" />

View file

@ -8,6 +8,6 @@
</div>
</div>
<input type="submit" class="btn btn-outline btn-primary" name="SaveLanguage" value="<?php echo _("Save settings"); ?>" />
<a href="?page=<?php echo $_GET['page'] ?>" class="btn btn-outline btn-primary"><i class="fas fa-sync-alt"></i> <?php echo _("Refresh") ?></a>
<a href="<?php echo $_GET['page'] ?>" class="btn btn-outline btn-primary"><i class="fas fa-sync-alt"></i> <?php echo _("Refresh") ?></a>
</div>

View file

@ -20,9 +20,9 @@
<input class="form-control color-input" value="#d8224c" aria-label="color" />
</div>
</div>
<form action="?page=system_info" method="POST">
<form action="system_info" method="POST">
<?php echo CSRFTokenFieldTag() ?>
<a href="?page=<?php echo $_GET['page'] ?>" class="btn btn-outline btn-primary"><i class="fas fa-sync-alt"></i> <?php echo _("Refresh"); ?></a>
<a href="<?php echo $_GET['page'] ?>" class="btn btn-outline btn-primary"><i class="fas fa-sync-alt"></i> <?php echo _("Refresh"); ?></a>
</form>
</div><!-- /.card-body -->
<div class="card-footer"></div>

View file

@ -16,7 +16,7 @@
<div class="tab-pane active" id="basic">
<h4>Basic settings</h4>
<form role="form" action="?page=save_hostapd_conf" method="POST">
<form role="form" action="save_hostapd_conf" method="POST">
<?php echo CSRFTokenFieldTag() ?>
<div class="row">
<div class="form-group col-md-6">