Subversion Repositories ALCASAR

Rev

Rev 3031 | Rev 3129 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 3031 Rev 3033
1
<?php
1
<?php
2
# Welcome page (sysinfo)
2
# Welcome page (sysinfo)
3
# by Rexy
3
# by Rexy
4
// request database
4
// request database
5
function request ($texte) {
5
function request ($texte) {
6
		$strResult = 0;
6
		$strResult = 0;
7
		// Déclaration des paramètres de connexion
7
		// Déclaration des paramètres de connexion
8
		$host = "localhost";
8
		$host = "localhost";
9
		$DB_USER = "radius";
9
		$DB_USER = "radius";
10
		$DB_RADIUS = "radius";
10
		$DB_RADIUS = "radius";
11
		$radiuspwd = "";
11
		$radiuspwd = "";
12
		// Connexion au serveur
12
		// Connexion au serveur
13
		$mysqli = new mysqli($host, $DB_USER, $radiuspwd, $DB_RADIUS);
13
		$mysqli = new mysqli($host, $DB_USER, $radiuspwd, $DB_RADIUS);
14
		if ($texte == 'user') {$query = "SELECT UserName FROM userinfo";}
14
		if ($texte == 'user') {$query = "SELECT UserName FROM userinfo";}
15
		else { $query = "SELECT GroupName FROM radusergroup GROUP BY GroupName";}
15
		else { $query = "SELECT GroupName FROM radusergroup GROUP BY GroupName";}
16
		$result = $mysqli->query($query);
16
		$result = $mysqli->query($query);
17
		// Recuperation des resultats
17
		// Recuperation des resultats
18
		$strResult = $result->num_rows;
18
		$strResult = $result->num_rows;
19
		// Deconnexion de la base de donnees
19
		// Deconnexion de la base de donnees
20
		$mysqli->close();
20
		$mysqli->close();
21
		return $strResult;
21
		return $strResult;
22
 }
22
 }
23
// router test
23
// router test
24
function routerTest($host) {
24
function routerTest($host) {
25
	$port = 80;
25
	$port = 80;
26
 
26
 
27
	$test = exec("ping -c 3 $host", $out, $res);
27
	$test = exec("ping -c 3 $host", $out, $res);
28
 
28
 
29
	return ($res == 0) ? true : false;
29
	return ($res == 0) ? true : false;
30
}
30
}
31
 
31
 
32
// Internet test
32
// Internet test
33
function internetTest() {
33
function internetTest() {
34
	$host  = 'www.google.com';
34
	$host  = 'www.google.com';
35
	$host2 = 'www.alcasar.net';
35
	$host2 = 'www.alcasar.net';
36
	$port = 80;
36
	$port = 80;
37
 
37
 
38
	$sock = @fsockopen($host, $port, $errno, $errstr, 2);
38
	$sock = @fsockopen($host, $port, $errno, $errstr, 2);
39
	if ($sock) {
39
	if ($sock) {
40
		fclose($sock);
40
		fclose($sock);
41
		return true;
41
		return true;
42
	}
42
	}
43
 
43
 
44
	$sock = @fsockopen($host2, $port, $errno, $errstr, 2);
44
	$sock = @fsockopen($host2, $port, $errno, $errstr, 2);
45
	if ($sock) {
45
	if ($sock) {
46
		fclose($sock);
46
		fclose($sock);
47
		return true;
47
		return true;
48
	}
48
	}
49
 
49
 
50
	return false;
50
	return false;
51
}
51
}
52
 
52
 
53
// filtering test
53
// filtering test
54
function filtrageTest($file, $search_regex){
54
function filtrageTest($file, $search_regex){
55
	$pointeur = fopen($file,"r");
55
	$pointeur = fopen($file,"r");
56
	$result = false;
56
	$result = false;
57
	if ($pointeur)
57
	if ($pointeur)
58
		{
58
		{
59
		while (!feof($pointeur))
59
		while (!feof($pointeur))
60
			{
60
			{
61
				$ligne = fgets($pointeur);
61
				$ligne = fgets($pointeur);
62
				if (preg_match($search_regex, $ligne, $r))
62
				if (preg_match($search_regex, $ligne, $r))
63
				{
63
				{
64
				$result = true;
64
				$result = true;
65
				break;
65
				break;
66
				}
66
				}
67
			}
67
			}
68
		}
68
		}
69
	fclose($pointeur);
69
	fclose($pointeur);
70
	return $result;
70
	return $result;
71
}
71
}
72
 
