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
  
1001
  
1002
  
1003
  
1004
  
1005
  
1006
  
1007
  
1008
  
1009
  
1010
  
1011
  
1012
  
1013
  
1014
  
1015
  
1016
  
1017
  
1018
  
1019
  
1020
  
1021
  
1022
  
1023
  
1024
  
1025
  
1026
  
1027
  
1028
  
1029
  
1030
  
1031
  
1032
  
1033
  
1034
  
1035
  
1036
  
1037
  
1038
  
1039
  
1040
  
1041
  
1042
  
1043
  
1044
  
1045
  
1046
  
1047
  
1048
  
1049
  
1050
  
1051
  
1052
  
1053
  
1054
  
1055
  
1056
  
1057
  
1058
  
1059
  
1060
  
1061
  
1062
  
1063
  
1064
  
1065
  
1066
  
1067
  
1068
  
1069
  
1070
  
1071
  
1072
  
1073
  
1074
  
1075
  
1076
  
1077
  
1078
  
1079
  
1080
  
1081
  
1082
  
1083
  
1084
  
1085
  
1086
  
1087
  
1088
  
1089
  
1090
  
1091
  
1092
  
1093
  
1094
  
1095
  
1096
  
1097
  
1098
  
1099
  
1100
  
1101
  
1102
  
1103
  
1104
  
1105
  
1106
  
1107
  
1108
  
1109
  
1110
  
1111
  
1112
  
1113
  
1114
  
1115
  
1116
  
1117
  
1118
  
1119
  
1120
  
1121
  
1122
  
1123
  
1124
  
1125
  
1126
  
1127
  
1128
  
1129
  
1130
  
1131
  
1132
  
1133
  
1134
  
1135
  
1136
  
1137
  
1138
  
1139
  
1140
  
1141
  
1142
  
1143
  
1144
  
1145
  
1146
  
1147
  
1148
  
1149
  
1150
  
1151
  
1152
  
1153
  
1154
  
1155
  
1156
  
1157
  
1158
  
1159
  
1160
  
1161
  
1162
  
1163
  
1164
  
1165
  
1166
  
1167
  
1168
  
1169
  
1170
  
1171
  
1172
  
1173
  
1174
  
1175
  
1176
  
1177
  
1178
  
1179
  
1180
  
1181
  
1182
  
1183
  
1184
  
1185
  
1186
  
1187
  
1188
  
1189
  
1190
  
1191
  
1192
  
1193
  
1194
  
1195
  
1196
  
1197
  
1198
  
1199
  
1200
  
1201
  
1202
  
1203
  
1204
  
1205
  
1206
  
1207
  
1208
  
1209
  
1210
  
1211
  
1212
  
1213
  
1214
  
1215
  
1216
  
1217
  
1218
  
1219
  
1220
  
1221
  
1222
  
1223
  
1224
  
1225
  
1226
  
1227
  
1228
  
1229
  
1230
  
1231
  
1232
  
1233
  
1234
  
1235
  
1236
  
1237
  
1238
  
1239
  
1240
  
1241
  
1242
  
1243
  
1244
  
1245
  
1246
  
1247
  
1248
  
1249
  
1250
  
1251
  
1252
  
1253
  
1254
  
1255
  
1256
  
1257
  
1258
  
1259
  
1260
  
1261
  
1262
  
1263
  
1264
  
1265
  
1266
  
1267
  
1268
  
1269
  
1270
  
1271
  
1272
  
1273
  
1274
  
1275
  
1276
  
1277
  
1278
  
1279
  
1280
  
1281
  
1282
  
1283
  
1284
  
1285
  
1286
  
1287
  
1288
  
1289
  
1290
  
1291
  
1292
  
1293
  
1294
  
1295
  
1296
  
1297
  
1298
  
1299
  
1300
  
1301
  
1302
  
1303
  
1304
  
1305
  
1306
  
1307
  
1308
  
1309
  
1310
  
1311
  
1312
  
1313
  
1314
  
1315
  
1316
  
1317
  
1318
  
1319
  
1320
  
1321
  
1322
  
1323
  
1324
  
1325
  
1326
  
1327
  
1328
  
1329
  
1330
  
1331
  
1332
  
1333
  
1334
  
1335
  
1336
  
1337
  
1338
  
1339
  
1340
  
1341
  
1342
  
1343
  
1344
  
1345
  
1346
  
1347
  
1348
  
1349
  
1350
  
1351
  
1352
  
1353
  
1354
  
1355
  
1356
  
1357
  
1358
  
1359
  
1360
  
1361
  
1362
  
1363
  
1364
  
1365
  
1366
  
1367
  
1368
  
1369
  
1370
  
1371
  
1372
  
1373
  
1374
  
1375
  
1376
  
1377
  
1378
  
1379
  
1380
  
1381
  
1382
  
1383
  
1384
  
1385
  
1386
  
1387
  
1388
  
1389
  
1390
  
1391
  
1392
  
1393
  
1394
  
1395
  
1396
  
1397
  
1398
  
1399
  
1400
  
1401
  
1402
  
1403
  
1404
  
1405
  
1406
  
1407
  
1408
  
1409
  
1410
  
1411
  
1412
  
1413
  
1414
  
1415
  
1416
  
1417
  
1418
  
1419
  
1420
  
1421
  
1422
  
1423
  
1424
  
1425
  
1426
  
1427
  
1428
  
1429
  
1430
  
1431
  
1432
  
1433
  
1434
  
1435
  
1436
  
1437
  
1438
  
1439
  
1440
  
1441
  
1442
  
1443
  
1444
  
1445
  
1446
  
1447
  
1448
  
1449
  
1450
  
1451
  
1452
  
1453
  
1454
  
1455
  
1456
  
1457
  
1458
  
1459
  
1460
  
1461
  
1462
  
1463
  
1464
  
1465
  
1466
  
1467
  
1468
  
1469
  
1470
  
1471
  
inherit "config/builders"; 
string cvs_version = "$Id: mainconfig.pike,v 1.42 1997/06/12 00:34:23 grubba Exp $"; 
inherit "roxenlib"; 
inherit "config/draw_things"; 
 
import Array; 
import Stdio; 
 
/* Work-around for Simulate.perror */ 
#define perror roxen_perror 
 
#include <confignode.h> 
#include <module.h> 
 
#define dR "00" 
#define dG "06" 
#define dB "30" 
 
