Subversion Repositories ALCASAR

Rev

Details | Last modification | View Log

Rev Author Line No. Line
1 root 1
<?php
2
//-------------------------------
3
// Fonctions
4
//-------------------------------
5
 
6
// Fonction de test de connectivité internet
7
function internetTest(){
8
	$host = "www.google.fr";
9
	$port = "80";
10
	//var $num;	//non utilisé
11
	//var $error;	//non utilisé
12
 
13
	if (! $sock = @fsockopen($host, $port, $num, $error, 5)) {
14
		return false;
15
	} else {
16
		fclose($sock);
17
		return true;
18
	}
19
}
20
 
21
// Fonction de test du filtrage
22
function filtrageTest($file, $search_regex){
23
	$pointeur = fopen($file,"r");
24
	$result = false;
25
	if ($pointeur)
26
		{
27
		while (!feof($pointeur))
28
			{
29
				$ligne = fgets($pointeur);
30
				if (preg_match($search_regex, $ligne, $r))
31
				{
32
				$result = true;
33
				break;
34
				}
35
			}
36
		}
37
	fclose($pointeur);
38
	return $result;
39
}
40
 
41
//fonction pour faire une action (start,stop,restart) sur un service
42
function serviceExec($service, $action){
43
	if (($action == "start")||($action == "stop")||($action == "restart")){
44
		exec("sudo /sbin/service $service $action",$retval, $retstatus);
45
		return $retstatus;
46
	} else {
47
		return false;
48
	}
49
}
50
//fonction définissant le status d'un service 
51
//(en fonction de la présence d'un mot clé dans la valeur de status)
52
function checkServiceStatus($service, $strMatch){
53
	$response = false;
54
	exec("sudo /sbin/service $service status",$retval);
55
	foreach( $retval as $val ) {
56
		if (strpos($val,$strMatch)){
57
			$response = true;
58
			break;
59
		}
60
	}
61
	return $response;
62
}
63
 
64
//-------------------------------
65
// Les actions sur un service
66
//-------------------------------
67
//sécurité sur les actions à réaliser
68
$autorizeService = array("radiusd","chilli","dansguardian","mysqld","squid","named","sshd");
69
$autorizeAction = array("start","stop","restart");
70
 
71
if (isset($_GET['service'])&&(in_array($_GET['service'], $autorizeService))) {
72
    if (isset($_GET['action'])&&(in_array($_GET['action'], $autorizeAction))) {
73
    	$execStatus = serviceExec($_GET['service'], $_GET['action']);
74
		// execStatus non exploité
75
	}
76
}
77
//-------------------------------
78
//recherche du status des services
79
//-------------------------------
80
$serviceStatus = array();
81
 
82
$serviceStatus['radiusd'] = checkServiceStatus("radiusd","pid");
83
$serviceStatus['chilli'] = checkServiceStatus("chilli","pid");
84
$serviceStatus['dansguardian'] = checkServiceStatus("dansguardian","pid");
85
$serviceStatus['mysqld'] = checkServiceStatus("mysqld","OK");
86
$serviceStatus['squid'] = checkServiceStatus("squid","pid");
87
$serviceStatus['named'] = checkServiceStatus("named","up");
88
$serviceStatus['sshd'] = checkServiceStatus("sshd","pid");
89
 
90
?>
91
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
92
<html>
93
<!-- written by steweb57 -->
94
<head>
95
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
96
<title>Services</title>
97
<link rel="stylesheet" href="/css/style.css" type="text/css">
98
</head>
99
<body>
100
<?php
101
# choice of language
102
$Language = "en";
103
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
104
 $Langue = explode(",",$_SERVER['HTTP_ACCEPT_LANGUAGE']);
105
 $Language = strtolower(substr(chop($Langue[0]),0,2));}
