shortcuts.inc 7.41 KB
Newer Older
Ad Schellevis's avatar
Ad Schellevis committed
1
<?php
2

Ad Schellevis's avatar
Ad Schellevis committed
3
/*
4
	Copyright (C) 2014-2015 Deciso B.V.
Ad Schellevis's avatar
Ad Schellevis committed
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
	Copyright (C) 2012 Jim Pingle
	Copyright (C) 2007, 2008 Scott Ullrich <sullrich@gmail.com>
	All rights reserved.

	Redistribution and use in source and binary forms, with or without
	modification, are permitted provided that the following conditions are met:

	1. Redistributions of source code must retain the above copyright notice,
	   this list of conditions and the following disclaimer.

	2. Redistributions in binary form must reproduce the above copyright
	   notice, this list of conditions and the following disclaimer in the
	   documentation and/or other materials provided with the distribution.

	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
	POSSIBILITY OF SUCH DAMAGE.

*/

$shortcuts = array();

/* Load and process custom shortcuts. */
35 36
function get_shortcut_files($directory)
{
Ad Schellevis's avatar
Ad Schellevis committed
37
	$dir_array = array();
38 39

	if ($dh = @opendir($directory)) {
Ad Schellevis's avatar
Ad Schellevis committed
40 41
		while (($file = readdir($dh)) !== false) {
			$canadd = 0;
42
			if($file == ".")
Ad Schellevis's avatar
Ad Schellevis committed
43
				$canadd = 1;
44
			if($file == "..")
Ad Schellevis's avatar
Ad Schellevis committed
45 46 47 48 49 50
				$canadd = 1;
			if($canadd == 0)
				array_push($dir_array, $file);
		}
		closedir($dh);
	}
51

Ad Schellevis's avatar
Ad Schellevis committed
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
	return $dir_array;
}

function get_shortcut_by_service_name($servicename) {
	global $shortcuts;
	foreach ($shortcuts as $name => $shortcut) {
		if (!empty($shortcut['service']) && ($shortcut['service'] == $servicename))
			return $name;
	}
	return null;
}

function get_shortcut_main_link($shortcut_section, $addspace = true, $service = array()) {
	global $g, $shortcuts;
	if(empty($shortcut_section))
		return "";
	$space = ($addspace) ? "&nbsp;" : "" ;
	switch ($shortcut_section) {
70 71 72 73 74 75
		case "openvpn":
			if (!empty($service['mode']) && is_numeric($service['id']))
				$link = "vpn_openvpn_{$service['mode']}.php?act=edit&amp;id={$service['id']}";
			else
				$link = $shortcuts[$shortcut_section]['main'];
			break;
Ad Schellevis's avatar
Ad Schellevis committed
76 77 78 79
		default:
			$link = $shortcuts[$shortcut_section]['main'];
			break;
	}
80
	if (!empty($link)) {
81 82 83 84
		if (strtok($_SERVER['REQUEST_URI'],'?') != "/status_services.php")
			return "{$space}<a href=\"{$link}\" title=\"" . gettext("Main page for this section") . "\">Main page</a>";
		else
			return "{$space}<a href=\"{$link}\" class=\"btn btn-default\" data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"" . gettext("Main page for this section") . "\"><span class=\"glyphicon glyphicon-home\"></span></a>";
85
	}
Ad Schellevis's avatar
Ad Schellevis committed
86 87
}

88 89 90 91 92 93 94 95
function get_shortcut_status_link($shortcut_section, $addspace = true, $service = array())
{
	global $g, $shortcuts;

	if (empty($shortcut_section)) {
		return '';
	}

Ad Schellevis's avatar
Ad Schellevis committed
96
	$space = ($addspace) ? "&nbsp;" : "" ;
97 98 99 100 101

	if (isset($shortcuts[$shortcut_section]['status'])) {
		$link = $shortcuts[$shortcut_section]['status'];
	} else {
		$link = null;
Ad Schellevis's avatar
Ad Schellevis committed
102
	}
103 104 105

	if (!empty($link)) {
		if (strtok($_SERVER['REQUEST_URI'],'?') != "/status_services.php") {
106
			return "{$space}<a href=\"{$link}\" title=\"" . gettext("Status of items on this page") . "\">Status</a>";
107
		} else {
108
			return "{$space}<a href=\"{$link}\" class=\"btn btn-default\" data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"" . gettext("Status of items on this page") . "\"><span class=\"glyphicon glyphicon-eye-open\"></span></a>";
109 110
		}
	}
Ad Schellevis's avatar
Ad Schellevis committed
111 112 113 114 115 116
}

