Subversion Repositories ALCASAR

Rev

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

Rev Author Line No. Line
2991 rexy 1
<?php
2
#Define
3
$gammu_wrong_port = "";
4
$gammu_puk = "";
5
$gammu_simfail = "";
6
$gammu_simsecu = "";
7
$gammu_writeerror = "";
8
$gammu_timeout = "";
9
$error_pin = "";
10
$error_time_account = "";
11
$error_nb_essais = "";
12
$error_time_perm = "";
13
$error_num_alcasar = "";
14
$country_filter="";
15
$find_key="false";
16
$listen_on_right_port="false";
17
$script="/usr/local/bin/alcasar-sms.sh";
18
$vendor='';
19
$model='';
20
$gammu_smsd_port='';
21
 
22
# Test if a modem is plugged on serial-usb port
23
$open_port=exec("ls /dev/ttyUSB*",$openned_ports); // list of USB-Serial ports openned by a modem
3076 rexy 24
if (!empty($open_port)) {
2991 rexy 25
	$find_key="true";
26
	$vendor=exec("udevadm info -n $openned_ports[0] | grep 'MODEL=' | cut -d'=' -f2"); 
27
	$model=exec("udevadm info -n $openned_ports[0] | grep 'MODEL_FROM_DATABASE=' | cut -d'=' -f2");
28
	$gammu_smsd_port=exec("cat /etc/gammu_smsd_conf| grep '^port\s\?=' | cut -d ' ' -f3"); // Gammu_smsd listen port 
3076 rexy 29
	foreach($openned_ports as $row) {
30
		if ( "$row" == "$gammu_smsd_port" ) { // is gammu listen on an openned port ?
2991 rexy 31
			$listen_on_right_port="true";
32
		}
33
	}
34
}	
35
$gammu_pid=exec("sudo $script --pidof");
3076 rexy 36
if ($find_key == "false") {	# close gammu if it's started
37
	if ($gammu_pid!="")	{
2991 rexy 38
		exec("sudo $script --stop");
39
		sleep(8);
2992 rexy 40
		header('Location: user_by_sms.php');
2991 rexy 41
		exit();
42
	}
43
}
44
 
45
# Choice of language
46
$Language = 'en';
47
if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
48
	$Langue = explode(",",$_SERVER['HTTP_ACCEPT_LANGUAGE']);
49
	$Language = strtolower(substr(chop($Langue[0]),0,2)); }