72
 
73
$Language = 'en';
73
$Language = 'en';
74
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
74
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
75
	$Langue	  = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
75
	$Langue	  = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
76
	$Language = strtolower(substr(chop($Langue[0]), 0, 2));
76
	$Language = strtolower(substr(chop($Langue[0]), 0, 2));
77
	}
77
	}
78
if ($Language === 'fr') {
78
if ($Language === 'fr') {
79
	$locale_time = "fr_FR";
79
	$locale_time = "fr_FR";
80
	$l_title = "Bienvenue dans l'ACC (ALCASAR Control Center)";
80
	$l_title = "Bienvenue dans l'ACC (ALCASAR Control Center)";
81
	$l_internet_link = "Accès";
81
	$l_internet_link = "Accès Internet";
82
	$l_lan = "LAN";
82
	$l_lan = "LAN";
83
	$l_router = "Routeur";
83
	$l_router = "Routeur";
84
	$l_DNS = "DNS";
84
	$l_DNS = "DNS";
85
	$l_enable = "Activé";
85
	$l_enable = "Activé";
86
	$l_disable = "Désactivé";
86
	$l_disable = "Désactivé";
87
	$l_version = "Version instalée";
87
	$l_version = "Version instalée";
88
	$l_available = "Version disponible";
88
	$l_available = "Version disponible";
89
	$l_users = "Nombre d'utilisateurs / connectés";
89
	$l_users = "Nombre d'utilisateurs / connectés";
90
	$l_groups = "Nombre de groupes";
90
	$l_groups = "Nombre de groupes";
91
	$l_system_date = "Date du système";
91
	$l_system_date = "Date du système";
92
}
92
}
93
else if ($Language === 'es') {
93
else if ($Language === 'es') {
94
	$locale_time = "es_ES";
94
	$locale_time = "es_ES";
95
	$l_title = "Bienvenido al ACC (Centro de Control de ALCASAR)";
95
	$l_title = "Bienvenido al ACC (Centro de Control de ALCASAR)";
96
	$l_internet_link = "Acceso";
96
	$l_internet_link = "Acceso a Internet";
97
	$l_enable = "Activo";
97
	$l_enable = "Activo";
98
	$l_lan = "LAN";
98
	$l_lan = "LAN";
99
	$l_router = "Rúter";
99
	$l_router = "Rúter";
100
	$l_DNS = "DNS";
100
	$l_DNS = "DNS";
101
	$l_disable = "Desactivado";
101
	$l_disable = "Desactivado";
102
	$l_version = "Versión instalada";
102
	$l_version = "Versión instalada";
103
	$l_available = "Versión disponible";
103
	$l_available = "Versión disponible";
104
	$l_users = "Número de usuarios / conectados";
104
	$l_users = "Número de usuarios / conectados";
105
	$l_groups = "Número de grupos";
105
	$l_groups = "Número de grupos";
106
	$l_system_date = "Fecha del sistema";
106
	$l_system_date = "Fecha del sistema";
107
}
107
}
108
else {
108
else {
109
	$locale_time = "en_EN";
109
	$locale_time = "en_EN";
110
	$l_title = "Welcome in ACC (ALCASAR Control Center)";
110
	$l_title = "Welcome in ACC (ALCASAR Control Center)";
111
	$l_internet_link = "Access";
111
	$l_internet_link = "Internet access";
112
	$l_lan = "LAN";
112
	$l_lan = "LAN";
113
	$l_router = "Router";
113
	$l_router = "Router";
114
	$l_DNS = "DNS";
114
	$l_DNS = "DNS";
115
	$l_enable = "Enabled";
115
	$l_enable = "Enabled";
116
	$l_disable = "Disabled";
116
	$l_disable = "Disabled";
117
	$l_version = "Installed version";
117
	$l_version = "Installed version";
118
	$l_available = "Available version";
118
	$l_available = "Available version";
119
	$l_users = "Number of users / connected";
119
	$l_users = "Number of users / connected";
120
	$l_groups = "Number of groups";
120
	$l_groups = "Number of groups";
121
	$l_system_date = "System date";
121
	$l_system_date = "System date";
122
}
122
}
123
?>
123
?>
124
<!DOCTYPE html>
124
<!DOCTYPE html>
125
<html>
125
<html>
126
<head>
126
<head>
127
	<link rel="stylesheet" href="/css/acc.css">