106
if ($Language == 'fr'){
107
 $l_service = "Services";
108
 $l_service_internet = "Lien Internet";
109
 $l_netfilter="Filtrage r&eacute;seau";
110
 $l_webfilter="Filtrage WEB";
111
 $l_enable = "actif";
112
 $l_disable = "inactif";
113
 $l_service_title = "Nom du services";
114
 $l_service_start = "D&eacute;marrer";
115
 $l_service_stop = "Arr&ecirc;ter";
116
 $l_service_restart = "Red&eacute;marrer";
117
 $l_service_status = "Status";
118
 $l_service_action = "Actions";
119
 $l_service_status_img_ok = "D&eacute;marr&eacute;";
120
 $l_service_status_img_ko = "Arr&ecirc;t&eacute;";
121
}
122
else {
123
 $l_service = "Services";
124
 $l_service_internet = "Internet connexion";
125
 $l_netfilter = "Network filter";
126
 $l_webfilter="WEB filter";
127
 $l_enable = "enable";
128
 $l_disable = "disable";
129
 $l_service_title = "Name of service";
130
 $l_service_start = "Start";
131
 $l_service_stop = "Stop";
132
 $l_service_restart = "Restart";
133
 $l_service_status = "Status";
134
 $l_service_action = "Actions";
135
 $l_service_status_img_ok = "Started";
136
 $l_service_status_img_ko = "Stopped";
137
}
138
?>
139
<table width="100%" border="0" cellspacing="0" cellpadding="0">
140
	<tr><th><?php echo $l_service;?></th></tr>
141
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td>	</tr>
142
</table>
143
<TABLE width="100%" border=1 cellspacing=0 cellpadding=1>
144
	<tr><td valign="middle" align="left">
145
<?php
146
if (InternetTest()){
147
	echo "<h1><img src='/images/state_ok.gif'> $l_service_internet : <font color='green'>$l_enable</font></h1>";
148
} else {
149
	echo "<h1><img src='/images/state_error.gif'> $l_service_internet : <font color='red'>$l_disable</font></h1>";
150
}
28 richard 151
if (filtrageTest("/usr/local/bin/alcasar-iptables.sh", "/^FILTERING=\"yes\"/")){
1 root 152
	echo "<h1><img src='/images/state_ok.gif'> $l_netfilter : <font color='green'>$l_enable</font></h1>";
153
} else {
154
	echo "<h1><img src='/images/state_error.gif'> $l_netfilter : <font color='red'>$l_disable</font></h1>";
155
}
156
if (filtrageTest("/etc/dansguardian/dansguardian.conf","/^reportinglevel = 3/")){
157
	echo "<h1><img src='/images/state_ok.gif'> $l_webfilter : <font color='green'>$l_enable</font></h1>";
158
} else {
159
	echo "<h1><img src='/images/state_error.gif'> $l_webfilter : <font color='red'>$l_disable</font></h1>";
160
}
161
?>
162
	</td></tr>
163
</table>
164
<table width="100%" border=0 cellspacing=0 cellpadding=0>
165
	<tr><th><?php echo $l_service_status;?></th><th><?php echo $l_service_title;?></th><th colspan="3"><?php echo $l_service_action;?></th></tr>
166
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td><td><img src="/images/pix.gif" width="1" height="2"></td><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
167
</table>
168
<TABLE width="100%" border=1 cellspacing=0 cellpadding=0>
169
	<TR align="center">
170
<?php foreach( $serviceStatus as $serviceName => $statusOK ) { ?>
171
<tr>
172
	<?php if ($statusOK) { ?>
173
    <td><img src="/images/state_ok.gif" width="15" height="15" alt="<?php echo $l_service_status_img_ok; ?>"></td>
174
    <td><?php echo $serviceName ;?></td>
175
    <td width="30" align="center">---</td>
176
    <td width="30" align="center"><a href="services.php?action=stop&service=<?php echo $serviceName;?>"><?php echo $l_service_stop;?></a></td>
177
    <td width="30" align="center"><a href="services.php?action=restart&service=<?php echo $serviceName;?>"><?php echo $l_service_restart;?></a></td>
178
	<?php } else { ?>
179
    <td><img src="/images/state_error.gif" width="15" height="15" alt="<?php echo $l_service_status_img_ko ?>"></td>
180
    <td><?php echo $serviceName ;?></td>
181
    <td width="30" align="center"><a href="services.php?action=start&service=<?php echo $serviceName;?>"><?php echo $l_service_start;?></a></td>
182
    <td width="30" align="center">---</td>
183
    <td width="30" align="center">---</td>
184
    <?php } ?>
185
</tr>
186
<?php } ?>
187
</td></tr></table>
188
</table>
189
</body>
190
</html>