-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy pathlibvirt_helpers.php
More file actions
3075 lines (2764 loc) · 105 KB
/
libvirt_helpers.php
File metadata and controls
3075 lines (2764 loc) · 105 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
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
<?PHP
/* Copyright 2005-2025, Lime Technology
* Copyright 2012-2025, Bergware International.
* Copyright 2015-2021, Derek Macias, Eric Schultz, Jon Panozzo.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*/
function create_cloud_init_iso($strPath, $strUserData, $strNetworkConfig) {
$strPath = rtrim($strPath, '/');
if (!is_dir($strPath)) {
return false;
}
$strImgPath = $strPath . '/cloud-init.img';
$strMountPoint = $strPath . '/cloud-init-mount';
// Create blank 4MB image
exec("dd if=/dev/zero of=" . escapeshellarg($strImgPath) . " bs=1M count=4 2>&1", $output, $return_var);
if ($return_var !== 0) {
error_log("Cloud-Init image creation failed (dd): " . implode("\n", $output));
return false;
}
// Format as VFAT with label 'cidata' (try mkfs.vfat first, then mkdosfs)
$output = [];
exec("which mkfs.vfat mkdosfs 2>/dev/null | head -n1", $mkfsTool);
$mkfsCmd = !empty($mkfsTool[0]) ? $mkfsTool[0] : '/sbin/mkdosfs';
exec($mkfsCmd . " -n cidata " . escapeshellarg($strImgPath) . " 2>&1", $output, $return_var);
if ($return_var !== 0) {
error_log("Cloud-Init image formatting failed (vfat): " . implode("\n", $output));
return false;
}
// Create mount point
if (!is_dir($strMountPoint)) {
mkdir($strMountPoint, 0777, true);
}
// Mount image
exec("mount -o loop " . escapeshellarg($strImgPath) . " " . escapeshellarg($strMountPoint) . " 2>&1", $output, $return_var);
if ($return_var !== 0) {
error_log("Cloud-Init image mount failed: " . implode("\n", $output));
return false;
}
// Write files
file_put_contents($strMountPoint . '/user-data', $strUserData);
if (!empty($strNetworkConfig)) {
file_put_contents($strMountPoint . '/network-config', $strNetworkConfig);
}
file_put_contents($strMountPoint . '/meta-data', "instance-id: " . uniqid() . "\nlocal-hostname: localhost\n");
// Sync and Unmount
exec("sync");
exec("umount " . escapeshellarg($strMountPoint) . " 2>&1", $output, $return_var);
// Clean up mount point
rmdir($strMountPoint);
if ($return_var !== 0) {
error_log("Cloud-Init image unmount failed: " . implode("\n", $output));
return false;
}
return $strImgPath;
}
?>
<?
/**
* Array2XML: A class to convert array in PHP to XML
* It also takes into account attributes names unlike SimpleXML in PHP
* It returns the XML in form of DOMDocument class for further manipulation.
* It throws exception if the tag name or attribute name has illegal chars.
*
* Author : Lalit Patel
* Website: http://www.lalit.org/lab/convert-php-array-to-xml-with-attributes
* License: Apache License 2.0
* http://www.apache.org/licenses/LICENSE-2.0
* Version: 0.1 (10 July 2011)
* Version: 0.2 (16 August 2011)
* - replaced htmlentities() with htmlspecialchars() (Thanks to Liel Dulev)
* - fixed a edge case where root node has a false/null/0 value. (Thanks to Liel Dulev)
* Version: 0.3 (22 August 2011)
* - fixed tag sanitize regex which didn't allow tagnames with single character.
* Version: 0.4 (18 September 2011)
* - Added support for CDATA section using @cdata instead of @value.
* Version: 0.5 (07 December 2011)
* - Changed logic to check numeric array indices not starting from 0.
* Version: 0.6 (04 March 2012)
* - Code now doesn't @cdata to be placed in an empty array
* Version: 0.7 (24 March 2012)
* - Reverted to version 0.5
* Version: 0.8 (02 May 2012)
* - Removed htmlspecialchars() before adding to text node or attributes.
*
* Usage:
* $xml = Array2XML::createXML('root_node_name', $php_array);
* echo $xml->saveXML();
**/
class Array2XML {
private static $xml = null;
private static $encoding = 'UTF-8';
/**
* Initialize the root XML node [optional]
* @param $version
* @param $encoding
* @param $format_output
*/
public static function init($version = '1.0', $encoding = 'UTF-8', $format_output = true) {
self::$xml = new DomDocument($version, $encoding);
self::$xml->formatOutput = $format_output;
self::$encoding = $encoding;
}
/**
* Convert an Array to XML
* @param string $node_name - name of the root node to be converted
* @param array $arr - aray to be converterd
* @return DomDocument
*/
public static function &createXML($node_name, $arr=array()) {
$xml = self::getXMLRoot();
$xml->appendChild(self::convert($node_name, $arr));
self::$xml = null; // clear the xml node in the class for 2nd time use.
return $xml;
}
/**
* Convert an Array to XML
* @param string $node_name - name of the root node to be converted
* @param array $arr - aray to be converterd
* @return DOMNode
*/
private static function &convert($node_name, $arr=array()) {
//print_arr($node_name);
$xml = self::getXMLRoot();
$node = $xml->createElement($node_name);
if(is_array($arr)){
// get the attributes first.;
if(isset($arr['@attributes'])) {
foreach($arr['@attributes'] as $key => $value) {
if(!self::isValidTagName($key)) {
throw new Exception('[Array2XML] Illegal character in attribute name. attribute: '.$key.' in node: '.$node_name);
}
$node->setAttribute($key, self::bool2str($value));
}
unset($arr['@attributes']); //remove the key from the array once done.
}
// check if it has a value stored in @value, if yes store the value and return
// else check if its directly stored as string
if(isset($arr['@value'])) {
$node->appendChild($xml->createTextNode(self::bool2str($arr['@value'])));
unset($arr['@value']); //remove the key from the array once done.
//return from recursion, as a note with value cannot have child nodes.
return $node;
} else if(isset($arr['@cdata'])) {
$node->appendChild($xml->createCDATASection(self::bool2str($arr['@cdata'])));
unset($arr['@cdata']); //remove the key from the array once done.
//return from recursion, as a note with cdata cannot have child nodes.
return $node;
}
}
//create subnodes using recursion
if(is_array($arr)){
// recurse to get the node for that key
foreach($arr as $key=>$value){
if(!self::isValidTagName($key)) {
throw new Exception('[Array2XML] Illegal character in tag name. tag: '.$key.' in node: '.$node_name);
}
if(is_array($value) && is_numeric(key($value))) {
// MORE THAN ONE NODE OF ITS KIND;
// if the new array is numeric index, means it is array of nodes of the same kind
// it should follow the parent key name
foreach($value as $k=>$v){
$node->appendChild(self::convert($key, $v));
}
} else {
// ONLY ONE NODE OF ITS KIND
$node->appendChild(self::convert($key, $value));
}
unset($arr[$key]); //remove the key from the array once done.
}
}
// after we are done with all the keys in the array (if it is one)
// we check if it has any text value, if yes, append it.
if(!is_array($arr)) {
$node->appendChild($xml->createTextNode(self::bool2str($arr ?? "")));
}
return $node;
}
/*
* Get the root XML node, if there isn't one, create it.
*/
private static function getXMLRoot(){
if(empty(self::$xml)) {
self::init();
}
return self::$xml;
}
/*
* Get string representation of boolean value
*/
private static function bool2str($v){
//convert boolean to text value.
$v = $v === true ? 'true' : $v;
$v = $v === false ? 'false' : $v;
return $v;
}
/*
* Check if the tag name or attribute name contains illegal characters
* Ref: http://www.w3.org/TR/xml/#sec-common-syn
*/
private static function isValidTagName($tag){
$pattern = '/^[a-z_]+[a-z0-9\:\-\.\_]*[^:]*$/i';
return preg_match($pattern, $tag, $matches) && $matches[0] == $tag;
}
}
$docroot ??= ($_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp');
require_once "$docroot/plugins/dynamix.vm.manager/include/libvirt.php";
require_once "$docroot/webGui/include/Custom.php";
require_once "$docroot/webGui/include/SriovHelpers.php";
// Load emhttp variables if needed.
if (!isset($var)){
$var = @parse_ini_file("$docroot/state/var.ini");
$disks = @parse_ini_file("$docroot/state/disks.ini", true);
extract(parse_plugin_cfg("dynamix",true));
}
$ethX = 'eth0';
if (!isset($$ethX) && is_file("$docroot/state/network.ini")) {
extract(parse_ini_file("$docroot/state/network.ini",true));
}
// Check if program is running and
$libvirt_running = trim(shell_exec( "[ -f /proc/`cat /var/run/libvirt/libvirtd.pid 2> /dev/null`/exe ] && echo 'yes' || echo 'no' 2> /dev/null" ));
$arrAllTemplates = [
' Windows ' => '', /* Windows Header */
'Windows 11' => [
'form' => 'Custom.form.php',
'icon' => 'windows11.png',
'os' => 'windowstpm',
'overrides' => [
'domain' => [
'ovmf' => 2,
'mem' => 4096 * 1024,
'maxmem' => 4096 * 1024,
'vcpus' => 2,
'vcpu' => [0,1],
],
'media' => [
'cdrombus' => 'sata',
'driversbus' => 'sata' ,
],
'disk' => [
[
'size' => '64G'
]
],
'nic'=>[
[
'model' => 'e1000'
]
]
]
],
'Windows 10' => [
'form' => 'Custom.form.php',
'icon' => 'windows.png',
'os' => 'windows10',
'overrides' => [
'domain' => [
'mem' => 2048 * 1024,
'maxmem' => 2048 * 1024
],
'disk' => [
[
'size' => '30G'
]
]
]
],
'Windows 8.x' => [
'form' => 'Custom.form.php',
'icon' => 'windows.png',
'os' => 'windows',
'overrides' => [
'domain' => [
'name' => 'Windows 8.1',
'mem' => 2048 * 1024,
'maxmem' => 2048 * 1024
],
'disk' => [
[
'size' => '30G'
]
]
]
],
'Windows 7' => [
'form' => 'Custom.form.php',
'icon' => 'windows7.png',
'os' => 'windows7',
'overrides' => [
'domain' => [
'mem' => 2048 * 1024,
'maxmem' => 2048 * 1024,
'ovmf' => 0,
'usbmode' => 'usb2'
],
'disk' => [
[
'size' => '30G'
]
]
]
],
'Windows XP' => [
'form' => 'Custom.form.php',
'icon' => 'windowsxp.png',
'os' => 'windowsxp',
'overrides' => [
'domain' => [
'ovmf' => 0,
'usbmode' => 'usb2'
],
'disk' => [
[
'size' => '15G'
]
]
]
],
'Windows Server 2016' => [
'form' => 'Custom.form.php',
'icon' => 'windows.png',
'os' => 'windows2016',
'overrides' => [
'domain' => [
'mem' => 2048 * 1024,
'maxmem' => 2048 * 1024
],
'disk' => [
[
'size' => '30G'
]
]
]
],
'Windows Server 2012' => [
'form' => 'Custom.form.php',
'icon' => 'windows.png',
'os' => 'windows2012',
'overrides' => [
'domain' => [
'mem' => 2048 * 1024,
'maxmem' => 2048 * 1024
],
'disk' => [
[
'size' => '30G'
]
]
]
],
'Windows Server 2008' => [
'form' => 'Custom.form.php',
'icon' => 'windows7.png',
'os' => 'windows2008',
'overrides' => [
'domain' => [
'usbmode' => 'usb2'
],
'disk' => [
[
'size' => '30G'
]
]
]
],
'Windows Server 2003' => [
'form' => 'Custom.form.php',
'icon' => 'windowsxp.png',
'os' => 'windows2003',
'overrides' => [
'domain' => [
'usbmode' => 'usb2'
],
'disk' => [
[
'size' => '15G'
]
]
]
],
' Linux ' => '', /* Linux Header */
'Linux' => [
'form' => 'Custom.form.php',
'icon' => 'linux.png',
'os' => 'linux'
],
'Arch' => [
'form' => 'Custom.form.php',
'icon' => 'arch.png',
'os' => 'arch'
],
'CentOS' => [
'form' => 'Custom.form.php',
'icon' => 'centos.png',
'os' => 'centos'
],
'ChromeOS' => [
'form' => 'Custom.form.php',
'icon' => 'chromeos.png',
'os' => 'chromeos'
],
'CoreOS' => [
'form' => 'Custom.form.php',
'icon' => 'coreos.png',
'os' => 'coreos'
],
'Debian' => [
'form' => 'Custom.form.php',
'icon' => 'debian.png',
'os' => 'debian'
],
'Fedora' => [
'form' => 'Custom.form.php',
'icon' => 'fedora.png',
'os' => 'fedora'
],
'FreeBSD' => [
'form' => 'Custom.form.php',
'icon' => 'freebsd.png',
'os' => 'freebsd'
],
'OpenSUSE' => [
'form' => 'Custom.form.php',
'icon' => 'opensuse.png',
'os' => 'opensuse'
],
'RedHat' => [
'form' => 'Custom.form.php',
'icon' => 'redhat.png',
'os' => 'redhat'
],
'Scientific' => [
'form' => 'Custom.form.php',
'icon' => 'scientific.png',
'os' => 'scientific'
],
'Slackware' => [
'form' => 'Custom.form.php',
'icon' => 'slackware.png',
'os' => 'slackware'
],
'SteamOS' => [
'form' => 'Custom.form.php',
'icon' => 'steamos.png',
'os' => 'steamos'
],
'Ubuntu' => [
'form' => 'Custom.form.php',
'icon' => 'ubuntu.png',
'os' => 'ubuntu'
],
'VyOS' => [
'form' => 'Custom.form.php',
'icon' => 'vyos.png',
'os' => 'vyos'
],
' ' => '', /* Custom / XML Expert Header */
'Custom' => [
'form' => 'XML_Expert.form.php',
'icon' => 'default.png'
]
];
$fedora = '/var/tmp/fedora-virtio-isos';
// set variable to obtained information
if (file_exists($fedora)) $virtio_isos = unserialize(file_get_contents($fedora)); else {
// else initialize variable
$virtio_isos = [
'virtio-win-0.1.208-1' => [
'name' => 'virtio-win-0.1.208-1.iso',
'url' => 'https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/archive-virtio/virtio-win-0.1.208-1/virtio-win-0.1.208.iso',
'size' => 556431360,
'md5' => '3bbc69bdcf1d46f4ee0ddaf35c2656f3'
],
'virtio-win-0.1.190-1' => [
'name' => 'virtio-win-0.1.190-1.iso',
'url' => 'https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/archive-virtio/virtio-win-0.1.190-1/virtio-win-0.1.190.iso',
'size' => 501745664,
'md5' => '6e30288fa45ba99a1434740204b8e8e8'
],
'virtio-win-0.1.189-1' => [
'name' => 'virtio-win-0.1.189-1.iso',
'url' => 'https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/archive-virtio/virtio-win-0.1.189-1/virtio-win-0.1.189.iso',
'size' => 500496384,
'md5' => '86c924cf591c275de81f0e64eefe69a3'
],
'virtio-win-0.1.173-2' => [
'name' => 'virtio-win-0.1.173-2.iso',
'url' => 'https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/archive-virtio/virtio-win-0.1.173-2/virtio-win-0.1.173.iso',
'size' => 394303488,
'md5' => '88fcd398b7d54301b559d1762240aa67'
],
'virtio-win-0.1.160-1' => [
'name' => 'virtio-win-0.1.160-1.iso',
'url' => 'https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/archive-virtio/virtio-win-0.1.160-1/virtio-win-0.1.160.iso',
'size' => 322842624,
'md5' => 'eec0b91dd72fb2b42774d5d0b39175c7'
],
'virtio-win-0.1.141-1' => [
'name' => 'virtio-win-0.1.141-1.iso',
'url' => 'https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/archive-virtio/virtio-win-0.1.141-1/virtio-win-0.1.141.iso',
'size' => 316628992,
'md5' => '6327d722bdea72bcb1849ce99604bbe0'
],
'virtio-win-0.1.126-2' => [
'name' => 'virtio-win-0.1.126-2.iso',
'url' => 'https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/archive-virtio/virtio-win-0.1.126-2/virtio-win-0.1.126.iso',
'size' => 155856896,
'md5' => 'b8379138ae5f8d0adecb839f9debf875'
],
'virtio-win-0.1.126-1' => [
'name' => 'virtio-win-0.1.126-1.iso',
'url' => 'https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/archive-virtio/virtio-win-0.1.126-1/virtio-win-0.1.126.iso',
'size' => 155856896,
'md5' => '85637076191887d4cd425bf8d59f8dd9'
],
'virtio-win-0.1.118-2' => [
'name' => 'virtio-win-0.1.118-2.iso',
'url' => 'https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/archive-virtio/virtio-win-0.1.118-2/virtio-win-0.1.118.iso',
'size' => 56967168,
'md5' => '9cb51bde60decfafdf8119ce01b7c1cf'
],
'virtio-win-0.1.118-1' => [
'name' => 'virtio-win-0.1.118-1.iso',
'url' => 'https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/archive-virtio/virtio-win-0.1.118-1/virtio-win-0.1.118.iso',
'size' => 56967168,
'md5' => 'cc5771f2f0ea5097946d3d447f21cce8'
],
'virtio-win-0.1.117-1' => [
'name' => 'virtio-win-0.1.117-1.iso',
'url' => 'https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/archive-virtio/virtio-win-0.1.117-1/virtio-win-0.1.117.iso',
'size' => 56999936,
'md5' => '2a79d6036ea4292f81c3370dd0a8b6d6'
],
'virtio-win-0.1.113-1' => [
'name' => 'virtio-win-0.1.113-1.iso',
'url' => 'https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/archive-virtio/virtio-win-0.1.113-1/virtio-win-0.1.113.iso',
'size' => 56936448,
'md5' => '11ed773055e19eca75ed186ff12d354c'
],
'virtio-win-0.1.112-1' => [
'name' => 'virtio-win-0.1.112-1.iso',
'url' => 'https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/archive-virtio/virtio-win-0.1.112-1/virtio-win-0.1.112.iso',
'size' => 56926208,
'md5' => '7db0211d7aec3e08fadd21c8eaaf35db'
],
'virtio-win-0.1.110-2' => [
'name' => 'virtio-win-0.1.110-2.iso',
'url' => 'https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/archive-virtio/virtio-win-0.1.110-2/virtio-win-0.1.110.iso',
'size' => 56586240,
'md5' => '93357a5105f1255591f1c389748288a9'
],
'virtio-win-0.1.110-1' => [
'name' => 'virtio-win-0.1.110-1.iso',
'url' => 'https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/archive-virtio/virtio-win-0.1.110-1/virtio-win-0.1.110.iso',
'size' => 56586240,
'md5' => '239e0eb442bb63c177deb4af39397731'
],
'virtio-win-0.1.109-2' => [
'name' => 'virtio-win-0.1.109-2.iso',
'url' => 'https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/archive-virtio/virtio-win-0.1.109-2/virtio-win-0.1.109.iso',
'size' => 56606720,
'md5' => '2a9f78f648f03fe72decdadb38837db3'
],
'virtio-win-0.1.109-1' => [
'name' => 'virtio-win-0.1.109-1.iso',
'url' => 'https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/archive-virtio/virtio-win-0.1.109-1/virtio-win-0.1.109.iso',
'size' => 56606720,
'md5' => '1b0da008d0ec79a6223d21be2fcce2ee'
],
'virtio-win-0.1.108-1' => [
'name' => 'virtio-win-0.1.108-1.iso',
'url' => 'https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/archive-virtio/virtio-win-0.1.108-1/virtio-win-0.1.108.iso',
'size' => 56598528,
'md5' => '46deb991f8c382f2d9af0fb786792990'
],
'virtio-win-0.1.106-1' => [
'name' => 'virtio-win-0.1.106-1.iso',
'url' => 'https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/archive-virtio/virtio-win-0.1.106-1/virtio-win-0.1.106.iso',
'size' => 56586240,
'md5' => '66228ea20fae1a28d7a1583b9a5a1b8b'
],
'virtio-win-0.1.105-1' => [
'name' => 'virtio-win-0.1.105-1.iso',
'url' => 'https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/archive-virtio/virtio-win-0.1.105-1/virtio-win-0.1.105.iso',
'size' => 56584192,
'md5' => 'c3194fa62a4a1ccbecfe784a52feda66'
],
'virtio-win-0.1.104-1' => [
'name' => 'virtio-win-0.1.104-1.iso',
'url' => 'https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/archive-virtio/virtio-win-0.1.104-1/virtio-win-0.1.104.iso',
'size' => 56584192,
'md5' => '9aa28b6f5b18770d796194aaaeeea31a'
],
'virtio-win-0.1.103-2' => [
'name' => 'virtio-win-0.1.103-2.iso',
'url' => 'https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/archive-virtio/virtio-win-0.1.103-2/virtio-win-0.1.103.iso',
'size' => 56340480,
'md5' => '07c4356880f0b385d6908392e48d6e75'
],
'virtio-win-0.1.103' => [
'name' => 'virtio-win-0.1.103.iso',
'url' => 'https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/archive-virtio/virtio-win-0.1.103/virtio-win-0.1.103.iso',
'size' => 49903616,
'md5' => 'd31069b620820b75730d2def7690c271'
],
'virtio-win-0.1.102' => [
'name' => 'virtio-win-0.1.102.iso',
'url' => 'https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/archive-virtio/virtio-win-0.1.102/virtio-win-0.1.102.iso',
'size' => 160755712,
'md5' => '712561dd78ef532c54f8fee927c1ce2e'
],
'virtio-win-0.1.101' => [
'name' => 'virtio-win-0.1.101.iso',
'url' => 'https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/archive-virtio/virtio-win-0.1.101/virtio-win-0.1.101.iso',
'size' => 160755712,
'md5' => 'cf73576efc03685907c1fa49180ea388'
],
'virtio-win-0.1.100' => [
'name' => 'virtio-win-0.1.100.iso',
'url' => 'https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/archive-virtio/virtio-win-0.1.100/virtio-win-0.1.100.iso',
'size' => 160704512,
'md5' => '8b21136f988bef7981ee580e9101b6b4'
],
'virtio-win-0.1.96' => [
'name' => 'virtio-win-0.1.96.iso',
'url' => 'https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/archive-virtio/virtio-win-0.1.96/virtio-win-0.1.96.iso',
'size' => 160659456,
'md5' => 'd406bf6748b9ba4c872c5b5301ba7272'
]
];}
$arrDefaultClocks = [
"windows" => [
"hpet" => [
"present" => "no",
"tickpolicy" => "delay"
],
"hypervclock" => [
"present" => "yes",
"tickpolicy" => "delay"
],
"pit" => [
"present" => "yes",
"tickpolicy" => "delay"
],
"rtc" => [
"present" => "yes",
"tickpolicy" => "catchup"
]
],
"hyperv" => [
"hpet" => [
"present" => "no",
"tickpolicy" => "delay"
],
"hypervclock" => [
"present" => "yes",
"tickpolicy" => "delay"
],
"pit" => [
"present" => "no",
"tickpolicy" => "delay"
],
"rtc" => [
"present" => "no",
"tickpolicy" => "catchup"
]
] ,
"other" => [
"hpet" => [
"present" => "no",
"tickpolicy" => "delay"
],
"hypervclock" => [
"present" => "no",
"tickpolicy" => "delay"
],
"pit" => [
"present" => "yes",
"tickpolicy" => "delay"
],
"rtc" => [
"present" => "yes",
"tickpolicy" => "catchup"
]
]
];
#<model type='qxl' ram='65536' vram='65536' vgamem='16384' heads='1' primary='yes'/>
$arrDisplayOptions = [
"H1.16M" => [
"text" => "1 Display 16Mb Memory",
"qxlxml" => "ram='65536' vram='16384' vgamem='16384' heads='1' primary='yes'",
],
"H1.32M" => [
"text" => "1 Display 32Mb Memory",
"qxlxml" => "ram='65536' vram='32768' vgamem='32768' heads='1' primary='yes'",
],
"H1.64M" => [
"text" => "1 Display 64Mb Memory",
"qxlxml" => "ram='65536' vram='65536' vram64='65535' vgamem='65536' heads='1' primary='yes'",
],
"H1.128M" => [
"text" => "1 Display 128Mb Memory",
"qxlxml"=> "ram='65536' vram='131072' vram64='131072' vgamem='65536' heads='1' primary='yes'",
],
"H1.256M" => [
"text" => "1 Display 256Mb Memory",
"qxlxml" => "ram='65536' vram='262144' vram64='262144' vgamem='65536' heads='1' primary='yes'",
],
"H2.64M" => [
"text" => "2 Displays 64Mb Memory",
"qxlxml" => "ram='65536' vram='65536' vram64='65535' vgamem='65536' heads='2' primary='yes'",
],
"H2.128M" => [
"text" => "2 Displays 128Mb Memory",
"qxlxml" => "ram='65536' vram='131072'vram64='131072' vgamem='65536' heads='2' primary='yes'",
],
"H2.256M" => [
"text" => "2 Displays 256Mb Memory",
"qxlxml" => "ram='65536' vram='262144'vram64='262144' vgamem='65536' heads='2' primary='yes'",
],
"H4.64M" => [
"text" => "4 Displays 64Mb Memory",
"qxlxml" => "ram='65536' vram='65536' vram64='65535' vgamem='65536' heads='4' primary='yes'",
],
"H4.128M" => [
"text" => "4 Displays 128Mb Memory",
"qxlxml" => "ram='65536' vram='131072'vram64='131072' vgamem='65536' heads='4' primary='yes'",
],
"H4.256M" => [
"text" => "4 Displays 256Mb Memory",
"qxlxml"=> "ram='65536' vram='262144' vram64='262144' vgamem='65536' heads='4' primary='yes'",
],
];
// Read configuration file (guaranteed to exist)
$domain_cfgfile = "/boot/config/domain.cfg";
$domain_cfg = parse_ini_file($domain_cfgfile);
if ( ($domain_cfg['DEBUG'] ?? false) != "yes") {
error_reporting(0);
}
if (empty($domain_cfg['VMSTORAGEMODE'])) {
$domain_cfg['VMSTORAGEMODE'] = "auto";
}
if (!empty($domain_cfg['DOMAINDIR'])) {
$domain_cfg['DOMAINDIR'] = rtrim($domain_cfg['DOMAINDIR'], '/').'/';
}
if (!empty($domain_cfg['MEDIADIR'])) {
$domain_cfg['MEDIADIR'] = rtrim($domain_cfg['MEDIADIR'], '/').'/';
}
if (empty($domain_cfg['TIMEOUT'])) {
$domain_cfg['TIMEOUT'] = 60;
}
$domain_bridge = (!($domain_cfg['BRNAME'])) ? 'virbr0' : $domain_cfg['BRNAME'];
$msg = (empty($domain_bridge)) ? "Error: Setup Bridge in Settings/Network Settings" : false;
$libvirt_service = isset($domain_cfg['SERVICE']) ? $domain_cfg['SERVICE'] : "disable";
if ($libvirt_running == "yes"){
$lv = new Libvirt('qemu:///system', null, null, false);
$arrHostInfo = $lv->host_get_node_info();
$maxcpu = (int)$arrHostInfo['cpus'];
$maxmem = number_format(($arrHostInfo['memory'] / 1048576), 1, '.', '');
}
function mk_dropdown_options($arrOptions, $strSelected) {
foreach ($arrOptions as $key => $label) {
echo mk_option($strSelected, $key, $label);
}
}
function appendOrdinalSuffix($number) {
$ends = ['th','st','nd','rd','th','th','th','th','th','th'];
if (($number % 100) >= 11 && ($number % 100) <= 13) {
$abbreviation = $number.'th';
} else {
$abbreviation = $number.$ends[$number % 10];
}
return $abbreviation;
}
function sanitizeVendor($strVendor) {
// Specialized vendor name cleanup
// e.g.: Advanced Micro Devices, Inc. [AMD/ATI] --> Advanced Micro Devices, Inc.
if (preg_match('/(?P<gpuvendor>.+) \[.+\]/', $strVendor, $arrGPUMatch)) {
$strVendor = $arrGPUMatch['gpuvendor'];
}
$strVendor = str_replace('Advanced Micro Devices', 'AMD', $strVendor);
$strVendor = str_replace('Samsung Electronics Co.', 'Samsung', $strVendor);
$strVendor = str_replace([' Corporation', ' Semiconductor ', ' Technology Group Ltd.', ' System, Inc.', ' Systems, Inc.'], '', $strVendor);
$strVendor = str_replace([' Co., Ltd.', ', Ltd.', ', Ltd', ', Inc.'], '', $strVendor);
return $strVendor;
}
function sanitizeProduct($strProduct) {
$strProduct = str_replace(' PCI Express', ' PCIe', $strProduct);
$strProduct = str_replace(' High Definition ', ' HD ', $strProduct);
return $strProduct;
}
function getDiskImageInfo($strImgPath) {
$arrJSON = json_decode(shell_exec("qemu-img info --output json ".escapeshellarg($strImgPath)." 2>/dev/null"), true);
return $arrJSON;
}
$cacheValidPCIDevices = null;
function getValidPCIDevices() {
global $cacheValidPCIDevices;
global $disks;
if (!is_null($cacheValidPCIDevices)) {
return $cacheValidPCIDevices;
}
$strOSNetworkDevice = trim(exec("udevadm info -q path -p /sys/class/net/eth0 2>/dev/null | grep -Po '0000:\K\w{2}:\w{2}\.\w{1}'"));
$arrOSDiskControllers = [];
foreach ($disks as $strDisk => $arrDisk) {
if (!empty($arrDisk['device']) && file_exists('/dev/'.$arrDisk['device'])) {
$strOSDiskController = trim(exec("udevadm info -q path -n /dev/".$arrDisk['device']." | grep -Po '0000:\K\w{2}:\w{2}\.\w{1}'"));
if (!empty($strOSDiskController)) {
$arrOSDiskControllers[] = $strOSDiskController;
}
}
}
$arrOSDiskControllers = array_values(array_unique($arrOSDiskControllers));
$arrBlacklistIDs = $arrOSDiskControllers;
if (!empty($strOSNetworkDevice)) {
$arrBlacklistIDs[] = $strOSNetworkDevice;
}
$arrBlacklistClassIDregex = '/^(05|06|08|0a|0b|0c05)/';
// Got Class IDs at the bottom of /usr/share/hwdata/pci.ids
$arrWhitelistGPUClassIDregex = '/^(0001|03)/';
$arrWhitelistAudioClassIDregex = '/^(0403)/';
# "System peripheral [0880]" "Global unichip corp. [1ac1]" "Coral Edge Tpu [089a]" -pff "Global unichip corp. [1ac1]" "Coral Edge Tpu [089a]"
# typeid productid
# file is csv typeid:productid
#
if (is_file("/boot/config/VMPCIOverride.cfg")) {
$arrWhiteListOverride = str_getcsv(file_get_contents("/boot/config/VMPCIOverride.cfg"));
}
$arrWhiteListOverride[] = "0880:089a";
$arrValidPCIDevices = [];
exec("lspci -m -nn 2>/dev/null", $arrAllPCIDevices);
foreach ($arrAllPCIDevices as $strPCIDevice) {
// Example: 00:1f.0 "ISA bridge [0601]" "Intel Corporation [8086]" "Z77 Express Chipset LPC Controller [1e44]" -r04 "Micro-Star International Co., Ltd. [MSI] [1462]" "Device [7759]"
if (preg_match('/^(?P<id>\S+) \"(?P<type>[^"]+) \[(?P<typeid>[a-f0-9]{4})\]\" \"(?P<vendorname>[^"]+) \[(?P<vendorid>[a-f0-9]{4})\]\" \"(?P<productname>[^"]+) \[(?P<productid>[a-f0-9]{4})\]\"/', $strPCIDevice, $arrMatch)) {
$boolBlacklisted = false;
if (in_array($arrMatch['id'], $arrBlacklistIDs) || preg_match($arrBlacklistClassIDregex, $arrMatch['typeid'])) {
// Device blacklisted, skip device
$boolBlacklisted = true;
}
$overrideCheck = "{$arrMatch['typeid']}:{$arrMatch['productid']}";
if (in_array($overrideCheck,$arrWhiteListOverride) ) $boolBlacklisted = false;
$strClass = 'other';
if (preg_match($arrWhitelistGPUClassIDregex, $arrMatch['typeid'])) {
$strClass = 'vga';
// Specialized product name cleanup for GPU
// GF116 [GeForce GTX 550 Ti] --> GeForce GTX 550 Ti
if (preg_match('/.+\[(?P<gpuname>.+)\]/', $arrMatch['productname'], $arrGPUMatch)) {
$arrMatch['productname'] = $arrGPUMatch['gpuname'];
}
} elseif (preg_match($arrWhitelistAudioClassIDregex, $arrMatch['typeid'])) {
$strClass = 'audio';
}
if (!file_exists('/sys/bus/pci/devices/0000:'.$arrMatch['id'].'/iommu_group/')) {
// No IOMMU support for device, skip device
continue;
}
// Attempt to get the current kernel-bound driver for this pci device
$strDriver = '';
if (is_link('/sys/bus/pci/devices/0000:'.$arrMatch['id'].'/driver')) {
$strLink = @readlink('/sys/bus/pci/devices/0000:'.$arrMatch['id'].'/driver');
if (!empty($strLink)) {
$strDriver = basename($strLink);
}
}
// Attempt to get the boot_vga driver for this pci device
$strBootVGA = '';
if (is_file('/sys/bus/pci/devices/0000:'.$arrMatch['id'].'/boot_vga') && $strClass == 'vga') {
$strFileVal = file_get_contents('/sys/bus/pci/devices/0000:'.$arrMatch['id'].'/boot_vga');
if (!empty($strFileVal)) {
$strBootVGA = trim($strFileVal);
}
}
// Clean up the vendor and product name
$arrMatch['vendorname'] = sanitizeVendor($arrMatch['vendorname']);
$arrMatch['productname'] = sanitizeProduct($arrMatch['productname']);
$arrValidPCIDevices[$arrMatch['id']] = [
'id' => $arrMatch['id'],
'type' => $arrMatch['type'],
'typeid' => $arrMatch['typeid'],
'vendorid' => $arrMatch['vendorid'],
'vendorname' => $arrMatch['vendorname'],
'productid' => $arrMatch['productid'],
'productname' => $arrMatch['productname'],
'class' => $strClass,
'driver' => $strDriver,
'bootvga' => $strBootVGA,
'name' => $arrMatch['vendorname'].' '.$arrMatch['productname'],
'blacklisted' => $boolBlacklisted
];
}
}
$cacheValidPCIDevices = $arrValidPCIDevices;
return $arrValidPCIDevices;
}
function getValidGPUDevices() {
$arrValidPCIDevices = getValidPCIDevices();
$arrValidGPUDevices = array_filter($arrValidPCIDevices, function($arrDev) {
return ($arrDev['class'] == 'vga' && !$arrDev['blacklisted']);
});
// Remove SR-IOV physical functions that have VFs defined
$sriov = json_decode(getSriovInfoJson(true), true);
foreach($arrValidGPUDevices as $key => $device) {
$pcid = $device['id'];
// Prepend domain if not present (e.g., 04:00.0 -> 0000:04:00.0)
if (!preg_match('/^[0-9a-fA-F]{4}:/', $pcid)) {
$pcid = "0000:" . $pcid;
}
if (isset($sriov[$pcid]) && !empty($sriov[$pcid]['vfs'])) {
unset($arrValidGPUDevices[$key]);
}
}
return $arrValidGPUDevices;
}
function getValidAudioDevices() {
$arrValidPCIDevices = getValidPCIDevices();
$arrValidAudioDevices = array_filter($arrValidPCIDevices, function($arrDev) {