function get_shortcut_log_link($shortcut_section, $addspace = true) {
	global $g, $shortcuts;
	$space = ($addspace) ? "&nbsp;" : "" ;
	if(!empty($shortcut_section) && !empty($shortcuts[$shortcut_section]['log'])) {
117 118 119 120
		if (strtok($_SERVER['REQUEST_URI'],'?') != "/status_services.php")
			return "{$space}<a href=\"{$shortcuts[$shortcut_section]['log']}\" title=\"" . gettext("Log entries for items on this page") . "\">Log</a>";
		else
			return "{$space}<a href=\"{$shortcuts[$shortcut_section]['log']}\" class=\"btn btn-default\" data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"" . gettext("Log entries for items on this page") . "\"><span class=\"glyphicon glyphicon-list\"></span></a>";
Ad Schellevis's avatar
Ad Schellevis committed
121 122 123
	}
}

124
$shortcuts['upnp'] = array();
125
$shortcuts['upnp']['main'] = "services_upnp.php";
126 127 128 129
$shortcuts['upnp']['log'] = "diag_logs_routing.php";
$shortcuts['upnp']['status'] = "status_upnp.php";
$shortcuts['upnp']['service'] = "miniupnpd";

Ad Schellevis's avatar
Ad Schellevis committed
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144

$shortcuts['relayd'] = array();
$shortcuts['relayd']['service'] = "relayd";

$shortcuts['dhcp'] = array();
$shortcuts['dhcp']['main'] = "services_dhcp.php";
$shortcuts['dhcp']['log'] = "diag_logs_dhcp.php";
$shortcuts['dhcp']['status'] = "status_dhcp_leases.php";
$shortcuts['dhcp']['service'] = "dhcpd";

$shortcuts['dhcp6'] = array();
$shortcuts['dhcp6']['main'] = "services_dhcpv6.php";
$shortcuts['dhcp6']['log'] = "diag_logs_dhcp.php";
$shortcuts['dhcp6']['status'] = "status_dhcpv6_leases.php";

145 146 147
$shortcuts['ipsec'] = array();
$shortcuts['ipsec']['service'] = "ipsec";

148 149 150
$shortcuts['openvpn'] = array();
$shortcuts['openvpn']['service'] = "openvpn";

Ad Schellevis's avatar
Ad Schellevis committed
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
$shortcuts['firewall'] = array();
$shortcuts['firewall']['main'] = "firewall_rules.php";
$shortcuts['firewall']['log'] = "diag_logs_filter.php";
$shortcuts['firewall']['status'] = "status_filter_reload.php";

$shortcuts['routing'] = array();
$shortcuts['routing']['main'] = "system_routes.php";
$shortcuts['routing']['log'] = "diag_logs_routing.php";
$shortcuts['routing']['status'] = "diag_routes.php";

$shortcuts['gateways'] = array();
$shortcuts['gateways']['main'] = "system_gateways.php";
$shortcuts['gateways']['log'] = "diag_logs_gateways.php";
$shortcuts['gateways']['status'] = "status_gateways.php";
$shortcuts['gateways']['service'] = "apinger";

$shortcuts['gateway-groups'] = array();
$shortcuts['gateway-groups']['main'] = "system_gateway_groups.php";
$shortcuts['gateway-groups']['log'] = "diag_logs_gateways.php";
$shortcuts['gateway-groups']['status'] = "status_gateway_groups.php";

172 173 174 175 176
$shortcuts['forwarder'] = array();
$shortcuts['forwarder']['main'] = "services_dnsmasq.php";
$shortcuts['forwarder']['log'] = "diag_logs_resolver.php";
$shortcuts['forwarder']['service'] = "dnsmasq";

Ad Schellevis's avatar
Ad Schellevis committed
177
$shortcuts['resolver'] = array();
178
$shortcuts['resolver']['main'] = "services_unbound.php";
Ad Schellevis's avatar
Ad Schellevis committed
179
$shortcuts['resolver']['log'] = "diag_logs_resolver.php";
180
$shortcuts['resolver']['service'] = "unbound";
Ad Schellevis's avatar
Ad Schellevis committed
181 182

$shortcuts['ntp'] = array();
183
$shortcuts['ntp']['service'] = "ntpd";	/* really, hook it all up through some weird hint? */
Ad Schellevis's avatar
Ad Schellevis committed
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199

$shortcuts['pppoes'] = array();
$shortcuts['pppoes']['main'] = "vpn_pppoe.php";
$shortcuts['pppoes']['log'] = "diag_logs_vpn.php?vpntype=poes";

$shortcuts['snmp'] = array();
$shortcuts['snmp']['main'] = "services_snmp.php";
$shortcuts['snmp']['service'] = "bsnmpd";

$shortcuts['authentication'] = array();
$shortcuts['authentication']['main'] = "system_authservers.php";
$shortcuts['authentication']['status'] = "diag_authentication.php";

$shortcuts['aliases'] = array();
$shortcuts['aliases']['main'] = "firewall_aliases.php";
$shortcuts['aliases']['status'] = "diag_tables.php";
200 201 202 203 204 205

$shortcuts['squid'] = array();
$shortcuts['squid']['main'] = "ui/proxy/";
$shortcuts['squid']['log'] = "diag_logs_proxy.php";
//TODO: $shortcuts['squid']['status'] = "";
$shortcuts['squid']['service'] = "squid";