#define bdR "00" 
#define bdG "50" 
#define bdB "90" 
 
 
#define BODY "<body "+(roxen->QUERY(BG)?"background=/image/background.gif ":"")+"bgcolor=#"+dR+dG+dB+" text=#ffffff link=#ffffaa vlink=#ffffaa alink=#f0e0f0>" 
 
#define TABLEP(x, y) (id->supports->tables ? x : y) 
#define PUSH(X) do{res+=({(X)});}while(0) 
 
int bar=time(1); 
 
class Node { 
  inherit "struct/node"; 
 
  import Simulate; 
 
  mixed original; 
  int changed, moredocs; 
 
  int bar=time(); 
  function saver = lambda(object o) { if(o->changed) o->change(-o->changed); }; 
   
  string|array error; 
   
  void change(int i) 
  { 
    changed += i; 
    if(up) up->change(i); 
  } 
 
  private string show_me(string s) 
  { 
    string name=path(1); 
    if(folded) 
      return ("<a name=\""+name+"\">\n" 
              "<a href=\"/(unfold)" + name + "?"+(bar++)+ 
              "\">\n<img border=0 align=baseline src=/auto/unfold" 
              +(changed?"2":"")+" alt=\""+(changed?"*-":"--")+"\">" 
              "</a>\n "+s+"\n"); 
    else 
      return ("<a name=\""+name+"\">\n" 
              "<a href=\"/(fold)" + name + "?"+(bar++)+ 
              "\">\n<img border=0 src=/auto/fold"+(changed?"2":"") 
              +"  alt="+(changed?"**":"\"\\/\"")+">" 
              "</a>\n "+s+"\n"); 
  } 
 
  string describe(int i) 
  { 
    array (string) res=({""}); 
    object node,prevnode; 
    mixed tmp; 
 
    if(describer) 
      tmp = describer(this_object()); 
#ifdef NODE_DEBUG 
    else 
    { 
      perror("No describer in node "+path(1)+"\n"); 
      return 0; 
    } 
#endif 
    if(arrayp(tmp) && sizeof(tmp)) 
      PUSH(tmp[0] +  "<dt>" + (i?tmp[i]:show_me(tmp[1])) + "\n"); 
    else if(stringp(tmp) && strlen(tmp)) 
      PUSH("<dt>"+(i?tmp:show_me(tmp)) + "\n"); 
    else if(!tmp) 
      return ""; 
 
    if(!folded) 
    { 
      PUSH("<dl><dd>\n"); 
      node = down; 
      while(node) 
      { 
        if(!objectp(node))  // ERROR! Destructed node in tree! 
        { 
          if(objectp(prevnode)) 
            prevnode->next=0; 
          node=0; 
          break; 
        } 
        prevnode = node; 
        node = node->next; 
        PUSH(prevnode->describe()); 
      } 
      PUSH("</dl>\n\n"); 
    } 
    return res*""; 
  } 
   
   
  object config() 
  { 
    object node; 
    node=this_object(); 
    while(node) 
      if(node->type == NODE_CONFIGURATION) 
        return node->data; 
      else 
        node=node->up; 
  } 
   
  void save() 
  { 
    object node; 
    node=down; 
     
    // depth-first save. 
    while(node) 
    { 
      if(node->changed) node->save(); 
      node=node->next;  
    } 
    if(saver) saver(this_object()); 
  } 
} 
 
object root=Node(); 
int expert_mode; 
 
 
void create() 
{ 
  build_root(root); 
  init_ip_list(); 
  call_out(init_ip_list, 0); 
} 
 
#define BUTTON(ACTION,TEXT,ALIGN) do{PUSH("<a href=\"/(ACTION)"+(o?o->path(1):"/")+"?"+(bar++)+"\"><img border=0 hspacing=0 vspacing=0 src=/auto/button/"+(lm?"lm/":"")+replace(TEXT," ","%20")+" alt=\""+(lm?"/ ":" ")+TEXT+" /\""+(("ALIGN"-" ")=="left"?"":" align="+("ALIGN"-" "))+"></a>");lm=0;}while(0) 
 
inline string shutdown_restart(string save, int compact,void|object o) 
{ 
  return /*"<br clear=all>"*/""; 
} 
 
string default_head(string h, string|void save) 
{ 
  return ("<head><title>"+h+"</title></head>\n"+ BODY+"\n"); 
} 
 
object find_node(string l) 
{  
  array tmp = l/"/"-({""}); 
  object o; 
  if(!sizeof(tmp)) return root; 
  for(o=root; sizeof(tmp) && (o=o->descend(tmp[0],1)); tmp=tmp[1..1000]); 
  if(!o) return 0; 
  return o; 
} 
 
mapping file_image(string img) 
{ 
  object o; 
  o=open("roxen-images/"+img, "r"); 
  if (!o)  return 0; 
  return ([ "file":o, "type":"image/" + ((img[-1]=='f')?"gif":"jpeg"), ]); 
} 
 
#define CONFIG_URL roxen->config_url() 
 
mapping save_it(object id, object o) 
{ 
  id->referer = ({ CONFIG_URL + o->path(1) }); 
  root->save(); 
  roxen->update_supports_from_roxen_com(); 
  roxen->initiate_configuration_port( 0 ); 
} 
 
mapping stores( string s ) 
{ 
  return  
    ([ 
      "data":replace(s, "$docurl", roxen->docurl), 
      "type":"text/html", 
      "extra_heads": 
      ([ 
        "Title":"Roxen Challenger maintenance", 
//      "Expires":http_date(time(1)+2), 
//    "Pragma":"no-cache", 
        "Last-Modified":http_date(time(1)), 
        ]) 
      ]); 
} 
 
object find_module(string name, object in) 
{ 
  mapping mod; 
  object o; 
  string s; 
  int i; 
  name = lower_case(name); 
  if(!sscanf(name, "%s#%d", name, i)) 
  { 
#ifdef MODULE_DEBUG 
#if defined(DEBUG) && (DEBUG > 1000) 
    perror("Modulename not in short form: "+name+"\n"); 
#endif 
#endif 
    foreach(values(in->modules), mod) 
    { 
      if(mod->copies) 
      { 
        foreach(values(mod->copies), o) 
          if(lower_case(s=name_of_module(o)) == name) 
            return o; 
      } else  
        if(mod->enabled && (lower_case(s=name_of_module(mod->enabled))==name)) 
          return mod->enabled;  
    } 
  } else { 
    mapping modules; 
#ifdef MODULE_DEBUG 
#if defined(DEBUG) && (DEBUG > 1000) 
    perror("Modulename in short form: "+name+"#"+i+"\n"); 
#endif 
#endif 
    modules = in->modules; 
    if(modules[name]) 
    { 
      if(modules[name]->copies) 
        return modules[name]->copies[i]; 
      else  
        if(modules[name]->enabled) 
          return modules[name]->enabled; 
    } 
  } 
  return 0; 
} 
 