127
	<link rel="stylesheet" href="/css/acc.css">
128
</head>
128
</head>
129
<body>	
129
<body>	
130
	<div class="panel">
130
	<div class="panel">
131
		<div class="panel-header"><?= $l_title ?></div>
131
		<div class="panel-header"><?= $l_title ?></div>
132
		<div class ="panel-row">
132
		<div class ="panel-row">
133
			<div class="panel-cell">
133
			<div class="panel-cell">
134
<?
134
<?
135
// Read CONF_FILE
135
// Read CONF_FILE
136
define ('CONF_FILE', '/usr/local/etc/alcasar.conf');
136
define ('CONF_FILE', '/usr/local/etc/alcasar.conf');
137
	$file_conf = fopen(CONF_FILE, 'r');
137
	$file_conf = fopen(CONF_FILE, 'r');
138
	if (!$file_conf) {
138
	if (!$file_conf) {
139
		exit('Error opening the file '.CONF_FILE);}
139
		exit('Error opening the file '.CONF_FILE);}
140
	while (!feof($file_conf)) {
140
	while (!feof($file_conf)) {
141
		$buffer = fgets($file_conf, 4096);
141
		$buffer = fgets($file_conf, 4096);
142
		if ((strpos($buffer, '=') !== false) && (substr($buffer, 0, 1) !== '#')) {
142
		if ((strpos($buffer, '=') !== false) && (substr($buffer, 0, 1) !== '#')) {
143
			$tmp = explode('=', $buffer, 2);
143
			$tmp = explode('=', $buffer, 2);
144
			$conf[trim($tmp[0])] = trim($tmp[1]);
144
			$conf[trim($tmp[0])] = trim($tmp[1]);
145
		}
145
		}
146
	}
146
	}
147
	fclose($file_conf);
147
	fclose($file_conf);
148
// Get current version
148
// Get current version
149
$INSTALLEDVERSION = $conf['VERSION'];
149
$INSTALLEDVERSION = $conf['VERSION'];
150
setlocale (LC_TIME, $locale_time);
150
setlocale (LC_TIME, $locale_time);
151
$SYSTEM_DATE = strftime('%A, %e %B %Y, %T %Z');
151
$SYSTEM_DATE = strftime('%A, %e %B %Y, %T %Z');
152
$nb_users = request ('user');
152
$nb_users = request ('user');
153
$nb_groups  = request ('group');
153
$nb_groups  = request ('group');
154
$nb_online_users = exec ("sudo /usr/sbin/chilli_query list | cut -d\" \" -f5 | grep \"1\" | wc -l");
154
$nb_online_users = exec ("sudo /usr/sbin/chilli_query list | cut -d\" \" -f5 | grep \"1\" | wc -l");
155
 
155
 
156
// LAN Status (Is connected and has IP)
156
// LAN Status (Is connected and has IP)
157
$tmp = file_get_contents("/sys/class/net/".$conf['EXTIF']."/operstate");
157
$tmp = file_get_contents("/sys/class/net/".$conf['EXTIF']."/operstate");
158
if(strcmp($tmp,"up")==1){
158
if(strcmp($tmp,"up")==1){
159
	$lan_status =  $l_lan." : ".$l_enable." <img src='/images/state_ok.gif'> ";	
159
	$lan_status =  $l_lan." "." <img src='/images/state_ok.gif'> ";	
160
} else{
160
} else{
161
	$lan_status =  $l_lan." : ".$l_disable." <img src='/images/state_error.gif'> ";
161
	$lan_status =  $l_lan." "." <img src='/images/state_error.gif'> ";
162
}
162
}
163
 
