Subversion Repositories ALCASAR

Rev

Rev 3031 | Rev 3127 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log

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