mixed decode_form_result(string var, int type, object node, mapping allvars) 
{ 
  switch(type) 
  { 
   case TYPE_CUSTOM: 
    return node->data[ VAR_MISC ][2]( var, type, node, allvars ); 
     
  case TYPE_MODULE_LIST: 
    return map(var/"\000", find_module); 
 
  case TYPE_MODULE: 
   return find_module(var, node->config()); 
 
  case TYPE_PORTS:   
   /* 
     Encoded like this: 
 
     new_port    --> Add a new port 
     ok[_<ID>]   --> Save the value for all or one port 
     delete_<ID> --> Delete a port 
 
     ---- { A port is defined by: 
     port_<ID> == INT 
     protocol_<ID> == STRING 
     ip_number_<ID> == STRING 
     arguments_<ID> == STRING 
     } ----  
    */ 
   if(allvars->new_port) 
     return node->data[VAR_VALUE] + ({ ({ 80, "http", "ANY", "" }) }); 
 
   array op = copy_value(node->data[VAR_VALUE]); 
   int i; 
   for(i = 0; i<sizeof(op); i++) 
   { 
     if(!allvars["delete_"+i]) 
     { 
       if(allvars["other_"+i] && (allvars["other_"+i] != op[i][2])) 
       { 
         allvars["ip_number_"+i] = allvars["other_"+i]; 
         ip_number_list += ({ allvars["other_"+i] }); 
       } 
       op[i][0] = (int)allvars["port_"+i]||op[i][0]; 
       op[i][1] = allvars["protocol_"+i]||op[i][1]; 
       op[i][2] = allvars["ip_number_"+i]||op[i][2]; 
       op[i][3] = allvars["arguments_"+i]||op[i][3]; 
     } else  // Delete this port. 
       op[i]=0; 
   } 
   return op  - ({ 0 }); 
 
   case TYPE_DIR_LIST: 
    array foo; 
    foo=map((var-" ")/",", lambda(string var, object node) { 
      if (!strlen( var ) || file_size( var ) != -2) 
      { 
        if(node->error)      
          node->error += ", " +var + " is not a directory"; 
        else 
          node->error = var + " is not a directory"; 
        return 0; 
      } 
      if(var[-1] != '/') 
        return var + "/"; 
      return var; 
    }, node); 
     
    if(sizeof(foo-({0})) != sizeof(foo)) 
      return 0; 
    return foo; 
     
   case TYPE_DIR: 
    array st; 
    if (!strlen( var ) || !(st = file_stat( var )) || (st[1] != -2)) 
    { 
      node->error = var + " is not a directory"; 
      return 0; 
    } 
    if(var[-1] != '/') 
      return var + "/"; 
    return var; 
     
   case TYPE_TEXT_FIELD: 
    var -= "\r"; 
   case TYPE_FONT: 
   case TYPE_STRING: 
   case TYPE_FILE: 
   case TYPE_LOCATION: 
    return var; 
     
   case TYPE_PASSWORD: 
    return crypt(var); 
     
   case TYPE_FLAG: 
    return lower_case(var) == "yes"; 
     
   case TYPE_INT: 
    int tmp; 
     
    if (!sscanf( var, "%d", tmp )) 
    { 
      node->error= var + " is not an integer"; 
      return 0; 
    } 
    return tmp; 
     
   case TYPE_FLOAT: 
    float tmp; 
     
    if (!sscanf( var, "%f", tmp )) 
    { 
      node->error= var + " is not a arbitary precision floating point number"; 
      return 0; 
    } 
    return tmp; 
     
   case TYPE_INT_LIST: 
    if(node->data[VAR_MISC]) 
      return (int)var; 
    else 
      return map((var-" ")/",", lambda(string s){  
        return (int)s; 
      }); 
     
     
   case TYPE_STRING_LIST: 
    if(node->data[VAR_MISC]) 
      return var; 
    else 
      return (var-" ")/","; 
     
   case TYPE_COLOR: 
    int red, green, blue; 
     
    if (sscanf( var, "%d:%d:%d", red, green, blue ) != 3 
        || red < 0 || red > 255 || green < 0 || green > 255 
        || blue < 0 || blue > 255) 
    { 
      node->error = var + " is not a valid color specification"; 
      return 0; 
    } 
    return (red << 16) + (green << 8) + blue; 
  } 
  error("Unknown type.\n"); 
} 
 
mapping std_redirect(object o, object id) 
{ 
  string loc, l2; 
 
  if(!o)  o=root; 
   
  if(id && sizeof(id->referer)) 
    loc=((((((id->referer*" ")/"#")[0])/"?")[0])+"?"+(bar++) 
         +"#"+o->path(1)); 
  else 
    loc = CONFIG_URL+o->path(1)[1..10000]+"?"+bar++; 
   
  if(sscanf(loc, "%s/(%*s)%s",l2, loc) == 3) 
    loc = l2 + loc;             // Remove the prestate. 
 
//  http://www:22020//Configuration/ -> http://www:22202/Configurations/ 
 
  loc = replace(replace(replace(loc, "://", ""), "//", "/"), "", "://"); 
 
  return http_redirect(http_decode_string(loc)); 
} 
 
string configuration_list() 
{ 
  string res=""; 
  object o; 
  foreach(roxen->configurations, o) 
    res += "<option>Copy of '"+o->name+"'"; 
  return res; 
} 
 
string new_configuration_form() 
{ 
  return replace(default_head("")+ read_bytes("etc/newconfig.html"), 
                 ({"$COPIES","$configurl"}),  
                 ({configuration_list(),CONFIG_URL})) + 
    "\n\n</body>"; 
} 
 
mapping module_nomore(string name, int type, object conf) 
{ 
  mapping module; 
  object o; 
// perror("Module: "+name+"\n"); 
  if((module = conf->modules[name]) 
    && (!module->copies && module->enabled)) 
    return module; 
  if(((type & MODULE_DIRECTORIES) && (o=conf->dir_module)) 
     || ((type & MODULE_AUTH)  && (o=conf->auth_module)) 
     || ((type & MODULE_TYPES) && (o=conf->types_module)) 
     || ((type & MODULE_MAIN_PARSER)  && (o=conf->parse_module))) 
    return conf->modules[conf->otomod[o]]; 
} 
 