163
 
164
// Router status
164
// Router status
165
$mask = strrchr($conf['PUBLIC_IP'],"/");
165
$mask = strrchr($conf['PUBLIC_IP'],"/");
166
if(routerTest($conf['GW']) && ($conf['GW'].$mask != $conf['PUBLIC_IP'])){
166
if(routerTest($conf['GW']) && ($conf['GW'].$mask != $conf['PUBLIC_IP'])){
167
	$router_status =  $l_router." : ".$l_enable." <img src='/images/state_ok.gif'> ";	
167
	$router_status =  $l_router." "." <img src='/images/state_ok.gif'> ";	
168
} else{
168
} else{
169
	$router_status =  $l_router." : ".$l_disable." <img src='/images/state_error.gif'> ";
169
	$router_status =  $l_router." "." <img src='/images/state_error.gif'> ";
170
}
170
}
171
 
171
 
172
// Internet status
172
// Internet status
173
if ((filtrageTest("/var/www/html/index.php","/network_pb = false/")) && (internetTest())) {
173
if ((filtrageTest("/var/www/html/index.php","/network_pb = false/")) && (internetTest())) {
174
	$internet_status =  $l_DNS." : ".$l_enable." <img src='/images/state_ok.gif'> ";
174
	$internet_status =  $l_DNS." "." <img src='/images/state_ok.gif'> ";
175
	$version = dns_get_record("version.alcasar.net",DNS_TXT);
175
	$version = dns_get_record("version.alcasar.net",DNS_TXT);
176
	if (!empty($version)) {
176
	if (!empty($version)) {
177
		$AVAILABLEDVERSION = $version[0]['txt'];
177
		$AVAILABLEDVERSION = $version[0]['txt'];
178
	} else {
178
	} else {
179
		$AVAILABLEDVERSION = "-";
179
		$AVAILABLEDVERSION = "-";
180
	}
180
	}
181
} else {
181
} else {
182
	$internet_status =  $l_DNS." : ".$l_disable." <img src='/images/state_error.gif'> ";
182
	$internet_status =  $l_DNS." "." <img src='/images/state_error.gif'> ";
183
	$AVAILABLEDVERSION = "-";
183
	$AVAILABLEDVERSION = "-";
184
}
184
}
185
 
185
 
186
echo $l_internet_link."\t".$lan_status.$router_status.$internet_status."<br>\n";
186
echo $l_internet_link." : ".$lan_status.$router_status.$internet_status."<br>\n";
187
echo $l_version."	: ".$INSTALLEDVERSION."<br>\n";
187
echo $l_version." : ".$INSTALLEDVERSION."<br>\n";
188
echo $l_available."	: ".$AVAILABLEDVERSION."<br>\n";
188
echo $l_available." : ".$AVAILABLEDVERSION."<br>\n";
189
echo "</div><div class=\"panel-cell\">";
189
echo "</div><div class=\"panel-cell\">";
190
echo $l_users."		: ".$nb_users." / ".$nb_online_users."<br>\n";
190
echo $l_users." : ".$nb_users." / ".$nb_online_users."<br>\n";
191
echo $l_groups."	: ".$nb_groups."<br>\n";
191
echo $l_groups." : ".$nb_groups."<br>\n";
192
echo $l_system_date."	: ".$SYSTEM_DATE."<br>\n";
192
echo $l_system_date." : ".$SYSTEM_DATE."<br>\n";
193
?>
193
?>
194
			</div>
194
			</div>
195
		</div>
195
		</div>
196
	</div>
196
	</div>
197
	<div class="panel">
197
	<div class="panel">
198
		<iframe class="panel-iframe" src="phpsysinfo/">
198
		<iframe class="panel-iframe" src="phpsysinfo/">
199
		</iframe>
199
		</iframe>
200
	</div>
200
	</div>
201
</body>
201
</body>
202
</html>
202
</html>
203
 
203