Logo Search packages:      
Sourcecode: sbnc version File versions  Download package

bool CCore::MakeConfig ( void   )  [private]

MakeConfig

Creates a simple configuration file (in case the user doesn't have one yet).

Definition at line 1670 of file Core.cpp.

References BuildPath(), CConfigModule::CreateConfigObject(), CConfig::Destroy(), IsValidUsername(), m_ConfigModule, CConfig::WriteInteger(), and CConfig::WriteString().

Referenced by CCore().

                           {
      int Port;
      char Buffer[30];
      char User[81], Password[81], PasswordConfirm[81];
      char *File;
      CConfig *MainConfig, *UserConfig;

      safe_printf("No valid configuration file has been found. A basic\n"
            "configuration file can be created for you automatically. Please\n"
            "answer the following questions:\n");

      while (true) {
            safe_printf("1. Which port should the bouncer listen on (valid ports are in the range 1025 - 65535): ");
            Buffer[0] = '\0';
            safe_scan(Buffer, sizeof(Buffer));
            Port = atoi(Buffer);

            if (Port == 0) {
                  return false;
            }

#ifdef _WIN32
            if (Port <= 1024 || Port >= 65536) {
#else
            if (Port <= 0 || Port >= 65536) {
#endif
                  safe_printf("You did not enter a valid port. Try again. Use 0 to abort.\n");
            } else {
                  break;
            }
      }

      while (true) {
            safe_printf("2. What should the first user's name be? ");
            User[0] = '\0';
            safe_scan(User, sizeof(User));
      
            if (strlen(User) == 0) {
                  return false;
            }

            if (IsValidUsername(User) == false) {
                  safe_printf("Sorry, this is not a valid username. Try again.\n");
            } else {
                  break;
            }
      }

      while (true) {
            safe_printf("Please note that passwords will not be echoed while you type them.\n");
            safe_printf("3. Please enter a password for the first user: ");

            Password[0] = '\0';
            safe_scan_passwd(Password, sizeof(Password));

            if (strlen(Password) == 0) {
                  return false;
            }

            safe_printf("\n4. Please confirm your password by typing it again: ");

            PasswordConfirm[0] = '\0';
            safe_scan_passwd(PasswordConfirm, sizeof(PasswordConfirm));

            safe_printf("\n");

            if (strcmp(Password, PasswordConfirm) == 0) {
                  break;
            } else {
                  safe_printf("The passwords you entered do not match. Please try again.\n");
            }
      }

      asprintf(&File, "users/%s.conf", User);

      // BuildPath is using a static buffer
      mkdir(BuildPath("users"));
      SetPermissions(BuildPath("users"), S_IRUSR | S_IWUSR | S_IXUSR);

      MainConfig = m_ConfigModule->CreateConfigObject("sbnc.conf", NULL);

      MainConfig->WriteInteger("system.port", Port);
      MainConfig->WriteInteger("system.md5", 1);
      MainConfig->WriteString("system.users", User);

      safe_printf("Writing main configuration file...");

      MainConfig->Destroy();

      safe_printf(" DONE\n");

      UserConfig = m_ConfigModule->CreateConfigObject(File, NULL);

      UserConfig->WriteString("user.password", UtilMd5(Password, GenerateSalt()));
      UserConfig->WriteInteger("user.admin", 1);

      safe_printf("Writing first user's configuration file...");

      UserConfig->Destroy();

      safe_printf(" DONE\n");

      free(File);

      return true;
}


Generated by  Doxygen 1.6.0   Back to index