Subversion Repositories ALCASAR

Rev

Go to most recent revision | Details | Last modification | View Log

Rev Author Line No. Line
1349 richard 1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2
<HTML><!-- written by Rexy -->
3
<head>
4
<META HTTP-EQUIV="Refresh" CONTENT="30">
5
<meta http-equiv="Content-Type" content="text/html; charset=$config[general_charset]">
6
<title>Auto enregistrement</title>
7
<link rel="stylesheet" href="/css/style.css">
8
</head>
9
<body>
10
<TABLE width="100%" border="0" cellspacing="0" cellpadding="0">
11
<?
12
#Commandes
13
$exec_com=exec("lsusb | grep -i huawei | cut -d ' ' -f6");
14
$exec_com2=exec("lsusb | grep -i d-link | cut -d ' ' -f7");
15
$status_key="false";
16
$script="/usr/local/bin/alcasar-sms.sh";
17
 
18
#Define
19
$gammu_puk = "";
20
$gammu_simfail = "";
21
$gammu_simsecu = "";
22
$gammu_writeerror = "";
23
$gammu_timeout = "";
24
$error_pin = "";
25
$error_time_account = "";
26
$error_nb_essais = "";
27
$error_time_perm = "";
28
$error_num_alcasar = "";
29
 
30
# Choice of language
31
$Language = 'en';
32
if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
33
  $Langue = explode(",",$_SERVER['HTTP_ACCEPT_LANGUAGE']);
34
  $Language = strtolower(substr(chop($Langue[0]),0,2)); }