mixed new_module_copy(object node, string name, object id) 
{ 
  object orig; 
  int i; 
  mapping module; 
  module = node->config()->modules[name]; 
  switch(node->type) 
  { 
   default: 
    error("Foo? Illegal node in new_module_copy\n"); 
     
   case NODE_MODULE_COPY: 
    node=node->up; 
     
   case NODE_MODULE_MASTER_COPY: 
   case NODE_MODULE: 
    node=node->up; 
     
   case NODE_CONFIGURATION: 
  } 
   
  if(module) if(module->copies) while(module->copies[i])  i++; 
  orig = node->config()->enable_module(name+"#"+i); 
 
  if(!orig) return http_string_answer("This module could not be enabled.\n"); 
     
  module = node->config()->modules[name]; 
  node = node->descend(module->name); 
  // Now it is the (probably unbuilt) module main node... 
   
  node->data = module; 
  node->describer = describe_module; 
  node->type = NODE_MODULE; 
  build_module(node); 
   
  //  We want to see the new module.. 
  node->folded=0;  
   
  // If the module have copies, select the actual copy added.. 
  if(module->copies) node = node->descend((string)i, 1);  
   
  // Now it is the module.. 
  // We want to see this one immediately. 
  if(node) 
  { 
    node->folded = 0; 
    // Mark the node and all its parents as modified. 
    node->change(1); 
  } 
  return std_redirect(root, id); 
} 
 
mixed new_module_copy_copy(object node, object id) 
{ 
  return new_module_copy(node, node->data->sname, id); 
} 
 
string new_module_form(object id, object node) 
{ 
  int i; 
  mixed a,b; 
  string q; 
  array mods; 
  array (string) res; 
   
  if(!roxen->allmodules || sizeof(id->pragma)) 
  { 
    werror("CONFIG: Rescanning modules.\n"); 
    roxen->current_configuration = node->config(); 
    roxen->rescan_modules(); 
    roxen->current_configuration = 0; 
    werror("CONFIG: Done.\n"); 
  } 
   
  a=roxen->allmodules; 
  mods=sort_array(indices(a), lambda(string a, string b, mapping m) {  
    return m[a][0] > m[b][0]; 
  }, a); 
   
  res = ({default_head("Add a module")+"\n\n"+ 
  "<h2>Select a module to add from the list below</h2>" }); 
   
  foreach(mods, q) 
  { 
    if(b = module_nomore(q, a[q][2], node->config())) 
    { 
      if(b->sname != q) 
        res += ({("<p>"+ 
                  (roxen->QUERY(BS)?"<h2>"+a[q][0]+"</h2>": 
                  "<img alt=\""+a[q][0]+"\" src=/auto/module/" + a[q][2]+"/"+ 
                   q+" height=24 width=500>")+ "<br><blockquote>" + a[q][1] + 
                  "<p><i>A module of the same type is already enabled (" + 
                  b->name + "). <a href=\"/(delete)" + 
                  node->descend(b->name, 1)->path(1) + "?" + (bar++) + 
                  "\">Disable that module</a> if you want this one insted</i>" 
                  "\n<p><br><p></blockquote>")}); 
    } else { 
      res += ({"<p><a href=/(newmodule)"+node->path(1)+"?"+q+"=1>"+ 
                 (roxen->QUERY(BS)?"<h2>"+a[q][0]+"</h2>": 
                  "<img border=0 alt=\""+a[q][0]+"\" src=/auto/module/"+ 
                  a[q][2]+"/"+q+" height=24 width=500>")+ 
                 "</a><blockquote><br>"+a[q][1]+"<p><br><p></blockquote>"}); 
    } 
  } 
  return res*""; 
} 
 
mapping new_module(object id, object node) 
{ 
  string varname; 
   
  if(!sizeof(id->variables)) 
    return stores(new_module_form(id, node)); 
   
  varname=indices(id->variables)[0]; 
   
  return new_module_copy(node, varname, id); 
} 
 
int low_enable_configuration(string name, string type) 
{ 
  object node; 
   
  if(strlen(name) && name[-1] == '~') 
    name = ""; 
 
  if(search(name, "/")!= -1) 
    return 0; 
   
  foreach(roxen->configurations, node) 
    if(node->name == name)  
      return 0; 
 
  switch(name) 
  { 
   case "": 
   case " ": 
   case "\t": 
   case "CVS": 
   case "Global Variables": 
   case "global variables": 
   case "Global variables": 
    return 0; 
    break; 
     
   default: 
    object o, confnode; 
     
    switch(lower_case((type/" ")[0])) 
    { 
     default: /* Minimal configuration */ 
       o=roxen->enable_configuration(name); 
      break; 
       
     case "standard": 
      o = roxen->enable_configuration(name); 
      o->enable_module("cgi#0"); 
      o->enable_module("contenttypes#0"); 
      o->enable_module("ismap#0"); 
      o->enable_module("pikescript#0"); 
      o->enable_module("htmlparse#0"); 
      o->enable_module("directories#0"); 
      o->enable_module("userdb#0"); 
      o->enable_module("userfs#0"); // I _think_ we want this. 
      o->enable_module("filesystem#0"); 
      break; 
       
     case "ipp": 
      o=roxen->enable_configuration(name); 
      o->enable_module("contenttypes#0"); 
      o->enable_module("ismap#0"); 
      o->enable_module("htmlparse#0"); 
      o->enable_module("directories#0"); 
      o->enable_module("filesystem#0"); 
      break; 
       
     case "proxy": 
      o=roxen->enable_configuration(name); 
      o->enable_module("proxy#0"); 
      o->enable_module("gopher#0"); 
      o->enable_module("ftpgateway#0"); 
      o->enable_module("contenttypes#0"); 
      o->enable_module("wais#0"); 
      break; 
       
     case "copy": 
      string from; 
      mapping tmp; 
      sscanf(type, "%*s'%s'", from); 
      tmp = roxen->copy_configuration(from, name); 
      if(!tmp) error("No configuration to copy from!\n"); 
      tmp["spider#0"]->LogFile = "../logs/"+roxenp()->short_name(name)+"/Log"; 
      roxenp()->save_it(name); 
      roxen->enable_configuration(name); 
    }     
    confnode = root->descend("Configurations"); 
    node=confnode->descend(name); 
 
    node->describer = describe_configuration; 
    node->saver = save_configuration; 
    node->data = roxen->configurations[-1]; 
    node->type = NODE_CONFIGURATION; 
    build_configuration(node); 
    node->folded=0; 
    node->change(1); 
     
    if(o = node) 
    { 
      if(o=o->descend( "Global", 1 )) 
      { 
        o->folded = 0; 
        if(o->descend( "Server URL", 1 )) 
        { 
          o->descend( "Server URL"  )->folded = 0; 
          o->descend( "Server URL"  )->change(1); 
        } 
        if(o->descend( "Listen ports", 1  )) 
        { 
          o->descend( "Listen ports"  )->folded = 0; 
          o->descend( "Listen ports"  )->change(1); 
        } 
      } 
    } 
    if(lower_case((type/" ")[0])=="standard" && (o=node)) 
    { 
      if(o=o->descend( "Filesystem", 1 )) 
      { 
        o->folded=0; 
        if(o=o->descend( "0", 1)) 
        { 
          o->folded=0; 
          if(o=o->descend( "Search path", 1)) 
          { 
            o->folded=0; 
            o->change(1); 
          } 
        } 
      } 
    } 
  } 
  return 1; 
} 
 
