Branch: Tag:

2000-04-03

2000-04-03 13:48:04 by Per Hedbor <ph@opera.com>

Verify port input

Rev: server/bin/create_configif.pike:1.16

1:   /* -  * $Id: create_configif.pike,v 1.15 2000/03/30 23:32:26 nilsson Exp $ +  * $Id: create_configif.pike,v 1.16 2000/04/03 13:48:04 per Exp $    *    * Create an initial administration interface server.    */
64:       do    { -  if(!admin) { +  if(!admin) +  {    name = rl->read( "Server name [Administration Interface]: " );    if( !strlen(name-" ") )    name = "Administration Interface";    -  port = rl->read( "Port ["+def_port+"]: "); +  int port_ok; +  while( !port_ok ) +  { +  string protocol, host, path; +  +  port = rl->read( "Port URL ["+def_port+"]: ");    if( !strlen(port-" ") )    port = def_port; -  +  else if( (int)port ) +  { +  int ok; +  while( !ok ) +  { +  switch( protocol = lower_case(rl->read( "Protocol [http]: ")) ) +  { +  case "": +  protocol = "http"; +  case "http": +  case "https": +  port = protocol+"://*:"+port+"/"; +  ok=1; +  break; +  default: +  write("Only http and https are supported for the " +  "configuration interface\n"); +  break;    } -  +  } +  }    -  do { +  if( sscanf( port, "%[^:]://%[^/]%s", protocol, host, path ) == 3) +  { +  switch( lower_case(protocol) ) +  { +  case "http": +  case "https": +  // Verify hostname here... +  port = lower_case( protocol )+"://"+host+path; +  port_ok = 1; +  break; +  default: +  write("Only http and https are supported for the " +  "configuration interface\n"); +  break; +  } +  } +  } +  } +  +  do +  {    user = rl->read( "Administrator user name [administrator]: ");    } while(((search(user, "/") != -1) || (search(user, "\\") != -1)) &&    write("User name may not contain slashes.\n"));
92:    } while( strlen( passwd2 = rl->read( "Ok? [y]: " ) ) && passwd2[0]=='n' );       +  if( !admin ) +  {    string community_user, community_password, proxy_host="", proxy_port="80";    string community_userpassword="";    int use_update_system=0;
131:    }    }    } -  -  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>Administration Interface Default User</str> -  <str>password</str> : <str>" + crypt(password) + #"</str> -  <str>name</str> : <str>" + user + "</str>\n</map>" )); -  -  if(admin) -  { -  write("Administrator user \"" + user + "\" created."); -  return 0; -  } -  +     mkdirhier( configdir );    Stdio.write_file( configdir+replace( name, " ", "_" ),   replace(
188:    ({ name, port, (string)use_update_system, proxy_port,    proxy_host, community_userpassword }) ));    write("Administration interface created\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>Administration Interface Default User</str> +  <str>password</str> : <str>" + crypt(password) + #"</str> +  <str>name</str> : <str>" + user + "</str>\n</map>" )); +  +  write("Administrator user \"" + user + "\" created.");   }