Subversion Repositories ALCASAR

Rev

Rev 2924 | Rev 3031 | 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
 }
23
 
24
// Internet test
25
function internetTest() {
26
	$host  = 'www.google.com';
27
	$host2 = 'www.alcasar.net';
28
	$port = 80;
29
 
30
	$sock = @fsockopen($host, $port, $errno, $errstr, 2);
31
	if ($sock) {
32
		fclose($sock);
33
		return true;
34
	}
35
 
36
	$sock = @fsockopen($host2, $port, $errno, $errstr, 2);
37
	if ($sock) {
38
		fclose($sock);
39
		return true;
40
	}
41
 
42
	return false;
43
}
44
 
45
// filtering test
46
function filtrageTest($file, $search_regex){
47
	$pointeur = fopen($file,"r");
48
	$result = false;
49
	if ($pointeur)
50
		{
51
		while (!feof($pointeur))
52
			{
53
				$ligne = fgets($pointeur);
54
				if (preg_match($search_regex, $ligne, $r))
55
				{
56
				$result = true;
57
				break;
58
				}
59
			}
60
		}
61
	fclose($pointeur);
62
	return $result;
63
}
64
 
65
$Language = 'en';
66
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
67
	$Langue	  = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
68
	$Language = strtolower(substr(chop($Langue[0]), 0, 2));
69
	}
70
if ($Language === 'fr') {
2887 rexy 71
	$locale_time = "fr_FR";
2815 rexy 72
	$l_title = "Bienvenue dans l'ACC (ALCASAR Control Center)";
73
	$l_internet_link = "Connexion Internet";
2823 rexy 74
	$l_enable = "Active";
75
	$l_disable = "Désactivée";
2815 rexy 76
	$l_version = "Version instalée";
77
	$l_available = "Version disponible";
78
	$l_users = "Nombre d'utilisateurs / connectés";
79
	$l_groups = "Nombre de groupes";
2887 rexy 80
	$l_system_date = "Date du système";
2815 rexy 81
}
2853 rexy 82
else if ($Language === 'es') {
2887 rexy 83
	$locale_time = "es_ES";
2853 rexy 84
	$l_title = "Bienvenido al ACC (Centro de Control de ALCASAR)";
85
	$l_internet_link = "Conexión a Internet";
86
	$l_enable = "Activo";
87
	$l_disable = "Desactivado";
88
	$l_version = "Versión instalada";
89
	$l_available = "Versión disponible";
90
	$l_users = "Número de usuarios / conectados";
91
	$l_groups = "Número de grupos";
2887 rexy 92
	$l_system_date = "Fecha del sistema";
2853 rexy 93
}
2815 rexy 94
else {
2887 rexy 95
	$locale_time = "en_EN";
2815 rexy 96
	$l_title = "Welcome in ACC (ALCASAR Control Center)";
2823 rexy 97
	$l_internet_link = "Internet connection";
98
	$l_enable = "Enabled";
99
	$l_disable = "Disabled";
2815 rexy 100
	$l_version = "Installed version";
101
	$l_available = "Available version";
2976 rexy 102
	$l_users = "Number of users / connected";
2815 rexy 103
	$l_groups = "Number of groups";
2924 rexy 104
	$l_system_date = "System date";
2815 rexy 105
}
106
?>
107
<!DOCTYPE html>
108
<html>
2823 rexy 109
<head>
110
	<link rel="stylesheet" href="/css/acc.css">
111
</head>
112
<body>	
113
	<div class="panel">
114
		<div class="panel-header"><?= $l_title ?></div>
115
		<div class ="panel-row">
116
			<div class="panel-cell">
2815 rexy 117
<?
118
// Read CONF_FILE
119
define ('CONF_FILE', '/usr/local/etc/alcasar.conf');
120
$file_conf = fopen(CONF_FILE, 'r');
121
if (!$file_conf) {
122
	exit('Error opening the file '.CONF_FILE);}
123
while (!feof($file_conf)) {
124
	$buffer = fgets($file_conf, 4096);
125
	if ((strpos($buffer, '=') !== false) && (substr($buffer, 0, 1) !== '#')) {
126
		$tmp = explode('=', $buffer, 2);
127
		$conf[trim($tmp[0])] = trim($tmp[1]);
128
	}
129
}
130
fclose($file_conf);
131
// Get current version
132
$INSTALLEDVERSION = $conf['VERSION'];
2887 rexy 133
setlocale (LC_TIME, $locale_time);
134
$SYSTEM_DATE = strftime('%A, %e %B %Y, %T %Z');
2815 rexy 135
$nb_users = request ('user');
136
$nb_groups  = request ('group');
137
$nb_online_users = exec ("sudo /usr/sbin/chilli_query list | cut -d\" \" -f5 | grep \"1\" | wc -l");
138
if ((filtrageTest("/var/www/html/index.php","/network_pb = false/")) && (internetTest())) {
2823 rexy 139
	$internet_status =  "<img src='/images/state_ok.gif'>".$l_enable;
2815 rexy 140
	$version = dns_get_record("version.alcasar.net",DNS_TXT);
2853 rexy 141
	if (!empty($version)) {
142
		$AVAILABLEDVERSION = $version[0]['txt'];
143
	} else {
144
		$AVAILABLEDVERSION = "-";
145
	}
2815 rexy 146
} else {
2823 rexy 147
	$internet_status =  "<img src='/images/state_error.gif'>".$l_disable;
2815 rexy 148
	$AVAILABLEDVERSION = "-";
149
}
150
echo $l_internet_link."	: ".$internet_status."<br>\n";
151
echo $l_version."	: ".$INSTALLEDVERSION."<br>\n";
152
echo $l_available."	: ".$AVAILABLEDVERSION."<br>\n";
153
echo "</div><div class=\"panel-cell\">";
154
echo $l_users."		: ".$nb_users." / ".$nb_online_users."<br>\n";
155
echo $l_groups."	: ".$nb_groups."<br>\n";
2887 rexy 156
echo $l_system_date."	: ".$SYSTEM_DATE."<br>\n";
2815 rexy 157
?>
158
			</div>
159
		</div>
2823 rexy 160
	</div>
161
	<div class="panel">
162
		<iframe class="panel-iframe" src="phpsysinfo/">
163
		</iframe>
164
	</div>
165
</body>
2815 rexy 166
</html>