mapping new_configuration(object id) 
{ 
  if(!sizeof(id->variables)) 
    return stores(new_configuration_form()); 
 
  if(!id->variables->name) 
    return stores(default_head("Bad luck")+ 
                  "<blockquote><h1>No configuration name?</h1>" 
                  "Either you entered no name, or your WWW-browser " 
                  "failed to include it in the request</blockquote>"); 
   
  id->variables->name=(replace(id->variables->name,"\000"," ")/" "-({""}))*" "; 
  if(!low_enable_configuration(id->variables->name, id->variables->type)) 
    return stores(default_head("Bad luck") + 
                  "<blockquote><h1>Illegal configuration name</h1>" 
                  "The name of the configuration must contain characters" 
                  " other than space and tab, it should not end with " 
                  "~, and it must not be 'CVS', 'Global Variables' or " 
                  "'global variables', nor the name of an existing " 
                  "configuration, and the character '/' cannot be included</blockquote>"); 
  return std_redirect(root->descend("Configurations"), id); 
} 
 
int conf_auth_ok(mixed auth) 
{ 
  if(!(auth && sizeof(auth)>1)) 
    return 0; 
   
  if(sscanf(auth[1], "%s:%s", auth[0], auth[1]) < 2) 
    return 0; 
   
  if((auth[0] == roxen->QUERY(ConfigurationUser)) 
     && crypt(auth[1], roxen->QUERY(ConfigurationPassword))) 
    return 1; 
} 
 
mapping initial_configuration(object id) 
{ 
  object n2; 
  string res, error; 
   
  if(id->prestate->initial && id->variables->pass) 
  { 
    error=""; 
    if(id->variables->pass != id->variables->pass2) 
      error = "You did not type the same password twice.\n"; 
    if(!strlen(id->variables->pass)) 
      error += "You must specify a password.\n"; 
    if(!strlen(id->variables->user)) 
      error += "You must specify a username.\n"; 
    if(!strlen(error)) 
    { 
      object node; 
/*    build_root(root);*/ 
      
      // Should find the real node instead of assuming 'Globals'... 
      node = find_node("/Globals"); 
      node->folded=0; 
      node->change(1); 
       
      if(!node) 
        return stores("Fatal configuration error, no 'Globals' node found.\n"); 
       
      roxen->QUERY(ConfigurationPassword) = crypt(id->variables->pass); 
      roxen->QUERY(ConfigurationUser) = id->variables->user; 
 
      n2 = node->descend("Configuration interface", 1)->descend("Password", 1); 
      n2->data[VAR_VALUE]=roxen->QUERY(ConfigurationPassword); 
      n2->change(1);     
 
      n2 = node->descend("Configuration interface", 1)->descend("User", 1); 
      n2->data[VAR_VALUE] = roxen->QUERY(ConfigurationUser); 
      n2->change(1);     
         
      root->save(); 
      return std_redirect(root, id); 
    } 
  } 
   
  res = default_head("Welcome to Roxen Challenger"); 
 
  res += read_bytes("etc/welcome.html"); 
  if(error && strlen(error)) 
    res += "<blockquote>\n<p><b>"+error+"</b>"; 
   
  res += ("<pre>" 
          "<font size=+1>" 
          "<form action=/(initial)/Globals/>" 
          " User name <input name=user type=string>\n" 
          "  Password <input name=pass type=password>\n" 
          "     Again <input name=pass2 type=password>\n" 
//   Avoid this trap for people who like to shoot themselves in the foot. 
//   /Peter 
//      "IP-pattern <input name=pattern type=string>\n" 
          "           <input type=submit value=\"Use these values\">\n" 
          "</form></font></pre></blockquote>"); 
   
  return stores(res); 
} 
 
object module_of(object node) 
{ 
  while(node) 
  { 
    if(node->type == NODE_MODULE_COPY) 
      return node->data; 
    if(node->type == NODE_MODULE_MASTER_COPY) 
      return node->data->master; 
    node = node->up; 
  } 
  return roxen; 
} 
 
string extract_almost_top(object node) 
{ 
  if(!node) return ""; 
  for(;node && (node->up!=root);node=node->up); 
  if(!node) return ""; 
  return node->path(1); 
} 
 
 
 
 
string tablist(array(string) nodes, array(string) links, int selected) 
{ 
  array res = ({}); 
  for(int i=0; i<sizeof(nodes); i++) 
    if(i!=selected) 
      PUSH("<a href=\""+links[i]+"\"><img alt=\"_/"+ 
           nodes[i][1..strlen(nodes[i])-2]+"\\__\" src=/auto/unselected/"+ 
           replace(nodes[i]," ","%20")+" border=0></a>"); 
    else 
      PUSH("<a href=\""+links[i]+"\"><b><img alt=\"_/"+ 
           nodes[i][1..strlen(nodes[i])-2]+"\\__\" src=/auto/selected/"+ 
           replace(nodes[i]," ","%20")+" border=0></b></a>"); 
//PUSH("<br>"); 
  return res*""; 
} 
 
mapping (string:string) selected_nodes = 
([ 
  "Configurations":"/Configurations", 
  "Globals":"/Globals", 
  "Status":"/Status", 
  "Errors":"/Errors", 
]); 
 
array tabs = ({ 
  "Configurations", 
  "Globals", 
  "Status", 
  "Errors", 
}); 
 