35
if($Language == 'fr'){
36
	$l_title = "Auto enregistrement (SMS)";
37
	$l_conf = "Configuration";
38
	$l_conf_actu = "Configuration actuelle";
39
	$l_pin = "Code PIN";
40
	$l_num_alcasar = "Le numero de téléphone de la clé 3G";
41
	$l_ban_temp = "Nombre d'essais max avant le ban permanant";
42
	$l_time_account = "Durée pour une session créée";
43
	$l_time_perm = "Durée en jours d'un bloquage (ban)";
44
	$l_status_gammu = "Etat du service";
45
	$l_start = "Démarrer";
46
	$l_status_device = "Status de votre périphérique";
47
	$l_key_diseable = "Aucune clé est connectée";
48
	$l_key_enable = "Votre clé est connectée";
49
	$l_force_signal = "Force du signal";
50
	$l_imei_device = "IMEI du périphérique";
51
	$l_sms_received = "Nombre de SMS reçu";
52
	$l_stop = "Arrêter";
53
	$l_gammu_on="Gammu est lancé";
54
	$l_gammu_off="Gammu est arrêté";
55
	$l_edit = "Editer";
56
	$l_error_label_empty = "Le champ est vide";
57
	$l_error_label_num = "Ce n'est pas un PIN valide";
58
	$l_error_label_num2 = "Ce n'est pas un nombre";
59
	$l_error_writefail = "Gammu semble ne pas parvenir à discuter avec la clé (port ttyUSB0).";
60
	$l_error_timeoutfail = "Impossible de se connecter à la clé 3G. Timeout.";
61
	$l_error_simfail = "Un problème au niveau de la carte SIM a été détecté. Est elle présente?";
62
	$l_error_simsecu_l = "Attention, lors du dernier démarrage, votre code PIN était erroné.<br>
63
	       			La SIM doit être bloqué (code PUK). Consultez la documentation.";
64
	$l_autorefresh = "Rafraichissement : 30 sec";
65
	$l_days = "jours ";
66
 
67
	$l_num_block="Liste des numéros bloqués";
68
	$l_num_num="Numéro";
69
	$l_num_raison="Raison";
70
	$l_num_expiration="Date d'expiration";
71
	$l_num_action="Action";
72
	$l_num_exist="Un compte a été créé";
73
	$l_num_flood="Le nombre d'essais maximum a été dépacé";
74
	$l_num_unlock="Effacer";
75
	$l_service_status_img_ok="Démarré";
76
	$l_service_status_img_ko="Arrété";
77
 
78
 
79
}
80
else {
81
	$l_title = "Auto registration (SMS)";
82
	$l_conf = "Configuration";
83
	$l_conf_actu = "Current configuration";
84
	$l_pin = "PIN password";
85
	$l_num_alcasar = "Phone number (3g key)";
86
	$l_ban_temp = "Max number of try before a permanent ban"; 
87
	$l_time_account = "Time for a new session";
88
	$l_time_perm = "Duration of a ban (for example, after X try)";
89
	$l_status_gammu = "Service status";
90
	$l_start = "Start";
91
	$l_status_device = "Status of your device";
92
	$l_key_diseable = "Your 3g key is not connected";
93
	$l_key_enable = "Your 3g key is connected";
94
	$l_force_signal = "Signal strength";
95
	$l_imei_device = "Device IMEI";
96
	$l_sms_received = "Number of SMS received";
97
	$l_stop = "Stop";
98
	$l_gammu_on="Gammu is running";
99
	$l_gammu_off="Gammu is down";
100
	$l_edit = "Edit";
101
	$l_error_label_empty = "Field empty";
102
	$l_error_label_num = "It's not a valid PIN password";
103
	$l_error_label_num2 = "It's not a number";
104
	$l_error_writefail = "Gammu can't listen the ttyUSB0 port.";
105
	$l_error_timeoutfail = "Timeout. Can not connect to modem.";
106
	$l_error_simfail = "An issue with your Sim card was detected. Is it in the key?";
107
	$l_error_simsecu_l = "Warning, during the last startup, the PIN code was wrong. <br>
108
				The Sim card must be blocked. Please read the documentation.";
109
	$l_autorefresh = "Refresh : 30 sec";
110
	$l_days = "days ";
111
 
112
	$l_num_block="List of blocked phone";
113
	$l_num_num="Phone number";
114
	$l_num_raison="Reason";
115
	$l_num_expiration="Expiration date";
116
	$l_num_action="Action";
117
	$l_num_exist="An account has been created";
118
	$l_num_flood="The number of try has been reached";
119
	$l_num_unlock="Erase";
120
	$l_service_status_img_ok="Running";
121
	$l_service_status_img_ko="Stopped";
122
}
123
echo "
124
	<tr>
125
		<th>$l_title</th>
126
	</tr>
127
	<tr bgcolor=\"#FFCC66\">
128
		<td><img src=\"/images/pix.gif\" width=\"1\" height=\"2\"></td>
129
	</tr>
130
	</TABLE>
131
	<br />
132
	$l_autorefresh	
133
	";
134
 
135
?>
136
<center>
137
<br /><br />
138
<table border=1 width=100%>
139
	<tr>
140
	<td colspan=2><h3><?php echo $l_status_device ?></h3></td>
141
	</tr>
142
 
143
<tr>
144
<?php
145
if(!empty($exec_com) || !empty($exec_com2))
146
{
147
	echo "<td>$l_key_enable</td>";
148
	$status_key="true";
149
}
150
else
151
{
152
	echo "<td>$l_key_diseable</td>";
153
	$status_key="false";
154
}
155
?>
156
	</tr>
157
</table>
158
</center>
159
<br /><br />
160
 
161
<?php
162
 
163
	#Test si gammu est lancé
164
	$gammu_pid=exec("sudo /sbin/pidof gammu-smsd");
165
 
166
 
167
if ($status_key=="false")
168
{
169
	if ($gammu_pid!="")
170
	{
171
		exec("sudo $script stop");
172
		sleep(8);
173
		header('Location: autoregistration.php');	
174
	}
175
}
176
 
