summaryrefslogtreecommitdiffstats
path: root/etc
diff options
context:
space:
mode:
authorjim-p <jimp@pfsense.org>2012-08-10 10:58:26 -0400
committerjim-p <jimp@pfsense.org>2012-08-10 10:58:26 -0400
commite48cdc01cb743e115c3b66127280c13a417915f7 (patch)
tree6e70ee3ba3ef6c9e89eb08ce2d58605a108280df /etc
parent4e5cfb02832630b55e5880201d3bdd1418406edf (diff)
downloadpfsense-e48cdc01cb743e115c3b66127280c13a417915f7.zip
pfsense-e48cdc01cb743e115c3b66127280c13a417915f7.tar.gz
Consolodate a bunch of duplicate service status code
Diffstat (limited to 'etc')
-rw-r--r--etc/inc/service-utils.inc218
1 files changed, 217 insertions, 1 deletions
diff --git a/etc/inc/service-utils.inc b/etc/inc/service-utils.inc
index 2a9ca99..51375cd 100644
--- a/etc/inc/service-utils.inc
+++ b/etc/inc/service-utils.inc
@@ -218,4 +218,220 @@ function is_service_running($service, $ps = "") {
return false;
}
-?>
+function get_services() {
+ global $config;
+ if (is_array($config['installedpackages']['service']))
+ $services = $config['installedpackages']['service'];
+ else
+ $services = array();
+
+ /* Add services that are in the base.
+ *
+ */
+ if(is_radvd_enabled()) {
+ $pconfig = array();
+ $pconfig['name'] = "radvd";
+ $pconfig['description'] = gettext("Router Advertisement Daemon");
+ $services[] = $pconfig;
+ }
+
+ if(isset($config['dnsmasq']['enable'])) {
+ $pconfig = array();
+ $pconfig['name'] = "dnsmasq";
+ $pconfig['description'] = gettext("DNS Forwarder");
+ $services[] = $pconfig;
+ }
+
+ $pconfig = array();
+ $pconfig['name'] = "ntpd";
+ $pconfig['description'] = gettext("NTP clock sync");
+ $services[] = $pconfig;
+
+ if (is_array($config['captiveportal'])) {
+ foreach ($config['captiveportal'] as $zone => $setting) {
+ if (isset($setting['enable'])) {
+ $pconfig = array();
+ $pconfig['name'] = "captiveportal";
+ $pconfig['zone'] = $zone;
+ $pconfig['description'] = gettext("Captive Portal") . ": ".htmlspecialchars($setting['zone']);
+ $services[] = $pconfig;
+ }
+ }
+ }
+
+ $iflist = array();
+ $ifdescrs = get_configured_interface_list();
+ foreach ($ifdescrs as $if) {
+ $oc = $config['interfaces'][$if];
+ if ($oc['if'] && (!link_interface_to_bridge($if)))
+ $iflist[$if] = $if;
+ }
+ $show_dhcprelay = false;
+ foreach($iflist as $if) {
+ if(isset($config['dhcrelay'][$if]['enable']))
+ $show_dhcprelay = true;
+ }
+
+ if($show_dhcprelay == true) {
+ $pconfig = array();
+ $pconfig['name'] = "dhcrelay";
+ $pconfig['description'] = gettext("DHCP Relay");
+ $services[] = $pconfig;
+ }
+
+ if(is_dhcp_server_enabled()) {
+ $pconfig = array();
+ $pconfig['name'] = "dhcpd";
+ $pconfig['description'] = gettext("DHCP Service");
+ $services[] = $pconfig;
+ }
+
+ if(isset($config['snmpd']['enable'])) {
+ $pconfig = array();
+ $pconfig['name'] = "bsnmpd";
+ $pconfig['description'] = gettext("SNMP Service");
+ $services[] = $pconfig;
+ }
+
+ if (is_array($config['igmpproxy']['igmpentry']) && (count($config['igmpproxy']['igmpentry']) > 0)) {
+ $pconfig = array();
+ $pconfig['name'] = "igmpproxy";
+ $pconfig['description'] = gettext("IGMP proxy");
+ $services[] = $pconfig;
+ }
+
+ if (isset($config['installedpackages']['miniupnpd']) && $config['installedpackages']['miniupnpd']['config'][0]['enable']) {
+ $pconfig = array();
+ $pconfig['name'] = "miniupnpd";
+ $pconfig['description'] = gettext("UPnP Service");
+ $services[] = $pconfig;
+ }
+
+ if (isset($config['ipsec']['enable'])) {
+ $pconfig = array();
+ $pconfig['name'] = "racoon";
+ $pconfig['description'] = gettext("IPsec VPN");
+ $services[] = $pconfig;
+ }
+
+ foreach (array('server', 'client') as $mode) {
+ if (is_array($config['openvpn']["openvpn-{$mode}"])) {
+ foreach ($config['openvpn']["openvpn-{$mode}"] as $id => $setting) {
+ if (!isset($setting['disable'])) {
+ $pconfig = array();
+ $pconfig['name'] = "openvpn";
+ $pconfig['mode'] = $mode;
+ $pconfig['id'] = $id;
+ $pconfig['vpnid'] = $setting['vpnid'];
+ $pconfig['description'] = gettext("OpenVPN") . " ".$mode.": ".htmlspecialchars($setting['description']);
+ $services[] = $pconfig;
+ }
+ }
+ }
+ }
+
+ if (count($config['load_balancer']['virtual_server']) && count($config['load_balancer']['lbpool'])) {
+ $pconfig = array();
+ $pconfig['name'] = "relayd";
+ $pconfig['description'] = gettext("Server load balancing daemon");
+ $services[] = $pconfig;
+ }
+ return $services;
+}
+
+function service_name_compare($a, $b) {
+ if (strtolower($a['name']) == strtolower($b['name']))
+ return 0;
+ return (strtolower($a['name']) < strtolower($b['name'])) ? -1 : 1;
+}
+
+function get_pkg_descr($package_name) {
+ global $config;
+ if (is_array($config['installedpackages']['package'])) {
+ foreach($config['installedpackages']['package'] as $pkg) {
+ if($pkg['name'] == $package_name)
+ return $pkg['descr'];
+ }
+ }
+ return gettext("Not available.");
+}
+
+function get_service_status($service) {
+ global $g;
+ switch ($service['name']) {
+ case "openvpn":
+ $running = is_pid_running("{$g['varrun_path']}/openvpn_{$service['mode']}{$service['vpnid']}.pid");
+ break;
+ case "captiveportal":
+ $running = is_pid_running("{$g['varrun_path']}/lighty-{$service['zone']}-CaptivePortal.pid");
+ if (isset($config['captiveportal'][$service['zone']]['httpslogin']))
+ $running = $running && is_pid_running("{$g['varrun_path']}/lighty-{$service['zone']}-CaptivePortal-SSL.pid");
+ break;
+ default:
+ $running = is_service_running($service['name']);
+ }
+ return $running;
+}
+
+function get_service_status_icon($service, $withtext = true) {
+ global $g;
+ $output = "";
+ if(get_service_status($service)) {
+ $output .= '<td class="listr"><center>' . "\n";
+ $output .= "<img src=\"/themes/" . $g["theme"] . "/images/icons/icon_pass.gif\">";
+ if ($withtext)
+ $output .= " " . gettext("Running");
+ $output .= "</td>\n";
+ } else {
+ $output .= '<td class="listbg"><center>' . "\n";
+ $output .= "<img src=\"/themes/" . $g["theme"] . "/images/icons/icon_block.gif\"> <font color=\"white\">";
+ if ($withtext)
+ $output .= " " . gettext("Stopped");
+ $output .= "</td>\n";
+ }
+ return $output;
+}
+
+function get_service_control_links($service) {
+ global $g;
+ $output = "";
+ if(get_service_status($service)) {
+ switch ($service['name']) {
+ case "openvpn":
+ $output .= "<a href='status_services.php?mode=restartservice&service={$service['name']}&vpnmode={$service['mode']}&id={$service['vpnid']}'>";
+ break;
+ case "captiveportal":
+ $output .= "<a href='status_services.php?mode=restartservice&service={$service['name']}&zone={$service['zone']}'>";
+ break;
+ default:
+ $output .= "<a href='status_services.php?mode=restartservice&service={$service['name']}'>";
+ }
+ $output .= "<img title='" . gettext("Restart Service") . "' border='0' src='./themes/".$g['theme']."/images/icons/icon_service_restart.gif'></a>\n";
+ switch ($service['name']) {
+ case "openvpn":
+ $output .= "<a href='status_services.php?mode=stopservice&service={$service['name']}&vpnmode={$service['mode']}&id={$service['vpnid']}'>";
+ break;
+ case "captiveportal":
+ $output .= "<a href='status_services.php?mode=stopservice&service={$service['name']}&zone={$service['zone']}'>";
+ break;
+ default:
+ $output .= "<a href='status_services.php?mode=stopservice&service={$service['name']}'>";
+ }
+ $output .= "<img title='" . gettext("Stop Service") . "' border='0' src='./themes/".$g['theme']."/images/icons/icon_service_stop.gif'>";
+ $output .= "</a>";
+ } else {
+ switch ($service['name']) {
+ case "openvpn":
+ $output .= "<a href='status_services.php?mode=startservice&service={$service['name']}&vpnmode={$service['mode']}&id={$service['vpnid']}'>";
+ break;
+ case "captiveportal":
+ $output .= "<a href='status_services.php?mode=startservice&service={$service['name']}&zone={$service['zone']}'>";
+ break;
+ default:
+ $output .= "<a href='status_services.php?mode=startservice&service={$service['name']}'>";
+ }
+ $output .= "<img title='" . gettext("Start Service") . "' border='0' src='./themes/".$g['theme']."/images/icons/icon_service_start.gif'></a>\n";
+ }
+ return $output;
+}
+?> \ No newline at end of file
OpenPOWER on IntegriCloud