Repository navigation
Expand file tree
/
Copy pathupdate.php
More file actions
716 lines (561 loc) · 22.2 KB
/
Copy pathupdate.php
File metadata and controls
716 lines (561 loc) · 22.2 KB
1
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
#!/usr/bin/php
<?php
// ------------------------------------------------------------
// (c) 2023/2025 by WRXB288 lagmrs.com all rights reserved
//
// Node image upgrade system.
// -------------------------------------------------------------
// 1.9 09/18/23 added cleanup of license files and linefeeds
// 3.2.1 2/10/25 Rebuild upgrade for image
// 3.4 2/20 debugging added
// 3.5 2/23 added update for sbin
// 3.6 2/24 Minor tweeks for new updates to menus.
// 3.7 fixes permissions on webmin service
// 3.9 3/8.25 Fix to stop upgrades to old versions.
// 4.0 3/22/25 fixes the connect line problem.
// 4.1 7/25 minor fix Asking for permission
// 4.2 7/28 rename sound files
// 4.3 9/4 cleanup sound.zip file unziping into /repo/sounds bug fix cleanup
$verInstaller= "4.3"; $verRt="9-4-2025";
$changeall=false;$year = date("Y");
$docRouteP="/srv/http";
$path = "/etc/asterisk/local/mm-software";
// Load version numbers
$currentVersion = getVersionFromCSV("$path/version.txt");
$imageVersion = getVersionFromCSV("$path/version-image.txt");
$header=
"-----------------------------------------------------------------------------
System Update Module $verInstaller Release Date:$verRt
(c) 2023/$year by WRXB288 lagmrs.com all rights reserved
-----------------------------------------------------------------------------
Running:$currentVersion Orginal Image:$imageVersion
";
proxieCheck();
if($imageVersion=="N/A" ){
print"
_ _ _ _ _ _
/ \ / \ / \ / \ / \ / \
( S | T | O | P | | 1!)
\_/ \_/ \_/ \_/ \_/ \_/
$header
Can not update to a beta version [$imageVersion] please download new image.
";
$a = readline('Enter your command: ');die;}
$test= 10.8;
if($imageVersion < $test ){
print"
_ _ _ _ _ _
/ \ / \ / \ / \ / \ / \
( S | T | O | P | | 2!)
\_/ \_/ \_/ \_/ \_/ \_/
$header
Can not update to a version older than [$test] you have [$imageVersion] please download new image.
";
$a = readline('Enter your command: ');die;}
print "
_ _ _ _ _ _
/ \ / \ / \ / \ / \ / \
( U | P | D | A | T | E )
\_/ \_/ \_/ \_/ \_/ \_/
$header
This will Update the Node image to the currect release.
Be sure you have backups. Use Win32DiskImager in read mode to make backups.
If you want to see whats in this update the code is at github for inspection.
https://github.com/tmastersmart/gmrs_live (certified safe)
u) Update (any other key to abort!)
";
$a = readline('Enter your command: ');
if ($a <> "u"){die;}
$repoURL= "https://raw.githubusercontent.com/tmastersmart/gmrs_live/main";
$pathS = "$path/sounds";//if(!is_dir($pathS)){ mkdir($pathS, 0755);}
$pathR = "$path/repo"; if(!is_dir($pathR)){ mkdir($pathR, 0755);}
$pathB = "$path/backup";if(!is_dir($pathB)){ mkdir($pathB, 0755);}
$pathG = "$docRouteP/status";//if(!is_dir($pathG)){ mkdir($pathG, 0755);}
$pathGA= "$docRouteP/admin";//if(!is_dir($pathGA)){ mkdir($pathGA, 0755);}
$pathGE= "$docRouteP/images";//if(!is_dir($pathGE)){ mkdir($pathGE, 0755);}
$pathI = "$docRouteP/status/images";//if(!is_dir($pathI)){ mkdir($pathI, 0755);}
$pathSBIN = "/usr/local/sbin";
$pathF = "/usr/local/sbin/firsttime";
$pathN = "/var/lib/asterisk/sounds/rpt/nodenames";
print "Running Live upgrade system ...........\n";
chdir($pathR);
if (file_exists("$pathR/version.txt")) {
rename ("$pathR/version.txt", "$pathR/version-new.txt");// safety to make sure its renamed
rename ("$pathR/version-new.txt", "$path/version-new.txt");
}
else {print "Cant find new version info So quiting. Did we even download anything? \n";
print "Press ANY Key\n";
$a = readline('Ready: ');
die;
}
//just to be safe backup or core files.
$backupFile = "$path/backup/core-backup.tar.gz"; $command = "tar -czvf $backupFile $path/*.php";exec($command, $output, $return_var);
if ($return_var === 0) {echo "Backup core successful: $backupFile\n";}
else {echo "Backup core failed!\n";}
//just to be safe backup or core files.
$backupFile = "$path/backup/core-backup-csv.tar.gz"; $command = "tar -czvf $backupFile $path/*.csv";exec($command, $output, $return_var);
if ($return_var === 0) {echo "Backup csv core successful: $backupFile\n";}
else {echo "Backup core failed!\n";}
// The update script is suposted to move this file it should not be here.
if (file_exists("$pathR/update.php")) {unlink ("$pathR/update.php");print "Fixing file that was not moved ....\n";}
if (file_exists("$pathR/version.txt")){ unlink("$pathR/version.txt");print "Fixing file that was not moved ....\n";}
if (file_exists("$pathR/image-info.txt")){ unlink("$pathR/image-info.txt");print "Fixing file that was not moved ....\n";}
// first check for core
chdir($pathR);
if (file_exists("$pathR/core-download.zip")) {
print"processing core-download\n";
exec("unzip $pathR/core-download.zip",$output,$return_var);
foreach (glob("*.php") as $file) {
if($file == '.' || $file == '..') continue;
if (is_file($file)) {
print"Installing php file:$path/$file ";
if (file_exists("$path/$file")){unlink("$path/$file");print"Replacing ";}// kill existing file
if (file_exists("$pathR/$file")){
rename ("$pathR/$file", "$path/$file");
exec("sudo chmod +x $path/$file",$output,$return_var);
}
print"ok\n";
}
}
foreach (glob("*.csv") as $file) {
if($file == '.' || $file == '..') continue;
if (is_file($file)) {
print"Installing csv file:$path/$file ";
if (file_exists("$path/$file")){unlink("$path/$file");print"Replacing ";}// kill existing file
if (file_exists("$pathR/$file")){rename ("$pathR/$file", "$path/$file"); }
print"ok\n";
}
}
foreach (glob("*.txt") as $file) {
if($file == '.' || $file == '..') continue;
if (is_file($file)) {
print"Installing txt file:$path/$file ";
if (file_exists("$path/$file")){unlink("$path/$file");print"Replacing ";}// kill existing file
if (file_exists("$pathR/$file")){rename ("$pathR/$file", "$path/$file"); }
print"ok\n";
}
}
}
//else {print "no core_download.zip found \n";}
// end of the core files.
// fix the bug where one upgrade had a filename in its zip
$pathFIX = "$path/repo/sounds";
if(is_dir($pathFIX)){print"Cleaning old ZIP archive ----------"; chdir($pathFIX);clean_repo($pathFIX);rmdir($pathFIX);print" ok\n";}
// sounds files
if (file_exists("$pathR/sounds.zip")){
// for this version we are only installing new files
// chdir($pathS); clean_repo($pathS);
chdir($pathR);
exec("unzip $pathR/sounds.zip",$output,$return_var);
print"processing new sounds\n";
foreach (glob("*.wav") as $file) {
if($file == '.' || $file == '..') continue;
if (is_file($file)) {
print"Instal wav:$pathS/$file ";
if (file_exists("$pathS/$file")){unlink("$pathS/$file");print"Replacing ";}// kill existing file
if (file_exists("$pathR/$file")){rename ("$pathR/$file", "$pathS/$file");} // Move it into the SOUNDS
print"ok\n";
}
}
foreach (glob("*.ul") as $file) {
if($file == '.' || $file == '..') continue;
if (is_file($file)) {
print"Instal ul $pathS/$file ";
if (file_exists("$pathS/$file")){unlink("$pathS/$file");print"Replacing ";}// kill existing file
if (file_exists("$pathR/$file")){rename ("$pathR/$file", "$pathS/$file");} // Move it into the SOUNDS
print"ok\n";
}
}
foreach (glob("*.gsm") as $file) {
if($file == '.' || $file == '..') continue;
if (is_file($file)) {
print"Instal gsm $pathS/$file ";
if (file_exists("$pathS/$file")){unlink("$pathS/$file");print"Replacing ";}// kill existing file
if (file_exists("$pathR/$file")){rename ("$pathR/$file", "$pathS/$file");} // Move it into the SOUNDS
print"ok\n";
}
}
}
//else {print "no sounds.zip found \n";}
// end new sounds
// install the status page updates
if (file_exists("$pathR/status.zip")){
exec("unzip $pathR/status.zip",$output,$return_var);
print"processing status\n";
chdir($pathR);
foreach (glob("*.php") as $file) {
if($file == '.' || $file == '..') continue;
if (is_file($file)) {
print"Installing php file:$pathG/$file ";
if (file_exists("$pathG/$file")){unlink("$pathG/$file");print"Replacing ";}// kill existing file
if (file_exists("$pathR/$file")){rename ("$pathR/$file", "$pathG/$file");}
print"ok\n";
}
}
foreach (glob("*.css") as $file) {
if($file == '.' || $file == '..') continue;
if (is_file($file)) {
print"Installing css file:$pathG/$file ";
if (file_exists("$pathG/$file")){unlink("$pathG/$file");print"Replacing ";}// kill existing file
if (file_exists("$pathR/$file")){rename ("$pathR/$file", "$pathG/$file");}
print"ok\n";
}
}
foreach (glob("*.js") as $file) {
if($file == '.' || $file == '..') continue;
if (is_file($file)) {
print"Installing js file:$pathG/$file ";
if (file_exists("$pathG/$file")){unlink("$pathG/$file");print"Replacing ";}// kill existing file
if (file_exists("$pathR/$file")){rename ("$pathR/$file", "$pathG/$file");}
print"ok\n";
}
}
foreach (glob("*.csv") as $file) {
if($file == '.' || $file == '..') continue;
if (is_file($file)) {
print"Installing csv file:$pathG/$file ";
if (file_exists("$pathG/$file")){unlink("$pathG/$file");print"Replacing ";}// kill existing file
if (file_exists("$pathR/$file")){rename ("$pathR/$file", "$pathG/$file");}
print"ok\n";
}
}
foreach (glob("*.txt") as $file) {
if($file == '.' || $file == '..') continue;
if (is_file($file)) {
print"Installing txt file:$pathG/$file ";
if (file_exists("$pathG/$file")){unlink("$pathG/$file");print"Replacing ";}// kill existing file
if (file_exists("$pathR/$file")){rename ("$pathR/$file", "$pathG/$file");}
print"ok\n";
}
}
}
//else {print "no sstatus.zip found \n";}
// end of status page updates
if (file_exists("$pathR/admin.zip")){
exec("unzip $pathR/admin.zip",$output,$return_var);
print"processing admin\n";
chdir($pathR);
foreach (glob("*.php") as $file) {
if($file == '.' || $file == '..') continue;
if (is_file($file)) {
print"Installing php file:$pathGA/$file ";
if (file_exists("$pathGA/$file")){unlink("$pathGA/$file");print"Replacing ";}// kill existing file
if (file_exists("$pathR/$file")){rename ("$pathR/$file", "$pathGA/$file");}
print"ok\n";
}
}
foreach (glob("*.css") as $file) {
if($file == '.' || $file == '..') continue;
if (is_file($file)) {
print"Installing css file:$pathGE/$file ";
if (file_exists("$pathGA/$file")){unlink("$pathGA/$file");print"Replacing ";}// kill existing file
if (file_exists("$pathR/$file")){rename ("$pathR/$file", "$pathGA/$file");}
print"ok\n";
}
}
foreach (glob("*.js") as $file) {
if($file == '.' || $file == '..') continue;
if (is_file($file)) {
print"Installing js file:$pathGE/$file ";
if (file_exists("$pathGA/$file")){unlink("$pathGA/$file");print"Replacing ";}// kill existing file
if (file_exists("$pathR/$file")){rename ("$pathR/$file", "$pathGA/$file");}
print"ok\n";
}
}
foreach (glob("*.csv") as $file) {
if($file == '.' || $file == '..') continue;
if (is_file($file)) {
print"Installing ini file:$pathGA/$file ";
if (file_exists("$pathGA/$file")){unlink("$pathGA/$file");print"Replacing ";}// kill existing file
if (file_exists("$pathR/$file")){rename ("$pathR/$file", "$pathGA/$file");}
print"ok\n";
}
}
}
//else {print "no admin.zip found \n";}
// end of admin
if (file_exists("$pathR/images-s.zip")){
exec("unzip $pathR/images-s.zip",$output,$return_var);
print"processing images-s\n";
chdir($pathR);
foreach (glob("*.gif") as $file) {
if($file == '.' || $file == '..') continue;
if (is_file($file)) {
print"Installing gif file:$pathI/$file ";
if (file_exists("$pathI/$file")){unlink("$pathI/$file");print"Replacing ";}// kill existing file
if (file_exists("$pathR/$file")){rename ("$pathR/$file", "$pathI/$file");}
print"ok\n";
}
}
foreach (glob("*.jpg") as $file) {
if($file == '.' || $file == '..') continue;
if (is_file($file)) {
print"Installing jpg file:$pathI/$file ";
if (file_exists("$pathI/$file")){unlink("$pathI/$file");print"Replacing ";}// kill existing file
if (file_exists("$pathR/$file")){rename ("$pathR/$file", "$pathI/$file");}
print"ok\n";
}
}
foreach (glob("*.png") as $file) {
if($file == '.' || $file == '..') continue;
if (is_file($file)) {
print"Installing png file:$pathI/$file ";
if (file_exists("$pathI/$file")){unlink("$pathI/$file");print"Replacing ";}// kill existing file
if (file_exists("$pathR/$file")){rename ("$pathR/$file", "$pathI/$file");}
print"ok\n";
}
}
foreach (glob("*.ico") as $file) {
if($file == '.' || $file == '..') continue;
if (is_file($file)) {
print"Installing ico file:$pathGA/$file ";
if (file_exists("$pathI/$file")){unlink("$pathI/$file");print"Replacing ";}// kill existing file
if (file_exists("$pathR/$file")){rename ("$pathR/$file", "$pathI/$file");}
print"ok\n";
}
}
}
//else {print "no images-s.zip found \n";}
// end images
if (file_exists("$pathR/images.zip")){
exec("unzip $pathR/images.zip",$output,$return_var);
print"processing images\n";
chdir($pathR);
foreach (glob("*.gif") as $file) {
if($file == '.' || $file == '..') continue;
if (is_file($file)) {
print"Installing gif file:$pathI/$file ";
if (file_exists("$pathI2/$file")){unlink("$pathI2/$file");print"Replacing ";}// kill existing file
if (file_exists("$pathR/$file")){rename ("$pathR/$file", "$pathI2/$file");}
print"ok\n";
}
}
foreach (glob("*.jpg") as $file) {
if($file == '.' || $file == '..') continue;
if (is_file($file)) {
print"Installing jpg file:$pathI/$file ";
if (file_exists("$pathI2/$file")){unlink("$pathI2/$file");print"Replacing ";}// kill existing file
if (file_exists("$pathR/$file")){rename ("$pathR/$file", "$pathI2/$file");}
print"ok\n";
}
}
foreach (glob("*.png") as $file) {
if($file == '.' || $file == '..') continue;
if (is_file($file)) {
print"Installing png file:$pathI/$file ";
if (file_exists("$pathI2/$file")){unlink("$pathI2/$file");print"Replacing ";}// kill existing file
if (file_exists("$pathR/$file")){rename ("$pathR/$file", "$pathI2/$file");}
print"ok\n";
}
}
foreach (glob("*.ico") as $file) {
if($file == '.' || $file == '..') continue;
if (is_file($file)) {
print"Installing ico file:$pathGA/$file ";
if (file_exists("$pathI2/$file")){unlink("$pathI2/$file");print"Replacing ";}// kill existing file
if (file_exists("$pathR/$file")){rename ("$pathR/$file", "$pathI2/$file");}
print"ok\n";
}
}
}
//else {print "no images.zip found \n";}
// end images
//======================================
// "/var/lib/asterisk/sounds/rpt/nodenames"; $pathN
if (file_exists("$pathR/nodenames.zip")){
exec("unzip $pathR/nodenames.zip",$output,$return_var);
print"processing nodenames\n";
foreach (glob("*.ul") as $file) {
if($file == '.' || $file == '..') continue;
if (is_file($file)) {
print"Instal $pathN/$file ";
if (file_exists("$pathN/$file")){unlink("$pathN/$file");print"Replacing ";}// kill existing file
if (file_exists("$pathR/$file")){rename ("$pathR/$file", "$pathN/$file");print"--";} // Move it into the SOUNDS
print"ok\n";
}
}
}
//else {print "no nodenames.zip found \n";}
// end nodenames. we wont update this very often
if (file_exists("$pathR/sbin.zip")) {
exec("unzip $pathR/sbin.zip",$output,$return_var);
print"processing sbin\n";
foreach (glob("*.sh") as $file) {
if($file == '.' || $file == '..') continue;
if (is_file($file)) {
print"Installing sh file:$pathSBIN/$file ";
if (file_exists("$pathSBIN/$file")) {rename("$pathSBIN/$file", "$pathB/$file.bak"); print "Back up ";}
rename("$pathR/$file", "$pathSBIN/$file");print "Replacing $file\n";
// Change permissions only if necessary
exec("sudo chmod 755 $pathSBIN/$file", $output, $return_var); print"CHMOD 755";
print"ok\n";
}
}
}
//else {print "no sbin.zip found \n";}
if (file_exists("$pathR/firsttime.zip")){
exec("unzip $pathR/firsttime.zip",$output,$return_var);
print"processing firsttime\n";
foreach (glob("*.sh") as $file) {
if($file == '.' || $file == '..') continue;
if (is_file($file)) {
print"Installing sh file:$pathF/$file ";
if (file_exists("$pathF/$file")) {rename("$pathF/$file", "$pathB/$file.bak"); print "Back up ";}
rename("$pathR/$file", "$pathF/$file");print "Replacing $file\n";
// Change permissions only if necessary
exec("sudo chmod 755 $pathF/$file", $output, $return_var); print"CHMOD 755";
print"ok\n";
}
}
}
//else {print "no firstime.zip found \n";}
// --------------------- expansion replace others at later date -----------------------
// webmin as released had wrong permissions
$file = "/usr/lib/systemd/system/webmin.service";
// Check current permissions
$perms = fileperms($file);
// Remove executable permissions if set
if ($perms & 0x0040 || $perms & 0x0008 || $perms & 0x0001) { // Check if owner, group, or others have execute permission
echo "Fixing permissions on webmin service ...";
exec("sudo chmod 644 $file", $output, $return_var);
if ($return_var === 0) { echo "ok.\n";}
else { echo "Error: unable to fix.[$file]\n"; }
}
// Orginal connect string didnt work. Modify
$configFile = "/usr/local/etc/asterisk_tpl/rpt.conf_tpl"; fixConnect($configFile);
$configFile = "/etc/asterisk/rpt.conf"; fixConnect($configFile);
$pathB = "$path/backup";
// make backups, erase the old ones to save space
$file = "$path/setup.txt"; $file2= "$pathB/setup.txt"; if (file_exists($file2)){unlink($file2);}
copy($file, $file2);print "Backup $file2\n";
$file = "$path/mm-node.txt"; $file2= "$pathB/mm-node.txt";if (file_exists($file2)){unlink($file2);}
copy($file, $file2);print "Backup $file2\n";
$file = "$path/logs/log.txt";$file2= "$pathB/log.txt"; if (file_exists($file2)){unlink($file2);}
copy($file, $file2);print "Backup $file2\n";
$file = "/etc/asterisk/rpt.conf";$file2= "$pathB/rpt.cfg";if (file_exists($file2)){unlink($file2);}
copy($file, $file2);print "Backup $file2\n";
$file = "/etc/asterisk/iax.conf";$file2= "$pathB/iax.cfg";if (file_exists($file2)){unlink($file2);}
copy($file, $file2);print "Backup $file2\n";
$file = "/etc/asterisk/manager.conf";$file2= "$pathB/manager.cfg"; if (file_exists($file2)){unlink($file2);}
copy($file, $file2);print "Backup $file2\n";
print "----\n";
chdir($pathR); clean_repo($pathR);
// cleanup old unused files
$file="$path/license-sounds.txt";if (file_exists($file)){unlink($file);}
$file="$path/license-core.txt"; if (file_exists($file)){unlink($file);}
$file="$path/license-web.txt"; if (file_exists($file)){unlink($file);}
if (file_exists("$path/version-new.txt")) {
$file="$path/version.txt"; if (file_exists($file)){unlink($file);}
rename ("$path/version-new.txt", "$path/version.txt");
print "Updating $file\n";
}
else{print "Unknown error \n";}
$file="$pathS/rain.gsm";
if (file_exists($file)){
rename($file,"$pathS/rain2.gsm");
print "Renaming sound file $file\n";
}
print "Finished Upgrade. In most cases this is a live update. No reboot needed.!\n";
print "\n";
print "Louisiana Image its just better!\n\n";
print "Press ANY Key\n";
$a = readline('Ready: ');
die;
function clean_repo($in){
chdir($in);
$files = glob($in.'/*');
foreach($files as $filed) {
if($filed == '.' || $filed == '..') continue;
if (is_file($filed)) { unlink($filed);print"del $filed\n"; }
}
}
function getVersionFromCSV($filename) {
if (file_exists($filename)) {
$file = fopen($filename, "r");
if ($file !== false) {
$line = fgetcsv($file); // Read first line as CSV
fclose($file);
return $line[0] ?? "N/A"; // Return the first column or "N/A" if empty
}
}
return "N/A"; // File not found or empty
}
//
function fixConnect($configFile){
$newConnPgm = "connpgm= php /etc/asterisk/local/mm-software/connect.php 1";
$newDiscPgm = "discpgm= php /etc/asterisk/local/mm-software/connect.php 2";
$lines = file($configFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$updated = false;
foreach ($lines as &$line) {
if (strpos($line, "connpgm=") === 0 && $line !== $newConnPgm) {
$line = $newConnPgm;
$updated = true;
}
if (strpos($line, "discpgm=") === 0 && $line !== $newDiscPgm) {
$line = $newDiscPgm;
$updated = true;
}
}
// Only write to the file if a change was made
if ($updated) {
file_put_contents($configFile, implode("\n", $lines) . "\n");
echo "Configuration $configFile fixed connect line.\n";
}
}
function proxieCheck(){
// File path to Apache config
$configFile = "/etc/httpd/conf/httpd.conf";
// Modules to disable
$modules = [
"proxy_module",
"proxy_connect_module",
"proxy_ftp_module",
"proxy_http_module",
"proxy_fcgi_module",
"proxy_scgi_module",
"proxy_wstunnel_module",
"proxy_ajp_module",
"proxy_balancer_module",
"proxy_express_module"
];
// Backup first
$backupFile = $configFile . ".bak." . date("YmdHis");
if (!copy($configFile, $backupFile)) {
die("<b>ERROR:</b> Could not back up config file.<br>\n");
}
echo "Backup created: $backupFile<br>\n";
// Read file
$lines = file($configFile, FILE_IGNORE_NEW_LINES);
// Track changes
$changes = [];
// Process each line
foreach ($lines as &$line) {
foreach ($modules as $mod) {
if (preg_match("/^LoadModule\s+$mod\s+/", $line)) {
if (strpos($line, "#") !== 0) { // if not already commented
$line = "#" . $line;
$changes[] = $mod;
}
}
}
}
unset($line); // break ref
// Save file
if (file_put_contents($configFile, implode("\n", $lines)) === false) {
die("ERROR: Could not write updated config file.\n");
}
// Show what was done
if (!empty($changes)) {
echo "Security Fix Applied:\n";
foreach ($changes as $c) {
echo " - Disabled proxy module: $c\n";
}
echo "Apache config updated successfully.\n";
echo "Restarting Apache ...\n";
// Restart Apache and reboot system
exec("systemctl restart httpd");
// exec("reboot");
}
else {echo "No active proxy modules found. .\n";}
}
?>