50
if($Language == 'fr'){
2992 rexy 51
	$l_title = "Inscription par SMS";
2991 rexy 52
	$l_conf = "Configuration";
53
	$l_conf_actu = "Configuration actuelle";
54
	$l_speed = "Vitesse de connexion au MODEM";
55
	$l_connect_port="Port de connexion au MODEM";
56
	$l_pin = "Code PIN de la carte SIM";
57
	$l_num_alcasar = "Numero de téléphone de la carte SIM";
58
	$l_ban_temp = "Nombre d'essais avant le blocage";
59
	$l_time_account = "Durée de validité des comptes crées";
60
	$l_time_perm = "Durée du blocage (en jours)";
61
	$l_status_gammu = "Etat du service";
62
	$l_start = "Démarrer";
63
	$l_status_device = "Status de votre MODEM GSM (clé 2G/3G/4G)";
64
	$l_key_diseable = "Aucun périphérique détecté";
65
	$l_key_enable_1 = "Un MODEM GSM '<b>".$vendor."(".$model.")</b>' est connecté.";
66
	$l_key_enable_2 = "Il a ouvert les ports suivants : ";
67
	$l_force_signal = "Force du signal";
68
	$l_imei_device = "IMEI du périphérique";
69
	$l_sms_received = "Nombre de SMS reçu";
70
	$l_stop = "Arrêter";
71
	$l_gammu_on="Le service est démarré";
72
	$l_gammu_off="Le service est arrêté";
73
	$l_edit = "Modifier";
74
	$l_error_wrong_port = "Le port d'écoute ($gammu_smsd_port) n'existe pas";
75
	$l_error_label_empty = "Le champ est vide";
76
	$l_error_label_num = "Ce n'est pas un PIN valide";
77
	$l_error_label_num2 = "Ce n'est pas un nombre";
78
	$l_error_label_num3 = "Le format n'est pas correct: +xxxYYYYYYYYY (xxx: code pays / YYYYYYYYY: numéro de téléphone)";
79
	$l_error_writefail = "Le service ne parvient pas à discuter avec le port du MODEM GSM (ttyUSB0).";
80
	$l_error_timeoutfail = "Impossible de se connecter au MODEM GSM (vérifiez la vitesse de connexion)";
81
	$l_error_simfail = "Un problème au niveau de la carte SIM a été détecté. Est-elle présente?";
82
	$l_error_simsecu_l = "Attention, lors du dernier démarrage, votre code PIN était erroné.<br>
83
					La SIM doit être bloqué (code PUK). Consultez la documentation.";
84
	$l_autorefresh = "Rafraichissement : 30 sec";
85
	$l_days = "jours ";
86
	$l_num_block="Liste des numéros bloqués";
87
	$l_num_num="Numéro";
88
	$l_num_raison="Raison";
89
	$l_num_expiration="Date d'expiration";
90
	$l_num_action="Action";
91
	$l_num_exist="Un compte a été créé";
92
	$l_num_flood="Le nombre d'essais maximum a été dépassé";
93
	$l_num_unlock="Effacer";
94
	$l_country_enable="Activer";
95
	$l_country_disable="Désactiver";
96
	$l_service_status_img_ok="Démarré";
97
	$l_service_status_img_ko="Arrété";
98
	$l_connect_speed="Modifier la vitesse de connexion : ";
99
	$l_tab_first = "premier";
100
	$l_tab_last = "dernier";
101
	$l_tab_next = "suivant";
102
	$l_tab_prev = "précédent";
103
	$l_tab_search = "Recherche :";
104
	$l_tab_pmenu = "Affiche la page _PAGE_ sur _PAGES_";
105
	$l_tab_info = "Montrer _MENU_ résultats par page";
106
	$l_tab_infoempty = "Aucun résultat";
107
	$l_country_filter = "Filtrage en cours : ";
108
	$l_country_filtering = " Filtrage par pays";
109
	$l_country_filtering_plus = " Filtrage par pays avancé";
110
	$l_phone_ban = " Comptes crées et numéros de téléphone bloqués";
111
	$l_country_france_ena = "Autorise les numéros français";
112
	$l_country_ue_ena = "Autorise les numéros européens";
113
	$l_country_all_ena = "Autorise tous les pays";
114
	$l_country_advanced_ena = "Autorisation personnalisée";
115
	$l_advance = "Avancé";
116
} else if($Language == 'es') {
2992 rexy 117
    $l_title = "Registro por SMS";
2991 rexy 118
	$l_conf = "Configuración";
119
	$l_conf_actu = "Configuración actual";
120
	$l_speed = "Velocidad de conexión al MODEM";
121
	$l_connect_port="Puerto de conexión al MODEM";
122
	$l_pin = "PIN de la tarjeta SIM";
123
	$l_num_alcasar = "Número de teléfono de la tarjeta SIM";
124
	$l_ban_temp = "Número máximo de intentos antes de una prohibición permanente (baneo)"; 
125
	$l_time_account = "Período de validez de la nueva cuenta.";
126
	$l_time_perm = "Duración del baneo (por ejemplo, después de X intentar)";
127
	$l_status_gammu = "Estado del servicio";
128
	$l_start = "Iniciar";
129
	$l_status_device = "Estado de su MODEM GSM (2G/3G/4G key)";
130
	$l_key_diseable = "Ningún dispositivo detectado";
131
	$l_key_enable_1 = "Un GSM MODEM '<b>".$vendor."(".$model.")</b>' está conectado.";
132
	$l_key_enable_2 = "Ha abierto los siguientes puertos: ";
133
	$l_force_signal = "Intensidad de señal";
134
	$l_imei_device = "IMEI del dispositivo";
135
	$l_sms_received = "Número de SMS recibidos";
136
	$l_stop = "Detener";
137
	$l_gammu_on="El servicio se está ejecutando";
138
	$l_gammu_off="El servicio está caído";
139
	$l_edit = "Modificar";
140
	$l_error_wrong_port = "El puerto de escucha ($gammu_smsd_port) no existe";
141
	$l_error_label_empty = "Campo vacío";
142
	$l_error_label_num = "No es un PIN válido";
143
	$l_error_label_num2 = "No es un número";
144
	$l_error_label_num3 = "El número de teléfono no es correcto: +xxxYYYYYYYYY (xxx: cod. de país / YYYYYYYYY: numéro de teléfono)";
145
	$l_error_writefail = "No hay comunicación con el puerto GSM MODEM (ttyUSB0).";
146
	$l_error_timeoutfail = "No se puede conectar al MODEM GSM (verifique la velocidad de conexión).";
147
	$l_error_simfail = "Se detectó un problema con su tarjeta SIM. ¿Está colocada?";
148
	$l_error_simsecu_l = "Advertencia, durante el último inicio, el código PIN era incorrecto. <br>
149
				La tarjeta Sim debe estar bloqueada. Por favor lea la documentación.";
150
	$l_autorefresh = "Actualizar en: 30 seg";
151
	$l_days = "días ";
152
	$l_num_block="Lista de teléfonos bloqueados";
153
	$l_num_num="Número de teléfono";
154
	$l_num_raison="Motivo";
155
	$l_num_expiration="Fecha de caducidad";
156
	$l_num_action="Acción";
157
	$l_num_exist="Una cuenta se ha creado";
158
	$l_num_flood="Se ha alcanzado el número de intentos.";
159
	$l_num_unlock="Borrar";
160
	$l_country_enable="Activar";
161
	$l_country_disable="Desactivar";
162
	$l_service_status_img_ok="Corriendo";
163
	$l_service_status_img_ko="Detenido";
164
	$l_connect_speed="Modificar la velocidad de conexión: ";
165
	$l_tab_first = "primero";
166
	$l_tab_last = "último";
167
	$l_tab_next = "siguiente";
168
	$l_tab_prev = "anterior";
169
	$l_tab_search = "Buscar:";
170
	$l_tab_pmenu = "Mostrando _PAGE_ a _PAGE_ de _PAGE_ entradas:";
171
	$l_tab_info = "Mostrar _MENU_ entradas";
172
	$l_tab_infoempty = "No se encontraron registros coincidentes";
173
	$l_country_filter = "Filtrado actual: ";
174
	$l_country_filtering = "Filtrado de país";
175
	$l_country_filtering_plus = " Filtrado de país avanzado";
176
	$l_phone_ban = " Cuentas creadas y números de teléfono prohibidos";
177
	$l_country_france_ena = "Autoriza los números franceses";
178
	$l_country_ue_ena = "Autoriza números europeos";
179
	$l_country_all_ena = "Autorizar todos los países";
180
	$l_country_advanced_ena = "Autorización avanzada";
181
	$l_advance = "Avanzado";
182
} else {
2992 rexy 183
	$l_title = "SMS registration";
2991 rexy 184
	$l_conf = "Configuration";
185
	$l_conf_actu = "Current configuration";
186
	$l_speed = "Connection speed to the MODEM";
187
	$l_connect_port="Connection port to the MODEM";
188
	$l_pin = "PIN password of the SIM card";
189
	$l_num_alcasar = "Phone number of the SIM card";
190
	$l_ban_temp = "Max number of try before a permanent ban"; 
191
	$l_time_account = "Validity period of new account";
192
	$l_time_perm = "Duration of a ban (for example, after X try)";
193
	$l_status_gammu = "Service status";
194
	$l_start = "Start";
195
	$l_status_device = "Status of your GSM MODEM (2G/3G/4G key)";
196
	$l_key_diseable = "No device detected";
197
	$l_key_enable_1 = "A GSM MODEM '<b>".$vendor."(".$model.")</b>' is connected.";
198
	$l_key_enable_2 = "It has openned the following ports : ";
199
	$l_force_signal = "Signal strength";
200
	$l_imei_device = "Device IMEI";
201
	$l_sms_received = "Number of SMS received";
202
	$l_stop = "Stop";
203
	$l_gammu_on="The service is running";
204
	$l_gammu_off="The service is down";
205
	$l_edit = "Modify";
206
	$l_error_wrong_port = "The listening port ($gammu_smsd_port) doesn't exist";
207
	$l_error_label_empty = "Field empty";
208
	$l_error_label_num = "It's not a valid PIN password";
209
	$l_error_label_num2 = "It's not a number";
210
	$l_error_label_num3 = "The phone number is not good: +xxxYYYYYYYYY (xxx: code pays / YYYYYYYYY: numéro de téléphone)";
211
	$l_error_writefail = "Can not communicate with the GSM MODEM port (ttyUSB0).";
212
	$l_error_timeoutfail = "Can not connect to the GSM MODEM (verify the connection speed).";
213
	$l_error_simfail = "An issue with your Sim card was detected. Is it in the key?";
214
	$l_error_simsecu_l = "Warning, during the last startup, the PIN code was wrong. <br>
215
				The Sim card must be blocked. Please read the documentation.";
216
	$l_autorefresh = "Refresh : 30 sec";
217
	$l_days = "days ";
218
	$l_num_block="List of blocked phone";
219
	$l_num_num="Phone number";
220
	$l_num_raison="Reason";
221
	$l_num_expiration="Expiration date";
222
	$l_num_action="Action";
223
	$l_num_exist="An account has been created";
224
	$l_num_flood="The number of try has been reached";
225
	$l_num_unlock="Erase";
226
	$l_country_enable="Enable";
227
	$l_country_disable="Disable";
228
	$l_service_status_img_ok="Running";
229
	$l_service_status_img_ko="Stopped";
230
	$l_connect_speed="Modify the connection speed : ";
231
	$l_tab_first = "first";
232
	$l_tab_last = "last";
233
	$l_tab_next = "next";
234
	$l_tab_prev = "previous";
235
	$l_tab_search = "Search :";
236
	$l_tab_pmenu = "Showing _PAGE_ to _PAGE_ of _PAGE_ entries :";
237
	$l_tab_info = "Show _MENU_ entries";
238
	$l_tab_infoempty = "No matching records found";
239
	$l_country_filter = "Current filtering : ";
240
	$l_country_filtering = " Country filtering";
241
	$l_country_filtering_plus = " Country filtering advanced";
242
	$l_phone_ban = " Accounts created and phone Numbers banned";
243
	$l_country_france_ena = "Authorize the french numbers";
244
	$l_country_ue_ena = "Authorize european numbers";
245
	$l_country_all_ena = "Authorize all countries";
246
	$l_country_advanced_ena = "Advanced Authorization";
247
	$l_advance = "Advanced";
248
}
249
?>
250
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
251
<HTML><!-- written by Rexy -->
252
<head>
253
<!--<META HTTP-EQUIV="Refresh" CONTENT="30">-->
254
<meta http-equiv="Content-Type" content="text/html; charset=$config[general_charset]">
255
<title>Auto enregistrement</title>
256
<link rel="stylesheet" href="/css/acc.css">
257
<!-- DataTables CSS -->
258
<link rel="stylesheet" type="text/css" href="/css/jquery.dataTables.css">
259
<!-- jQuery -->
260
<script type="text/javascript" charset="utf8" src="/js/jquery.min.js"></script>
261
<!-- DataTables -->
262
<script type="text/javascript" charset="utf8" src="/js/jquery.dataTables.js"></script>
263
<script type="text/javascript">
264
function timedRefresh(timeoutPeriod) {
265
    var interval = setInterval(refreshPage, timeoutPeriod);
266
}
267
 
