2d5b1e2000-03-07Henrik Grubbström (Grubba) /* * $Id: create_configif.pike,v 1.6 2000/03/07 18:52:37 grubba Exp $ * * Create an initial configuration interface server. */
cd03b41999-11-22Per Hedbor 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
cbc7ea2000-02-19Martin Nilsson  write( "Roxen 2.0 configuration interface installation script\n");
cd03b41999-11-22Per Hedbor  configdir = Getopt.find_option(argv, "d",({"config-dir","configuration-directory" }),
62d9572000-02-04Per Hedbor  ({ "ROXEN_CONFIGDIR", "CONFIGURATIONS" }),
cd03b41999-11-22Per Hedbor  "../configurations");
cbc7ea2000-02-19Martin Nilsson  int admin = has_value(argv, "-a");
cd03b41999-11-22Per Hedbor 
cbc7ea2000-02-19Martin Nilsson  if(configdir[-1] != '/')
46132e1999-11-26Honza Petrous  configdir+="/";
cbc7ea2000-02-19Martin Nilsson  if(admin) write( "Creating an administrator user.\n" ); else write( "Creating a configuration interface server in "+configdir+"\n");
cd03b41999-11-22Per Hedbor 
62d9572000-02-04Per Hedbor  do
cd03b41999-11-22Per Hedbor  {
cbc7ea2000-02-19Martin Nilsson  if(!admin) { name = rl->read( "Server name [Configuration Interface]: " ); if( !strlen(name-" ") ) name = "Configuration Interface";
cd03b41999-11-22Per Hedbor 
cbc7ea2000-02-19Martin Nilsson  port = rl->read( "Port ["+def_port+"]: "); if( !strlen(port-" ") ) port = def_port; }
cd03b41999-11-22Per Hedbor 
2d5b1e2000-03-07Henrik Grubbström (Grubba)  do { user = rl->read( "Administrator user name [administrator]: "); } while(((search(user, "/") != -1) || (search(user, "\\"))) && write("User name may not contain slashes.\n"));
cd03b41999-11-22Per Hedbor  if( !strlen(user-" ") ) user = "administrator";
62d9572000-02-04Per Hedbor  do
cd03b41999-11-22Per Hedbor  { 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' );
2d5b1e2000-03-07Henrik Grubbström (Grubba)  string ufile=(configdir+"_configinterface/settings/" + user + "_uid");
cd03b41999-11-22Per Hedbor  mkdirhier( ufile );
2d5b1e2000-03-07Henrik Grubbström (Grubba)  Stdio.write_file(ufile,
4906d02000-03-01Per Hedbor 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>
2d5b1e2000-03-07Henrik Grubbström (Grubba)  <str>password</str> : <str>" + crypt(password) + #" <str>name</str> : <str>" + user + "\n</map>" ));
cd03b41999-11-22Per Hedbor 
4906d02000-03-01Per Hedbor  if(admin) {
2d5b1e2000-03-07Henrik Grubbström (Grubba)  write("Administrator user \"" + user + "\" created.");
cbc7ea2000-02-19Martin Nilsson  return 0; }
cd03b41999-11-22Per Hedbor  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"); }