array tab_names = ({ 
 " Virtual servers ",  
 " Global variables ", 
 " Status info ", 
 " Error log ", 
}); 
                 
 
string display_tabular_header(object node) 
{ 
  string p, s; 
   
  array links = ({ 
    selected_nodes[tabs[0]]+"?"+(bar++), 
    selected_nodes[tabs[1]]+"?"+(bar++), 
    selected_nodes[tabs[2]]+"?"+(bar++), 
    selected_nodes[tabs[3]]+"?"+(bar++), 
  }); 
 
  if(node != root) 
  { 
    s = extract_almost_top(node) - "/"; 
    selected_nodes[s] = node->path(1); 
 
    links[search(tabs,s)]="/"+s+"/"+"?"+(bar++); 
  } 
  return tablist(tab_names, links, search(tabs,s)); 
} 
 
// Return the number of unfolded nodes on the level directly below the passed 
// node. 
 
int nunfolded(object o) 
{ 
  int i; 
  if(o = o->down) 
    do { i+=!o->folded; } while(o=o->next); 
  return i; 
} 
 
 
object module_font = get_font("base_server/config/font",0,0,0,"left",1.0,1.0); 
object button_font = get_font("base_server/config/button_font",0,0,0,"left",1.0,1.0); 
 
mapping auto_image(string in, object id) 
{ 
  string key, value; 
  array trans = ({ (int)("0x"+dR),(int)("0x"+dG),(int)("0x"+dB) }); 
  mapping r; 
  mixed e; 
  object i; 
 
  string img_key = "auto/"+replace(in,"/","_")+".gif"-" "; 
   
  if(e=file_image(img_key)) 
    return e; 
   
  if(!sscanf(in, "%s/%s", key, value)) key=in; 
 
  switch(key) 
  { 
   case "module": 
     sscanf(value, "%*d/%s", value); 
     i = draw_module_header(roxen->allmodules[value][0], 
                            roxen->allmodules[value][2], 
                            module_font); 
     break; 
     
   case "button": 
     int lm,rm; 
     if(sscanf(value, "lm/%s", value)) lm=1; 
     if(sscanf(value, "rm/%s", value)) rm=1; 
     i=draw_config_button(value,button_font,lm,rm); 
     break; 
 
   case "fold": 
   case "fold2": 
     i = draw_fold((int)reverse(key)); 
     break; 
     
   case "unfold": 
   case "unfold2": 
     i = draw_unfold((int)reverse(key)); 
     break; 
 
   case "back": 
     i = draw_back((int)reverse(key)); 
     break; 
     
   case "selected": 
     i=draw_selected_button(value,button_font); 
     break; 
 
   case "unselected": 
     i=draw_unselected_button(value,button_font); 
     break; 
  } 
  if(i) 
  { 
    object o = open("roxen-images/"+img_key,"wct"); 
    e=i->map_closest(i->select_colors(64)+({trans}))->togif(@trans); 
    i=0; 
    if(o) { o->write(e); o=0; } 
#ifdef DEBUG 
    else {perror("Cannot open file for "+in+"\n");} 
#endif 
    return http_string_answer(e,"image/gif"); 
  } 
  return 0; 
} 
 
 
string remove_font(string t, mapping m, string c) 
{ 
  return "<b>"+c+"</b>"; 
} 
 
 
int nfolded(object o) 
{ 
  int i; 
  if(o = o->down) 
    do { i+=!!o->folded; } while(o=o->next); 
  return i; 
} 
 