268
function refreshPage() {
269
    if ($("input[name=autoRefreshCheckboxes]").is(":checked")) {
270
        location.reload(true);
271
    }
272
}
273
 
274
$(document).ready( function () {
275
    	$('#table_id').DataTable({
276
		"language": {
277
			"paginate": {
278
			"sFirst": "<?php echo $l_tab_first; ?>",
279
			"sLast": "<?php echo $l_tab_last; ?>",
280
			"sPrevious": "<?php echo $l_tab_prev; ?>",
281
			"sNext": "<?php echo $l_tab_next; ?>"
282
			},
283
            "lengthMenu": "<?php echo $l_tab_info; ?>",
284
            "zeroRecords": "<?php echo $l_tab_infoempty; ?>",
285
            "info": "<?php echo $l_tab_pmenu; ?>",
286
            "infoEmpty": "<?php echo $l_tab_infoempty; ?>",
287
			"sSearch": "<?php echo $l_tab_search; ?>"
288
        }
289
	});
290
	$('#table_country').DataTable({
291
		"language": {
292
			"paginate": {
293
			"sFirst": "<?php echo $l_tab_first; ?>",
294
			"sLast": "<?php echo $l_tab_last; ?>",
295
			"sPrevious": "<?php echo $l_tab_prev; ?>",
296
			"sNext": "<?php echo $l_tab_next; ?>"
297
			},
298
            "lengthMenu": "<?php echo $l_tab_info; ?>",
299
            "zeroRecords": "<?php echo $l_tab_infoempty; ?>",
300
            "info": "<?php echo $l_tab_pmenu; ?>",
301
            "infoEmpty": "<?php echo $l_tab_infoempty; ?>",
302
			"sSearch": "<?php echo $l_tab_search; ?>"
303
        }
304
	});
305
	$(".showhide-div_country").slideUp("slow");	
306
	$(".showhide-div_ban").slideUp("slow");
307
	$(".showhide-div_country_plus").slideUp("slow");
308
	$(".showhide-but_country").on("click", function(){
309
	    $(".showhide-div_country").slideToggle("slow");
310
	});
311
	$(".showhide-but_country_plus").on("click", function(){
312
	    $(".showhide-div_country_plus").slideToggle("slow");
313
	});
314
	$(".showhide-but_ban").on("click", function(){
315
	    $(".showhide-div_ban").slideToggle("slow");
316
	});
317
} );
318
</script>
319
</head>
320
<body onload="JavaScript:timedRefresh(30000);">
321
<TABLE width="100%" border="0" cellspacing="0" cellpadding="0">
322
<?php
323
echo "
324
	<tr>
