Project

General

Profile

Download (4.59 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php
2
<?php
3
/*
4
    services_status.php
5
    Copyright (C) 2004, 2005 Scott Ullrich
6
    All rights reserved.
7

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

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

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

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

    
30
require("guiconfig.inc");
31
require("xmlparse_pkg.inc");
32

    
33
function gentitle_pkg($pgname) {
34
	global $config;
35
	return $config['system']['hostname'] . "." . $config['system']['domain'] . " - " . $pgname;
36
}
37

    
38
function get_package_rcd_details($extd) {
39
	global $package_name, $executable_name, $description;
40
	$file_contents = return_filename_as_string("/usr/local/etc/rc.d/{$extd}");
41
        if (preg_match_all("/\# PACKAGE\: (.*)\n/",$file_contents,$match_array))
42
            $package_name = $match_array[1][0];
43
        if (preg_match_all("/\# EXECUTABLE\: (.*)\n/",$file_contents,$match_array))
44
            $executable_name = $match_array[1][0];
45
	/* if we cannot locate it atleast return what they passed us */
46
	if($package_name = "") 
47
		$package_name = str_replace(".xml","",$extd);
48
	if($executable_name = "") 
49
		$executable_name = str_replace(".xml","",$extd);
50
	/* XXX: needs a get_pkg_description($packagename) function */
51
	$description = "";
52
}
53

    
54
if($_GET['service'] <> "")
55
	get_package_rcd_details($_GET['service'] . ".sh");
56

    
57
if($_GET['restartservice'] == "true") {
58
	mwexec("/sbin/killall $executable_name");
59
	mwexec("/bin/sh /usr/local/etc/rc.d/{$service}.sh");
60
	$savemsg = "{$package_name} has been restarted.";
61
}
62

    
63
if($_GET['stopservice'] == "true") {
64
	mwexec("/sbin/killall $executable_name");
65
	$savemsg = "{$package_name} has been stopped.";
66
}
67

    
68
if($_GET['startservice'] == "true") {	
69
	mwexec("/bin/sh /usr/local/etc/rc.d/{$service}.sh");
70
	$savemsg = "{$package_name} has been started.";
71
}
72

    
73
/* batch mode, allow other scripts to call this script */
74
if($_GET['batch'] <> "") exit;
75

    
76
?>
77
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
78
<html>
79
<head>
80
<?php $title = "Status: Services"; ?>
81
<title><?=gentitle_pkg($title);?></title>
82
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
83
<link href="gui.css" rel="stylesheet" type="text/css">
84
</head>
85

    
86
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
87
<?php
88
include("fbegin.inc");
89
?>
90
<p class="pgtitle"><?=$title?></p>
91
<form action="status_services.php" method="post">
92
<?php if ($savemsg) print_info_box($savemsg); ?>
93

    
94
<p>
95

    
96
<table width="100%" border="0" cellpadding="6" cellspacing="0">
97
</tr>
98
<tr>
99
  <td class="listhdrr"><b><center>Service</center></b></td>
100
  <td class="listhdrr"><b><center>Description</center></b></td>
101
  <td class="listhdrr"><b><center>Status</center></b></td>
102
  <td class="listhdrr"><b><center>Maintenance</center></b></td>
103
</tr>
104
<?php
105

    
106
$dh = @opendir("/usr/local/etc/rc.d/");
107
if ($dh)
108
	while (($extd = readdir($dh)) !== false) {
109
		if (($extd === ".") || ($extd === ".."))
110
			continue;
111
		get_package_rcd_details($extd);
112
		if($executable_name= "")
113
			continue;
114
		$status = is_service_running($executable_name);
115
		if($status == 1)
116
			$status_txt = "Running";
117
		else
118
			$status_txt = "Stopped";
119
		echo "<tr><td>{$package_name}</td><td>{$description}</td><td>{$status_txt}</td>";
120
		echo "<td>";
121
		if($status == 1) {
122
			echo "<a href='status_services.php?restartservice=true&service={$package_name}'>Restart</a> ";
123
			echo "<a href='status_services.php?stopservice=true&service={$package_name}'>Stop</a> ";
124
		} else {
125
			echo "<a href='status_services.php?startservice=true&service={$package_name}'>Start</a> ";
126
		}
127
		echo "</td>";
128
		echo "</tr>";
129
	}
130

    
131
?>
132
<tr><td>
133
</td></tr>
134
</table>
135

    
136
<?php include("fend.inc"); ?>
137
</body>
138
</html>
(93-93/117)