Subversion Repositories ALCASAR

Rev

Rev 3127 | 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";
3129 rexy 11
		$radiuspwd = "pJHKcy9Jv1HrCMHM";
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) {
25
	$out = exec("(sudo arping -I$nic -c1 $host|grep response|cut -d' ' -f2)");
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
 
161
// Router status
162
$mask = strrchr($conf['PUBLIC_IP'],"/");
3129 rexy 163
if(routerTest($conf['GW'],$conf['EXTIF']) && ($conf['GW'].$mask != $conf['PUBLIC_IP'])){
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
}
168
 
169
// Internet status
3127 rexy 170
if ((searchString("/var/www/html/index.php","/network_pb = false/")) && (internetTest())) {
3033 rexy 171
	$internet_status =  $l_DNS." "." <img src='/images/state_ok.gif'> ";
2815 rexy 172
	$version = dns_get_record("version.alcasar.net",DNS_TXT);
2853 rexy 173
	if (!empty($version)) {
174
		$AVAILABLEDVERSION = $version[0]['txt'];
175
	} else {
176
		$AVAILABLEDVERSION = "-";
177
	}
2815 rexy 178
} else {
3033 rexy 179
	$internet_status =  $l_DNS." "." <img src='/images/state_error.gif'> ";
2815 rexy 180
	$AVAILABLEDVERSION = "-";
181
}
3031 rexy 182
 
3033 rexy 183
echo $l_internet_link." : ".$lan_status.$router_status.$internet_status."<br>\n";
184
echo $l_version." : ".$INSTALLEDVERSION."<br>\n";
185
echo $l_available." : ".$AVAILABLEDVERSION."<br>\n";
2815 rexy 186
echo "</div><div class=\"panel-cell\">";
3033 rexy 187
echo $l_users." : ".$nb_users." / ".$nb_online_users."<br>\n";
188
echo $l_groups." : ".$nb_groups."<br>\n";
189
echo $l_system_date." : ".$SYSTEM_DATE."<br>\n";
2815 rexy 190
?>
191
			</div>
192
		</div>
2823 rexy 193
	</div>
194
	<div class="panel">
195
		<iframe class="panel-iframe" src="phpsysinfo/">
196
		</iframe>
197
	</div>
198
</body>
2815 rexy 199
</html>