325
		<th>$l_title</th>
326
	</tr>
327
	<tr bgcolor=\"#FFCC66\">
328
		<td><img src=\"/images/pix.gif\" width=\"1\" height=\"2\"></td>
329
	</tr>
330
	</TABLE>
331
	<br>
332
	<input type='checkbox' checked='checked' name='autoRefreshCheckboxes' >".$l_autorefresh."
333
	";
334
?>
335
<center>
336
<br>
337
<table border=1 width=100%>
338
<tr>
339
<td colspan=2><h3><center><?php echo $l_status_device ?></center></h3></td>
340
</tr>
341
<tr>
342
<?php
3076 rexy 343
if($find_key=="true") {
2991 rexy 344
	# Start / stop of gammu-smsd (3*7sec) --> to be improve with  systemd unit (see tarball in contrib/init folder) 
345
	if(isset($_POST["start"])){
346
		$gammu_1=exec("sudo $script --start");
347
		sleep(7);
3076 rexy 348
		if($current_last_secu!="") {
349
			if(($current_last_secu > $current_last_start) && ($current_last_secu > $current_last_stop)) {
2991 rexy 350
				exec("sudo $script --stop");
351
			}
352
		}
353
		sleep(7);
3076 rexy 354
		if($current_last_secu!="") {
355
			if(($current_last_secu > $current_last_start) && ($current_last_secu > $current_last_stop)) {
2991 rexy 356
				exec("sudo $script --stop");
357
			}
358
		}
359
		sleep(7);	
3076 rexy 360
		if($current_last_secu!="") {
361
			if(($current_last_secu > $current_last_start) && ($current_last_secu > $current_last_stop)) {
2991 rexy 362
				exec("sudo $script --stop");
363
			}
364
		}
2992 rexy 365
		header('Location: user_by_sms.php');
2991 rexy 366
		exit();
367
	}
368
	if(isset($_POST["stop"])){
369
		exec("sudo $script --stop");
370
		sleep(8);
2992 rexy 371
		header('Location: user_by_sms.php');
2991 rexy 372
		exit();
373
	}
374
 
375
	# Set the connexion speed to MODEM	
376
	if(isset($_POST['b_speed'])){
377
		switch ($_POST['speed']) {
378
		case "at":
379
			exec("sudo $script --replace_speed");
380
			break;
381
		case "9600":
382
			exec("sudo $script --replace_speed 9600");
383
			break;
384
		case "19200":
385
			exec("sudo $script --replace_speed 19200");
386
			break;
387
		case "115200":
388
			exec("sudo $script --replace_speed 115200");
389
			break;
2992 rexy 390
		header('Location: user_by_sms.php');
2991 rexy 391
		exit();
392
		}
393
	}
394
 
395
	# Set the connexion port to MODEM	
396
	if(isset($_POST['b_port'])){
397
		echo "speed = ".$_POST['port'];
398
		$port = $_POST['port'];
399
		exec("sudo $script --replace_port ".escapeshellarg($port));
2992 rexy 400
		header('Location: user_by_sms.php');
2991 rexy 401
		exit();
402
	}
403
 
404
	# Set the SIM phone number
405
	if(isset($_POST["b_num_alcasar"])){
406
		echo "speed = ".$_POST['num_alcasar'];
407
		$num = $_POST["num_alcasar"];
408
		$error_num_alcasar = "";
3076 rexy 409
		if($num !="") {
410
			if(preg_match('#^\+#',$num)) {
2991 rexy 411
				exec("sudo $script --replace_numero_alcasar ".escapeshellarg($num));
2992 rexy 412
				header('Location: user_by_sms.php');
2991 rexy 413
				exit();
414
			}
3076 rexy 415
			else {
2991 rexy 416
				$error_num_alcasar=$l_error_label_num3;
417
			}
418
		}
3076 rexy 419
		else {
2991 rexy 420
			$error_num_alcasar=$l_error_label_empty;
421
		}
422
	}
423
 
424
	# Set the SIM card PIN number
425
	if(isset($_POST["b_pin"])){
426
		$pin = $_POST["pin"];
427
		$error_pin = "";
3076 rexy 428
		if($pin !="") {
429
			if(is_numeric($pin)) {
2991 rexy 430
				exec("sudo $script --replace_pin ".escapeshellarg($pin));
2992 rexy 431
				header('Location: user_by_sms.php');
2991 rexy 432
				exit();
433
			}
3076 rexy 434
			else {
2991 rexy 435
				$error_pin=$l_error_label_num;			
436
			}
437
		}
3076 rexy 438
		else {
2991 rexy 439
			$error_pin=$l_error_label_empty;
440
		}
441
	}
442
 
443
	# Set the session timeout for each new account
444
	if(isset($_POST["b_time_account"])){
445
		$time_account = $_POST["time_account"];
446
		$error_time_account = "";
3076 rexy 447
		if($time_account !="") {
448
			if(is_numeric($time_account)) {
2991 rexy 449
				exec("sudo $script --replace_time_account ".escapeshellarg($time_account));
2992 rexy 450
				header('Location: user_by_sms.php');
2991 rexy 451
				exit();
452
			}
3076 rexy 453
			else {
2991 rexy 454
				$error_time_account=$l_error_label_num2;
455
			}
456
		}
3076 rexy 457
		else {
2991 rexy 458
			$error_time_account=$l_error_label_empty;
459
		}
460
	}
461
 
462
	# Set the number of tries before ban
463
	if(isset($_POST["b_ban_temp"])){
464
		$nb_ban_temp = $_POST["nb_essais"];
465
		$error_nb_essais = "";
3076 rexy 466
		if($nb_ban_temp !="") {
467
			if(is_numeric($nb_ban_temp)) {
2991 rexy 468
				exec("sudo $script --replace_try_ban ".escapeshellarg($nb_ban_temp));
2992 rexy 469
				header('Location: user_by_sms.php');
2991 rexy 470
				exit();
471
			}
3076 rexy 472
			else {
2991 rexy 473
				$error_nb_essais=$l_error_label_num2;			
474
			}
475
		}
3076 rexy 476
		else {
2991 rexy 477
			$error_nb_essais=$l_error_label_empty;
478
		}
479
	}
480
 
481
	# Set the ban timeout
482
	if(isset($_POST["b_time_perm"])){
483
		$time_perm = $_POST["time_perm"];
484
		$error_time_perm = "";
3076 rexy 485
		if($time_perm !="") {
486
			if(is_numeric($time_perm)) {
2991 rexy 487
				exec("sudo $script --replace_time_perm ".escapeshellarg($time_perm));
2992 rexy 488
				header('Location: user_by_sms.php');
2991 rexy 489
				exit();
490
			}
3076 rexy 491
			else {
2991 rexy 492
				$error_time_perm=$l_error_label_num2;
493
			}
494
		}
3076 rexy 495
		else {
2991 rexy 496
			$error_time_perm=$l_error_label_empty;
497
		}
498
	}
499
 
500
	# removing a banned phone number
3076 rexy 501
	if(isset($_POST['num_select'])) {
2991 rexy 502
		$numero=$_POST['num_select'];
503
		$add_mac=exec("sudo /usr/sbin/chilli_query list | grep ".escapeshellarg($numero)." | cut -d ' ' -f1");
504
		if (!empty($add_mac)) {
505
			exec("sudo /usr/sbin/chilli_query logout ".escapeshellarg($add_mac));
506
		}
507
		exec("sudo $script --unlock_num $numero");
2992 rexy 508
		header('Location: user_by_sms.php');
2991 rexy 509
		exit();
510
	}
511
 
512
	# Edition etat pays
3076 rexy 513
	if(isset($_POST['country_select'])) {
2991 rexy 514
		$country=utf8_decode($_POST['country_select']);
515
		exec("sudo $script --change_country ".escapeshellarg($country));
516
		exec("sudo $script --change_country_filter advance");
2992 rexy 517
		header('Location: user_by_sms.php');
2991 rexy 518
		exit();
519
	}
3076 rexy 520
	if(isset($_POST['b_france_enable'])) {
2991 rexy 521
		exec("sudo $script --change_country_dis_all");
522
		exec("sudo $script --change_country France");
523
		exec("sudo $script --change_country_filter fr");
2992 rexy 524
		header('Location: user_by_sms.php');
2991 rexy 525
		exit();
526
	}
3076 rexy 527
	if(isset($_POST['b_ue_enable'])) {
2991 rexy 528
		exec("sudo $script --change_country_dis_all");
529
		$array_ue = array("Allemagne","Autriche","Belgique","Bulgarie","Chypre","Croatie","Danemark","Espagne","Estonie","Finlande","France","Grece","Hongrie","Irlande","Italie","Lettonie","Lituanie","Luxembourg","Malte","Pays-Bas"," Pologne","Portugal","Republique Tcheque","Roumanie","Angleterre","Slovaquie","Slovenie","Suede");
530
		foreach ($array_ue as $pays){
531
			exec("sudo $script --change_country ".escapeshellarg($pays));
532
		}
533
		exec("sudo $script --change_country_filter ue");
2992 rexy 534
		header('Location: user_by_sms.php');
2991 rexy 535
		exit();
536
	}
3076 rexy 537
	if(isset($_POST["b_country_enable"])) {
2991 rexy 538
		exec("sudo $script --change_country_ena_all");		
539
		exec("sudo $script --change_country_filter all");
2992 rexy 540
		header('Location: user_by_sms.php');
2991 rexy 541
		exit();
542
	}
3076 rexy 543
	if(isset($_POST["b_country_disable"])) {
2991 rexy 544
		exec("sudo $script --change_country_dis_all");
2992 rexy 545
		header('Location: user_by_sms.php');
2991 rexy 546
		exit();
547
	}
548
	echo '	<td>'.$l_key_enable_1;
549
	echo '<br>'.$l_key_enable_2.'<b>';
550
	reset ($openned_ports);
3076 rexy 551
	foreach ($openned_ports as $row) {
2991 rexy 552
		echo $row." ";
553
	}
554
	echo '</b></td>';
555
}
3076 rexy 556
else {
2991 rexy 557
	echo "<td>$l_key_diseable</td>";
558
}
559
?>
560
</tr>
561
</table>
562
</center>
563
<br>
564
<?php
565
 
