1
|
<?php
|
2
|
|
3
|
|
4
|
|
5
|
|
6
|
|
7
|
|
8
|
|
9
|
|
10
|
|
11
|
|
12
|
|
13
|
|
14
|
|
15
|
|
16
|
|
17
|
|
18
|
|
19
|
|
20
|
|
21
|
|
22
|
|
23
|
|
24
|
|
25
|
|
26
|
|
27
|
|
28
|
|
29
|
|
30
|
|
31
|
|
32
|
|
33
|
|
34
|
|
35
|
|
36
|
|
37
|
|
38
|
|
39
|
|
40
|
|
41
|
|
42
|
|
43
|
|
44
|
|
45
|
global $system_gid_min, $system_gid_max, $system_uid_min, $system_uid_max;
|
46
|
$system_gid_min=trim(`grep ^GID_MIN /etc/login.defs | awk '{print $2}'`);
|
47
|
$system_gid_max=trim(`grep ^GID_MAX /etc/login.defs | awk '{print $2}'`);
|
48
|
$system_uid_min=trim(`grep ^UID_MIN /etc/login.defs | awk '{print $2}'`);
|
49
|
$system_uid_max=trim(`grep ^UID_MAX /etc/login.defs | awk '{print $2}'`);
|
50
|
|
51
|
function save_config($config) {
|
52
|
global $conf_fichier_conf;
|
53
|
$textetosave = $config->GetTextToSave();
|
54
|
$commande = "
|
55
|
cat << EOF > $conf_fichier_conf
|
56
|
$textetosave
|
57
|
EOF
|
58
|
chmod 644 $conf_fichier_conf
|
59
|
";
|
60
|
$res = fichier_script($commande,"iconnect");
|
61
|
return $res;
|
62
|
}
|
63
|
|
64
|
if (!function_exists('maxlengthcsv')) {
|
65
|
function maxlengthcsv($file) {
|
66
|
|
67
|
|
68
|
if(! file_exists($file)) {
|
69
|
return FALSE;
|
70
|
}
|
71
|
|
72
|
$length = 1024;
|
73
|
$array = file($file);
|
74
|
for($i=0;$i<count($array);$i++) {
|
75
|
if ($length < strlen($array[$i])) {
|
76
|
$length = strlen($array[$i]);
|
77
|
}
|
78
|
}
|
79
|
unset($array);
|
80
|
return $length;
|
81
|
}
|
82
|
}
|
83
|
|
84
|
if (!function_exists('array_trim')) {
|
85
|
function array_trim(&$arr) {
|
86
|
|
87
|
|
88
|
|
89
|
|
90
|
|
91
|
|
92
|
|
93
|
|
94
|
|
95
|
if(! is_array($arr))
|
96
|
return $arr;
|
97
|
|
98
|
while (list($key,$val)=each($arr)) {
|
99
|
if (is_string($val)) {
|
100
|
$arr[$key] = trim($val);
|
101
|
|
102
|
}
|
103
|
if (is_array($val)) {
|
104
|
$arr[$key] = array_trim($val);
|
105
|
}
|
106
|
}
|
107
|
return $arr;
|
108
|
}
|
109
|
}
|
110
|
|
111
|
function abstraction_indexwebadmin($s) {
|
112
|
|
113
|
global $config;
|
114
|
if(is_string($s)) {
|
115
|
if(strpos($s,"@") !== false) {
|
116
|
if(! is_object($config)) {
|
117
|
$config = new AbE_General_Config();
|
118
|
}
|
119
|
$tab = explode("@@",$s);
|
120
|
$texte = $tab[0];
|
121
|
for($i = 1; $i < count($tab); $i++) {
|
122
|
if($i%2 == 0)
|
123
|
$texte .= $tab[$i];
|
124
|
else {
|
125
|
|
126
|
|
127
|
global ${$tab[$i]};
|
128
|
$texte .= ucfirst(${$tab[$i]});
|
129
|
}
|
130
|
}
|
131
|
}
|
132
|
else {
|
133
|
$texte = $s;
|
134
|
}
|
135
|
}
|
136
|
return $texte;
|
137
|
}
|
138
|
|
139
|
if (!function_exists('nbaleatoire')) {
|
140
|
function nbaleatoire() {
|
141
|
|
142
|
mt_srand((double)microtime()*1000000);
|
143
|
$num = mt_rand(46,122);
|
144
|
return $num;
|
145
|
}
|
146
|
}
|
147
|
|
148
|
if (!function_exists('gencharactere')) {
|
149
|
function gencharactere() {
|
150
|
|
151
|
|
152
|
do{
|
153
|
$num = nbaleatoire();
|
154
|
} while ( ( $num > 57 && $num < 65 ) || ( $num > 90 && $num < 97 ));
|
155
|
$char = chr($num);
|
156
|
return $char;
|
157
|
}
|
158
|
}
|
159
|
|
160
|
|
161
|
|
162
|
|
163
|
|
164
|
|
165
|
|
166
|
|
167
|
|
168
|
|
169
|
if (!function_exists('saltstr')) {
|
170
|
function saltstr($size) {
|
171
|
for($i=1;$i<=$size;$i++) {
|
172
|
$string = $string.gencharactere();
|
173
|
}
|
174
|
return $string;
|
175
|
}
|
176
|
}
|
177
|
|
178
|
|
179
|
|
180
|
|
181
|
|
182
|
|
183
|
|
184
|
|
185
|
|
186
|
|
187
|
|
188
|
if (!function_exists('generer_clef')) {
|
189
|
function generer_clef($type) {
|
190
|
if($type == "des-std") {
|
191
|
return saltstr(2);
|
192
|
} else if ($type == "des-ext") {
|
193
|
return saltstr(9);
|
194
|
} else if ($type == "md5") {
|
195
|
|
196
|
$tmpslt = saltstr(8);
|
197
|
return sprintf("$1$%s$",$tmpslt);
|
198
|
} else if ($type == "blowfish") {
|
199
|
|
200
|
$tmpslt = saltstr(13);
|
201
|
return sprintf("$2$%s$",$tmpslt);
|
202
|
} else {
|
203
|
return saltstr(2);
|
204
|
}
|
205
|
}
|
206
|
}
|
207
|
|
208
|
|
209
|
|
210
|
|
211
|
|
212
|
|
213
|
|
214
|
|
215
|
|
216
|
|
217
|
|
218
|
if (!function_exists('file_csv')) {
|
219
|
function file_csv($file,$sep) {
|
220
|
if(! file_exists($file)) {
|
221
|
return FALSE;
|
222
|
}
|
223
|
|
224
|
$f = file($file);
|
225
|
for($i = 0; $i < count($f); $i++) {
|
226
|
$t = explode($sep,$f[$i]);
|
227
|
$tab[$i] = $t;
|
228
|
}
|
229
|
|
230
|
return $tab;
|
231
|
}
|
232
|
}
|
233
|
|
234
|
|
235
|
|
236
|
|
237
|
|
238
|
|
239
|
|
240
|
|
241
|
|
242
|
|
243
|
|
244
|
function file_cache_csv($file,$sep) {
|
245
|
$f = @file($file);
|
246
|
for($i = 0; $i < count($f); $i++) {
|
247
|
$t = explode($sep,$f[$i]);
|
248
|
$tab[$t[0]] = $t;
|
249
|
}
|
250
|
return $tab;
|
251
|
}
|
252
|
|
253
|
function to_group($gid) {
|
254
|
|
255
|
|
256
|
|
257
|
|
258
|
@assert(is_numeric($gid));
|
259
|
|
260
|
$group = trim(`grep ":$gid:" /etc/group | cut -d: -f1`);
|
261
|
if ("" == $group) {
|
262
|
return false;
|
263
|
}
|
264
|
else {
|
265
|
return $group;
|
266
|
}
|
267
|
}
|
268
|
|
269
|
function to_gid($groupname) {
|
270
|
|
271
|
|
272
|
|
273
|
|
274
|
$gid = trim(`grep "^$groupname:" /etc/group | cut -d: -f3`);
|
275
|
|
276
|
if ("" == $gid) {
|
277
|
return false;
|
278
|
}
|
279
|
else {
|
280
|
return $gid;
|
281
|
}
|
282
|
}
|
283
|
|
284
|
|
285
|
|
286
|
|
287
|
|
288
|
|
289
|
function anti_speciaux($t, $agressif=0) {
|
290
|
if(trim($t) == "")
|
291
|
return ;
|
292
|
|
293
|
|
294
|
if($agressif >= 1) {
|
295
|
$texte = strtolower($t);
|
296
|
$texte = remove_accents($texte);
|
297
|
|
298
|
if($agressif == 2) {
|
299
|
|
300
|
$texte = str_replace(" ","",$texte);
|
301
|
$texte = str_replace("-","",$texte);
|
302
|
$texte = str_replace("_","",$texte);
|
303
|
|
304
|
|
305
|
}
|
306
|
}
|
307
|
else {
|
308
|
$texte=$t;
|
309
|
}
|
310
|
|
311
|
return $texte;
|
312
|
}
|
313
|
|
314
|
|
315
|
|
316
|
|
317
|
function compare_ip($a,$b) {
|
318
|
|
319
|
|
320
|
|
321
|
|
322
|
|
323
|
|
324
|
$taba = explode(".",$a);
|
325
|
$tabb = explode(".",$b);
|
326
|
$retour = 0;
|
327
|
for($i = 0; ($i < count($taba)) && ($retour == 0); $i++) {
|
328
|
|
329
|
if($taba[$i] < $tabb[$i]) {
|
330
|
$retour = -1;
|
331
|
}
|
332
|
else if($taba[$i] > $tabb[$i]) {
|
333
|
$retour = 1;
|
334
|
}
|
335
|
}
|
336
|
return $retour;
|
337
|
}
|
338
|
|
339
|
|
340
|
|
341
|
|
342
|
function liste_terminaux($fic_dhcp = ""){
|
343
|
abe_api_debug("entering liste_terminaux()", 2);
|
344
|
global $conf_fic_dhcp, $conf_zone;
|
345
|
|
346
|
|
347
|
global $tab_macaddr_terminaux;
|
348
|
if($fic_dhcp == "")
|
349
|
$fic_dhcp = $conf_fic_dhcp;
|
350
|
|
351
|
$i = 0;
|
352
|
$fdhcp = @fopen($fic_dhcp,"r");
|
353
|
if($fdhcp){
|
354
|
while(!feof($fdhcp)){
|
355
|
$ligne = fgets($fdhcp,4096);
|
356
|
if(ereg("(host )(.*)( \{)",$ligne,$res)){
|
357
|
|
358
|
|
359
|
|
360
|
$tab[$i]["host"] = str_replace(".".$conf_zone, "", $res[2]);
|
361
|
$tab[$i]["ip"] = @gethostbyname($res[2]);
|
362
|
|
363
|
$ligne = fgets($fdhcp,4096);
|
364
|
|
365
|
if(ereg("(option option-128)",$ligne, $res)){
|
366
|
$ligne = fgets($fdhcp,4096);
|
367
|
}
|
368
|
|
369
|
if(ereg("(option option-129)",$ligne, $res)){
|
370
|
$ligne = fgets($fdhcp,4096);
|
371
|
}
|
372
|
|
373
|
if(ereg("(hardware ethernet )(.*)(;)",$ligne,$res)){
|
374
|
$tab[$i]["mac"] = strtolower($res[2]);
|
375
|
$tab_macaddr_terminaux[] = strtolower($res[2]);
|
376
|
abe_api_debug("found a TX: " . $tab[$i]['host'] . ", mac=" . $tab[$i]['mac'], 5);
|
377
|
|
378
|
}
|
379
|
|
380
|
|
381
|
$file = "/home/machines/" . $tab[$i]["host"] . "/.maquette";
|
382
|
if(file_exists($file)) {
|
383
|
$contenu = file_get_contents($file);
|
384
|
$tab[$i]["maquette"] = $contenu;
|
385
|
}
|
386
|
|
387
|
|
388
|
$file = "/home/machines/" . $tab[$i]["host"] . "/horizon-computers_last_seen";
|
389
|
if(file_exists($file)) {
|
390
|
$contenu = file_get_contents($file);
|
391
|
$tab[$i]["lastboot"] = $contenu;
|
392
|
}
|
393
|
|
394
|
|
395
|
$file = "/home/machines/" . $tab[$i]["host"] . "/boot.pxe";
|
396
|
if(file_exists($file)) {
|
397
|
$contenu = file_get_contents($file);
|
398
|
if(strpos($contenu,"=restaure")) {
|
399
|
$tab[$i]["boot"] = "Restaure";
|
400
|
}
|
401
|
else if(strpos($contenu,"=backup")) {
|
402
|
$tab[$i]["boot"] = "Sauvegarde";
|
403
|
}
|
404
|
else if(strpos($contenu,"initrd=initrd-p2.gz")) {
|
405
|
$tab[$i]["boot"] = "Terminal léger v4";
|
406
|
}
|
407
|
else if(strpos($contenu,"=startx")) {
|
408
|
$tab[$i]["boot"] = "Terminal léger v4";
|
409
|
}
|
410
|
else if(strpos($contenu,"append hd0")) {
|
411
|
$tab[$i]["boot"] = "Disque dur";
|
412
|
}
|
413
|
else if(strpos($contenu,"localboot 0x80")) {
|
414
|
$tab[$i]["boot"] = "Disque dur";
|
415
|
}
|
416
|
else if(strpos($contenu,"nbdport=")) {
|
417
|
$tab[$i]["boot"] = "Terminal léger v5";
|
418
|
}
|
419
|
}
|
420
|
$i++;
|
421
|
}
|
422
|
}
|
423
|
fclose($fdhcp);
|
424
|
}
|
425
|
|
426
|
|
427
|
|
428
|
|
429
|
|
430
|
|
431
|
return $tab;
|
432
|
}
|
433
|
|
434
|
|
435
|
|
436
|
function liste_terminaux_leases(){
|
437
|
|
438
|
global $conf_fic_dhcp_leases;
|
439
|
|
440
|
|
441
|
global $tab_macaddr_terminaux;
|
442
|
$i = 0;
|
443
|
$fdhcp = @fopen($conf_fic_dhcp_leases,"r");
|
444
|
if($fdhcp){
|
445
|
while(!feof($fdhcp)) {
|
446
|
$ligne = fgets($fdhcp,4096);
|
447
|
if(ereg("(lease )(.*)( \{)",$ligne,$res)) {
|
448
|
$active = 0;
|
449
|
$name = "";
|
450
|
$ip = $res[2];
|
451
|
|
452
|
|
453
|
for(;trim($ligne) != "}" && !feof($fdhcp); $ligne = fgets($fdhcp,4096)) {
|
454
|
if(ereg("(hardware ethernet )(.*)(;)",$ligne,$res)) {
|
455
|
$mac = strtoupper($res[2]);
|
456
|
|
457
|
}
|
458
|
if(ereg("(client-hostname )(.*)(;)",$ligne,$res)) {
|
459
|
$name = $res[2];
|
460
|
|
461
|
}
|
462
|
if(ereg("(binding state )(.*)(;)",$ligne,$res)) {
|
463
|
if(trim($res[2]) == "active") {
|
464
|
$active = 1;
|
465
|
}
|
466
|
}
|
467
|
}
|
468
|
if($active) {
|
469
|
$tabip[$mac] = $ip;
|
470
|
$tabmac[] = $mac;
|
471
|
$tabname[$mac] = $name;
|
472
|
}
|
473
|
}
|
474
|
}
|
475
|
fclose($fdhcp);
|
476
|
}
|
477
|
if(count($tabmac)>0) {
|
478
|
$tabmactemp = array_unique($tabmac);
|
479
|
$i = 0;
|
480
|
foreach($tabmactemp as $macaddr) {
|
481
|
|
482
|
if(is_array($tab_macaddr_terminaux)) {
|
483
|
if(!in_array(strtolower($macaddr), array_map('strtolower',$tab_macaddr_terminaux))) {
|
484
|
$tab[$i]["mac"] = $macaddr;
|
485
|
$tab[$i]["ip"] = $tabip[$macaddr];
|
486
|
$tab[$i]["host"] = _("en attente");
|
487
|
if($tabname[$macaddr] != "")
|
488
|
$tab[$i]["host"] .= " (" . $tabname[$macaddr] . ")";
|
489
|
$i++;
|
490
|
}
|
491
|
}
|
492
|
else {
|
493
|
$tab[$i]["mac"] = $macaddr;
|
494
|
$tab[$i]["ip"] = $tabip[$macaddr];
|
495
|
$tab[$i]["host"] = _("en attente");
|
496
|
if($tabname[$macaddr] != "")
|
497
|
$tab[$i]["host"] .= " (" . $tabname[$macaddr] . ")";
|
498
|
$i++;
|
499
|
}
|
500
|
}
|
501
|
}
|
502
|
return $tab;
|
503
|
}
|
504
|
|
505
|
function hostname_deja_pris($hostname,$vlan=""){
|
506
|
|
507
|
|
508
|
|
509
|
global $conf_dir_bind;
|
510
|
if(trim($vlan) != "")
|
511
|
$res = exec("grep -w " . $hostname . "." . $vlan . " " . $conf_dir_bind . "/* | wc -l");
|
512
|
else
|
513
|
$res = exec("grep -w " . $hostname . " " . $conf_dir_bind . "/* | wc -l");
|
514
|
|
515
|
if(trim($res) > 0)
|
516
|
$trouve = 1;
|
517
|
else
|
518
|
$trouve = 0;
|
519
|
return $trouve;
|
520
|
}
|
521
|
|
522
|
function erreur_mac_addr($mac){
|
523
|
|
524
|
$retour = 0;
|
525
|
|
526
|
|
527
|
$liste = liste_terminaux();
|
528
|
for($i = 0; ($i < count($liste)) && ($retour == 0); $i++) {
|
529
|
|
530
|
if($liste[$i]["mac"] == strtolower($mac)) {
|
531
|
|
532
|
$retour = 1;
|
533
|
}
|
534
|
}
|
535
|
return $retour;
|
536
|
}
|
537
|
|
538
|
|
539
|
|
540
|
function prochaine_ip_libre($fic_bind_rev,$min_ip,$dhcp_bas){
|
541
|
$temp = explode(".",$dhcp_bas);
|
542
|
$dhcp_bas_local = $temp[3];
|
543
|
if($dhcp_bas_local < 0 || $dhcp_bas_local > 250) {
|
544
|
return -1;
|
545
|
}
|
546
|
|
547
|
$fd = @fopen($fic_bind_rev, "r");
|
548
|
$retour = 0;
|
549
|
$tabip = array();
|
550
|
if($fd) {
|
551
|
while (!(feof($fd))) {
|
552
|
$buffer = fgets($fd);
|
553
|
unset($tab);
|
554
|
if(preg_match("/(.*).*IN.*PTR.*/",$buffer,$tab)) {
|
555
|
$tabip[] = chop($tab[1]);
|
556
|
}
|
557
|
}
|
558
|
fclose($fd);
|
559
|
}
|
560
|
|
561
|
|
562
|
|
563
|
|
564
|
asort($tabip);
|
565
|
for($i = $min_ip; $retour == 0 && $i < $dhcp_bas_local; $i++) {
|
566
|
if(! in_array($i, $tabip)) {
|
567
|
$retour = $i;
|
568
|
}
|
569
|
}
|
570
|
|
571
|
|
572
|
if ($retour < $min_ip) {
|
573
|
$retour = $min_ip;
|
574
|
}
|
575
|
else {
|
576
|
$retour = $retour;
|
577
|
}
|
578
|
|
579
|
|
580
|
if($retour > 255 || $retour > $dhcp_bas_local)
|
581
|
$retour = -1;
|
582
|
return $retour;
|
583
|
}
|
584
|
|
585
|
function recup_infos($h){
|
586
|
|
587
|
|
588
|
global $conf_fic_ltsconf;
|
589
|
|
590
|
|
591
|
|
592
|
|
593
|
|
594
|
|
595
|
|
596
|
|
597
|
$tab["computerarch"] = "default";
|
598
|
$tab["serverx"] = "";
|
599
|
$tab["mouse"] = "";
|
600
|
$tab["mousetty"] = "";
|
601
|
$tab["mousebtns"] = "";
|
602
|
$tab["video1"] = "";
|
603
|
$tab["bpp"] = "";
|
604
|
$tab["sound"] = "none";
|
605
|
$tab["appendopt"] = "";
|
606
|
$tab["windowslicence"] = "";
|
607
|
$tab["localstorage"] = "Y";
|
608
|
$tab["swapsize"] = "";
|
609
|
|
610
|
$sortir = 0;
|
611
|
$fp = fopen($conf_fic_ltsconf,"r");
|
612
|
if($fp) {
|
613
|
|
614
|
while(!feof($fp)) {
|
615
|
|
616
|
$ligne = fgets($fp,4096);
|
617
|
|
618
|
if(ereg("\[$h\]",$ligne)) {
|
619
|
|
620
|
|
621
|
|
622
|
while( ! feof($fp) && ! $sortir) {
|
623
|
$ligne = fgetcsv($fp,4096,"=");
|
624
|
|
625
|
array_trim($ligne);
|
626
|
switch($ligne[0]) {
|
627
|
case "COMPUTERARCH":
|
628
|
$tab["computerarch"] = $ligne[1];
|
629
|
if ("none" == $tab["computerarch"] ) {
|
630
|
|
631
|
|
632
|
|
633
|
|
634
|
$sortir = 1;
|
635
|
}
|
636
|
|
637
|
if ($tab["computerarch"] == "maui") {
|
638
|
$tab["computerarch"] = "ltsp";
|
639
|
}
|
640
|
else if ($tab["computerarch"] == "p1") {
|
641
|
$tab["computerarch"] = "ltsp3";
|
642
|
}
|
643
|
|
644
|
break;
|
645
|
case "XSERVER":
|
646
|
if(trim($tab["serverx"]) != "")
|
647
|
$tab["serverx"] = $ligne[1];
|
648
|
else
|
649
|
$tab["serverx"] = "auto";
|
650
|
break;
|
651
|
case "SOUND":
|
652
|
if ($ligne[1] == "N") {
|
653
|
$tab["sound"] = "none";
|
654
|
}
|
655
|
break;
|
656
|
case "SOUND_DAEMON":
|
657
|
$tab["sound"] = $ligne[1];
|
658
|
break;
|
659
|
case "APPENDOPT":
|
660
|
$tab["appendopt"] = $ligne[1];
|
661
|
break;
|
662
|
case "WINDOWSLICENCE":
|
663
|
$tab["windowslicence"] = $ligne[1];
|
664
|
break;
|
665
|
case "LOCAL_STORAGE":
|
666
|
$tab["localstorage"] = $ligne[1];
|
667
|
break;
|
668
|
case "X_MOUSE_PROTOCOL":
|
669
|
$tab["mouse"] = $ligne[1];
|
670
|
break;
|
671
|
case "X_MOUSE_DEVICE":
|
672
|
$tab["mousetty"] = $ligne[1];
|
673
|
break;
|
674
|
case "X_MOUSE_BUTTONS":
|
675
|
$tab["mousebtns"] = $ligne[1];
|
676
|
break;
|
677
|
case "X_MODE_0":
|
678
|
$tab["video1"] = $ligne[1];
|
679
|
break;
|
680
|
case "X_COLOR_DEPTH":
|
681
|
$tab["bpp"] = $ligne[1];
|
682
|
break;
|
683
|
case "SWAP_BLOCKS":
|
684
|
$tab["swapsize"] = $ligne[1];
|
685
|
break;
|
686
|
case "ISA_NIC":
|
687
|
$tab["nic"] = $ligne[1];
|
688
|
break;
|
689
|
case "XkbModel":
|
690
|
case "XKBMODEL":
|
691
|
$tab["keyboard"] = $ligne[1];
|
692
|
break;
|
693
|
case "XkbLayout":
|
694
|
case "XKBLAYOUT":
|
695
|
$tab["keyboardlang"] = $ligne[1];
|
696
|
break;
|
697
|
case "XKBNUMPAD":
|
698
|
$tab["keynumpad"] = $ligne[1];
|
699
|
break;
|
700
|
case "PRINTER_0_DEVICE":
|
701
|
$tab["printerdevice"] = $ligne[1];
|
702
|
break;
|
703
|
case "PRINTER_0_TYPE":
|
704
|
$tab["printertype"] = $ligne[1];
|
705
|
break;
|
706
|
case "WRITE_ONLY" :
|
707
|
$tab["printerdevice"] .= "w";
|
708
|
break;
|
709
|
case "PRINTERSAVAILABLE" :
|
710
|
$tab["printersavailable"] = $ligne[1];
|
711
|
break;
|
712
|
case "MODULE_01":
|
713
|
if($ligne[1] == "i810")
|
714
|
$tab["serverx"] = "XF86_SVGA-i810";
|
715
|
else if($ligne[1] == "radeon")
|
716
|
$tab["serverx"] = "auto-radeon";
|
717
|
$tab["MODULE_01"] = $ligne[1];
|
718
|
break;
|
719
|
case "MODULE_02":
|
720
|
if($ligne[1] == "i810")
|
721
|
$tab["serverx"] = "XF86_SVGA-i810";
|
722
|
else if($ligne[1] == "radeon")
|
723
|
$tab["serverx"] = "auto-radeon";
|
724
|
$tab["MODULE_02"] = $ligne[1];
|
725
|
break;
|
726
|
case "MODULE_03":
|
727
|
if($ligne[1] == "i810")
|
728
|
$tab["serverx"] = "XF86_SVGA-i810";
|
729
|
else if($ligne[1] == "radeon")
|
730
|
$tab["serverx"] = "auto-radeon";
|
731
|
$tab["MODULE_03"] = $ligne[1];
|
732
|
break;
|
733
|
case "OptionParamS0":
|
734
|
if ($ligne[1] == "sw_cursor" and $tab["serverx"] == "XF86_SVGA")
|
735
|
$tab["serverx"] = "XF86_S3-3D";
|
736
|
break;
|
737
|
}
|
738
|
|
739
|
if(ereg("\[.*\]",$ligne[0])) {
|
740
|
|
741
|
$sortir = 1;
|
742
|
}
|
743
|
}
|
744
|
}
|
745
|
}
|
746
|
fclose($fp);
|
747
|
}
|
748
|
return $tab;
|
749
|
}
|
750
|
|
751
|
function make_dhcp_block($hostname, $mac, $computerarch, $nic = "") {
|
752
|
|
753
|
|
754
|
global $conf_ip_server;
|
755
|
if($computerarch == "none") {
|
756
|
return "\\\n\\\thost $hostname {\\\n\\\t\\\thardware ethernet $mac;\\\n\\\t\\\t fixed-address $hostname;\\\n\\\t}\\\n\\\n";
|
757
|
}
|
758
|
else {
|
759
|
$isa_block="";
|
760
|
if ($computerarch == "ltsp5") {
|
761
|
|
762
|
$kernel = "kernel-maui.nbi";
|
763
|
}
|
764
|
else if ($computerarch == "qooqv2") {
|
765
|
|
766
|
$kernel = "kernel-qooqv2";
|
767
|
}
|
768
|
else if ($computerarch == "ltsp44") {
|
769
|
|
770
|
$kernel = "kernel-maui.nbi";
|
771
|
}
|
772
|
else if ( $computerarch == "ltsp3" ) {
|
773
|
if (!empty($nic) && $nic != "none") {
|
774
|
$isa_block = '\\n\\t\\toption option-128 e4:45:74:68:00:00;\\n\\t\\toption option-129 "NIC=' . $nic . '";';
|
775
|
}
|
776
|
$kernel = "kernel-p1.nbi";
|
777
|
}
|
778
|
else if ( $computerarch == "ltsp" ) {
|
779
|
$kernel = "kernel-p2.nbi";
|
780
|
}
|
781
|
else {
|
782
|
$kernel = "kernel-default.nbi";
|
783
|
}
|
784
|
return "\\\n\\\thost $hostname {\\\n\\\t\\\thardware ethernet $mac;$isa_block\\\n\\\t\\\tfixed-address $hostname;\\\n\\\t\\\tif substring (option vendor-class-identifier, 0, 9) = \"PXEClient\" {\\\n\\\t\\\t\\\tfilename \"pxelinux.0\";\\\n\\\t\\\t}\\\n\\\t\\\telse {\\\n\\\t\\\t\\\tfilename \"$kernel\";\\\n\\\t\\\t}\\\n\\\t\\\toption root-path \"$conf_ip_server:\/opt\/$computerarch\/i386\";\\\n\\\t}\\\n\\\n";
|
785
|
}
|
786
|
}
|
787
|
|
788
|
function make_syslinux_block($arch, $appendopt, $specialcase="", $imagename="", $action) {
|
789
|
global $conf_ip_server;
|
790
|
|
791
|
|
792
|
|
793
|
$kernelclonezilla = "vmlinuz-4.19.0-4-amd64";
|
794
|
$initrdclonezilla = "initrd.img-4.19.0-4-amd64";
|
795
|
|
796
|
|
797
|
|
798
|
if($imagename != "" && $action == "restaure") {
|
799
|
|
800
|
if(is_dir("/opt/clonezilla")) {
|
801
|
|
802
|
return "DEFAULT vesamenu.c32
|
803
|
MENU INCLUDE messages/graphics.conf
|
804
|
TIMEOUT 50
|
805
|
TOTALTIMEOUT 9000
|
806
|
|
807
|
label abuledu
|
808
|
kernel $kernelclonezilla
|
809
|
append SCREEN_01=restaure initrd=$initrdclonezilla nofb live-config boot=live noswap nolocales edd=on ocs_live_extra_param=\\\"\\\" keyboard-layouts=NONE ocs_live_batch=\\\"no\\\" locales=\\\"fr_FR.UTF-8\\\" ip=frommedia nosplash noprompt netboot=nfs nfsroot=$conf_ip_server:/opt/clonezilla/ ocs_server=\\\"$conf_ip_server\\\" ocs_daemonon=\\\"ssh\\\" ocs_prerun=\\\"mount -t nfs -o vers=3 $conf_ip_server:/opt/ltsp44/i386 /opt\\\" ocs_prerun1=\\\"/opt/etc/screen.d/restaure2\\\" ocs_live_run=\\\"\\\" ocs_postrun=\\\"\\\" net.ifnames=0 biosdevname=0
|
810
|
|
811
|
";
|
812
|
|
813
|
}
|
814
|
}
|
815
|
|
816
|
|
817
|
if($specialcase == "backup-restaure") {
|
818
|
$arch="ltsp44";
|
819
|
}
|
820
|
switch($arch) {
|
821
|
case "ltsp":
|
822
|
$kernel = "kernel-p2";
|
823
|
$initrd = "initrd-p2.gz";
|
824
|
break;
|
825
|
case "ltsp44":
|
826
|
$kernel = "kernel-maui";
|
827
|
$initrd = "initrd-maui.gz";
|
828
|
break;
|
829
|
case "qooqv2":
|
830
|
$kernel = "kernel-qooqv2";
|
831
|
$initrd = "initrd-qooqv2.gz";
|
832
|
break;
|
833
|
case "ltsp5":
|
834
|
return "DEFAULT vesamenu.c32
|
835
|
MENU INCLUDE messages/graphics.conf
|
836
|
TIMEOUT 50
|
837
|
TOTALTIMEOUT 9000
|
838
|
|
839
|
label abuledu
|
840
|
kernel vmlinuz
|
841
|
append ro initrd=initrd.img $appendopt quiet splash nbdport=2001
|
842
|
";
|
843
|
break;
|
844
|
default:
|
845
|
$kernel = "kernel-default";
|
846
|
$initrd = "initrd-default.gz";
|
847
|
break;
|
848
|
}
|
849
|
|
850
|
|
851
|
|
852
|
if(is_dir("/opt/clonezilla") && $specialcase == "backup-restaure") {
|
853
|
return "DEFAULT vesamenu.c32
|
854
|
MENU INCLUDE messages/graphics.conf
|
855
|
TIMEOUT 50
|
856
|
TOTALTIMEOUT 9000
|
857
|
|
858
|
label abuledu
|
859
|
kernel $kernelclonezilla
|
860
|
append SCREEN_01=backup initrd=$initrdclonezilla nofb live-config boot=live noswap nolocales edd=on ocs_live_extra_param=\\\"\\\" keyboard-layouts=NONE ocs_live_batch=\\\"no\\\" locales=\\\"fr_FR.UTF-8\\\" ip=frommedia nosplash noprompt netboot=nfs nfsroot=$conf_ip_server:/opt/clonezilla/ ocs_server=\\\"$conf_ip_server\\\" ocs_daemonon=\\\"ssh\\\" ocs_prerun=\\\"mount -t nfs -o vers=3 $conf_ip_server:/opt/ltsp44/i386 /opt/\\\" ocs_prerun1=\\\"/opt/etc/screen.d/backup2\\\" ocs_live_run=\\\"\\\" ocs_postrun=\\\"\\\"
|
861
|
|
862
|
";
|
863
|
|
864
|
}
|
865
|
else {
|
866
|
return "DEFAULT vesamenu.c32
|
867
|
MENU INCLUDE messages/graphics.conf
|
868
|
TIMEOUT 50
|
869
|
TOTALTIMEOUT 9000
|
870
|
|
871
|
label abuledu
|
872
|
kernel $kernel
|
873
|
append init=/linuxrc $appendopt rw root=/dev/ram0 initrd=$initrd MOPTS=nolock,ro,wsize=2048,rsize=2048 quiet splash
|
874
|
";
|
875
|
}
|
876
|
}
|
877
|
|
878
|
function fixe_tx($tab, $mac, $ip, $ip_actuelle, $hostname, $addnewtx, $have_to_build_syslinux=1, $local_arch_for_dhcp="") {
|
879
|
|
880
|
|
881
|
|
882
|
|
883
|
|
884
|
global $conf_fic_bind, $conf_fic_bind_rev,
|
885
|
$conf_zone,
|
886
|
$conf_fic_ltsconf, $conf_fic_dhcp,
|
887
|
$conf_rep_syslinux,
|
888
|
$conf_ip_network_base,
|
889
|
$conf_fic_dhcp_leases, $computerarch,
|
890
|
$fichier_script_output, $vlan, $conf_dir_bind, $conf_dir_dhcp,
|
891
|
$metamode, $comptemachine;
|
892
|
|
893
|
|
894
|
if($comptemachine == "")
|
895
|
$comptemachine = $hostname;
|
896
|
|
897
|
if(trim($mac) == "" ||
|
898
|
trim($ip) == "" ||
|
899
|
trim($hostname) == "")
|
900
|
return -1;
|
901
|
|
902
|
$config = new AbE_General_Config();
|
903
|
|
904
|
if(trim($vlan) != "") {
|
905
|
$fic_bind = $conf_dir_bind . "/db." . $vlan;
|
906
|
$fic_bind_rev = $conf_dir_bind . "/db." . $vlan . ".rev";
|
907
|
$fic_dhcp = $conf_dir_dhcp . "/dhcpd.hosts-" . $vlan . ".conf";
|
908
|
$ip_network_base = $config->GetValue(strtoupper($vlan) . "_BASE");
|
909
|
$dhcphostname = $hostname . "." . $vlan . "." . $conf_zone;
|
910
|
$bindhostname = $hostname . "." . $vlan . "." . $conf_zone . ".";
|
911
|
}
|
912
|
else{
|
913
|
$fic_bind = $conf_fic_bind;
|
914
|
$fic_bind_rev = $conf_fic_bind_rev;
|
915
|
$fic_dhcp = $conf_fic_dhcp;
|
916
|
$ip_network_base = $conf_ip_network_base;
|
917
|
$dhcphostname = $hostname;
|
918
|
$bindhostname = $hostname . "." . $conf_zone . ".";
|
919
|
}
|
920
|
|
921
|
|
922
|
|
923
|
if(strpos($ip,".") > 0) {
|
924
|
$tip = explode(".",$ip);
|
925
|
$ip = $tip[count($tip)-1];
|
926
|
}
|
927
|
$retour = "";
|
928
|
|
929
|
$dns = "$hostname IN A $ip_network_base.$ip";
|
930
|
$dnsrev = "$ip IN PTR $bindhostname";
|
931
|
if(trim($computerarch) == "")
|
932
|
$computerarch = "ltsp";
|
933
|
|
934
|
if($local_arch_for_dhcp == "") {
|
935
|
$dhcp = make_dhcp_block($dhcphostname, $mac, $computerarch, $tab["nic"]);
|
936
|
}
|
937
|
else {
|
938
|
|
939
|
$dhcp = make_dhcp_block($dhcphostname, $mac, $local_arch_for_dhcp, $tab["nic"]);
|
940
|
}
|
941
|
|
942
|
|
943
|
if($have_to_build_syslinux) {
|
944
|
$syslinuxfile = "$conf_rep_syslinux/01-" . strtolower(strtr($mac,":","-"));
|
945
|
$syslinuxsymlink = "/home/machines/" . $comptemachine . "/boot.pxe";
|
946
|
$syslinux = make_syslinux_block($computerarch,$tab["appendopt"]);
|
947
|
}
|
948
|
|
949
|
|
950
|
$tab["printerdevice"] = "";
|
951
|
$tab["printertype"] = "";
|
952
|
if($tab["printer"] != "") {
|
953
|
if(strstr($tab["printer"],"lp0w")) {
|
954
|
$tab["printerdevice"] = "/dev/lp0";
|
955
|
$writeonly = "Y";
|
956
|
}
|
957
|
else {
|
958
|
$writeonly = "";
|
959
|
$tab["printerdevice"] = "/dev/" . $tab["printer"];
|
960
|
}
|
961
|
if(strstr($tab["printer"],"lp"))
|
962
|
$tab["printertype"] = "P";
|
963
|
else if(strstr($tab["printer"],"tty"))
|
964
|
$tab["printertype"] = "S";
|
965
|
}
|
966
|
|
967
|
|
968
|
|
969
|
|
970
|
$mousetbemulate = "";
|
971
|
|
972
|
|
973
|
if($tab["mouse"] == "ExplorerPS/2") {
|
974
|
|
975
|
$tab["mousebtns"] = "7";
|
976
|
$tab["zaxismapping"] = "6 7";
|
977
|
}
|
978
|
else if($tab["mousebtns"] == 2){
|
979
|
$mousetbemulate = "Y";
|
980
|
}
|
981
|
else if($tab["mousebtns"] == 5){
|
982
|
|
983
|
$tab["mousebtns"] = "5";
|
984
|
$tab["zaxismapping"] = "4 5";
|
985
|
}
|
986
|
|
987
|
if($tab["serverx"] == "XF86_S3-3D") {
|
988
|
$tab["serverx"] = "XF86_SVGA";
|
989
|
$specialparam = " OptionParamS0 = \\\"sw_cursor\\\"";
|
990
|
}
|
991
|
else if($tab["serverx"] == "XF86_SVGA-i810") {
|
992
|
|
993
|
$tab["serverx"] = "\\\"XF86_SVGA\\\"";
|
994
|
$specialparam = " MODULE_01 = \\\"agpgart\\\"
|
995
|
MODULE_02 = \\\"i810\\\"";
|
996
|
$nb_modules=2;
|
997
|
}
|
998
|
else if($tab["serverx"] == "auto-radeon") {
|
999
|
|
1000
|
$tab["serverx"] = "\\\"auto\\\"";
|
1001
|
$specialparam = " MODULE_01 = \\\"agpgart\\\"
|
1002
|
MODULE_02 = \\\"radeon\\\"";
|
1003
|
$nb_modules=2;
|
1004
|
}
|
1005
|
|
1006
|
$ltsconf = "#$comptemachine debut
|
1007
|
[$comptemachine]
|
1008
|
";
|
1009
|
if ( "none" == $computerarch ) {
|
1010
|
$ltsconf .= " # NOT A THIN CLIENT, NOT MANAGED BY LTSP/LTSCONF
|
1011
|
computerarch = \\\"none\\\"
|
1012
|
";
|
1013
|
}
|
1014
|
else {
|
1015
|
|
1016
|
$ltsconf .= " XSERVER = \\\"" . $tab["serverx"] . "\\\"
|
1017
|
X_MOUSE_PROTOCOL = \\\"" . $tab["mouse"] . "\\\"
|
1018
|
X_MOUSE_DEVICE = \\\"/dev/" . str_replace("/dev/","",$tab["mousetty"]) . "\\\"
|
1019
|
X_MOUSE_BUTTONS = \\\"" . $tab["mousebtns"] . "\\\"
|
1020
|
";
|
1021
|
|
1022
|
if (!empty($mousetbemulate)) {
|
1023
|
$ltsconf .= " X_MOUSE_EMULATE3BTN = \\\"" . $mousetbemulate . "\\\"
|
1024
|
";
|
1025
|
}
|
1026
|
|
1027
|
if (!empty( $tab["zaxismapping"])) {
|
1028
|
$ltsconf .= " ZAXISMAPPING = \\\"" . $tab["zaxismapping"] . "\\\"
|
1029
|
";
|
1030
|
}
|
1031
|
|
1032
|
|
1033
|
|
1034
|
|
1035
|
|
1036
|
|
1037
|
if ( !empty($tab["swapsize"])) {
|
1038
|
$ltsconf .= " SWAP_BLOCKS = \\\"" . $tab["swapsize"] . "\\\"
|
1039
|
";
|
1040
|
}
|
1041
|
|
1042
|
$ltsconf .= " XKBLAYOUT = \\\"" . $tab["keyboardlang"] . "\\\"
|
1043
|
XKBMODEL = \\\"" . $tab["keyboard"] . "\\\"
|
1044
|
XKBNUMPAD = \\\"" . $tab["keynumpad"] . "\\\"
|
1045
|
";
|
1046
|
|
1047
|
if ( !empty($tab["printerdevice"]) ) {
|
1048
|
$ltsconf .= " PRINTER_0_DEVICE = \\\"" . $tab["printerdevice"] . "\\\"
|
1049
|
PRINTER_0_TYPE = \\\"" . $tab["printertype"] . "\\\"
|
1050
|
";
|
1051
|
}
|
1052
|
if ( !empty($writeonly)) {
|
1053
|
$ltsconf .= " # please ensure WRITE_ONLY always comes *after* PRINTER_0_DEVICE, else
|
1054
|
# the web interface will not parse the config correctly.
|
1055
|
WRITE_ONLY = \\\"Y\\\"
|
1056
|
";
|
1057
|
}
|
1058
|
|
1059
|
|
1060
|
if( !empty($tab["printersavailable"]) ) {
|
1061
|
$ltsconf .= " PRINTERSAVAILABLE = \\\"" . $tab["printersavailable"] . "\\\"
|
1062
|
";
|
1063
|
}
|
1064
|
|
1065
|
|
1066
|
$ltsconf .= " COMPUTERARCH = \\\"" . $computerarch . "\\\"
|
1067
|
X_COLOR_DEPTH = \\\"" . $tab["bpp"] . "\\\"
|
1068
|
X_MODE_0 = \\\"" . $tab["video1"] . "\\\"
|
1069
|
";
|
1070
|
|
1071
|
if ( "1280x1024" == $tab["video1"] || "1280x800" == $tab["video1"]
|
1072
|
|| "1280x960" == $tab["video1"] || "1280x768" == $tab["video1"]) {
|
1073
|
$ltsconf .= " X_VERTREFRESH = \\\"50-75\\\"
|
1074
|
# 1024x768 and 800x600 will be automatically appended during client bootup.
|
1075
|
X_HORZSYNC = \\\"31-120\\\"
|
1076
|
";
|
1077
|
}
|
1078
|
if ( "1400x1050" == $tab["video1"] || "1440x900" == $tab["video1"] ) {
|
1079
|
$ltsconf .= " X_MODE_1 = \\\"" . ("1400x1050" == $tab["video1"]?"1280x1024":"1280x800") . "\\\"
|
1080
|
# 1024x768 and 800x600 will be automatically appended during client bootup.
|
1081
|
X_VERTREFRESH = \\\"60-100\\\"
|
1082
|
X_HORZSYNC = \\\"31-120\\\"
|
1083
|
";
|
1084
|
}
|
1085
|
if ( "1600x1200" == $tab["video1"] || "1680x1050" == $tab["video1"] ) {
|
1086
|
$ltsconf .= " X_MODE_1 = \\\"" . ("1600x1200" == $tab["video1"]?"1400x1050":"1440x900") . "\\\"
|
1087
|
X_MODE_2 = \\\"" . ("1600x1200" == $tab["video1"]?"1280x1024":"1280x800") . "\\\"
|
1088
|
# 1024x768 and 800x600 will be automatically
|
1089
|
# appended during thin client bootup.
|
1090
|
X_VERTREFRESH = \\\"60-120\\\"
|
1091
|
X_HORZSYNC = \\\"31-150\\\"
|
1092
|
";
|
1093
|
}
|
1094
|
|
1095
|
if ( $tab["sound"] == "esd" ) {
|
1096
|
$ltsconf .= " SOUND = \\\"Y\\\"
|
1097
|
SOUND_DAEMON = \\\"" . $tab["sound"] . "\\\"
|
1098
|
";
|
1099
|
}
|
1100
|
else {
|
1101
|
$ltsconf .= " SOUND = \\\"N\\\"
|
1102
|
";
|
1103
|
}
|
1104
|
$ltsconf .= " WINDOWSLICENCE = \\\"" . $tab["windowslicence"] . "\\\"
|
1105
|
";
|
1106
|
$ltsconf .= " LOCAL_STORAGE = \\\"" . $tab["localstorage"] . "\\\"
|
1107
|
";
|
1108
|
$ltsconf .= " APPENDOPT = \\\"" . $tab["appendopt"] . "\\\"
|
1109
|
";
|
1110
|
if (!empty($tab["screen_01"]) ) {
|
1111
|
$ltsconf .= " SCREEN_01 = \\\"" . $tab["screen_01"] . "\\\"
|
1112
|
";
|
1113
|
}
|
1114
|
if (!empty($specialparam))
|
1115
|
$ltsconf .= $specialparam . "\n";
|
1116
|
|
1117
|
|
1118
|
if (!empty($tab["nic"]) and $tab["nic"] != "none") {
|
1119
|
$ltsconf .= "
|
1120
|
# this is used to generate a DHCP bloc, not directly by LTSP.
|
1121
|
ISA_NIC = \\\"" . $tab["nic"] . "\\\"
|
1122
|
";
|
1123
|
}
|
1124
|
}
|
1125
|
$ltsconf .= "#$comptemachine fin
|
1126
|
";
|
1127
|
|
1128
|
|
1129
|
|
1130
|
|
1131
|
|
1132
|
|
1133
|
|
1134
|
|
1135
|
$commande = "
|
1136
|
#creer le nouveau compte machine
|
1137
|
horizon-add user --profile machines --disabled-password " . $comptemachine . " || true
|
1138
|
if [ -d /home/machines/" . $comptemachine . " ]; then
|
1139
|
if [ ! -d /home/machines/" . $comptemachine . "/horizon-apt/ ]; then
|
1140
|
mkdir /home/machines/" . $comptemachine . "/horizon-apt/
|
1141
|
touch /home/machines/" . $comptemachine . "/horizon-apt/boot
|
1142
|
fi
|
1143
|
fi
|
1144
|
|
1145
|
if [ -f $conf_fic_ltsconf ]; then
|
1146
|
|
1147
|
sed -i -e '/^#\\s*$comptemachine debut/,/^#\\s*$comptemachine fin/d' -e '/./,/^$/!d' $conf_fic_ltsconf
|
1148
|
|
1149
|
echo \"$ltsconf\" >> $conf_fic_ltsconf
|
1150
|
chmod 644 $conf_fic_ltsconf
|
1151
|
if [ -d /opt/ltsp3/i386/etc ]; then
|
1152
|
cp -a $conf_fic_ltsconf /opt/ltsp3/i386/etc/lts.conf || true
|
1153
|
fi
|
1154
|
|
1155
|
if [ -d /opt/ltsp44/i386/etc ]; then
|
1156
|
cp -a $conf_fic_ltsconf /opt/ltsp44/i386/etc/lts.conf || true
|
1157
|
fi
|
1158
|
|
1159
|
if [ -d /opt/qooqv2/etc ]; then
|
1160
|
cp -a $conf_fic_ltsconf /opt/qooqv2/etc/lts.conf || true
|
1161
|
fi
|
1162
|
|
1163
|
else
|
1164
|
echo \"configuration système incomplète, il manque LTSP et/ou son fichier de configuration.\"
|
1165
|
exit 1
|
1166
|
fi
|
1167
|
|
1168
|
";
|
1169
|
|
1170
|
if(trim($syslinux)!="") {
|
1171
|
$commande .= "
|
1172
|
#on ecrase le syslinux dans tous les cas (nouveau ou modif)
|
1173
|
echo \"$syslinux\" > $syslinuxfile || true
|
1174
|
|
1175
|
#le lien
|
1176
|
if [ ! -e $syslinuxsymlink ]; then
|
1177
|
ln $syslinuxfile $syslinuxsymlink
|
1178
|
fi
|
1179
|
";
|
1180
|
}
|
1181
|
|
1182
|
$commande .= "
|
1183
|
|
1184
|
if [ -f $fic_bind ]; then
|
1185
|
|
1186
|
/etc/init.d/dhcp3-server stop
|
1187
|
|
1188
|
TESTRYCKS=`grep -w $hostname $fic_bind || true`
|
1189
|
if [ -z \"\${TESTRYCKS}\" ]; then
|
1190
|
echo \"$dns\" >> $fic_bind;
|
1191
|
echo \"$dnsrev\" >> $fic_bind_rev;
|
1192
|
/etc/init.d/bind9 restart
|
1193
|
";
|
1194
|
|
1195
|
if($ip_actuelle != "") {
|
1196
|
$commande .= "
|
1197
|
cat $conf_fic_dhcp_leases | sed s/\"^}\$\"/\"}%\"/ | tr \"\\n%\" \"*\\n\" | grep -v \"$ip_actuelle\" | tr \"*\" \"\\n\" > $conf_fic_dhcp_leases.temp
|
1198
|
";
|
1199
|
}
|
1200
|
$commande .= " mv $conf_fic_dhcp_leases.temp $conf_fic_dhcp_leases
|
1201
|
|
1202
|
fi # if -z TESTRYCKS
|
1203
|
|
1204
|
TMPFILE=`mktemp`
|
1205
|
|
1206
|
# remove host block from DHCPd.conf, insert the new block at the end
|
1207
|
# of the file, and supress multiple blank lines.
|
1208
|
# be carefull with poste-01 and poste-01w ... this is not the same ... $dhcphostname with space after
|
1209
|
sed -i -e '/./{H;$!d;}' -e 'x;/host $dhcphostname /d' -e 's/\(^.*ltsconfinsertend\)/$dhcp\\1/' -e '/./,/^$/!d' $fic_dhcp
|
1210
|
|
1211
|
/etc/init.d/dhcp3-server start
|
1212
|
|
1213
|
else
|
1214
|
echo \"configuration système incomplète, il manque au moins BIND et DHCPd.\"
|
1215
|
exit 1
|
1216
|
fi # if -f $fic_bind
|
1217
|
";
|
1218
|
|
1219
|
if( fichier_script($commande) == 0 ){
|
1220
|
$retour .= sprintf(_("%s Configuration enregistrée %s Merci d'attendre quelques instants, puis éteignez la machine et relancez-la pour qu'elle prenne en compte ses nouveaux paramètres de configuration."), "<div style=\"text-align: center; margin: 3em;\"><div style=\"color: #3A3;\">", "<br /> </div>") . "</div>" ;
|
1221
|
}
|
1222
|
else {
|
1223
|
$retour .= $fichier_script_output . "<div style=\"text-align: center; margin: 3em;\"><div style=\"color: #A33;\">" . sprintf(_("Erreur d'exécution de la commande !%s Regardez le journal d'exécution et contactez le support."), "<br /> </div>") . "</div>";
|
1224
|
}
|
1225
|
|
1226
|
return $retour;
|
1227
|
}
|
1228
|
|
1229
|
function config_tx($erreurflash, $modifier = false ) {
|
1230
|
global $mac, $tabconftx;
|
1231
|
|
1232
|
if( ! $modifier && erreur_mac_addr($mac) != 0){
|
1233
|
$retour .= "<p>" . _("ERREUR: Cette adresse MAC est déjà présente dans les fichiers de configurations !") . "</p>\n";
|
1234
|
}
|
1235
|
else {
|
1236
|
$retour .= "<p style=\"text-align: justify;\">" . _("ATTENTION: pour le nom de vos terminaux, <u>n'utilisez pas de caractères spéciaux</u> ! Utilisez des noms comme <i>grincheux, patatix, silencieux, rapide, discrete, bordeaux, saintandredecubzac, larochelle</i> ... (sans espaces, sans accents). Vous pouvez aussi utiliser des chiffres et des tirets, mais pas en début de mot (exemple : poste-23).") . "</p>\n";
|
1237
|
|
1238
|
|
1239
|
|
1240
|
|
1241
|
if(trim($erreurflash) == "")
|
1242
|
$add = 1;
|
1243
|
else
|
1244
|
$add = 0;
|
1245
|
|
1246
|
if ( $modifier ) {
|
1247
|
$add = 0;
|
1248
|
}
|
1249
|
$retour .= make_all_boxes($tabconftx, $add);
|
1250
|
}
|
1251
|
return $retour;
|
1252
|
}
|
1253
|
|
1254
|
|
1255
|
|
1256
|
|
1257
|
|
1258
|
|
1259
|
|
1260
|
|
1261
|
function ipstr2nb($ipstr) {
|
1262
|
$octs = explode('.', $ipstr);
|
1263
|
$octs = array_reverse($octs);
|
1264
|
$i = 0;
|
1265
|
$c = count($octs);
|
1266
|
for ($j=0; $j < $c ; $j++) {
|
1267
|
$i += pow(256, $j) * $octs[$j];
|
1268
|
}
|
1269
|
return $i;
|
1270
|
}
|
1271
|
|
1272
|
function short_mask($mask) {
|
1273
|
|
1274
|
if ($mask[0]=='0'){
|
1275
|
return 0;
|
1276
|
}
|
1277
|
$masknumb = ipstr2nb($mask);
|
1278
|
$test = 0xffffffff;
|
1279
|
for ( $i=0; $i<32; $i++) {
|
1280
|
if ( $test == $masknumb ) {
|
1281
|
return 32 - $i;
|
1282
|
}
|
1283
|
$test = $test - pow(2, $i);
|
1284
|
}
|
1285
|
return FALSE;
|
1286
|
}
|
1287
|
|
1288
|
|
1289
|
|
1290
|
|
1291
|
|
1292
|
|
1293
|
function ListeApplications() {
|
1294
|
|
1295
|
|
1296
|
|
1297
|
|
1298
|
|
1299
|
|
1300
|
|
1301
|
|
1302
|
$fichier = "listeapplications";
|
1303
|
|
1304
|
if ( ! file_exists($fichier) || filesize($fichier) < 10 ) {
|
1305
|
return false;
|
1306
|
}
|
1307
|
$fp = fopen($fichier,"r");
|
1308
|
if($fp = @fopen($fichier,"r")){
|
1309
|
$i = 0;
|
1310
|
while(!feof($fp)){
|
1311
|
$ligne = fgetcsv($fp,"1024","=");
|
1312
|
array_trim($ligne);
|
1313
|
if($ligne[0] == "TITLE") {
|
1314
|
if($retour[$i]["title"] != "")
|
1315
|
$i++;
|
1316
|
$retour[$i]["title"] = $ligne[1];
|
1317
|
}
|
1318
|
else if($ligne[0] == "URL")
|
1319
|
$retour[$i]["url"] = $ligne[1];
|
1320
|
else if($ligne[0] == "DESC") {
|
1321
|
$desc = explode("!",$ligne[1]);
|
1322
|
$retour[$i]["desc"][$desc[0]] = $desc[1];
|
1323
|
}
|
1324
|
}
|
1325
|
fclose($fp);
|
1326
|
}
|
1327
|
return $retour;
|
1328
|
}
|
1329
|
|
1330
|
|
1331
|
|
1332
|
|
1333
|
|
1334
|
|
1335
|
|
1336
|
|
1337
|
|
1338
|
|
1339
|
|
1340
|
|
1341
|
function remove_accents($string) {
|
1342
|
if ( !preg_match('/[\x80-\xff]/', $string) )
|
1343
|
return $string;
|
1344
|
|
1345
|
if (seems_utf8($string)) {
|
1346
|
$chars = array(
|
1347
|
|
1348
|
chr(195).chr(128) => 'A', chr(195).chr(129) => 'A',
|
1349
|
chr(195).chr(130) => 'A', chr(195).chr(131) => 'A',
|
1350
|
chr(195).chr(132) => 'A', chr(195).chr(133) => 'A',
|
1351
|
chr(195).chr(135) => 'C', chr(195).chr(136) => 'E',
|
1352
|
chr(195).chr(137) => 'E', chr(195).chr(138) => 'E',
|
1353
|
chr(195).chr(139) => 'E', chr(195).chr(140) => 'I',
|
1354
|
chr(195).chr(141) => 'I', chr(195).chr(142) => 'I',
|
1355
|
chr(195).chr(143) => 'I', chr(195).chr(145) => 'N',
|
1356
|
chr(195).chr(146) => 'O', chr(195).chr(147) => 'O',
|
1357
|
chr(195).chr(148) => 'O', chr(195).chr(149) => 'O',
|
1358
|
chr(195).chr(150) => 'O', chr(195).chr(153) => 'U',
|
1359
|
chr(195).chr(154) => 'U', chr(195).chr(155) => 'U',
|
1360
|
chr(195).chr(156) => 'U', chr(195).chr(157) => 'Y',
|
1361
|
chr(195).chr(159) => 's', chr(195).chr(160) => 'a',
|
1362
|
chr(195).chr(161) => 'a', chr(195).chr(162) => 'a',
|
1363
|
chr(195).chr(163) => 'a', chr(195).chr(164) => 'a',
|
1364
|
chr(195).chr(165) => 'a', chr(195).chr(167) => 'c',
|
1365
|
chr(195).chr(168) => 'e', chr(195).chr(169) => 'e',
|
1366
|
chr(195).chr(170) => 'e', chr(195).chr(171) => 'e',
|
1367
|
chr(195).chr(172) => 'i', chr(195).chr(173) => 'i',
|
1368
|
chr(195).chr(174) => 'i', chr(195).chr(175) => 'i',
|
1369
|
chr(195).chr(177) => 'n', chr(195).chr(178) => 'o',
|
1370
|
chr(195).chr(179) => 'o', chr(195).chr(180) => 'o',
|
1371
|
chr(195).chr(181) => 'o', chr(195).chr(182) => 'o',
|
1372
|
chr(195).chr(182) => 'o', chr(195).chr(185) => 'u',
|
1373
|
chr(195).chr(186) => 'u', chr(195).chr(187) => 'u',
|
1374
|
chr(195).chr(188) => 'u', chr(195).chr(189) => 'y',
|
1375
|
chr(195).chr(191) => 'y',
|
1376
|
|
1377
|
chr(196).chr(128) => 'A', chr(196).chr(129) => 'a',
|
1378
|
chr(196).chr(130) => 'A', chr(196).chr(131) => 'a',
|
1379
|
chr(196).chr(132) => 'A', chr(196).chr(133) => 'a',
|
1380
|
chr(196).chr(134) => 'C', chr(196).chr(135) => 'c',
|
1381
|
chr(196).chr(136) => 'C', chr(196).chr(137) => 'c',
|
1382
|
chr(196).chr(138) => 'C', chr(196).chr(139) => 'c',
|
1383
|
chr(196).chr(140) => 'C', chr(196).chr(141) => 'c',
|
1384
|
chr(196).chr(142) => 'D', chr(196).chr(143) => 'd',
|
1385
|
chr(196).chr(144) => 'D', chr(196).chr(145) => 'd',
|
1386
|
chr(196).chr(146) => 'E', chr(196).chr(147) => 'e',
|
1387
|
chr(196).chr(148) => 'E', chr(196).chr(149) => 'e',
|
1388
|
chr(196).chr(150) => 'E', chr(196).chr(151) => 'e',
|
1389
|
chr(196).chr(152) => 'E', chr(196).chr(153) => 'e',
|
1390
|
chr(196).chr(154) => 'E', chr(196).chr(155) => 'e',
|
1391
|
chr(196).chr(156) => 'G', chr(196).chr(157) => 'g',
|
1392
|
chr(196).chr(158) => 'G', chr(196).chr(159) => 'g',
|
1393
|
chr(196).chr(160) => 'G', chr(196).chr(161) => 'g',
|
1394
|
chr(196).chr(162) => 'G', chr(196).chr(163) => 'g',
|
1395
|
chr(196).chr(164) => 'H', chr(196).chr(165) => 'h',
|
1396
|
chr(196).chr(166) => 'H', chr(196).chr(167) => 'h',
|
1397
|
chr(196).chr(168) => 'I', chr(196).chr(169) => 'i',
|
1398
|
chr(196).chr(170) => 'I', chr(196).chr(171) => 'i',
|
1399
|
chr(196).chr(172) => 'I', chr(196).chr(173) => 'i',
|
1400
|
chr(196).chr(174) => 'I', chr(196).chr(175) => 'i',
|
1401
|
chr(196).chr(176) => 'I', chr(196).chr(177) => 'i',
|
1402
|
chr(196).chr(178) => 'IJ',chr(196).chr(179) => 'ij',
|
1403
|
chr(196).chr(180) => 'J', chr(196).chr(181) => 'j',
|
1404
|
chr(196).chr(182) => 'K', chr(196).chr(183) => 'k',
|
1405
|
chr(196).chr(184) => 'k', chr(196).chr(185) => 'L',
|
1406
|
chr(196).chr(186) => 'l', chr(196).chr(187) => 'L',
|
1407
|
chr(196).chr(188) => 'l', chr(196).chr(189) => 'L',
|
1408
|
chr(196).chr(190) => 'l', chr(196).chr(191) => 'L',
|
1409
|
chr(197).chr(128) => 'l', chr(197).chr(129) => 'L',
|
1410
|
chr(197).chr(130) => 'l', chr(197).chr(131) => 'N',
|
1411
|
chr(197).chr(132) => 'n', chr(197).chr(133) => 'N',
|
1412
|
chr(197).chr(134) => 'n', chr(197).chr(135) => 'N',
|
1413
|
chr(197).chr(136) => 'n', chr(197).chr(137) => 'N',
|
1414
|
chr(197).chr(138) => 'n', chr(197).chr(139) => 'N',
|
1415
|
chr(197).chr(140) => 'O', chr(197).chr(141) => 'o',
|
1416
|
chr(197).chr(142) => 'O', chr(197).chr(143) => 'o',
|
1417
|
chr(197).chr(144) => 'O', chr(197).chr(145) => 'o',
|
1418
|
chr(197).chr(146) => 'OE',chr(197).chr(147) => 'oe',
|
1419
|
chr(197).chr(148) => 'R',chr(197).chr(149) => 'r',
|
1420
|
chr(197).chr(150) => 'R',chr(197).chr(151) => 'r',
|
1421
|
chr(197).chr(152) => 'R',chr(197).chr(153) => 'r',
|
1422
|
chr(197).chr(154) => 'S',chr(197).chr(155) => 's',
|
1423
|
chr(197).chr(156) => 'S',chr(197).chr(157) => 's',
|
1424
|
chr(197).chr(158) => 'S',chr(197).chr(159) => 's',
|
1425
|
chr(197).chr(160) => 'S', chr(197).chr(161) => 's',
|
1426
|
chr(197).chr(162) => 'T', chr(197).chr(163) => 't',
|
1427
|
chr(197).chr(164) => 'T', chr(197).chr(165) => 't',
|
1428
|
chr(197).chr(166) => 'T', chr(197).chr(167) => 't',
|
1429
|
chr(197).chr(168) => 'U', chr(197).chr(169) => 'u',
|
1430
|
chr(197).chr(170) => 'U', chr(197).chr(171) => 'u',
|
1431
|
chr(197).chr(172) => 'U', chr(197).chr(173) => 'u',
|
1432
|
chr(197).chr(174) => 'U', chr(197).chr(175) => 'u',
|
1433
|
chr(197).chr(176) => 'U', chr(197).chr(177) => 'u',
|
1434
|
chr(197).chr(178) => 'U', chr(197).chr(179) => 'u',
|
1435
|
chr(197).chr(180) => 'W', chr(197).chr(181) => 'w',
|
1436
|
chr(197).chr(182) => 'Y', chr(197).chr(183) => 'y',
|
1437
|
chr(197).chr(184) => 'Y', chr(197).chr(185) => 'Z',
|
1438
|
chr(197).chr(186) => 'z', chr(197).chr(187) => 'Z',
|
1439
|
chr(197).chr(188) => 'z', chr(197).chr(189) => 'Z',
|
1440
|
chr(197).chr(190) => 'z', chr(197).chr(191) => 's',
|
1441
|
|
1442
|
chr(226).chr(130).chr(172) => 'E',
|
1443
|
|
1444
|
chr(194).chr(163) => '');
|
1445
|
|
1446
|
$string = strtr($string, $chars);
|
1447
|
} else {
|
1448
|
|
1449
|
$chars['in'] = chr(128).chr(131).chr(138).chr(142).chr(154).chr(158)
|
1450
|
.chr(159).chr(162).chr(165).chr(181).chr(192).chr(193).chr(194)
|
1451
|
.chr(195).chr(196).chr(197).chr(199).chr(200).chr(201).chr(202)
|
1452
|
.chr(203).chr(204).chr(205).chr(206).chr(207).chr(209).chr(210)
|
1453
|
.chr(211).chr(212).chr(213).chr(214).chr(216).chr(217).chr(218)
|
1454
|
.chr(219).chr(220).chr(221).chr(224).chr(225).chr(226).chr(227)
|
1455
|
.chr(228).chr(229).chr(231).chr(232).chr(233).chr(234).chr(235)
|
1456
|
.chr(236).chr(237).chr(238).chr(239).chr(241).chr(242).chr(243)
|
1457
|
.chr(244).chr(245).chr(246).chr(248).chr(249).chr(250).chr(251)
|
1458
|
.chr(252).chr(253).chr(255);
|
1459
|
|
1460
|
$chars['out'] = "EfSZszYcYuAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy";
|
1461
|
|
1462
|
$string = strtr($string, $chars['in'], $chars['out']);
|
1463
|
$double_chars['in'] = array(chr(140), chr(156), chr(198), chr(208), chr(222), chr(223), chr(230), chr(240), chr(254));
|
1464
|
$double_chars['out'] = array('OE', 'oe', 'AE', 'DH', 'TH', 'ss', 'ae', 'dh', 'th');
|
1465
|
$string = str_replace($double_chars['in'], $double_chars['out'], $string);
|
1466
|
}
|
1467
|
|
1468
|
return $string;
|
1469
|
}
|
1470
|
|
1471
|
|
1472
|
|
1473
|
|
1474
|
|
1475
|
|
1476
|
|
1477
|
|
1478
|
|
1479
|
|
1480
|
|
1481
|
|
1482
|
|
1483
|
|
1484
|
function seems_utf8($str) {
|
1485
|
$length = strlen($str);
|
1486
|
for ($i=0; $i < $length; $i++) {
|
1487
|
$c = ord($str[$i]);
|
1488
|
if ($c < 0x80) $n = 0;
|
1489
|
elseif (($c & 0xE0) == 0xC0) $n=1;
|
1490
|
elseif (($c & 0xF0) == 0xE0) $n=2;
|
1491
|
elseif (($c & 0xF8) == 0xF0) $n=3;
|
1492
|
elseif (($c & 0xFC) == 0xF8) $n=4;
|
1493
|
elseif (($c & 0xFE) == 0xFC) $n=5;
|
1494
|
else return false;
|
1495
|
for ($j=0; $j<$n; $j++) {
|
1496
|
if ((++$i == $length) || ((ord($str[$i]) & 0xC0) != 0x80))
|
1497
|
return false;
|
1498
|
}
|
1499
|
}
|
1500
|
return true;
|
1501
|
}
|
1502
|
|
1503
|
function slugify($text)
|
1504
|
{
|
1505
|
|
1506
|
$text = preg_replace('~[^\\pL\d]+~u', '-', $text);
|
1507
|
|
1508
|
|
1509
|
$text = trim($text, '-');
|
1510
|
|
1511
|
|
1512
|
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
|
1513
|
|
1514
|
|
1515
|
$text = strtolower($text);
|
1516
|
|
1517
|
|
1518
|
$text = preg_replace('~[^-\w]+~', '', $text);
|
1519
|
|
1520
|
if (empty($text))
|
1521
|
{
|
1522
|
return 'n-a';
|
1523
|
}
|
1524
|
return $text;
|
1525
|
}
|
1526
|
|
1527
|
?>
|