-
Notifications
You must be signed in to change notification settings - Fork 5
/
system.pl
executable file
·2127 lines (1865 loc) · 67.6 KB
/
system.pl
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
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/perl
sub AddLocalStorage
{
local($device)=$formdata{device};
local($volume)=$formdata{volume};
require "action.pl";
print "<CENTER>\n";
print "<H2>Adding Local Storage</H2>\n";
print "</CENTER>\n";
print "<FORM NAME=WIZARDFORM>\n";
local($actionid)=$$;
print "<INPUT TYPE=HIDDEN NAME=actionid ID=actionid VALUE=\"$actionid\">\n";
print "<CENTER>\n";
print "<TABLE>\n";
print "<TR><TD>Volume</TD><TD>$volume</TD></TR>\n";
print "<TR><TD>Device</TD><TD>$device</TD></TR>\n";
print "</TABLE>\n";
print "<BR>\n";
&PrintProgressBar();
print "<BR>\n";
&PrintStatusDiv();
print "</CENTER>\n";
&RunAction($actionid,"Add local $device to $volume","system.pl","\&AddLocalStorage_DoIt($actionid);");
print "<script language='javascript' src='/js/progress.js'></script>\n";
print "<script language='javascript'>\n";
print "Update($actionid);\n";
print "</script>\n";
}
sub AddLocalStorage_DoIt
{
local($actionid)=shift;
require "general.pl";
require "config.pl";
require "action.pl";
local(%args)=&ReadActionArgs($actionid);
local($result)=&UpdateActionProgress($actionid,5,"Read Action Arguments");
if ($result) {
&UpdateActionProgress($actionid,-1,"Could not read arguments");
return 1;
}
#for $key (keys(%args))
#{
# print "<LI>KEY $key -> $args{$key}\n";
#}
local($device)=$args{device};
local($volume)=$args{volume};
local(@pvstatus)=&GetPVStatusInfo($device);
if ($pvstatus[1] ne "Unallocated" || $device =~ /\/dev\/sda/)
{
&UpdateActionProgress($actionid,-2,"Device is already assigned to a volume group, not adding");
return 2;
} else {
&UpdateActionProgress($actionid,10,"Checked previous device allocation");
local($command)="/usr/sbin/pvcreate $device";
local($result)=&RunCommand($command,"Creating Physical device for $device");
if ($result)
{
&UpdateActionProgress($actionid,-2,"Could not label the drive as lvm");
return 1;
}
&UpdateActionProgress($actionid,20,"Checked previous device allocation");
local($command)="/usr/sbin/vgextend udavg $device";
local($result)=&RunCommand($command,"Extending udavg with $device");
if ($result)
{
&UpdateActionProgress($actionid,-2,"Could not extend volume group udavg");
return 1;
}
&UpdateActionProgress($actionid,30,"Extended volume group udavg");
local($command)="/usr/sbin/lvextend -v /dev/udavg/$volume $device";
local($result)=&RunCommand($command,"extending logical volume $volume");
if ($result)
{
&UpdateActionProgress($actionid,-2,"Could not extend logical volume $volume");
return 1;
}
&UpdateActionProgress($actionid,40,"Extended logical volume $volume");
local($command)="/usr/sbin/xfs_growfs /dev/udavg/$volume";
local($result)=&RunCommand($command,"Resizing filesystem");
if ($result)
{
&UpdateActionProgress($actionid,100,"Could not resize the filesystem on volume $volume");
return 1;
}
}
&UpdateActionProgress($actionid,100,"Successfull");
return 0;
}
sub GetLogicalVolumeStatus
{
local(@result)=`df -h -P | grep udavg`;
local(%status)=();
for $line (@result)
{
local(@info)=split(/\s+/,$line);
$info[0] =~ /\/dev\/mapper\/udavg-(.*)/ ;
$status{$1}="$info[1];$info[2];$info[3];$info[4]";
}
return %status;
}
sub GetPVStatusInfo
{
local($pv)=shift;
local(@info)=`sudo pvs --segments $pv`;
if ($? != 0)
{
local($partedsize)=`sudo /sbin/fdisk -l $pv print | grep ^Disk | awk '{print \$2}' FS=\: | awk '{print \$1}' FS=\,`;
return ($pv,"Unallocated",$partedsize);
}
local(@myarray)=split(/\s+/,$info[1]);
local($status)=$myarray[2];
local($size)=$myarray[5];
return ($pv,$status,$size);
}
sub LocalStorage
{
print "<CENTER>\n";
print "<H2>Local Storage</H2>\n";
&PrintToolbar("Extend","Cancel");
print "<script language='javascript' src='/js/table.js'></script>\n";
print "<script language='javascript' src='/js/localstorage.js'></script>\n";
print "<BR><BR>\n";
print "<FORM NAME=LOCALSTORAGE ACTION='uda3.pl' METHOD=GET>\n";
print "<INPUT TYPE=HIDDEN NAME=module VALUE=system>\n";
print "<INPUT TYPE=HIDDEN NAME=action VALUE=localstorage>\n";
print "<INPUT TYPE=HIDDEN NAME=button VALUE=none>\n";
print "<INPUT TYPE=HIDDEN NAME=volume VALUE=none>\n";
print "</FORM>\n";
local(%status)=&GetLogicalVolumeStatus();
print "<TABLE BORDER=1>\n";
print "<TR CLASS=tableheader><TD>Volume</TD><TD>Total</TD><TD>Used</TD><TD>Free</TD><TD>Usage</TD></TR>\n";
for $volume (keys(%status))
{
local(@info)=split(";",$status{$volume});
print "<TR onclick='SelectRow(this)' ID='$volume'><TD>$volume</TD><TD>$info[0]</TD><TD>$info[1]</TD><TD>$info[2]</TD><TD>$info[3]</TD></TR>\n";
}
print "</TABLE>\n";
print "<TABLE BORDER=1>\n";
return 0;
}
sub ExtendVolume
{
local($volume)=$formdata{volume};
print "<FORM NAME=LOCALSTORAGE ACTION='uda3.pl' METHOD=GET>\n";
print "<INPUT TYPE=HIDDEN NAME=module VALUE=system>\n";
print "<INPUT TYPE=HIDDEN NAME=action VALUE=localstorage>\n";
print "<INPUT TYPE=HIDDEN NAME=button VALUE=none>\n";
print "<INPUT TYPE=HIDDEN NAME=volume VALUE='$volume'>\n";
print "<INPUT TYPE=HIDDEN NAME=device VALUE=none>\n";
print "</FORM>\n";
print "<script language='javascript' src='/js/table.js'></script>\n";
print "<script language='javascript' src='/js/extendvolume.js'></script>\n";
print "<CENTER>\n";
print "<H2>Extending volume $volume</H2>\n";
&PrintToolbar("Apply","Cancel");
print "<BR>\n";
local(@result)=`echo "echo \'- - -\' \> /sys/class/scsi_host/host0/scan" | sudo su -`;
#print "<PRE>@result</PRE>";
local($command)="ls -1 /dev/sd* | grep -v \/dev\/sda";
# local($command)="ls -1 /dev/sd*";
local(@devices)=`sudo $command`;
if ($#devices<0)
{
print "No devices found to extend the volume with";
} else {
print "<TABLE BORDER=1>\n";
print "<TR CLASS=tableheader><TD>Device</TD><TD>Status</TD><TD>Size</TD></TR>\n";
for $device (@devices)
{
chomp($device);
local(@info)=GetPVStatusInfo($device);
if ($info[1] eq "Unallocated")
{
print "<TR onclick='SelectRow(this)' ID='$device'><TD>$device</TD><TD>$info[1]</TD><TD>$info[2]</TD></TR>\n";
}
}
print "</TABLE>\n";
}
print "</CENTER>\n";
}
sub Network
{
local(%config)=&GetSystemVariables();
print "<CENTER>\n";
print "<H2>Network Settings</H2>\n";
&PrintToolbar("Apply","Cancel");
print "<script language='javascript' src='/js/network.js'></script>\n";
print "<BR>\n";
print "<FORM NAME=NETWORKFORM METHOD=POST ACTION='uda3.pl'>\n";
print "<INPUT TYPE=HIDDEN NAME=module VALUE='system'>\n";
print "<INPUT TYPE=HIDDEN NAME=action VALUE='applynetwork'>\n";
print "<TABLE>\n";
print "<TR><TD>Hostname</TD><TD><INPUT TYPE=TEXT NAME=HOSTNAME VALUE='$config{UDA_HOSTNAME}'></TD></TR>\n";
print "<TR><TD> </TD><TD> </TD></TR>\n";
print "<TR><TD>IP Address</TD><TD><INPUT TYPE=TEXT NAME=IPADDRESS VALUE='$config{UDA_IPADDR}'></TD></TR>\n";
print "<TR><TD>Netmask</TD><TD><INPUT TYPE=TEXT NAME=NETMASK VALUE='$config{UDA_NETMASK}'></TD></TR>\n";
print "<TR><TD>Gateway</TD><TD><INPUT TYPE=TEXT NAME=GATEWAY VALUE='$config{UDA_GATEWAY}'></TD></TR>\n";
print "<TR><TD> </TD><TD> </TD></TR>\n";
local($counter)=1;
while (defined($config{'UDA_DNS_'.$counter}))
{
print "<TR><TD>DNS Server $counter</TD><TD><INPUT TYPE=TEXT NAME=UDA_DNS_$counter VALUE='".$config{'UDA_DNS_'.$counter}."'></TD></TR>\n";
$counter++;
}
#for $item (keys(%config))
#{
# if ($item =~ /UDA_DNS_([0-9]+)/)
# {
# print "<TR><TD>DNS Server $counter</TD><TD><INPUT TYPE=TEXT NAME=UDA_DNS_$counter VALUE='$config{$item}'></TD></TR>\n";
# $counter++;
# }
#}
print "<TR><TD>DNS Server $counter</TD><TD><INPUT TYPE=TEXT NAME=UDA_DNS_$counter></TD></TR>\n";
print "<TR><TD>DNS search order</TD><TD><INPUT TYPE=TEXT NAME=DNSSEARCH VALUE='$config{UDA_DNS_SEARCH_PATH}'></TD></TR>\n";
print "</TABLE>\n";
print "</FORM>\n";
print "</CENTER>\n";
return 0;
}
sub ApplyNetwork
{
print "<CENTER>\n";
print "<H3>Applying network configuration</H3>\n";
local($hostname)=$formdata{HOSTNAME};
local($gateway)=$formdata{GATEWAY};
local($netmask)=$formdata{NETMASK};
local($ipaddr)=$formdata{IPADDRESS};
local($dnssearch)=$formdata{DNSSEARCH};
local($tempeth0file)=$TEMPDIR."/ifcfg-eth0.$$";
local(%config)=&GetSystemVariables();
if ($ipaddr ne $config{UDA_IPADDR})
{
print "You have changed the IP-address of the UDA<BR>\n";
print "The browser will stop responding after in few moments\n";
print "Please follow the link below to the<BR><BR>\n";
print "<A HREF='http://$ipaddr/cgi-bin/uda3.pl'>New location of UDA</A><BR>\n";
print "</CENTER>\n";
}
local($result)=open(ETH0FILE,">$tempeth0file");
print ETH0FILE "DEVICE=eth0\n";
print ETH0FILE "BOOTPROTO=static\n";
print ETH0FILE "ONBOOT=yes\n";
print ETH0FILE "IPADDR=$ipaddr\n";
if ($netmask ne "")
{
print ETH0FILE "NETMASK=$netmask\n";
}
close (ETH0FILE);
local($tempnetworkfile)=$TEMPDIR."/network.$$";
local($result)=open(NETWORK,">$tempnetworkfile");
print NETWORK "NETWORKING=yes\n";
print NETWORK "NETWORKING_IPV6=no\n";
#if($hostname ne "")
#{
# print NETWORK "HOSTNAME=$hostname\n";
#}
if ($gateway ne "")
{
print NETWORK "GATEWAY=$gateway\n";
}
close (NETWORK);
# print "<LI>DNS Settings in /etc/resolv.conf\n";
local($tempresolvfile)=$TEMPDIR."/resolv.conf.$$";
local($result)=open(RESOLV,">$tempresolvfile");
if ($dnssearch ne "")
{
print RESOLV "search $dnssearch\n";
}
for $item (keys(%formdata))
{
if ($item =~ /^UDA_DNS_[0-9]+/)
{
if ($formdata{$item} ne "")
{
print RESOLV "nameserver $formdata{$item}\n";
}
}
}
close(RESOLV);
local($savedhcpfile)=$TEMPDIR."/dhcpd.conf.ok.$$";
local($dhcpdconf)=$TEMPDIR."/dhcpd.conf.new.$$";
local($original)="/etc/dhcp/dhcpd.conf";
local($command)="cp $original $dhcpdconf";
local($result)=&RunCommand($command,"Making $original copy to edit in $dhcpdconf");
local($command)="cp $original $savedhcpfile";
local($result)=&RunCommand($command,"Making $original safecopy in $savedhcpfile");
# print "<LI>New UDA IP in /etc/dhcp/dhcpd.conf\n";
local($command)="sed -i -e 's/next-server\\s*$config{UDA_IPADDR}/next-server $ipaddr/gi' $dhcpdconf";
local($result)=&RunCommand($command,"Adjusting next-server entry in $dhcpdconf");
local($command)="sed -i -e 's/domain-name-servers\\s+$config{UDA_IPADDR}/domain-name-servers $ipaddr/gi' $dhcpdconf";
local($result)=&RunCommand($command,"Adjusting domain-name-servers entry in $dhcpdconf");
local($command)="sed -i -e 's/routers\\s+$config{UDA_IPADDR}/routers $ipaddr/gi' $dhcpdconf";
local($result)=&RunCommand($command,"Adjusting routers entry in $dhcpdconf");
#### Commit changes
# TODO Republish all templates
#print "<LI>setting hostname\n";
if($hostname ne "")
{
local($command)="/usr/bin/hostnamectl set-hostname $hostname";
local($result)=&RunCommand($command,"Setting hostname");
if ($result)
{
&PrintError("Could not write network file");
return 1;
}
}
# Copy resolv.conf
local($command)="cp $tempresolvfile /etc/resolv.conf";
local($result)=&RunCommand($command,"Writing resolv.conf");
if ($result)
{
&PrintError("Could not write resolv.conf file");
return 1;
}
# Copy network
local($command)="cp $tempnetworkfile /etc/sysconfig/network";
local($result)=&RunCommand($command,"Writing network file");
if ($result)
{
&PrintError("Could not write network file");
return 1;
}
# Copy ifcfg-eth0
local($command)="cp $tempeth0file /etc/sysconfig/network-scripts/ifcfg-eth0";
local($result)=&RunCommand($command,"Writing eth0 file");
if ($result)
{
&PrintError("Could not write eth0 interface file");
return 1;
}
# Copy dhcpd.conf
local($command)="cp $dhcpdconf /etc/dhcp/dhcpd.conf";
local($result)=&RunCommand($command,"Writing dhcpd file");
if ($result)
{
&PrintError("Could not write dhcpd file");
return 1;
}
require "templates.pl";
local($result)=&PublishAllTemplates();
if ($result)
{
&PrintError("Could not publish all templates");
return 1;
}
# Restart network
local($command)="/sbin/service network restart";
local($result)=&RunCommand($command,"Restarting network");
if ($result)
{
&PrintError("Could not restart network");
return 1;
}
# Restart dhcp
local($command)="/sbin/service dhcpd restart";
local($result)=&RunCommand($command,"Restarting dhcpd");
if ($result)
{
&PrintError("Could not restart dhcpd");
return 1;
}
&PrintSuccess("Succesfully changed network configuration");
}
sub Storage
{
print "<H2>Local Storage</H2>\n";
return 0;
}
sub Password
{
print "<CENTER>\n";
print "<H2>Change Password</H2>\n";
&PrintToolbar("Apply","Cancel");
print "<script language='javascript' src='/js/password.js'></script>\n";
print "<BR>\n";
print "<FORM NAME=PASSWORDFORM METHOD=POST ACTION='uda3.pl'>\n";
print "<INPUT TYPE=HIDDEN NAME=module VALUE='system'>\n";
print "<INPUT TYPE=HIDDEN NAME=action VALUE='applypassword'>\n";
print "<TABLE>\n";
print "<TR><TD>Old Password</TD><TD><INPUT TYPE=PASSWORD NAME=OLDPASSWORD></TD></TR>\n";
print "<TR><TD>New Password</TD><TD><INPUT TYPE=PASSWORD NAME=NEWPASSWORD1></TD></TR>\n";
print "<TR><TD>Confirm new password</TD><TD><INPUT TYPE=PASSWORD NAME=NEWPASSWORD2></TD></TR>\n";
print "</TABLE>\n";
print "</FORM>\n";
print "</CENTER>\n";
return 0;
}
sub ApplyPassword
{
local($old,$new1,$new2)=@_;
if ($new1 ne $new2)
{
&PrintError("New passwords do not match");
return 1;
}
local($hash)=`sudo cat /etc/shadow | grep "^root:" | awk '{print \$2}' FS=\:`;
chomp($hash);
local(@pwdarray)=split(/\$/,$hash);
local($salt)=$pwdarray[2];
local($md5option)="-1";
if ($salt eq "")
{
$md5option="";
$salt=$hash;
$salt=~ s/^(..).*/\1/g;
}
#local($checkhash)=`echo $old | openssl passwd $md5option -stdin -salt "$salt"`;
local($checkhash)=crypt("$old","\$6\$$salt\$");
chomp($checkhash);
if ($checkhash ne $hash)
{
&PrintError("Current password failed!");
return 1;
}
local($command)="/usr/bin/htpasswd -c -b /var/public/conf/passwd admin $new1";
local($result)=&RunCommand($command,"Setting new admin webuser password");
if ($result)
{
&PrintError("Could not set the password for the web admin user",
"I will try to change the root user's password");
return 1;
}
local($command)="echo $new1 | passwd root --stdin";
local($result)=&RunCommand($command,"Setting new OS root user password");
if ($result)
{
&PrintError("Could not set the password for the root user",
"Caution: I have aready changed the password for the webuser!");
return $result
}
&PrintSuccess("The passwords for the web admin user and the root user",
"have been updated succesfully!");
return 0;
}
sub Shutdown
{
print "<CENTER>\n";
print "<H2>Shutdown</H2>\n";
print "</CENTER>\n";
&PrintToolbar("Shutdown","Reboot","Cancel");
print "<script language='javascript' src='/js/shutdown.js'></script>\n";
print "<FORM NAME=SHUTDOWNFORM METHOD=POST ACTION='uda3.pl'>\n";
print "<INPUT TYPE=HIDDEN NAME=module VALUE='system'>\n";
print "<INPUT TYPE=HIDDEN NAME=action VALUE='status'>\n";
print "<INPUT TYPE=HIDDEN NAME=button VALUE='unknown'>\n";
print "</FORM>\n";
return 0;
}
sub SaveGlobalVariables
{
# print "<H1>Saving Global variables</H1>";
local($conffile)=$CONFDIR."/general.conf";
local($tmpfile)=$CONFDIR."/general.conf.$$";
local($result)=open(TEMPFILE,">$tmpfile");
print TEMPFILE $formdata{GLOBALS};
close(TEMPFILE);
local($command)="/usr/bin/dos2unix $tmpfile";
local($result)=&RunCommand($command,"Forcing unix file format");
local($result)=&RunCommand("cp $tmpfile $conffile","Copying temporary file |$tmpfile| to |$conffile|\n");
if ($result)
{
&PrintError("Could not copy temporary file $tmpfile","to pxe config file $conffile");
return 1;
}
unlink($tmpfile);
return 0;
}
sub EditGlobalVariables
{
print "<CENTER>\n";
print "<H2>Edit Global Variables</H2>\n";
&PrintToolbar("Apply","Cancel");
local(@lines)=GetConfigFile("$CONFDIR/general.conf");
print "<script language='javascript' src='/js/editvars.js'></script>\n";
print "<FORM NAME=EDITVARSFORM METHOD=POST ACTION='uda3.pl'>\n";
print "<INPUT TYPE=HIDDEN NAME=module VALUE='system'>\n";
print "<INPUT TYPE=HIDDEN NAME=action VALUE='systemvars'>\n";
print "<INPUT TYPE=HIDDEN NAME=button VALUE='unknown'>\n";
print "<TEXTAREA ROWS=25 COLS=60 NAME=GLOBALS>";
print @lines;
print "</TEXTAREA>";
print "</FORM>\n";
return 0;
}
sub DisplaySystemVariables
{
print "<CENTER>\n";
print "<H2>System Variables</H2>\n";
local(%config)=&GetOnlySystemVariables();
print " <TABLE BORDER=1>\n";
print "<TR CLASS=tableheader><TD>Variable name</TD><TD>Value</TD></TR>\n";
for $item (keys(%config))
{
print "<TR><TD>$item</TD><TD>$config{$item}</TD></TR>\n";
}
print "</TABLE>\n";
print "<H2>Global Variables</H2>\n";
&PrintToolbar("Edit");
print "<script language='javascript' src='/js/showvars.js'></script>\n";
print "<FORM NAME=SHOWVARSFORM METHOD=POST ACTION='uda3.pl'>\n";
print "<INPUT TYPE=HIDDEN NAME=module VALUE='system'>\n";
print "<INPUT TYPE=HIDDEN NAME=action VALUE='systemvars'>\n";
print "<INPUT TYPE=HIDDEN NAME=button VALUE='unknown'>\n";
print "</FORM>\n";
local(%config)=&GetGeneralConfig();
print " <TABLE BORDER=1>\n";
print "<TR CLASS=tableheader><TD>Variable name</TD><TD>Value</TD></TR>\n";
for $item (keys(%config))
{
print "<TR><TD>$item</TD><TD>$config{$item}</TD></TR>\n";
}
print "</TABLE>\n";
print "</CENTER>\n";
return 0;
}
sub ApplyShutdown
{
print "<CENTER>\n";
print "<H3>Shutting Down system</H3>\n";
print "</CENTER>\n";
local($command)="/sbin/shutdown -h now";
local($result)=&RunCommand($command,"Shutdown system");
return 0;
}
sub ApplyReboot
{
print "<CENTER>\n";
print "<H3>Rebooting system</H3>\n";
print "</CENTER>\n";
local($command)="/sbin/shutdown -r now";
local($result)=&RunCommand($command,"Reboot system");
return 0;
}
sub SystemStatus
{
print "<CENTER>\n";
print "<H2>System</H2>\n";
print "<FORM NAME=SYSTEMFORM ACION='uda3.pl' METHOD=POST>\n";
print "<INPUT TYPE=HIDDEN NAME=module VALUE=system>\n";
print "<INPUT TYPE=HIDDEN NAME=action VALUE=none>\n";
print "<H4>Configuration</H4>\n";
&PrintToolbar("Network","Password","Diskspace","PXE","Shutdown");
print "<H4>Tools</H4>\n";
&PrintToolbar("Upload","Upgrade","PowerShell","WinPE");
print "<H4>VMware</H4>\n";
&PrintToolbar("Esx4NoSan","VMTools","OvfTool");
print "<H4>Information</H4>\n";
&PrintToolbar("Actions","Variables","Version","Help");
print "<script language='javascript' src='/js/system.js'></script>\n";
print "</FORM>\n";
print "</CENTER>\n";
return 0;
}
sub Upload
{
local($freespace)=`df -hP /local | tail -1 | awk '{print \$4}'`;
print "<CENTER>\n";
print "<script language='javascript' src='/js/upload.js'></script>\n";
local($html)=<<EOT;
<H2>Upload</H2>
<DIV ID=upload_div STYLE="display: block">
The file will be uploaded to the local storage of the UDA. <BR>
Current Free space is: $freespace<BR><BR>
<iframe name="my_iframe" src="about:blank" width="500" height="200" style="display: none"></iframe>
<FORM NAME="upload" ENCTYPE="multipart/form-data" METHOD="POST" ACTION="/cgi-bin/upload.cgi?uploadid=$$" TARGET="my_iframe">
<INPUT TYPE=HIDDEN NAME=uploadid VALUE=$$><BR><BR>
Select File to upload<BR><BR><INPUT TYPE=FILE NAME=upload_file><BR><BR>
<INPUT TYPE=BUTTON VALUE=Upload ONCLICK='ClickUploadButton();'>
</FORM>
</DIV>
<DIV ID=progress_div STYLE="display:none">
<TABLE>
<TR><TD>Filename: </TD><TD>
<DIV ID=filename_div STYLE="display: none">Unknown</DIV>
</TD></TR>
<TR><TD>Size: </TD><TD>
<DIV ID=size_div STYLE="display: none">Unknown (bytes)</DIV>
</TD></TR>
<TR><TD>Progress: </TD><TD>
<DIV ID=total_div STYLE="display: none">Unknown (bytes)</DIV>
</TD></TR>
</TABLE>
<BR><BR>
<div id="empty3" style="background-color:#cccccc;border:1px solid black;height:30px;width:300px;padding:0px;" align="left">
<div id="d6" style="position:relative;top:0px;left:0px;background-color:#1111cc;height:30px;width:0px;padding-top:5px;padding:0px;">
<div id="d5" style="position:relative;top:0px;left:0px;color:#f0ffff;height:30px;text-align:center;font:bold;padding:0px;padding-top:5px;">
</div></div> </div>
<DIV ID=UPLOADRESULT STYLE="display: none">Starting upload</DIV>
</DIV>
EOT
print $html;
}
sub Version
{
print "<CENTER>\n";
print "<H2>Version Information</H2>\n";
local(%config)=&GetVersionList();
print " <TABLE BORDER=1>\n";
print "<TR CLASS=tableheader><TD>Build</TD><TD>Source</TD></TR>\n";
for $item (keys(%config))
{
print "<TR><TD>$item</TD><TD>$config{$item}</TD></TR>\n";
}
print "</TABLE>\n";
print "</CENTER>\n";
return 0;
}
sub Upgrade
{
print "<CENTER>\n";
print "<H2>Upgrade UDA</H2>\n";
print "<FORM NAME='WIZARDFORM' ENCTYPE='multipart/form-data' METHOD='POST' ACTION='/cgi-bin/upload_upgrade.cgi'>\n";
print "<INPUT TYPE=HIDDEN NAME=module VALUE=system>\n";
print "<INPUT TYPE=HIDDEN NAME=action VALUE=upgrade>\n";
print "<INPUT TYPE=HIDDEN NAME=button VALUE=none>\n";
print "<script language='javascript' src='/js/upgrade.js'></script>\n";
&PrintToolbar("Apply","Cancel");
print "<BR><BR>\n";
print "<FONT COLOR=RED>BACKUP your UDA or make a snapshot before you do this!!!</FONT>\n";
print "<BR><BR>\n";
print "Choose the .tgz file with the patch\n";
print "<BR><BR>\n";
print "<TABLE>\n";
print "<TR><TD>Upgrade file</TD><TD><INPUT TYPE=FILE NAME=UPGRADEFILE></TD></TR>\n";
print "</CENTER>\n";
print "</FORM>\n";
}
sub ApplyUpgrade
{
local($fullfilename)=shift;
require "action.pl";
print "<CENTER>\n";
print "<H2>Applying upgrade</H2>\n";
print "</CENTER>\n";
print "<FORM NAME=WIZARDFORM>\n";
local($actionid)=$$;
print "<INPUT TYPE=HIDDEN NAME=actionid ID=actionid VALUE=\"$actionid\">\n";
print "<CENTER>\n";
print "<TABLE>\n";
print "<TR><TD>Filename</TD><TD>$fullfilename</TD></TR>\n";
#print "<TR><TD>Action ID</TD><TD>$actionid</TD></TR>\n";
print "<TR><TD>Action ID</TD><TD><A HREF='uda3.pl?module=system&action=actions&button=view&actionid=$actionid'>$actionid</A></TD></TR>\n";
print "</TABLE>\n";
print "<BR>\n";
&PrintProgressBar();
print "<BR>\n";
&PrintStatusDiv();
print "</CENTER>\n";
&RunAction($actionid,"Upgrade UDA","system.pl","\&ApplyUpgrade_DoIt($actionid,\"$fullfilename\");");
print "<script language='javascript' src='/js/progress.js'></script>\n";
print "<script language='javascript'>\n";
print "Update($actionid);\n";
print "</script>\n";
}
sub ApplyUpgrade_DoIt
{
local($actionid)=shift;
local($filename)=shift;
require "general.pl";
require "config.pl";
require "action.pl";
local(%args)=&ReadActionArgs($actionid);
local($result)=&UpdateActionProgress($actionid,5,"Read Action Arguments");
if ($result) {
&UpdateActionProgress($actionid,-1,"Could not read arguments");
return 1;
}
#for $key (keys(%args))
#{
# print "<LI>KEY $key -> $args{$key}\n";
#}
local($upgradefile)=$filename;
local($patchdir)="$TMPDIR/action.$actionid/patch";
local($result)=&CreateDir("$patchdir");
if ($result)
{
&UpdateActionProgress($actionid,-2,"Could not create $patchdir");
return 2;
}
&UpdateActionProgress($actionid,30,"Created patch directory $patchdir");
local($command)="tar -xvzf $upgradefile -C $patchdir";
local($result)=&RunCommand($command);
if ($result)
{
&UpdateActionProgress($actionid,-2,"Failed to unpack the patch $upgradefile");
return 2;
}
&UpdateActionProgress($actionid,40,"Unpacked the patch succesfully");
local($command)="chmod -R 644 $patchdir";
local($result)=&RunCommand($command);
if ($result)
{
&UpdateActionProgress($actionid,-2,"Failed to set permissions on unpacked files");
return 2;
}
&UpdateActionProgress($actionid,50,"Set permissions on unpacked files");
local($command)="chmod -R 755 $patchdir/install.sh";
local($result)=&RunCommand($command);
if ($result)
{
&UpdateActionProgress($actionid,-2,"Failed to set permissions on install script");
return 2;
}
&UpdateActionProgress($actionid,60,"Set permissions on install script");
local($command)="$patchdir/install.sh $patchdir > $TMPDIR/action.$actionid/action.out";
local($result)=&RunCommand($command);
if ($result)
{
&UpdateActionProgress($actionid,-2,"Upgrade failed");
return 2;
}
&UpdateActionProgress($actionid,100,"Patch installed succesfully");
return 0;
}
sub Help
{
print "<CENTER>\n";
print "<H2>Help</H2>\n";
print "<H4>This is the great stuff that ties the UDA together</H4>";
print "<TABLE><TR><TD>\n";
print "<LI><A HREF='http://www.centos.org'>Centos 7</A>";
print "<LI><A HREF='http://syslinux.zytor.com/pxe.php'>Pxelinux</A>\n";
print "<LI>tftp-server";
print "<LI><A HREF='http://www.kyz.uklinux.net/cabextract.php'>Cabextract</A>\n";
print "<LI><A HREF='http://oss.netfarm.it/guides/pxe.php'>RIS for linux package</A>\n";
print "<LI><A HREF='https://www.isc.org'>in.dhcpd</A>\n";
print "<LI>nfs server\n";
print "<LI><A HREF='http://www.samba.org'>samba</A>\n";
print "<LI><A HREF='https://wimlib.net'>wimlib</A>\n";
print "<LI><A HREF='http://www.perl.org/'>perl</A>\n";
print "<LI><A HREF='http://www.python.org/'>python</A>\n";
print "<LI><A HREF='http://www.apache.org'>apache</A>\n";
print "<LI><A HREF='http://www.famfamfam.com/lab/icons/silk/'>famfamfam silk icons</A>\n";
print "</TD></TR></TABLE>\n";
print "<BR><BR>\n";
print "For more information go to<BR>\n";
print "<A HREF='http://www.ultimatedeployment.org'>www.ultimatedeployment.org</A>\n";
print "<BR><BR>\n";
print "Thanks to all the people on the forum!!!!\n";
print "</CENTER>\n";
}
sub Esx3NoSan
{
print "<CENTER>\n";
print "<H2>Remove ESX3 San Drivers</H2>\n";
print "<FORM NAME=SYSTEMFORM>\n";
print "<INPUT TYPE=HIDDEN NAME=module VALUE=system>\n";
print "<INPUT TYPE=HIDDEN NAME=action VALUE=applyesx3nosan>\n";
print "<INPUT TYPE=HIDDEN NAME=button VALUE=none>\n";
print "<script language='javascript' src='/js/esx3nosan.js'></script>\n";
&PrintToolbar("Apply","Cancel");
print "<BR><BR>\n";
local(@mountlist)=&GetMountList();;
&PrintJavascriptArray("mountsarray",@mountlist);
print "<script language='javascript' src='/js/loadvalues.js'></script>\n";
print "<script language='javascript' src='/js/tree.js'></script>\n";
print "Show me the esx3 iso file<BR>and I'll create an iso file next to it without the san drivers<BR><BR>";
print "<TABLE>\n";
print "<TR><TD>Storage</TD><TD><SELECT NAME=MOUNT ID=MOUNT ONCHANGE=\"expand('/')\"></SELECT></TD></TR>\n";
print "<TR><TD>ImageFile</TD><TD><INPUT TYPE=TEXT NAME=FILE1 ID=FILE1 SIZE=60 VALUE='/'></TD></TR>\n";
print "<TR><TD COLSPAN=2><DIV ID=browse_div></DIV></TD></TR>\n";
print "</TABLE>\n";
print "<BR>\n";
print "</FORM>\n";
print "<script language='javascript'>\n";
print "LoadValues(\"MOUNT\",mountsarray);\n";
print "expand('/');\n";
print "</script>\n";
print "</CENTER>\n";
}
sub ApplyEsx3NoSan
{
local($mount)=$formdata{MOUNT};
local($file1)=$formdata{FILE1};
require "action.pl";
print "<CENTER>\n";
print "<H2>Creating ESX3 iso image without SAN drivers</H2>\n";
print "</CENTER>\n";
print "<FORM NAME=WIZARDFORM>\n";
local($actionid)=$$;
print "<INPUT TYPE=HIDDEN NAME=actionid ID=actionid VALUE=\"$actionid\">\n";
print "<CENTER>\n";
print "<TABLE>\n";
print "<TR><TD>Mount</TD><TD>$mount</TD></TR>\n";
print "<TR><TD>File 1</TD><TD>$file1</TD></TR>\n";
#print "<TR><TD>Action ID</TD><TD>$actionid</TD></TR>\n";
print "<TR><TD>Action ID</TD><TD><A HREF='uda3.pl?module=system&action=actions&button=view&actionid=$actionid'>$actionid</A></TD></TR>\n";
print "</TABLE>\n";
print "<BR>\n";
&PrintProgressBar();
print "<BR>\n";
&PrintStatusDiv();
print "</CENTER>\n";
&RunAction($actionid,"Removing ESX3 HBA Drivers","system.pl","\&ApplyEsx3NoSan_DoIt($actionid);");
print "<script language='javascript' src='/js/progress.js'></script>\n";
print "<script language='javascript'>\n";
print "Update($actionid);\n";
print "</script>\n";
}
sub ApplyEsx3NoSan_DoIt
{
local($actionid)=shift;
require "general.pl";
require "config.pl";
require "action.pl";
local(%args)=&ReadActionArgs($actionid);
local($result)=&UpdateActionProgress($actionid,5,"Read Action Arguments");
if ($result) {
&UpdateActionProgress($actionid,-1,"Could not read arguments");
return 1;
}
local(%mountinfo)=&GetMountInfo($args{MOUNT});
local($isofile)=$SMBMOUNTDIR."/".$args{MOUNT}."/".$args{FILE1};
if ($mountinfo{TYPE} eq "CDROM")
{
$isofile=$mountinfo{SHARE};
}
local($workspace)=$isofile.".workdir.".$actionid;
local($result)=&CreateDir($workspace);
if ($result)
{
&UpdateActionProgress($actionid,-2,"Could not create workspace directory $workspace");
return 2;
}
&UpdateActionProgress($actionid,10,"Created workspace directory $workspace");
local($initrddir)=$workspace."/initrd";
local($result)=&CreateDir($initrddir);
if ($result)
{
&UpdateActionProgress($actionid,-2,"Could not create initrd directory $initrddir");
return 2;
}
&UpdateActionProgress($actionid,15,"Created initrd directory $initrddir");
my($tempdir)="$TMPDIR/action.$actionid/mountiso";
local($result)=&CreateDir($tempdir);
if ($result)
{
&UpdateActionProgress($actionid,-2,"Could not create temporary directory $tempdir");
return 2;
}
&UpdateActionProgress($actionid,20,"Created/checked temporary directory $tempdir");
local($result)=&MountIso($isofile,$tempdir);
if ($result)
{
&UpdateActionProgress($actionid,-2,"Could not mount iso file $isofile on $tempdir");
return 4;
}
&UpdateActionProgress($actionid,30,"Mounted iso file $isofile on $tempdir");
local($srcinitrd)="$tempdir/images/pexboot/initrd.img";
local($dstinitrd)="$workspace/initrd/initrd.img.gz";
local($result)=&ImportFile($srcinitrd,$dstinitrd);
if ($result)
{
&UpdateActionProgress($actionid,-2,"Could not copy initrd $srcinitrd to $dstinitrd");
return 4;
}
&UpdateActionProgress($actionid,35,"Imported Initrd to $dstinitrd");
local($command)="gunzip $dstinitrd";
local($result)=&RunCommand($command,"Unzipping the current initrd");
if ($result)
{
&UpdateActionProgress($actionid,-2,"Could not unzip $dstinitrd");
return 4;
}
&UpdateActionProgress($actionid,35,"Unzipped Initrd $dstinitrd");
local($initrdunzipped)="$workspace/initrd/initrd.img";
local($command)="cd $workspace/initrd && cpio -idvm --file $initrdunzipped";
local($result)=&RunCommand($command,"Unarchiving the unzipped initrd");
if ($result)
{
&UpdateActionProgress($actionid,-2,"Could not unarchive $initrdunzipped");
return 4;
}
&UpdateActionProgress($actionid,40,"Unarchived Initrd $initrdunzipped");
local($qladrivers)="$workspace/initrd/usr/lib/vmware/vkmod/qla*";
local($lpfdirvers)="$workspace/initrd/usr/lib/vmware/vkmod/lpf*";
local($qlaids)="$workspace/initrd/usr/share/hwdata/pciids/qla*";
local($lpfids)="$workspace/initrd/usr/share/hwdata/pciids/lpf*";
local($command)="rm -f $dstinitrd $initrdunzipped $qladrivers $lpfdrivers $qlaids $lpfids";