3076 rexy 566
if ($find_key=="true") {
2991 rexy 567
	#Nom du fichier de log lorsque gammu est démarré
568
	#$file_log = "gammu-smsd.log";
569
 
570
	#Recuperation de la vitesse de connexion
571
	$current_speed = exec("sudo $script --connect");
572
 
573
	#Recuperation du code PIN actuel
574
	$current_pin = exec("sudo $script --pin");	
575
 
576
	#Recuperation du nombre de try avant le ban perm
577
	$current_try_ban = exec("sudo $script --try_ban");	
578
 
579
	#Recuperation de la durée d'une session créée
580
	$current_time_account = exec("sudo $script --time_account");	
581
 
582
	#Recuperation de la durée dun ban perm (après flood)
583
	$current_time_perm = exec("sudo $script --time_perm");	
584
 
585
	#Detection neméro de tel
586
	$current_num_alcasar = exec("sudo $script --numero_alcasar");
587
 
588
	#Detection problème avec la SIM
589
	$current_simfail = exec("sudo $script --last_nosim");
590
 
591
	#Recuperation de la dernière ligne de START
592
	$current_last_start = exec("sudo $script --last_start");
593
 
594
	#Recuperarion de la dernière ligne de STOP
595
	$current_last_stop = exec("sudo $script --last_stop");
596
 
597
	#Recuperation de la dernière ligne de SECURITYERROR
598
	$current_last_secu = exec("sudo $script --last_secu");
599
 
600
	#Recuperation de la dernière ligne de DEVICEWRITEERROR
601
	$current_last_write = exec("sudo $script --last_writeerror");
602
 
603
	#Recuperation de la dernière ligne de TIMEOUT
604
	$current_last_timeout = exec("sudo $script --last_timeout");
605
 
606
	# Test si le service est lancé
3076 rexy 607
	if ($gammu_pid=="") {
2991 rexy 608
		$force_signal = "-";
609
		$imei_device = "-";
610
		$sms_received = "-";
611
		$gammu="<td><img src=\"/images/state_error.gif\" width=\"15\" height=\"15\" alt=\"".$l_service_status_img_ko."\"></td><td>$l_gammu_off</td>";	
612
		$gammu_status_on="";
613
		$gammu_status_off="disabled";
3076 rexy 614
		if($current_last_secu!="") {
615
			if(($current_last_secu > $current_last_start) && ($current_last_secu < $current_last_stop)) {
2991 rexy 616
				$gammu_simsecu="<tr><td colspan=7><font color=red>$l_error_simsecu_l</font></td></tr>";	
617
			}
618
		}
619
	} else {
620
		# Recuperation de la force du signal et IMEI et nombre de sms reçu
621
		$val_force_signal = exec("sudo $script --signal_device");
622
		$imei_device = exec("sudo $script --imei_device");
623
		$sms_received = exec("sudo $script --sms_received");
624
		if ($val_force_signal < 21) {
625
			$force_signal = "<img src=\"/images/signal_0.png\">  --  ".$val_force_signal." %";
626
		} elseif ($val_force_signal < 41) {
627
			$force_signal = "<img src=\"/images/signal_20.png\">  --  ".$val_force_signal." %";
628
		} elseif ($val_force_signal < 61) {
629
			$force_signal = "<img src=\"/images/signal_40.png\">  --  ".$val_force_signal." %";
630
		} elseif ($val_force_signal < 81) {
631
			$force_signal = "<img src=\"/images/signal_60.png\">  --  ".$val_force_signal." %";
632
		} elseif ($val_force_signal < 101) {
633
			$force_signal = "<img src=\"/images/signal_80.png\">  --  ".$val_force_signal." %";
634
		}
635
		$gammu="<td><img src=\"/images/state_ok.gif\" width=\"15\" height=\"15\" alt=\"".$l_service_status_img_ok."\"></td><td>$l_gammu_on</td>";	
3076 rexy 636
		if ($listen_on_right_port != "true") {
2991 rexy 637
			$gammu_wrong_port="<tr><td colspan=7><font color=red>$l_error_wrong_port</font></td></tr>";
638
		}	
3076 rexy 639
		if($current_last_timeout!="") {
640
			if(($current_last_timeout > $current_last_start) && ($current_last_timeout > $current_last_stop)) {
2991 rexy 641
				$gammu_timeout="<tr><td colspan=7><font color=red>$l_error_timeoutfail</font></td></tr>";
642
			}
643
		}
3076 rexy 644
		if($current_last_secu!="") {
645
			if(($current_last_secu > $current_last_start) && ($current_last_secu > $current_last_stop)) {
2991 rexy 646
				exec("sudo $script --stop");
647
			}
648
		}
3076 rexy 649
		if($current_last_write!="") {
650
			if(($current_last_write > $current_last_start) && ($current_last_write > $current_last_stop)) {
2991 rexy 651
				$gammu_writeerror="<tr><td colspan=7><font color=red>$l_error_writefail</font></td></tr>";	
652
			}
653
		}
3076 rexy 654
		if($current_simfail!="") {
655
			if(($current_simfail > $current_last_start) && ($current_simfail > $current_last_stop)) {
2991 rexy 656
				$gammu_simfail="<tr><td colspan=7><font color=red>$l_error_simfail</font></td></tr>";
657
			}
658
		}
659
		$gammu_status_on="disabled";
660
		$gammu_status_off="";
661
	}
2992 rexy 662
	echo "<form action=\"user_by_sms.php\" method=\"post\">
2991 rexy 663
		<table border=1>
664
		<tr>
665
		<td colspan=3><b>$l_conf</b></td>
666
		<td><b>$l_conf_actu</b></td>
667
		</tr>
668
		<tr>
669
		<td> $l_connect_port </td><td><select name=\"port\">'";
670
		reset ($openned_ports);
3076 rexy 671
		foreach ($openned_ports as $row) {
2991 rexy 672
			echo '<option value="'.$row.'"';;if ("$row" == "$gammu_smsd_port") echo " selected";echo '>'.$row.'</option>';
673
			echo $row." ";
674
		}
675
	echo "</select></td>
676
		<td><button type=\"submit\" name=\"b_port\" $gammu_status_on>$l_edit</button></td>
677
		<td><center><font color=\"green\">$gammu_smsd_port</font></center></td>
678
		</tr>
679
		<td> $l_speed </td><td>
680
			<select name=\"speed\">
681
				<option value=\"at\"";if ($current_speed == "at") echo " selected";echo ">Auto</option>
682
				<option value=\"9600\"";if ($current_speed == "at9600") echo " selected"; echo ">9600 Bauds</option>
683
				<option value=\"19200\"";if ($current_speed == "at19200") echo " selected"; echo ">19200 Bauds</option>
684
				<option value=\"115200\"";if ($current_speed == "at115200") echo " selected";echo ">115200 Bauds</option>
685
			</select>
686
		<td><button type=\"submit\" name=\"b_speed\">$l_edit</button></td>
687
		<td><center><font color=\"green\">".str_replace("at","",$current_speed);if ($current_speed == "at"){ echo "Auto"; } else { echo " Bauds";}echo "</font></center></td>
688
		<tr>
689
		<tr>
690
		<td> $l_num_alcasar </td><td><input type=text name='num_alcasar' maxlength=\"20\"></td>
691
		<td><button type=\"submit\" name=\"b_num_alcasar\" $gammu_status_on>$l_edit</button></td>
692
		<td><center><font color=\"green\">$current_num_alcasar</font></center></td>
693
		</tr>
694
		<tr><td colspan=\"4\"><font color=red><b>$error_num_alcasar</b></font></td></tr>
695
		<tr>		
696
		<td> $l_pin </td><td><input type=text name='pin' maxlength=\"8\"></td>
697
		<td><button type=\"submit\" name=\"b_pin\" $gammu_status_on>$l_edit</button></td>
698
		<td><center><font color=\"green\">$current_pin</font></center></td>
699
		</tr>
700
		<tr><td colspan=\"4\"><font color=red><b>$error_pin</b></font></td></tr>
701
		<tr>
702
		<td> $l_time_account </td><td><input type=text name='time_account'> $l_days </td>
703
		<td><button type=\"submit\" name=\"b_time_account\" $gammu_status_on>$l_edit</button></td>	
704
		<td><center><font color=\"blue\">$current_time_account</font></center></td>
705
		</tr>
706
		<tr><td colspan=\"4\"><font color=red><b>$error_time_account</b></font></td></tr>
707
		<tr>
708
		<td> $l_ban_temp </td><td><input type=text name='nb_essais'></td>	
709
		<td><button type=\"submit\" name=\"b_ban_temp\" $gammu_status_on>$l_edit</button></td>	
710
		<td><center><font color=\"orange\">$current_try_ban</font></center></td>
711
		</tr>
712
		<tr><td colspan=\"4\"><font color=red><b>$error_nb_essais</b></font></td></tr>
713
		<tr>
714
		<td>$l_time_perm</td><td><input type=text name='time_perm'> $l_days</td>
715
		<td><button type=\"submit\" name=\"b_time_perm\" $gammu_status_on>$l_edit</button></td>	
716
		<td><center><font color=\"orange\">$current_time_perm</font></center></td>
717
		</tr>
718
		<tr><td colspan=\"4\"><font color=red><b>$error_time_perm</b></font></td></tr>
719
		</table>
720
		<br>
721
		<table border=1>
722
		<tr>
723
			<td colspan=4><b>$l_status_gammu</b></td>
724
			<td><b><center>$l_force_signal</center></b></td>
725
			<td><b><center>$l_imei_device</center></b></td> 
726
			<td><b><center>$l_sms_received</center></b></td> 
727
		</tr>
728
		<tr>
729
			$gammu
730
			<td><button type=\"submit\" name=\"start\" $gammu_status_on>$l_start</button></td>		
731
			<td><button type=\"submit\" name=\"stop\" $gammu_status_off>$l_stop</button></td>
732
			<td><center>$force_signal</center></td>
733
			<td><center>$imei_device</center></td>
734
			<td><center>$sms_received</center></td>
735
		</tr>
736
		$gammu_wrong_port
737
		$gammu_puk
738
		$gammu_simfail
739
		$gammu_simsecu
740
		$gammu_timeout
741
		$gammu_writeerror
742
		</table>
743
		</form>";
744
	require('/etc/freeradius-web/config.php');
745
	if (is_file("../lib/sql/drivers/$config[sql_type]/functions.php"))
746
		include_once("../lib/sql/drivers/$config[sql_type]/functions.php");
3076 rexy 747
	else {
2991 rexy 748
		echo "<b>Could not include SQL library</b>\n";
749
		exit();
750
	}
751
	$con = mysqli_connect("$config[sql_server]","$config[sql_username]","$config[sql_password]","gammu");
3076 rexy 752
	if(mysqli_connect_errno()) {
2991 rexy 753
		echo "Fail to connect to $config[sql_type]" . mysqli_connect_error();
754
	}
755
	# Country table
756
?>
757
	<div style="border-radius: 5px; background: #BDBDBD; margin-top: 15px;">
758
		 <span class="showhide-but_country"><?php echo "<strong>$l_country_filtering</strong>" ?><img src="/images/down2.gif" width="15" height="15"></span>
759
		<div class="showhide-div_country">
760
		<br />
761
			<table width=100% style="background: #BDBDBD;">
762
			<tr>
763
				<?php 
764
					$result_country_filter = mysqli_query($con, "SELECT id FROM SMS_country WHERE name = 'FILTRAGE'");
765
					$row = mysqli_fetch_array($result_country_filter);
766
 
767
					if($row['id'] == "advance") {
768
						$country_filter = $l_country_advanced_ena;
769
					} elseif($row['id'] == "ue") {
770
						$country_filter = $l_country_ue_ena;
771
					} elseif($row['id'] == "fr") {
772
						$country_filter = $l_country_france_ena;
773
					} elseif($row['id'] == "all") {
774
						$country_filter = $l_country_all_ena;
775
					} else {
776
						$country_filter = "Err.";
777
					}
778
				?>
779
				<td colspan="3" align="center"><strong><?php echo $l_country_filter; ?></strong><font size="3" color="red"><?php echo $country_filter; ?></font></td>
780
			</tr>
781
			<tr>
2992 rexy 782
				<form action="user_by_sms.php" method="post">
2991 rexy 783
					<td align="center" width=33%><button type="submit" name="b_france_enable"><?php echo "$l_country_france_ena" ?></button></td>
784
					<td align="center" width=34%><button type="submit" name="b_ue_enable"><?php echo "$l_country_ue_ena" ?></button></td>
785
					<td align="center" width=33%><button type="submit" name="b_country_enable"><?php echo "$l_country_all_ena" ?></button></td>
786
				</form>
787
			</tr>	
788
			</table>
789
			<div style="border-radius: 5px; background: #D8D8D8; margin: 15px;">
790
			<span class="showhide-but_country_plus"><?php echo "<strong>$l_country_filtering_plus</strong>" ?> <img src="/images/down2.gif" width="15" height="15"></span>
791
				<div class="showhide-div_country_plus">
792
				<table id="table_country" class="display">
793
					<thead>
794
						<tr>
795
							<th><b><font color="black">Pays</font></b></th>
796
							<th><b><font color="black">code</font></b></th>
797
							<th><b><font color="black">Etat</font></b></th>
798
						</tr>
799
					</thead>
800
					<tbody>
801
						<?php 
802
						$result_country = mysqli_query($con, "SELECT * FROM SMS_country WHERE name != 'FILTRAGE'");
3076 rexy 803
						while($row = mysqli_fetch_array($result_country)) {
804
							echo "	
805
							<tr>
806
							<form action=\"user_by_sms.php\" method=\"post\">
807
							<td>
808
								<input type=\"hidden\" name=\"country_select\" value=\"" .$row['name']."\">	
809
								".$row['name']."
810
							</td>
811
							<td>".$row['id']."</td>
812
							";
813
						if($row['status']=='0') {
2991 rexy 814
							echo "<td><input type='image' src=\"/images/state_error.gif\" width=\"15\" height=\"15\"></td>";
815
						}
3076 rexy 816
						if($row['status']=='1') {
2991 rexy 817
							echo "<td><input type='image' src=\"/images/state_ok.gif\" width=\"15\" height=\"15\"></td>";
818
						}
819
						echo "	</form>
820
							</tr>
821
							";
822
						}
823
						?>
824
					</tbody>
825
				</table>
826
				</div>
827
			</div>
828
		</div>	
829
	</div>
830
<?php 
831
	$result = mysqli_query($con, "SELECT * FROM SMS_ban_perm");
832
?>
833
<div style="border-radius: 5px; background: #BDBDBD; margin-top: 15px;">
834
		<span class="showhide-but_ban"><?php echo "<strong>$l_phone_ban</strong>" ?><img src="/images/down2.gif" width="15" height="15"></span>
835
		<div class="showhide-div_ban">
836
			<table id="table_id" class="display">
837
				<thead>
838
					<tr>
839
						<th><b><font color="black"><?php echo $l_num_num; ?></font></b></th>
840
						<th><b><font color="black"><?php echo $l_num_raison; ?></font></b></th>
841
						<th><b><font color="black"><?php echo $l_num_expiration; ?></font></b></th>
842
						<th><b><font color="black">Action</font></b></th>
843
					</tr>
844
				</thead>
845
				<tbody>
846
					<?php 
3076 rexy 847
					while($row = mysqli_fetch_array($result)) {
848
						echo "	
2991 rexy 849
						<tr>
3076 rexy 850
							<form action=\"user_by_sms.php\" method=\"post\">
2991 rexy 851
							<td>
3076 rexy 852
								<input type=\"hidden\" name=\"num_select\" value=\"" .$row['SenderNumber']."\">	
853
								".$row['SenderNumber']."
854
							</td>";
855
						if($row['Perm']=='0') {
856
							echo "<td>$l_num_exist</td>";
857
						}
858
						if($row['Perm']=='1') {
859
							echo "<td>$l_num_flood</td>";
860
						}
861
						echo "	<td>" . $row['Expiration']. "</td>
862
							<td>
2991 rexy 863
								<input type='submit' value='".$l_num_unlock."'>
864
							</td>
865
							</form>
866
						</tr>
867
						";
868
					}
869
					?>
870
				</tbody>
871
			</table>
872
		</div>
873
	</div>
874
<?php
875
	mysqli_close($con);
876
	}
877
?>
878
</html>