Subversion Repositories ALCASAR

Rev

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