177
if ($status_key=="true")
178
{
179
	#Nom du fichier de log lorsque gammu est démarré
180
	$file_log = "gammu-smsd.log";
181
 
182
	#Recuperation du code PIN actuel
183
	$current_pin = exec("sudo $script --pin");	
184
 
185
	#Recuperation du nombre de try avant le ban perm
186
	$current_try_ban = exec("sudo $script --try_ban");	
187
 
188
	#Recuperation de la durée d'une session créée
189
	$current_time_account = exec("sudo $script --time_account");	
190
 
191
	#Recuperation de la durée dun ban perm (après flood)
192
	$current_time_perm = exec("sudo $script --time_perm");	
193
 
194
	#Recuperation de l'adresse du log
195
	$current_log = exec("sudo $script --log");
196
 
197
	#Detection neméro de tel
198
	$current_num_alcasar = exec("sudo $script --numero_alcasar");
199
 
200
	#Detection problème avec la SIM
201
	$current_simfail = exec("sudo $script --last_nosim");
202
 
203
	#Recuperation de la dernière ligne de START
204
	$current_last_start = exec("sudo $script --last_start");
205
 
206
	#Recuperarion de la dernière ligne de STOP
207
	$current_last_stop = exec("sudo $script --last_stop");
208
 
209
	#Recuperation de la dernière ligne de SECURITYERROR
210
	$current_last_secu = exec("sudo $script --last_secu");
211
 
212
	#Recuperation de la dernière ligne de DEVICEWRITEERROR
213
	$current_last_write = exec("sudo $script --last_writeerror");
214
 
215
	#Recuperation de la dernière ligne de TIMEOUT
216
	$current_last_timeout = exec("sudo $script --last_timeout");
217
 
218
	if ($gammu_pid=="")
219
	{
220
		$force_signal = "-";
221
		$imei_device = "-";
222
		$sms_received = "-";
223
 
224
		$gammu="<td><img src=\"/images/state_error.gif\" width=\"15\" height=\"15\" alt=\"".$l_service_status_img_ko."\"></td><td>$l_gammu_off</td>";	
225
		$gammu_log="";
226
		$gammu_status_on="";
227
		$gammu_status_off="disabled";
228
 
229
		if($current_last_secu!="")
230
		{
231
			if(($current_last_secu > $current_last_start) && ($current_last_secu < $current_last_stop))
232
			{
233
				$gammu_simsecu="<tr><td colspan=7><font color=red>$l_error_simsecu_l</font></td></tr>";	
234
			}
235
		}
236
	} else {
237
		# Recuperation de la force du signal et IMEI et nombre de sms reçu
238
		$val_force_signal = exec("sudo $script --signal_device");
239
		$imei_device = exec("sudo $script --imei_device");
240
		$sms_received = exec("sudo $script --sms_received");
241
 
242
		if ($val_force_signal < 21) {
243
			$force_signal = "<img src=\"/images/signal_0.png\">  --  ".$val_force_signal." %";
244
		} elseif ($val_force_signal < 41) {
245
			$force_signal = "<img src=\"/images/signal_20.png\">  --  ".$val_force_signal." %";
246
 
247
		} elseif ($val_force_signal < 61) {
248
			$force_signal = "<img src=\"/images/signal_40.png\">  --  ".$val_force_signal." %";
249
 
250
		} elseif ($val_force_signal < 81) {
251
			$force_signal = "<img src=\"/images/signal_60.png\">  --  ".$val_force_signal." %";
252
 
253
		} elseif ($val_force_signal < 101) {
254
			$force_signal = "<img src=\"/images/signal_80.png\">  --  ".$val_force_signal." %";
255
 
256
		}
257
 
258
 
259
 
260
 
261
 
262
		$gammu="<td><img src=\"/images/state_ok.gif\" width=\"15\" height=\"15\" alt=\"".$l_service_status_img_ok."\"></td><td>$l_gammu_on</td>";	
263
		$gammu_log="<tr><td colspan=7>$current_log</td></tr>";
264
 
265
 
266
		if($current_last_timeout!=""){
267
			if(($current_last_timeout > $current_last_start) && ($current_last_timeout > $current_last_stop))
268
			{
269
				$gammu_timeout="<tr><td colspan=7><font color=red>$l_error_timeoutfail</font></td></tr>";	
270
			}
271
		}
272
 
273
		if($current_last_secu!="")
274
		{
275
			if(($current_last_secu > $current_last_start) && ($current_last_secu > $current_last_stop))
276
			{
277
				exec("sudo $script --stop");
278
			}
279
		}
280
 
281
		if($current_last_write!=""){
282
			if(($current_last_write > $current_last_start) && ($current_last_write > $current_last_stop))
283
			{
284
				$gammu_writeerror="<tr><td colspan=7><font color=red>$l_error_writefail</font></td></tr>";	
285
			}
286
		}
287
 
288
		if($current_simfail!="")
289
		{
290
			if(($current_simfail > $current_last_start) && ($current_simfail > $current_last_stop))
291
			{
292
			$gammu_simfail="<tr><td colspan=7><font color=red>$l_error_simfail</font></td></tr>";
293
			}
294
		}
295
		$gammu_status_on="disabled";
296
		$gammu_status_off="";
297
	}
298
 
299
 
300
	#Lancement et arret de gammu-smsd
301
	if(isset($_GET["start"])){
302
		$gammu_1=exec("sudo $script --start");
303
		sleep(7);
304
 
305
		if($current_last_secu!="")
306
		{
307
			if(($current_last_secu > $current_last_start) && ($current_last_secu > $current_last_stop))
308
			{
309
				exec("sudo $script --stop");
310
			}
311
		}
312
 
313
		sleep(7);
314
		if($current_last_secu!="")
315
		{
316
			if(($current_last_secu > $current_last_start) && ($current_last_secu > $current_last_stop))
317
			{
318
				exec("sudo $script --stop");
319
			}
320
		}
321
 
322
		sleep(7);	
323
		if($current_last_secu!="")
324
		{
325
			if(($current_last_secu > $current_last_start) && ($current_last_secu > $current_last_stop))
326
			{
327
				exec("sudo $script --stop");
328
			}
329
		}
330
 
331
 
332
 
333
		header('Location: autoregistration.php');
334
	}
335
 
336
	if(isset($_GET["stop"])){
337
		exec("sudo $script --stop");
338
		sleep(8);
339
		header('Location: autoregistration.php');
340
	}
341
 
342
 
343
	#Edition du NUMERO de telephone
344
	if(isset($_GET["b_num_alcasar"])){
345
		$num = $_GET["num_alcasar"];
346
		$error_num_alcasar = "";
347
		if($num !="")
348
		{
349
			if(is_numeric($num))
350
			{
351
				exec("sudo $script --replace_numero_alcasar  $num");
352
				header('Location: autoregistration.php');
353
			}
354
			else
355
			{
356
				$error_num_alcasar=$l_error_label_num2;			
357
			}
358
		}
359
		else
360
		{
361
			$error_num_alcasar=$l_error_label_empty;
362
		}
363
	}
364
 
365
	#Edition du code PIN
366
	if(isset($_GET["b_pin"])){
367
		$pin = $_GET["pin"];
368
		$error_pin = "";
369
		if($pin !="")
370
		{
371
			if(is_numeric($pin))
372
			{
373
				exec("sudo $script --replace_pin  $pin");
374
				header('Location: autoregistration.php');
375
			}
376
			else
377
			{
378
				$error_pin=$l_error_label_num;			
379
			}
380
		}
381
		else
382
		{
383
			$error_pin=$l_error_label_empty;
384
		}
385
	}
386
 
387
	#Edition du nombre d'essais avant le ban perm
388
	if(isset($_GET["b_ban_temp"])){
389
		$nb_ban_temp = $_GET["nb_essais"];
390
		$error_nb_essais = "";
391
		if($nb_ban_temp !="")
392
		{
393
			if(is_numeric($nb_ban_temp))
394
			{
395
				exec("sudo $script --replace_try_ban  $nb_ban_temp");
396
				header('Location: autoregistration.php');
397
			}
398
			else
399
			{
400
				$error_nb_essais=$l_error_label_num2;			
401
			}
402
		}
403
		else
404
		{
405
			$error_nb_essais=$l_error_label_empty;
406
		}
407
	}
408
 
409
 
410
	#Edition de la durée pour un compte créé
411
	if(isset($_GET["b_time_account"])){
412
		$time_account = $_GET["time_account"];
413
		$error_time_account = "";
414
		if($time_account !="")
415
		{
416
			if(is_numeric($time_account))
417
			{
418
				exec("sudo $script --replace_time_account  $time_account");
419
				header('Location: autoregistration.php');
420
			}
421
			else
422
			{
423
				$error_time_account=$l_error_label_num2;			
424
			}
425
		}
426
		else
427
		{
428
			$error_time_account=$l_error_label_empty;
429
		}
430
	}
431
 
432
	#Edition de la durée d'un ban perm (après flood)
433
	if(isset($_GET["b_time_perm"])){
434
		$time_perm = $_GET["time_perm"];
435
		$error_time_perm = "";
436
		if($time_perm !="")
437
		{
438
			if(is_numeric($time_perm))
439
			{
440
				exec("sudo $script --replace_time_perm  $time_perm");
441
				header('Location: autoregistration.php');
442
			}
443
			else
444
			{
445
				$error_time_perm=$l_error_label_num2;			
446
			}
447
		}
448
		else
449
		{
450
			$error_time_perm=$l_error_label_empty;
451
		}
452
	}
453
 
454
	# Suppression d'un numero bloqué
455
	if(isset($_GET['num_select'])){
456
		$numero=$_GET['num_select'];
457
 
458
		$add_mac=exec("sudo /usr/sbin/chilli_query list | grep $numero | cut -d ' ' -f1");
459
		exec("sudo /usr/sbin/chilli_query logout $add_mac");
460
 
461
		exec("sudo $script --unlock_num $numero");
462
		header('Location: autoregistration.php');
463
	}
464
 
465
 
466
 
467
	#Si une clé 3g est plugué
468
	echo "<form action=\"autoregistration.php\" methode=\"GET\">
469
 
470
		<table border=1>
471
		<tr>
472
		<td colspan=4><b>$l_status_gammu</b></td>
473
		<td><b><center>$l_force_signal</center></b></td>
474
		<td><b><center>$l_imei_device</center></b></td> 
475
		<td><b><center>$l_sms_received</center></b></td> 
476
		</tr>
477
		<tr>
478
		$gammu
479
		<td><button type=\"submit\" name=\"start\" $gammu_status_on>$l_start</button></td>		
480
		<td><button type=\"submit\" name=\"stop\" $gammu_status_off>$l_stop</button></td>
481
		<td><center>$force_signal</center></td>
482
		<td><center>$imei_device</center></td>
483
		<td><center>$sms_received</center></td>
484
		</tr>
485
		$gammu_log
486
		$gammu_puk
487
		$gammu_simfail
488
		$gammu_simsecu
489
		$gammu_timeout
490
		$gammu_writeerror
491
		</table>
492
	<br /><br />
493
 
494
		<table border=1>
495
		<tr>
496
		<td colspan=3><b>$l_conf</b></td>
497
		<td><b>$l_conf_actu</b></td>
498
		</tr>
499
 
500
		<tr>
501
		<td> $l_num_alcasar </td><td><input type=text name='num_alcasar' maxlength=\"10\"><font color=red><b>$error_num_alcasar</b></font></td>
502
		<td><button type=\"submit\" name=\"b_num_alcasar\" $gammu_status_on>$l_edit</button></td>
503
		<td><center><font color=\"green\">$current_num_alcasar</font></center></td>
504
		</tr>
505
 
506
		<tr>
507
		<td> $l_pin </td><td><input type=text name='pin' maxlength=\"8\"><font color=red><b>$error_pin</b></font></td>
508
		<td><button type=\"submit\" name=\"b_pin\" $gammu_status_on>$l_edit</button></td>
509
		<td><center><font color=\"green\">$current_pin</font></center></td>
510
		</tr>
511
 
512
		<tr>
513
		<td> $l_time_account </td><td><input type=text name='time_account'> $l_days <font color=red><b>$error_time_account</b></font>
514
		<td><button type=\"submit\" name=\"b_time_account\" $gammu_status_on>$l_edit</button></td>	
515
		<td><center><font color=\"blue\">$current_time_account</font></center></td>
516
		</tr>
517
 
518
		<tr>
519
		<td> $l_ban_temp </td><td><input type=text name='nb_essais'><font color=red><b>$error_nb_essais</b></font></td>	
520
		<td><button type=\"submit\" name=\"b_ban_temp\" $gammu_status_on>$l_edit</button></td>	
521
		<td><center><font color=\"orange\">$current_try_ban</font></center></td>
522
		</tr>
523
 
524
		<tr>
525
		<td>$l_time_perm</td><td><input type=text name='time_perm'> $l_days <font color=red><b>$error_time_perm</b></font>
526
		<td><button type=\"submit\" name=\"b_time_perm\" $gammu_status_on>$l_edit</button></td>	
527
		<td><center><font color=\"orange\">$current_time_perm</font></center></td>
528
		</tr>
529
		</tr>
530
		</table>
531
		</form>";		
532
 
533
 
534
	require('/etc/freeradius-web/config.php');
535
 
536
	if (is_file("../../../pass/sql/drivers/$config[sql_type]/functions.php"))
537
		include_once("../../../pass/sql/drivers/$config[sql_type]/functions.php");
538
	else{
539
		echo "<b>Could not include SQL library</b>\n";
540
		exit();
541
	}
542
 
543
 
544
	$con = mysqli_connect("$config[sql_server]","$config[sql_username]","$config[sql_password]","gammu");
545
 
546
	if(mysqli_connect_errno())
547
	{
548
		echo "Fail to connect to $config[sql_type]" . mysqli_connect_error();
549
	}
550
 
551
	$result = mysqli_query($con, "SELECT * FROM SMS_ban_perm");
552
 
553
		echo "	<br />
554
			<table border =1>
555
			<tr>
556
		<td colspan=4><b>$l_num_block</b></td>
557
 
558
			</tr>
559
			<tr>
560
			<td><b>$l_num_num</b></td>
561
			<td><b>$l_num_raison</b></td>
562
			<td><b>$l_num_expiration</b></td>
563
			<td><b>$l_num_action</b></td>
564
			</tr>";
565
 
566
	while($row = mysqli_fetch_array($result))
567
	{
568
		echo "	
569
			<form action=\"autoregistration.php\" methode=\"POST\">
570
			<tr>
571
			<td>
572
	       		<input type=\"hidden\" name=\"num_select\" value=\"" .$row['SenderNumber']."\">	
573
			" . $row['SenderNumber'] . "</td>";
574
 
575
		if($row['Perm']=='0')
576
		{
577
			echo "<td>$l_num_exist</td>";
578
		}
579
		if($row['Perm']=='1')
580
		{
581
			echo "<td>$l_num_flood</td>";
582
		}
583
		echo "	<td>" . $row['Expiration']. "</td>
584
 
585
			<td>
586
			<input type='submit' value='".$l_num_unlock."'>
587
			</td>
588
			</form>	
589
			</tr>";
590
	}
591
	echo "</table>";
592
 
593
	mysqli_close($con);
594
 
595
}
596
?>
597
 
598
</html>