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
  
/* 
 * $Id: create_configif.pike,v 1.6 2000/03/07 18:52:37 grubba Exp $ 
 * 
 * Create an initial configuration interface server. 
 */ 
 
int mkdirhier(string from) 
{ 
  string a, b; 
  array f; 
 
  f=(from/"/"); 
  b=""; 
 
  foreach(f[0..sizeof(f)-2], a) 
  { 
    mkdir(b+a); 
    b+=a+"/"; 
  } 
} 
 
 
int main(int argc, array argv) 
{ 
  Stdio.Readline rl = Stdio.Readline(); 
  string name, user, password, configdir, port; 
  string passwd2; 
 
  rl->redisplay( 1 ); 
 
#if constant( SSL3 ) 
  string def_port = "https://*:"+(random(20000)+10000)+"/"; 
#else 
  string def_port = "http://*:"+(random(20000)+10000)+"/"; 
#endif 
 
  write( "Roxen 2.0 configuration interface installation script\n"); 
 
  configdir = 
   Getopt.find_option(argv, "d",({"config-dir","configuration-directory" }), 
                      ({ "ROXEN_CONFIGDIR", "CONFIGURATIONS" }), 
                      "../configurations"); 
  int admin = has_value(argv, "-a"); 
 
  if(configdir[-1] != '/') 
    configdir+="/"; 
  if(admin) 
    write( "Creating an administrator user.\n" ); 
  else 
    write( "Creating a configuration interface server in "+configdir+"\n"); 
 
  do 
  { 
    if(!admin) { 
      name = rl->read( "Server name [Configuration Interface]: " ); 
      if( !strlen(name-" ") ) 
        name = "Configuration Interface"; 
 
      port = rl->read( "Port ["+def_port+"]: "); 
      if( !strlen(port-" ") ) 
        port = def_port; 
    } 
 
    do { 
      user = rl->read( "Administrator user name [administrator]: "); 
    } while(((search(user, "/") != -1) || (search(user, "\\"))) && 
            write("User name may not contain slashes.\n")); 
    if( !strlen(user-" ") ) 
      user = "administrator"; 
 
    do 
    { 
      rl->get_input_controller()->dumb=1; 
      password = rl->read( "Administrator Password: "); 
      passwd2 = rl->read( "Administrator Password (again): "); 
      rl->get_input_controller()->dumb=0; 
      write("\n"); 
    } while(!strlen(password) || (password != passwd2)); 
  } while( strlen( passwd2 = rl->read( "Ok? [y]: " ) ) && passwd2[0]=='n' ); 
 
  string ufile=(configdir+"_configinterface/settings/" + user + "_uid"); 
  mkdirhier( ufile ); 
  Stdio.write_file(ufile, 
string_to_utf8(#"<?XML version=\"1.0\"  encoding=\"UTF-8\"?> 
<map> 
  <str>permissions</str> : <a> <str>Everything</str> </a> 
  <str>real_name</str>   : <str>Configuration Interface Default User</str> 
  <str>password</str>    : <str>" + crypt(password) + #" 
  <str>name</str>        : <str>" + user + "\n</map>" )); 
 
  if(admin) 
  { 
    write("Administrator user \"" + user + "\" created."); 
    return 0; 
  } 
 
  mkdirhier( configdir ); 
  Stdio.write_file( configdir+replace( name, " ", "_" ), 
replace( 
#" 
<!-- -*- html -*- --> 
<?XML version=\"1.0\"?> 
 
<region name='EnabledModules'> 
  <var name='config_filesystem#0'> <int>1</int>  </var> <!-- Configration Filesystem --> 
</region> 
 
<region name='spider#0'> 
  <var name='Domain'> <str></str> </var> 
  <var name='MyWorldLocation'><str></str></var> 
  <var name='URLs'> <a> <str>$URL$</str></a> </var> 
 
  <var name='comment'> 
    <str>Automatically created by create_configuration</str> 
  </var> 
 
  <var name='name'> 
    <str>$NAME$</str> 
  </var> 
</region>", 
 ({ "$NAME$", "$URL$" }), 
 ({ name, port }) )); 
  write("Configuration interface created\n"); 
 
}