/dev/null"); return (!empty($running)); } function is_dhcp_running($interface) { $status = find_dhclient_process($interface); if($status <> "") return true; return false; } function restart_service_if_running($service) { global $config; if(is_service_running($service)) restart_service($service); return; } function is_service_running($service, $ps = "") { global $config; if(is_array($config['installedpackages']['service'])) { foreach($config['installedpackages']['service'] as $aservice) { if(strtolower($service) == strtolower($aservice['name'])) { if ($aservice['custom_php_service_status_command'] <> "") { eval("\$rc={$aservice['custom_php_service_status_command']};"); return $rc; } if(empty($aservice['executable'])) return false; if (is_process_running($aservice['executable'])) return true; return false; } } } if (is_process_running($service)) return true; 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['installedpackages']['routed']) && $config['installedpackages']['routed']['config'][0]['enable']) { $pconfig = array(); $pconfig['name'] = "routed"; $pconfig['description'] = gettext("RIP Daemon"); $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 find_service_by_name($name) { $services = get_services(); foreach ($services as $service) if ($service["name"] == $name) return $service; return array(); } function find_service_by_openvpn_vpnid($vpnid) { $services = get_services(); foreach ($services as $service) if (($service["name"] == "openvpn") && isset($service["vpnid"]) && ($service["vpnid"] == $vpnid)) return $service; return array(); } function find_service_by_cp_zone($zone) { $services = get_services(); foreach ($services as $service) if (($service["name"] == "captiveportal") && isset($service["zone"]) && ($service["zone"] == $zone)) return $service; return array(); } 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, $smallicon = false) { global $g; $output = ""; if(get_service_status($service)) { $statustext = gettext("Running"); $output .= '