Menu

[r2158]: / trunk / etc / inc / config.inc  Maximize  Restore  History

Download this file

994 lines (818 with data), 30.6 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
<?php
/*
config.inc
part of FreeNAS (http://www.freenas.org)
Copyright (C) 2005-2007 Olivier Cochard-Labbe <olivier@freenas.org>.
All rights reserved.
Based on m0n0wall (http://m0n0.ch/wall)
Copyright (C) 2003-2006 Manuel Kasper <mk@neon1.net>.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
require_once("globals.inc");
require_once("util.inc");
require_once("xmlparse.inc");
require_once("system.inc");
/* Get product information */
$productname = get_product_name();
/* read platform */
if (file_exists("{$g['etc_path']}/platform")) {
$g['fullplatform'] = strtolower(chop(file_get_contents("{$g['etc_path']}/platform")));
$data = explode("-", $g['fullplatform']);
$g['arch'] = $data[0];
$g['platform'] = $data[1];
} else {
$g['arch'] = "unknown";
$g['platform'] = "unknown";
$g['fullplatform'] = "unknown";
}
if (is_booting()) {
// Find the device where config.xml resides and write out an fstab.
unset($cfgdevice);
// Check if there's already an fstab ('full' release booting?).
if (!file_exists("{$g['etc_path']}/fstab")) {
// Display platform type.
echo "Booting platform: {$g['platform']}\n";
echo "Looking for configuration file:";
// Get list of kernel known disks.
$disks = explode(" ", trim(preg_replace("/kern.disks: /", "", exec("/sbin/sysctl kern.disks"))));
if (stristr($g['platform'], "livecd")) {
// Config is on floppy disk/USB stick for LiveCD version per default.
$cfgdevice = $cfgpartition = "fd0";
$cfgfstype = "msdos";
// Display progress...
echo " fd0";
// Check if there is any USB device that can be used.
foreach ($disks as $disk) {
$found = false;
// Skip non USB (SCSI) device. The filesystem type must be MSDOS.
if (FALSE === ereg("da[0-9]*", $disk))
continue;
// Display progress...
echo " {$disk}";
// Try to mount device using file system MSDOS (FAT16/32).
if (0 == mwexec("/sbin/mount -r -t msdos /dev/{$disk}s1 {$g['cf_path']}")) {
$cfgdevice = $disk;
$cfgpartition = "{$cfgdevice}s1";
$found = true;
} else if (0 == mwexec("/sbin/mount -r -t msdos /dev/{$disk} {$g['cf_path']}")) {
$cfgdevice = $disk;
$cfgpartition = $cfgdevice;
$found = true;
}
// Unmount device if necessary and exit foreach loop.
if (true == $found) {
mwexec("/sbin/umount -f {$g['cf_path']}");
break;
}
}
// Display device information that is used to store the configuration.
echo "\n";
echo "Using device=/dev/{$cfgpartition} fstype={$cfgfstype} to store configuration.\n";
} else {
// Probe kernel known disks until we find one with config.xml.
foreach ($disks as $disk) {
// Skip mfs mounted filesystems.
if (TRUE === ereg("md[0-9]*", $disk))
continue;
// Display progress...
echo " {$disk}";
// Try to mount device using file system UFS.
if (0 == mwexec("/sbin/mount -r /dev/{$disk}s1 {$g['cf_path']}")) { // Search on slice 1.
if (file_exists("{$g['cf_conf_path']}/config.xml")) {
$cfgdevice = $disk;
$cfgpartition = "{$cfgdevice}s1";
$cfgfstype = "ufs";
}
// Umount device.
mwexec("/sbin/umount -f {$g['cf_path']}");
} else if (0 == mwexec("/sbin/mount -r /dev/{$disk}a {$g['cf_path']}")) { // Search on partition 'a'.
if (file_exists("{$g['cf_conf_path']}/config.xml")) {
$cfgdevice = $disk;
$cfgpartition = "{$cfgdevice}a";
$cfgfstype = "ufs";
}
// Umount device.
mwexec("/sbin/umount -f {$g['cf_path']}");
}
// Device found, exit.
if ($cfgdevice) {
break;
}
}
// Display device information where configuration is found.
echo "\n";
if ($cfgdevice) {
echo "Found configuration on device=/dev/{$cfgpartition} fstype={$cfgfstype}.\n";
}
}
if (!$cfgdevice) {
// No device found, print an error and die.
echo <<<EOD
*******************************************************************************
FATAL ERROR!
The device that contains the configuration file (config.xml) could not be
found. {$productname} cannot continue booting.
*******************************************************************************
EOD;
mwexec("/sbin/halt");
exit;
}
// Write device name to a file (used by rc.firmware for example).
$fd = fopen("{$g['varetc_path']}/cfdevice", "w");
if ($fd) {
fwrite($fd, "{$cfgpartition}\n");
fclose($fd);
}
// Write out an fstab.
$fd = fopen("{$g['etc_path']}/fstab", "w");
if ($fd) {
$fstab = "/dev/{$cfgpartition} {$g['cf_path']} {$cfgfstype} ro 1 1\n";
fwrite($fd, $fstab);
fclose($fd);
}
}
// Mount all filesystems.
mwexec("/sbin/mount -a");
}
/* parse configuration */
if (!$noparseconfig) {
config_lock();
/* see if there's a newer cache file */
if (file_exists("{$g['tmp_path']}/config.cache") &&
(filemtime("{$g['tmp_path']}/config.cache") >=
filemtime("{$g['conf_path']}/config.xml"))) {
/* read cache */
$config = unserialize(file_get_contents("{$g['tmp_path']}/config.cache"));
} else {
if (!file_exists("{$g['conf_path']}/config.xml")) {
if (is_booting()) {
if (stristr($g['platform'], "liveCD")) {
// Try copying the default config.xml to the floppy disk/USB stick.
reset_factory_defaults();
echo "\n";
echo "*******************************************************************************\n";
echo "No XML configuration file found - using factory defaults.\n";
echo "Make sure that the configuration floppy disk or USB stick with the config.xml\n";
echo "file is inserted. If it isn't, your configuration changes will be lost\n";
echo "on reboot.\n";
echo "*******************************************************************************\n";
echo "\n";
} else {
echo "\n";
echo "*******************************************************************************\n";
echo "XML configuration file not found. {$productname} cannot continue booting.\n";
echo "*******************************************************************************\n";
echo "\n";
mwexec("/sbin/halt");
exit;
}
} else {
config_unlock();
exit(0);
}
}
/* Load configuration file into array. */
$config = parse_xml_config("{$g['conf_path']}/config.xml", $g['xml_rootobj']);
if (false === $config) {
echo "Error: Failed to load '{$g['conf_path']}/config.xml' file. {$productname} cannot continue booting.\n";
mwexec("/sbin/halt");
exit;
}
if ((float)$config['version'] > (float)$g['latest_config']) {
if (is_booting()) {
echo <<<EOD
*******************************************************************************
WARNING!
The current configuration has been created with a newer version of
{$productname} than this one! This can lead to serious misbehavior and
even security holes! You are urged to either upgrade to a newer version of
{$productname} or revert to the default configuration immediately!
*******************************************************************************
EOD;
}
}
/* write config cache */
$result = config_write_cache($config);
if (false === $result) {
echo "Error: Failed to write '{$g['tmp_path']}/config.cache' file.\n";
}
}
config_unlock();
/* make alias table (for faster lookups) */
alias_make_table();
}
/* mount flash card read/write */
function conf_mount_rw() {
global $g;
if ($g['platform'] != "full") {
/* don't use mount -u anymore
(doesn't sync the files properly and /bin/sync won't help either) */
mwexec("/sbin/umount -f {$g['cf_path']}");
mwexec("/sbin/mount -w -o noatime {$g['cf_path']}");
}
}
/* mount flash card read only */
function conf_mount_ro() {
global $g;
if ($g['platform'] != "full") {
mwexec("/sbin/umount -f {$g['cf_path']}");
mwexec("/sbin/mount -r {$g['cf_path']}");
}
}
/* save the system configuration */
function write_config() {
global $config, $g;
config_lock();
conf_mount_rw();
if (time() > mktime(0, 0, 0, 9, 1, 2004)) { /* make sure the clock settings is plausible */
$config['lastchange'] = time();
}
/* generate configuration XML */
$xmlconfig = dump_xml_config($config, $g['xml_rootobj'], system_get_language_codeset());
/* write configuration */
$fd = fopen("{$g['cf_conf_path']}/config.xml", "w");
if (!$fd)
die("Error: Failed to write '{$g['cf_conf_path']}/config.xml' file.\n");
fwrite($fd, $xmlconfig);
fclose($fd);
// Modify file permissions.
@chmod("{$g['cf_conf_path']}/config.xml", 0600);
conf_mount_ro();
/* re-read configuration */
$config = parse_xml_config("{$g['conf_path']}/config.xml", $g['xml_rootobj']);
/* write config cache */
$result = config_write_cache($config);
if (false === $result) {
echo "Error: Failed to write '{$g['tmp_path']}/config.cache' file.\n";
}
/* tell kernel to sync fs data */
mwexec("/bin/sync");
config_unlock();
}
function reset_factory_defaults() {
global $g;
config_lock();
conf_mount_rw();
/* create conf directory, if necessary */
if (!file_exists("{$g['cf_conf_path']}"))
@mkdir("{$g['cf_conf_path']}");
/* clear out /conf */
$dh = opendir($g['conf_path']);
while ($filename = readdir($dh)) {
if (($filename != ".") && ($filename != "..")) {
unlink($g['conf_path'] . "/" . $filename);
}
}
closedir($dh);
/* copy default configuration */
@copy("{$g['conf_default_path']}/config.xml", "{$g['conf_path']}/config.xml");
// Modify file permissions.
@chmod("{$g['cf_conf_path']}/config.xml", 0600);
conf_mount_ro();
config_unlock();
return 0;
}
function config_install($conffile) {
global $config, $g;
if (!file_exists($conffile))
return 1;
config_lock();
conf_mount_rw();
copy($conffile, "{$g['conf_path']}/config.xml");
conf_mount_ro();
config_unlock();
return 0;
}
/* Lock configuration file, decide that the lock file is stale after 10 seconds. */
function config_lock() {
global $g;
$lockfile = "{$g['varrun_path']}/config.lock";
$n = 0;
while ($n < 10) {
/* open the lock file in append mode to avoid race condition */
if ($fd = @fopen($lockfile, "x")) {
/* succeeded */
fclose($fd);
return;
} else {
/* file locked, wait and try again */
sleep(1);
$n++;
}
}
}
/* Unlock configuration file. */
function config_unlock() {
global $g;
$lockfile = "{$g['varrun_path']}/config.lock";
if (file_exists($lockfile))
unlink($lockfile);
}
// Convert the config file.
// Return 0 if successful, otherwise 1
function config_upgrade() {
global $config, $g;
if ($config['version'] == $g['latest_config'])
return 0; /* already at latest version */
if (is_booting())
echo "Converting configuration. ";
/* convert 1 -> 1.1 */
/* changing partition name, and initializing old bad user parameters */
if ($config['version'] === "1") {
/* change the partitions name "1" to "s1" */
for ($i = 0; isset($config['mounts']['mount'][$i]); $i++)
{
if (isset($config['mounts']['mount'][$i]['partition']))
{
switch ($config['mounts']['mount'][$i]['partition'])
{
case "1":
$config['mounts']['mount'][$i]['partition']="s1";
break;
case "2":
$config['mounts']['mount'][$i]['partition']="s2";
break;
case "3":
$config['mounts']['mount'][$i]['partition']="s3";
break;
case "4":
$config['mounts']['mount'][$i]['partition']="s4";
break;
}
}
}
if (is_array($config['nfs']['network'])) {
$config['nfs']['nfsnetwork'] = $config['nfs']['network'];
unset($config['nfs']['network']);
}
$config['access']['groupid']=1002;
$config['access']['userid']=1002;
unset($config['access']['group']);
unset($config['access']['user']);
$config['version'] = "1.1";
}
/* convert 1.1 -> 1.2 */
/* change the gvnium mount point type 'sraid' to 'gvinum' */
if ($config['version'] === "1.1") {
for ($i = 0; isset($config['mounts']['mount'][$i]); $i++) {
if (isset($config['mounts']['mount'][$i]['partition'])) {
if (strcmp($config['mounts']['mount'][$i]['partition'],"sraid") == 0)
$config['mounts']['mount'][$i]['partition'] = "gvinum";
}
}
$config['version'] = "1.2";
}
/* convert 1.2 -> 1.3 */
/* change the FTP anonymous and local user authentication YES/NO value to right/flase type */
if ($config['version'] === "1.2") {
if ($config['ftp']['anonymous'] === "YES")
$config['ftp']['anonymous'] = true;
else
$config['ftp']['anonymous'] = false;
if ($config['ftp']['localuser'] === "YES")
$config['ftp']['localuser'] = true;
else
$config['ftp']['localuser'] = false;
$config['version'] = "1.3";
}
/* convert 1.3 -> 1.4 */
/* change the gvnium disk fstype attribute 'raid' to 'gvinum' */
/* change <raid> to <gvinum> */
if ($config['version'] === "1.3") {
for ($i = 0; isset($config['disks']['disk'][$i]); $i++) {
if (0==strcmp($config['disks']['disk'][$i]['fstype'],"raid")) {
$config['disks']['disk'][$i]['fstype'] = "gvinum";
}
}
if(is_array($config['raid'])) {
$config['gvinum'] = $config['raid'];
}
unset($config['raid']);
$config['version'] = "1.4";
}
/* convert 1.4 -> 1.5 */
/* Add [fullname] information on mount,disk, gmirror, gvinum and graid5 */
if ($config['version'] === "1.4") {
/* Add fullname (/dev/ad0) under disk */
for ($i = 0; isset($config['disks']['disk'][$i]); $i++) {
if (isset($config['disks']['disk'][$i]['name'])) {
$config['disks']['disk'][$i]['fullname']="/dev/{$config['disks']['disk'][$i]['name']}";
}
}
/* Add fullname (/dev/ad0s1) under mount point */
for ($i = 0; isset($config['mounts']['mount'][$i]); $i++) {
switch ($config['mounts']['mount'][$i]['partition']) {
case "gvinum":
$config['mounts']['mount'][$i]['fullname'] = "/dev/gvinum/{$config['mounts']['mount'][$i]['mdisk']}";
break;
case "gmirror":
$config['mounts']['mount'][$i]['fullname'] = "/dev/mirror/{$config['mounts']['mount'][$i]['mdisk']}";
break;
case "gconcat":
$config['mounts']['mount'][$i]['fullname'] = "/dev/concat/{$config['mounts']['mount'][$i]['mdisk']}";
break;
case "gstripe":
$config['mounts']['mount'][$i]['fullname'] = "/dev/stripe/{$config['mounts']['mount'][$i]['mdisk']}";
break;
case "graid5":
$config['mounts']['mount'][$i]['fullname'] = "/dev/raid5/{$config['mounts']['mount'][$i]['mdisk']}";
break;
default:
$config['mounts']['mount'][$i]['fullname'] = "/dev/{$config['mounts']['mount'][$i]['mdisk']}{$config['mounts']['mount'][$i]['partition']}";
}
}
// Add fullname (/dev/mirror/toto) under gmirror
for ($i = 0; isset($config['gmirror']['vdisk'][$i]); $i++) {
if (isset($config['gmirror']['vdisk'][$i]['name'])) {
$config['gmirror']['vdisk'][$i]['fullname']="/dev/mirror/{$config['gmirror']['vdisk'][$i]['name']}";
}
}
// Add fullname (/dev/gvinum/toto) under gvinum
for ($i = 0; isset($config['gvinum']['vdisk'][$i]); $i++) {
if (isset($config['gvinum']['vdisk'][$i]['name'])) {
$config['gvinum']['vdisk'][$i]['fullname']="/dev/gvinum/{$config['gvinum']['vdisk'][$i]['name']}";
}
}
// Add fullname (/dev/raid5/toto) under graid5
for ($i = 0; isset($config['graid5']['vdisk'][$i]); $i++) {
if (isset($config['graid5']['vdisk'][$i]['name'])) {
$config['graid5']['vdisk'][$i]['fullname']="/dev/raid5/{$config['graid5']['vdisk'][$i]['name']}";
}
}
$config['version'] = "1.5";
}
/* convert 1.5 -> 1.6 */
/* Upgrade iSCSI and NFS configurations
Upgrade RSYNC client configuration */
if ($config['version'] === "1.5") {
if (isset($config['nfs']['enable'])) {
$config['nfs']['nfsnetworks']=array();
$config['nfs']['nfsnetworks'][]=$config['nfs']['nfsnetwork'];
unset($config['nfs']['nfsnetwork']);
}
if (isset($config['iscsi']['enable'])) {
$iscsivdisk = array();
$iscsivdisk['targetname'] = $config['iscsi']['targetname'];
$iscsivdisk['targetaddress'] = $config['iscsi']['targetaddress'];
$iscsivdisk['name'] = "target0";
$iscsivdisk['initiatorname'] = "iqn.2005-01.il.ac.huji.cs";
$config['iscsiinit']['vdisk'] = array();
$config['iscsiinit']['vdisk'][] = $iscsivdisk;
unset($config['iscsi']['enable']);
unset($config['iscsi']['targetaddress']);
unset($config['iscsi']['targetname']);
}
/* Convert 'rsyncclient' part
Special note: rsyncclient is now an array, then the xml parse will create an array.
We must use an array
*/
if (isset($config['rsyncclient'][0]['enable'])) {
if (!is_array($config['rsync'])) {
$config['rsync'] = array();
if (!is_array($config['rsync']['rsyncclient'])) {
$config['rsync']['rsyncclient'] = array();
}
} else if (!is_array($config['rsync']['rsyncclient'])) {
$config['rsync']['rsyncclient'] = array();
}
foreach ($config['rsyncclient'][0]['sharetosync'] as $sharek => $sharev) {
$rsyncclient = array();
$rsyncclient['opt_delete'] = isset($config['rsyncclient'][0]['opt_delete']);
$rsyncclient['rsyncserverip'] = $config['rsyncclient'][0]['rsyncserverip'];
$rsyncclient['localshare'] = $sharev;
$rsyncclient['remoteshare'] = $sharev;
$rsyncclient['minute'] = $config['rsyncclient'][0]['minute'];
$rsyncclient['hour'] = $config['rsyncclient'][0]['hour'];
$rsyncclient['day'] = $config['rsyncclient'][0]['day'];
$rsyncclient['month'] = $config['rsyncclient'][0]['month'];
$rsyncclient['weekday'] = $config['rsyncclient'][0]['weekday'];
$rsyncclient['all_mins'] = $config['rsyncclient'][0]['all_mins'];
$rsyncclient['all_hours'] = $config['rsyncclient'][0]['all_hours'];
$rsyncclient['all_days'] = $config['rsyncclient'][0]['all_days'];
$rsyncclient['all_months'] = $config['rsyncclient'][0]['all_months'];
$rsyncclient['all_weekdays'] = $config['rsyncclient'][0]['all_weekdays'];
$config['rsync']['rsyncclient'][] = $rsyncclient;
unset($rsyncclient);
}
unset ($config['rsyncclient']);
} else if (is_array($config['rsyncclient'])) {
// Clean old unused code
unset ($config['rsyncclient']);
}
if (isset($config['rsync_local']['enable'])) {
if (!is_array($config['rsync'])) {
$config['rsync'] = array();
if (!is_array($config['rsync']['rsynclocal'])) {
$config['rsync']['rsynclocal'] = array();
}
} else if (!is_array($config['rsync']['rsynclocal'])) {
$config['rsync']['rsynclocal'] = array();
}
$rsynclocal['opt_delete'] = isset($config['rsync_local']['opt_delete']);
$rsynclocal['source'] = $config['rsync_local']['source'];
$rsynclocal['destination'] = $config['rsync_local']['destination'];
$rsynclocal['minute'] = $config['rsync_local']['minute'];
$rsynclocal['hour'] = $config['rsync_local']['hour'];
$rsynclocal['day'] = $config['rsync_local']['day'];
$rsynclocal['month'] = $config['rsync_local']['month'];
$rsynclocal['weekday'] = $config['rsync_local']['weekday'];
$rsynclocal['all_mins'] = $config['rsync_local']['all_mins'];
$rsynclocal['all_hours'] = $config['rsync_local']['all_hours'];
$rsynclocal['all_days'] = $config['rsync_local']['all_days'];
$rsynclocal['all_months'] = $config['rsync_local']['all_months'];
$rsynclocal['all_weekdays'] = $config['rsync_local']['all_weekdays'];
$config['rsync']['rsynclocal'][] = $rsynclocal;
unset ($config['rsync_local']);
}
$config['version'] = "1.6";
}
/* Convert 1.6 -> 1.7 */
/* - Change ['system']['howl_disable'] to ['system']['zeroconf']. */
/* - Delete ['system']['polling']. */
/* - Delete ['filter']['bypassstaticroutes']. */
/* - Delete ['bridge'], ['bridge']['filteringbridge']. */
if ($config['version'] === "1.6") {
if (isset($config['system']['howl_disable'])) {
unset($config['system']['howl_disable']);
} else {
$config['system']['zeroconf'] = true;
}
if (isset($config['system']['polling'])) {
unset($config['system']['polling']);
}
if (isset($config['filter']['bypassstaticroutes'])) {
unset($config['filter']['bypassstaticroutes']);
}
if (isset($config['bridge'])) {
unset($config['bridge']);
}
$config['version'] = "1.7";
}
/* Convert 1.7 -> 1.8 */
/* Bug Fix: Forget to confert old fstype value with new one */
/* Create bug "You must add disks first" with older configured disk */
/* - Change ['fstype']='gmirror' to 'softraid' */
/* - Change ['fstype']='gconcat' to 'softraid' */
/* - Change ['fstype']='gstripe' to 'softraid' */
/* - Change ['fstype']='graid5' to 'softraid' */
if ($config['version'] === "1.7") {
for ($i = 0; isset($config['disks']['disk'][$i]); $i++) {
if (isset($config['disks']['disk'][$i]['name'])) {
switch ($config['disks']['disk'][$i]['fstype']) {
case "gmirror":
$config['disks']['disk'][$i]['fstype']="softraid";
break;
case "gconcat":
$config['disks']['disk'][$i]['fstype']="softraid";
break;
case "gstripe":
$config['disks']['disk'][$i]['fstype']="softraid";
break;
case "graid5":
$config['disks']['disk'][$i]['fstype']="softraid";
break;
}
}
}
$config['version'] = "1.8";
}
/* Convert 1.8 -> 1.9 */
/* Add type "disk" to existing mountpoint */
/* Add fullname (/dev/ad0s1) under mount point */
if ($config['version'] === "1.8") {
for ($i = 0; isset($config['mounts']['mount'][$i]); $i++) {
$config['mounts']['mount'][$i]['type']= "disk";
}
$config['version'] = "1.9";
}
/* Convert 1.9 -> 2.0 */
/* Add ipv6 address type */
if ($config['version'] === "1.9") {
$config['interfaces']['lan']['ipv6addr']="auto";
$config['interfaces']['lan']['ipv6subnet']=64;
for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
$optcfg = $config['interfaces']['opt' . $i];
if (isset($optcfg['enable'])) {
$config['interfaces']['opt' . $i]['ipv6addr']="auto";
$config['interfaces']['opt' . $i]['ipv6subnet']=64;
}
}
$config['version'] = "2.0";
}
/* Convert 2.0 -> 2.1 */
/* Remove //system/harddiskstandby */
if ($config['version'] === "2.0") {
if (isset($config['system']['harddiskstandby'])) {
unset($config['system']['harddiskstandby']);
}
$config['version'] = "2.1";
}
/* Convert 2.1 -> 2.2 */
/* Add //samba/share and remove useless //samba/xxx attributes. */
if ($config['version'] === "2.1") {
for ($i = 0; isset($config['mounts']['mount'][$i]); $i++) {
$share = array();
$share['name'] = $config['mounts']['mount'][$i]['sharename'];
$share['path'] = "/mnt/{$config['mounts']['mount'][$i]['sharename']}";
$share['comment'] = $config['mounts']['mount'][$i]['desc'];
$share['browseable'] = true;
if (is_array($config['samba']['hidemount'])) {
if (in_array($config['mounts']['mount'][$i]['sharename'],$config['samba']['hidemount']))
$share['browseable'] = false;
}
$share['inheritpermissions'] = true;
$share['recyclebin'] = isset($config['samba']['recyclebin']);
$config['samba']['share'][] = $share;
}
unset($config['samba']['hidemount']);
unset($config['samba']['recyclebin']);
$config['version'] = "2.2";
}
/* Convert 2.2 -> 2.3 */
/* Set default UPnP profile //upnp/profile. */
if ($config['version'] === "2.2") {
$config['upnp']['profile'] = "default";
$config['version'] = "2.3";
}
/* Convert 2.3 -> 2.4 */
/* Refactor //syslog. */
if ($config['version'] === "2.3") {
$config['syslogd']['reverse'] = isset($config['syslog']['reverse']);
$config['syslogd']['nentries'] = $config['syslog']['nentries'];
$config['syslogd']['resolve'] = isset($config['syslog']['resolve']);
$config['syslogd']['remote']['enable'] = isset($config['syslog']['enable']);
$config['syslogd']['remote']['ipaddr'] = $config['syslog']['remoteserver'];
$config['syslogd']['remote']['daemon'] = isset($config['syslog']['daemon']);
$config['syslogd']['remote']['ftp'] = isset($config['syslog']['ftp']);
$config['syslogd']['remote']['rsyncd'] = isset($config['syslog']['rsyncd']);
$config['syslogd']['remote']['smartd'] = isset($config['syslog']['smartd']);
$config['syslogd']['remote']['sshd'] = isset($config['syslog']['sshd']);
$config['syslogd']['remote']['system'] = isset($config['syslog']['system']);
unset($config['syslog']);
$config['version'] = "2.4";
}
/* Convert 2.4 -> 2.5 */
/* Refactor //iscsitarget. */
if ($config['version'] === "2.4") {
for ($i = 0; isset($config['iscsitarget']['vdisk'][$i]); $i++) {
$extent = array();
$extent['name'] = "extent{$i}";
$extent['path'] = "/mnt/" . $config['iscsitarget']['vdisk'][$i]['sharename'];
$extent['size'] = $config['iscsitarget']['vdisk'][$i]['size'];
$network = explode("/", $config['iscsitarget']['vdisk'][$i]['network']);
$target = array();
$target['name'] = "target{$i}";
$target['storage'] = "extent{$i}";
$target['flags'] = "rw";
$target['ipaddr'] = $network[0];
$target['subnet'] = $network[1];
$config['iscsitarget']['extent'][] = $extent;
$config['iscsitarget']['target'][] = $target;
unset($config['iscsitarget']['vdisk'][$i]);
}
$config['version'] = "2.5";
}
/* Convert 2.5 -> 2.6 */
/* Remove useless //access/userid and //access/groupid. */
/* Remove useless //access/user/usergroup. */
/* Rename //access/user/usergroupid to //access/user/group. */
if ($config['version'] === "2.5") {
for ($i = 0; isset($config['access']['user'][$i]); $i++) {
$config['access']['user'][$i]['primarygroup'] = $config['access']['user'][$i]['usergroupid'];
unset($config['access']['user'][$i]['usergroupid']);
unset($config['access']['user'][$i]['usergroup']);
}
unset($config['access']['userid']);
unset($config['access']['groupid']);
$config['version'] = "2.6";
}
/* Convert 2.6 -> 2.7 */
/* Convert language setting. */
if ($config['version'] === "2.6") {
$language = array(
"Bulgarian" => "bg",
"Dutch" => "nl",
"English" => "en_US",
"French" => "fr",
"German" => "de",
"Greek" => "el",
"Italian" => "it",
"Japanese" => "ja",
"Romanian" => "ro",
"Russian" => "ru",
"SimplifiedChinese" => "zh_CN",
"Spanish" => "es",
"TraditionalChinese" => "zh_TW"
);
if (array_key_exists($config['system']['language'], $language)) {
$config['system']['language'] = $language[$config['system']['language']];
} else {
$config['system']['language'] = "en_US"; // Set default language.
}
$config['version'] = "2.7";
}
/* Convert 2.7 -> 2.8 */
/* Add new default sshd settings. */
/* Remove useless //sshd/readonly. */
if ($config['version'] === "2.7") {
$config['sshd']['passwordauthentication'] = true;
$config['sshd']['pubkeyauthentication'] = true;
unset($config['sshd']['readonly']);
$config['version'] = "2.8";
}
/* Convert 2.8 -> 2.9 */
/* Add //samba/share/hostallow and //samba/share/hostdeny. */
/* Add //ftp/chrooteveryone. */
/* Check if //syslogd/nentries is set. */
if ($config['version'] === "2.8") {
for ($i = 0; isset($config['samba']['share'][$i]); $i++) {
$config['samba']['share'][$i]['hostsallow'] = "ALL";
$config['samba']['share'][$i]['hostsdeny'] = "ALL";
}
$config['ftp']['chrooteveryone'] = true;
if (!$config['syslogd']['nentries']) {
$config['syslogd']['nentries'] = 50;
}
$config['version'] = "2.9";
}
/* Convert 2.9 -> 3.0 */
/* Rename //system/earlyshellcmd -> //rc/preinit/cmd */
/* Rename //system/shellcmd -> //rc/postinit/cmd */
/* Rename //snmpd/rocommunity -> //snmpd/read */
if ($config['version'] === "2.9") {
for ($i = 0; isset($config['system']['earlyshellcmd'][$i]); $i++) {
$config['rc']['preinit']['cmd'][] = $config['system']['earlyshellcmd'][$i];
unset($config['system']['earlyshellcmd'][$i]);
}
for ($i = 0; isset($config['system']['shellcmd'][$i]); $i++) {
$config['rc']['postinit']['cmd'][] = $config['system']['shellcmd'][$i];
unset($config['system']['shellcmd'][$i]);
}
$config['snmpd']['mibii'] = true;
$config['snmpd']['netgraph'] = true;
$config['snmpd']['hostres'] = true;
$config['snmpd']['read'] = $config['snmpd']['rocommunity'];
unset($config['snmpd']['rocommunity']);
$config['version'] = "3.0";
}
/* Convert 3.0 -> 3.1 */
/* Append file name to path. */
if ($config['version'] === "3.0") {
for ($i = 0; isset($config['iscsitarget']['extent'][$i]); $i++) {
$extent = &$config['iscsitarget']['extent'][$i];
$extent['path'] = $extent['path'] . "/" . $extent['name'];
}
$config['version'] = "3.1";
}
/* Convert 3.1 -> 3.2 */
/* Modify NTP settings. */
if ($config['version'] === "3.1") {
$config['system']['ntp']['timeservers'] = $config['system']['timeservers'];
if ("0" !== $config['system']['time-update-interval']) {
$config['system']['ntp']['enable'] = true;
$config['system']['ntp']['updateinterval'] = $config['system']['time-update-interval'];
} else {
$config['system']['ntp']['updateinterval'] = 300;
}
unset($config['system']['time-update-interval']);
unset($config['system']['timeservers']);
$config['version'] = "3.2";
}
write_config();
if (is_booting())
echo "done\n";
return 0;
}
// Write configuration cache file.
// Return true if successful, otherwise false.
function config_write_cache($data) {
global $g;
$result = false;
$fd = @fopen("{$g['tmp_path']}/config.cache", "wb");
if ($fd) {
fwrite($fd, serialize($data));
fclose($fd);
// Modify file permissions.
@chmod("{$g['tmp_path']}/config.cache", 0600);
$result = true;
}
return $result;
}
?>
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.