int nfoldedr(object o) 
{ 
  object node; 
  int i; 
  i = o->folded; 
  node=o->down; 
  while(node) 
  { 
    i+=nfoldedr(node); 
    node=node->next;  
  } 
  return i; 
} 
 
 
mapping configuration_parse(object id) 
{ 
  array (string) res=({}); 
  string tmp; 
  // Is it an image? 
  if(sscanf(id->not_query, "/image/%s", tmp)) 
    return file_image(tmp) || (["data":"No such image"]); 
   
  object o; 
  int i; 
 
  id->since = 0; // We do not want 'get-if-modified-since' to work here. 
 
  // Permisson denied by address? 
  if(id->remoteaddr) 
    if(strlen(roxen->QUERY(ConfigurationIPpattern)) && 
       !glob(roxen->QUERY(ConfigurationIPpattern),id->remoteaddr)) 
      return stores("Permission denied.\n"); 
   
  // Permission denied by userid? 
  if(!id->misc->read_allow) 
  { 
    if(!(strlen(roxen->QUERY(ConfigurationPassword)) 
         && strlen(roxen->QUERY(ConfigurationUser)))) 
      return initial_configuration(id); // Never configured before 
    else if(!conf_auth_ok(id->auth)) 
      return http_auth_failed("Roxen server maintenance"); // Denied 
  } else { 
    id->prestate = aggregate_multiset(@indices(id->prestate) 
                                      &({"fold","unfold"})); 
 
    if(sizeof(id->variables)) // This is not 100% neccesary, really. 
      id->variables = ([ ]); 
  } 
 
  // Automatically generated image? 
  if(sscanf(id->not_query, "/auto/%s", tmp)) 
    return auto_image(tmp,id) || (["data":"No such image"]); 
 
  o = find_node(id->not_query); // Find the requested node (from the filename) 
 
  if(!o) // Bad node, perhaps an old bookmark or something. 
  { 
    id->referer = ({ }); 
    return std_redirect(0, id); 
  } else if(o == root) { 
    // The URL is http://config-url/, not one of the top nodes, but 
    // _above_ them. This is supposed to be some nice introductory 
    // text about the configuration interface... 
    return http_string_answer(default_head("Roxen Challenger")+ 
                              display_tabular_header(root)+ 
                              read_bytes("etc/config.html"),"text/html"); 
  } 
   
  if(sizeof(id->prestate)) 
  { 
    switch(indices(id->prestate)[0]) 
    { 
      // It is possible to mark variables as 'VAR_EXPERT', this 
      // will make it impossible to configure them whithout the 
      // 'expert' mode. It can be useful. 
    case "expert":   expert_mode = 1;  break; 
    case "noexpert": expert_mode = 0;  break; 
       
      // Fold and unfold nodes, this is _very_ simple, once all the 
      // supporting code was writte. 
    case "fold":     o->folded=1;      break; 
    case "unfold":   o->folded=0;      break; 
 
    case "moredocs":   o->moredocs=1;      break; 
    case "lessdocs":   o->moredocs=0;      break; 
 
    case "foldall": 
      o->map(lambda(object o) { o->folded=1; }); 
      break; 
 
 
    case "unfoldmodified": 
      o->map(lambda(object o) { if(o->changed) o->folded=0; }); 
      break; 
 
 
      // There is no button for this in the configuration interface, 
      // the results are quite horrible, especially when applied to 
      // one of the top nodes. 
    case "unfoldall": 
      o->map(lambda(object o) { o->folded=0; }); 
      break; 
 
     case "unfoldlevel": 
      object node; 
      node=o->down; 
      while(node) 
      { 
        node->folded=0; 
        node = node->next; 
      } 
      break; 
 
       
      // And now the actual actions.. 
       
      // Re-read a module from disk 
      // This is _not_ as easy as it sounds, since quite a lot of 
      // caches and stuff have to be invalidated.. 
    case "refresh": 
    case "reload": 
      object mod; 
      string name, modname; 
      mapping cmod; 
       
      mod = module_of(o); 
      if(!mod || mod==roxen) 
        error("This module cannot be updated.\n"); 
      name = module_short_name(mod, o->config()); 
      if(!name) 
        error("This module cannot be updated"); 
      sscanf(name, "%s#%*s", modname); 
 
      if(!(cmod = o->config()->modules[ modname ])) 
        error("This module cannot be updated"); 
       
      o->save(); 
      cache_remove("modules", modname); 
 
      // Not usefull since load_module() also does it. 
      // _master->set_inhibit_compile_errors(""); 
       
      if(!o->config()->load_module(modname)) 
      { 
        mapping rep; 
        rep = http_string_answer("The reload of this module failed.\n" 
                                 "This is (probably) the reason:\n<pre>" 
                                 + roxen->last_error + "</pre>" ); 
        // _master->set_inhibit_compile_errors(0); 
        return rep; 
      } 
      // _master->set_inhibit_compile_errors(0); 
      object mod; 
      if(!o->config()->disable_module(name))error("Failed to disable module.\n"); 
      if(!(mod=o->config()->enable_module(name)))error("Failed to enable module.\n"); 
       
      o->clear(); 
//    roxen->fork_it(); 
       
      if(mappingp(o->data)) 
      { 
        o->data = o->config()->modules[modname]; 
        build_module(o); 
      } else { 
        object n = o->up; 
        n->clear(); 
        n->data = n->config()->modules[modname]; 
        build_module(n); 
      } 
      break; 
       
      /* Shutdown Roxen... */ 
    case "shutdown":     
      return roxen->shutdown(); 
       
      /* Restart Roxen, somewhat more nice. */ 
    case "restart":      
       return roxen->restart(); 
       
       /* Rename a configuration. Not Yet Used... */ 
    case "rename": 
      if(o->type == NODE_CONFIGURATION) 
      { 
        mv("configurations/"+o->data->name,  
           "configurations/"+id->variables->name); 
        o->data->name=id->variables->name; 
      } 
      break; 
       
      /* This only asks "do you really want to...", it does not delete 
       * the node */ 
 
    case "delete":       
     PUSH(default_head("Roxen Configuration")); 
//     PUSH("<hr noshade>"); 
       
      switch(o->type) 
      { 
       case NODE_CONFIGURATION: 
        PUSH("<font size=+2>Do you really want to delete the configuration "+ 
             o->data->name + ", all its modules and their copies?" 
             "\n\n<p></font>"); 
        break; 
         
       case NODE_MODULE_MASTER_COPY: 
       case NODE_MODULE: 
        PUSH("<font size=+2>Do you really want to delete the module "+ 
             o->data->name + ", and its copies?\n\n<p></font>"); 
        break; 
         
       case NODE_MODULE_COPY_VARIABLES: 
         
       case NODE_MODULE_COPY: 
        PUSH("<font size=+2>Do you really want to delete this copy " 
             " of the module "+ o->up->data->name + "?\n\n<p></font>"); 
        break; 
         
       case NODE_CONFIGURATIONS: 
        return stores("You don't want to do that...\n"); 
      } 
      PUSH("<blockquote><font size=+2><i>This action cannot be undone.\n\n<p></font>"+ 
           TABLEP("<table>", "") +"<tr><td><form action="+ 
           o->path(1)+">" 
           "<input type=submit value=\"No, I do not want to delete it\"> " 
           "</form></td><td><form action=/(really_delete)"+o->path(1)+ 
           "><input type=submit value=\"Go ahead\"></form></td></tr> " 
           "</table></blockquote>"); 
       
      return stores(res*""); 
      break; 
       
      /* When this has been called, the node will be * _very_ deleted 
       * The amount of work needed to delete a node does vary 
       * depending on the node, since there is no 'zap' function in 
       * the nodes at the moment. I will probably move this code into 
       * function-pointers in the nodes. 
       */ 
 
    case "really_delete": 
      id->referer = ({ CONFIG_URL + o->up->path(1) }); 
       
      switch(o->type) 
      { 
       case NODE_CONFIGURATION: 
        object oroot; 
         
        for(i=0; i<sizeof(roxen->configurations); i++) 
          if(roxen->configurations[i] == o->data) 
            break; 
         
        if(i==sizeof(roxen->configurations)) 
          error("Configuration not found.\n"); 
         
        roxen->remove_configuration(o->data->name); 
 
        if(roxen->configurations[i]->ports_open) 
          map(values(roxen->configurations[i]->ports_open), destruct); 
        destruct(roxen->configurations[i]); 
         
        roxen->configurations =  
          roxen->configurations[..i-1] + roxen->configurations[i+1..]; 
         
        o->change(-o->changed); 
        o->dest(); 
        break; 
         
       case NODE_MODULE_COPY_VARIABLE: 
       case NODE_MODULE_COPY_VARIABLES: 
        // Ehum? Lets zap the module instead of it's variables... 
        o=o->up; 
         
       case NODE_MODULE_COPY: 
        string name; 
        object n; 
         
        name = module_short_name(o->data, o->config()); 
        o->config()->disable_module(name); 
        // Remove the suitable part of the configuration file. 
        roxen->remove(name, o->config()); 
        o->change(-o->changed); 
        n=o->up; 
        o->dest(); 
         
        if(!objectp(n)) 
        { 
          o=root;  
          // Error, really, no parent module for this module class. 
        } else { 
          if(!sizeof(n->data->copies)) 
          { 
            // No more instances in this module, let's zap the whole class. 
            /*  
               object hmm=n->config(); 
               if(!hmm) error("Cannot find configuration node for module.\n"); 
               */ 
 
            // The configuration node. n->config() seems to be  
            // n->up->data... 
            o=n->up;  
             
            n->change(-n->changed); 
            n->dest(); 
            build_configuration(o); 
            return std_redirect(o, 0);  
            // Bugs and returns to the top if id is set... 
          } else 
            o = n; 
        } 
        break; 
         
       case NODE_MODULE_MASTER_COPY: 
       case NODE_MODULE: 
         // A 'one of a kind' module. 
        if(o->data->copies) 
        { 
          if(sizeof(o->data->copies)) 
          { 
            int i; 
            array a,b; 
            a=indices(o->data->copies); 
            b=values(o->data->copies); 
            name=o->config()->otomod[b[0]]; 
            i=sizeof(a); 
            while(i--)  
            { 
              o->config()->disable_module(name+"#"+a[i]); 
              roxen->remove(name+"#"+a[i], o->config()); 
            } 
          } else if(o->data->master) { 
            name=o->config()->otomod[o->data->enabled]; 
          }  
        } else if(o->data->enabled) { 
          name=o->config()->otomod[o->data->enabled]; 
          o->config()->disable_module(name+"#0"); 
          roxen->remove(name+"#0", o->config()); 
        } 
        o->change(-o->changed); 
        o->dest(); 
        break; 
      } 
      break; 
 
 
      // Create a new configuration. All the work is done in another 
      // function.. This _should_ be the case with some of the other 
      // actions too. 
     case "newconfig": 
       id->referer = ({ CONFIG_URL + o->path(1) }); 
       return new_configuration(id); 
 
 
       // Save changes done to the node 'o'. Currently 'o' is the root 
       // node most of the time, thus saving _everything_. 
     case "save": 
      if(save_it(id, o)) 
        return 0; 
      break; 
 
 
      // Set the password and username, the first time, or when 
      // the action 'changepass' is requested. 
     case "initial": 
     case "changepass": 
      return initial_configuration(id); 
       
 
      // Hmm. No idea, really. Beats me :-)  /Per 
    case "new": 
      o->new(); 
      break; 
 
      // Add a new module to the current configuration. 
    case "newmodule": 
      id->referer = ({ CONFIG_URL + o->path(1) }); 
      return new_module(id,o); 
 
 
      // Add a new copy of the current module to the current configuration. 
     case "newmodulecopy": 
      id->referer = ({ CONFIG_URL + o->path(1) }); 
      new_module_copy_copy(o, id); 
      break; 
 
 
      // Set a variable to a new (or back to an old..) value. 
     case "set": 
      mixed tmp; 
      o->error = 0; 
      if(sizeof(id->variables)) 
        tmp=decode_form_result(values(id->variables)[0], 
                               o->data[VAR_TYPE], o, id->variables); 
      else 
        tmp=0; 
      if(!module_of(o)) perror("No module for this node.\n"); 
      if(!o->error && module_of(o)  
         && module_of(o)->check_variable) 
        o->error = module_of(o)->check_variable(o->data[VAR_SHORTNAME], tmp); 
         
      if(!o->error) 
        if(!equal(tmp, o->data[VAR_VALUE])) 
        { 
          if(!o->original) 
            o->original = o->data[VAR_VALUE]; 
          o->data[VAR_VALUE]=tmp; 
          if(equal(o->original, tmp)) 
            o->change(-1); 
          else if(!o->changed) 
            o->change(1); 
        }  
      break; 
    } 
    return std_redirect(o, id); 
  } 
   
  PUSH(default_head("Roxen server configuration", root->changed?o->path(1):0)); 
  PUSH("<dl>\n"); 
  PUSH("\n"+display_tabular_header( o )+"\n"); 
  PUSH("<p>"); 
  if(o->up != root && o->up) 
    PUSH("<a href=\""+ o->up->path(1)+"?"+(bar++)+"\">" 
         "<img src=/auto/back alt='[Up]' align=left hspace=0 border=0></a>\n"); 
 
  if(i=o->folded) o->folded=0; 
  string tmp = o->describe(1); 
  if(!id->supports->font) 
    tmp = parse_html(tmp, ([]),(["font":remove_font, ])); 
  PUSH(tmp); 
  o->folded=i; 
   
  PUSH("</dl>"); 
  PUSH("<p><br clear=all>&nbsp;\n"); 
 
  int lm=1; 
   
  if(o->type == NODE_CONFIGURATIONS) 
    BUTTON(newconfig, "New virtual server", left); 
   
  if(o->type == NODE_CONFIGURATION) 
    BUTTON(newmodule, "New module", left); 
   
  if(o->type == NODE_MODULE) 
  { 
    BUTTON(delete, "Delete module", left); 
    if(o->data->copies) 
      BUTTON(newmodulecopy, "Copy module", left); 
  } 
 
  i=0; 
  if(o->type == NODE_MODULE_MASTER_COPY || o->type == NODE_MODULE_COPY  
     || o->type == NODE_MODULE_COPY_VARIABLES) 
  { 
    BUTTON(delete, "Delete module", left); 
    BUTTON(refresh, "Reload module", left); 
  } 
   
  if(o->type == NODE_CONFIGURATION) 
    BUTTON(delete,"Delete this server", left); 
 
  if(nunfolded(o)) 
    BUTTON(foldall, "Fold all",left); 
  if(o->changed) 
    BUTTON(unfoldmodified, "Unfold modified", left); 
 
  if(nfolded(o)) 
    BUTTON(unfoldlevel, "Unfold level", left); 
//  else if(nfoldedr(o)) 
//    BUTTON(unfoldall, "Unfold all", left); 
 
   
  if(!lm) 
  { 
    PUSH("<img border=0 alt=\"\" hspacing=0 vspacing=0 src=/auto/button/rm/%20>"); 
    PUSH("</nobr><br clear=all>"); 
    lm=1; 
  } 
 
  if((o->changed||root->changed)) 
  { 
    BUTTON(save, "Save", left); 
    PUSH("<img border=0 alt=\"\" hspacing=0 vspacing=0 src=/auto/button/%20%20%20%20%20%20>"); 
  } 
  BUTTON(restart, "Restart", left); 
  BUTTON(shutdown,"Shutdown", left); 
 
  PUSH("<img border=0 alt=\"\" hspacing=0 vspacing=0 src=/auto/button/rm/%20>"); 
  PUSH("</nobr><br clear=all>"); 
//  PUSH("<p align=right><font size=-1 color=blue><a href=$docurl><font color=blue>"+roxen->real_version +"</font></a></font></p>"); 
  PUSH("</body>\n"); 
  return stores(res*""); 
}