コード例 #1
0
void ProxySettings::toOptions(OptionsTree* o, QString base) const
{
	o->setOption(base + ".host", host);
	o->setOption(base + ".port", port);
	o->setOption(base + ".url", url);
	o->setOption(base + ".useAuth", useAuth);
	o->setOption(base + ".user", user);
	o->setOption(base + ".pass", encodePassword(pass, PASSWORDKEY));
}
コード例 #2
0
ファイル: accounts.cpp プロジェクト: Miguel-J/eneboo-core
void Account::saveSettings()
{
  QString group = QString("/Aethera/Accounts/") + accname + "/";
  
//  qDebug("Save Account Path=%s", group.latin1());
  
  // receive account type
  switch( type )
  {
    case Account::POP3 :
      Settings::instance()->writeEntry(group+"Type", "POP3");
      break;
    case Account::IMAP4 :
      Settings::instance()->writeEntry(group+"Type", "IMAP4");
      break;
    default:
      Settings::instance()->writeEntry(group+"Type", "MAILBOX");
      break;
  }
  
  // send account type
  switch( s_type )
  {
    case Account::Qmail :
      Settings::instance()->writeEntry(group+"SendType", "Qmail");
      break;
    case Account::SMTP :
      Settings::instance()->writeEntry(group+"SendType", "SMTP");
      break;
    case Account::Sendmail :
    default:
      Settings::instance()->writeEntry(group+"SendType", "Sendmail");
      break;
  }
  
  // receive account auth type
  switch( auth )
  {
    case LOGIN:
      Settings::instance()->writeEntry(group+"AuthType", "LOGIN");
      break;
    case PLAIN:
      Settings::instance()->writeEntry(group+"AuthType", "PLAIN");
      break;
    case DIGEST_MD5:
      Settings::instance()->writeEntry(group+"AuthType", "DIGEST_MD5");
      break;
    case CRAM_MD5:
      Settings::instance()->writeEntry(group+"AuthType", "CRAM_MD5");
      break;
    case NONE:
    default:
      Settings::instance()->writeEntry(group+"AuthType", "NONE");
      break;
  }
  
  // send account auth type
  switch( s_auth )
  {
    case LOGIN:
      Settings::instance()->writeEntry(group+"SendAuthType", "LOGIN");
      break;
    case PLAIN:
      Settings::instance()->writeEntry(group+"SendAuthType", "PLAIN");
      break;
    case DIGEST_MD5:
      Settings::instance()->writeEntry(group+"SendAuthType", "DIGEST_MD5");
      break;
    case CRAM_MD5:
      Settings::instance()->writeEntry(group+"SendAuthType", "CRAM_MD5");
      break;
    case NONE:
    default:
      Settings::instance()->writeEntry(group+"SendAuthType", "NONE");
      break;
  }
  
  // SMTP server and port
  Settings::instance()->writeEntry(group + "Smtp", smtp);
  Settings::instance()->writeEntry(group + "SPort", s_port);
  
  // send login
  Settings::instance()->writeEntry(group + "SendUser", s_user);

  // has password?
  Settings::instance()->writeEntry(group + "SendRememberPassword", s_haspassword);
  // password
  if( s_haspassword )
    Settings::instance()->writeEntry(group + "SendPassword", QString(encodePassword(s_password)) );

  // Send SSL
  Settings::instance()->writeEntry(group + "SendSSL", s_ssl);
    
  // Send TLS
  Settings::instance()->writeEntry(group + "SendTLS", s_tls);
    
  // Send uses SSL Certificates
  Settings::instance()->writeEntry(group + "SendCertificates", s_useCertificates);
    
  // "From" address
  Settings::instance()->writeEntry(group + "From", from);

  // "Reply-To" address
  Settings::instance()->writeEntry(group + "Reply To", reply);

  // full user name
  Settings::instance()->writeEntry(group + "Name", name);

  // speed
  Settings::instance()->writeEntry(group + "Speed", speed);

  // max download
  Settings::instance()->writeEntry(group + "Max download", max_dl);

  // enabled
  Settings::instance()->writeEntry(group + "Enabled", enabled);
    
  // max download action
//  Settings::instance()->writeEntry(group + "Max action", max_action);

  if(type==MAILBOX)
    Settings::instance()->writeEntry(group + "Mailbox", mbox);
  else
  {
    Settings::instance()->writeEntry(group + "Server", server);
    Settings::instance()->writeEntry(group + "Port", port);

    // server login
    Settings::instance()->writeEntry(group + "User", user);

    // has password?
    Settings::instance()->writeEntry(group + "Remember password", haspassword);
    // password
    if( haspassword )
      Settings::instance()->writeEntry(group + "Password", QString(encodePassword(password)) );

    // SSL
    Settings::instance()->writeEntry(group + "SSL", ssl);
    
    // TLS
    Settings::instance()->writeEntry(group + "TLS", tls);
    
    // SSL Certificates
    Settings::instance()->writeEntry(group + "Certificates", useCertificates);
    
    if(type==POP3) // POP3 specific options
    {
      // persistence
      Settings::instance()->writeEntry(group + "Persistence", persistence);

      // leave on server
      Settings::instance()->writeEntry(group + "Leave on server", leave);
      
      // sync on delete
      Settings::instance()->writeEntry(group + "Sync", sync);

      // retrieve sorted by size
      Settings::instance()->writeEntry(group + "Sorted", sorted);
    }
    else // IMAP specific options
    {
      Settings::instance()->writeEntry(group + "Mailbox", mbox);
      Settings::instance()->writeEntry(group + "Kolab", groupware);
      
      if(groupware)
      {
        Settings::instance()->writeEntry(group + "Kolab/Calendar", calendarFolder);
        Settings::instance()->writeEntry(group + "Kolab/Contacts", contactsFolder);
        Settings::instance()->writeEntry(group + "Kolab/Notes", notesFolder);
        Settings::instance()->writeEntry(group + "Kolab/ToDo", todoFolder);
      }
    }
  }
  
  Settings::forceWrite();
}
コード例 #3
0
int main (int argc, char **argv)
{
  unsigned errorCode;	
  char cookieName[COOKIE_NAME_LENGTH +1];
  char cookieValue[COOKIE_VALUE_LENGTH +1];
  char cookieFileName[MAX_LENGTH_LONG_FILENAME +1];
  char temp[10 +1];
  char givenId[20 +1];
  userDataType userData;
  userIdType callerOfProgramId;

  if ((errorCode = mlCgiInitialize ()) != ML_CGI_OK)
  {
    if (errorCode == ML_CGI_FATAL_ERROR)
      showHtmlErrorPage (FATAL_ERROR);
    if (errorCode == ML_CGI_MEMORY_ALLOCATION_ERROR)
      showHtmlErrorPage (MEMORY_ALLOCATION_ERROR);
    if (errorCode == ML_CGI_INVALID_CONTENT_LENGTH)
      showHtmlErrorPage (INVALID_CONTENT_LENGTH);
    if (errorCode == ML_CGI_IO_ERROR)
      showHtmlErrorPage (CGI_IO_ERROR);
    if (errorCode == ML_CGI_INVALID_CONTENT_TYPE)
      showHtmlErrorPage (INVALID_CONTENT_TYPE);
    if (errorCode == ML_CGI_INVALID_REQUEST_METHOD)
      showHtmlErrorPage (INVALID_REQUEST_METHOD);
    exit (ML_CGI_OK);
  }

  if (!isCgi)
  {
    printf ("%s\n", showTextErrorMessage (IS_NOT_CGI));
    exit (ML_CGI_OK);
  }
	  
  mlCgiBeginHttpHeader ("text/html");
    
  if ((errorCode = mlCgiGetFormStringNoNewLines ("cookieName", cookieName, COOKIE_NAME_LENGTH)) != ML_CGI_OK)
  {
    mlCgiEndHttpHeader ();
    mlCgiFreeResources ();
    if (errorCode == ML_CGI_FORM_FIELD_NOT_FOUND)
      showHtmlErrorPage (FORM_FIELD_NOT_FOUND);
    if (errorCode == ML_CGI_INVALID_FORM_LENGTH)
      showHtmlErrorPage (INVALID_FORM_FIELD_LENGTH);
    exit (ML_CGI_OK);
  }

  if ((errorCode = mlCgiGetSpecificCookie (cookieName, COOKIE_NAME_LENGTH, cookieValue, COOKIE_VALUE_LENGTH)) != ML_CGI_OK)
  {
    mlCgiEndHttpHeader();
    mlCgiFreeResources ();
    if (errorCode == ML_CGI_INVALID_COOKIE_NAME)     
      showHtmlErrorPage (INVALID_COOKIE_NAME);
    if (errorCode == ML_CGI_INVALID_COOKIE_VALUE)
      showHtmlErrorPage (INVALID_COOKIE_VALUE);
    if (errorCode == ML_CGI_COOKIE_NOT_FOUND)
      showHtmlErrorPage (COOKIE_NOT_FOUND);
    exit (ML_CGI_OK); 
  }
  
  if ((errorCode = validateCookie (cookieName, cookieValue, mlCgiEnvironmentVariablesValues[ML_CGI_REMOTE_ADDRESS])) != OK)
  {
    if (errorCode != VALIDATE_COOKIE__COOKIE_FILE_DOES_NOT_EXIST)
    {
      if ((errorCode = getCookieValue (cookieName, cookieValue)) != OK)
      {
        mlCgiEndHttpHeader ();
        mlCgiFreeResources ();
        showHtmlErrorPage (errorCode);
        exit (ML_CGI_OK);
      }
      if ((errorCode = mlCgiSetCookie (cookieName, cookieValue, 0, NULL, NULL, NULL)) != ML_CGI_OK)
      {
        mlCgiEndHttpHeader();
        mlCgiFreeResources ();
        if (errorCode == ML_CGI_INVALID_COOKIE_NAME)     
          showHtmlErrorPage (INVALID_COOKIE_NAME);
        if (errorCode == ML_CGI_INVALID_COOKIE_VALUE)
          showHtmlErrorPage (INVALID_COOKIE_VALUE);
        if (errorCode == ML_CGI_INVALID_COOKIE_EXPIRATION)
          showHtmlErrorPage (INVALID_COOKIE_EXPIRATION);
        exit (ML_CGI_OK); 
      }
      if ((errorCode = getLongFilename (COOKIES_DIR, cookieName, cookieFileName)) != OK)
      {
        mlCgiEndHttpHeader();
        mlCgiFreeResources ();
        showHtmlErrorPage (errorCode);
        exit (ML_CGI_OK); 
      }
      remove (cookieFileName); 
    }
    mlCgiEndHttpHeader();
    mlCgiFreeResources ();
    showHtmlErrorPage (errorCode);
    exit (ML_CGI_OK); 
  }
  
  if ((errorCode = mlCgiGetFormStringNoNewLines ("userId", givenId, 20)) != ML_CGI_OK)
  {
    mlCgiEndHttpHeader ();
    mlCgiFreeResources ();
    if (errorCode == ML_CGI_FORM_FIELD_NOT_FOUND)
      showHtmlErrorPage (FORM_USER_ID_NOT_FOUND);
    if (errorCode == ML_CGI_INVALID_FORM_LENGTH)
      showHtmlErrorPage (INVALID_FORM_USER_ID_LENGTH);
    exit (ML_CGI_OK);
  }
  userData.userId   = strtoul (givenId   , NULL, 10);
  callerOfProgramId = strtoul (cookieName, NULL, 10); 
  
  if ((callerOfProgramId != 0) && (userData.userId != callerOfProgramId))
  {
    mlCgiEndHttpHeader ();
    mlCgiFreeResources ();
    showHtmlErrorPage (ONLY_THE_ADMINISTRATOR_CAN_EDIT_DATA_OF_OTHERS_USERS);
    exit (ML_CGI_OK);
  }
  
  if ((errorCode = getDataFromId (userData.userId, &userData)) != OK)
  {
    mlCgiEndHttpHeader ();
    mlCgiFreeResources ();
    showHtmlErrorPage (errorCode);
    exit (ML_CGI_OK);
  }
    
  if ((errorCode = mlCgiGetFormStringNoNewLines ("name", userData.name, MAX_LENGTH_NAME)) != ML_CGI_OK)
  {
    mlCgiEndHttpHeader ();
    mlCgiFreeResources ();
    if (errorCode == ML_CGI_FORM_FIELD_NOT_FOUND)
      showHtmlErrorPage (FORM_NAME_NOT_FOUND);
    if (errorCode == ML_CGI_INVALID_FORM_LENGTH)
      showHtmlErrorPage (INVALID_FORM_NAME_LENGTH);
    exit (ML_CGI_OK);
  }
  
  if (userData.category == webUser)  
  {
    if ((errorCode = mlCgiGetFormStringNoNewLines ("email", userData.email, MAX_LENGTH_EMAIL)) != ML_CGI_OK)
    {
      mlCgiEndHttpHeader ();
      mlCgiFreeResources ();
      if (errorCode == ML_CGI_FORM_FIELD_NOT_FOUND)
        showHtmlErrorPage (FORM_EMAIL_NOT_FOUND);
      if (errorCode == ML_CGI_INVALID_FORM_LENGTH)
       showHtmlErrorPage (INVALID_FORM_EMAIL_LENGTH);
      exit (ML_CGI_OK);
    }
  }
  else
  {
    errorCode = mlCgiGetFormStringNoNewLines ("email", userData.email, MAX_LENGTH_EMAIL);
    if (errorCode == ML_CGI_FORM_FIELD_NOT_FOUND)
      userData.email[0] = EOS;
    if (errorCode != ML_CGI_OK)
    {
      mlCgiEndHttpHeader ();
      mlCgiFreeResources ();
      if (errorCode == ML_CGI_INVALID_FORM_LENGTH)
       showHtmlErrorPage (INVALID_FORM_EMAIL_LENGTH);
      exit (ML_CGI_OK);
    }
  }
    

  errorCode = mlCgiGetFormStringNoNewLines ("homepage", userData.homepage, MAX_LENGTH_HOMEPAGE);
  if (errorCode == ML_CGI_FORM_FIELD_NOT_FOUND)
    userData.homepage[0] = EOS;
  if (errorCode != ML_CGI_OK)
  {
    mlCgiEndHttpHeader ();
    mlCgiFreeResources ();
    if (errorCode == ML_CGI_INVALID_FORM_LENGTH)
      showHtmlErrorPage (INVALID_FORM_HOMEPAGE_LENGTH);
    exit (ML_CGI_OK);
  }
  
  errorCode = mlCgiGetFormStringNoNewLines ("street", userData.address.street, MAX_LENGTH_STREET);
  if (errorCode == ML_CGI_FORM_FIELD_NOT_FOUND)
    userData.address.street[0] = EOS;
  if (errorCode != ML_CGI_OK)
  {
    mlCgiEndHttpHeader ();
    mlCgiFreeResources ();
    if (errorCode == ML_CGI_INVALID_FORM_LENGTH)
      showHtmlErrorPage (INVALID_FORM_STREET_LENGTH);
    exit (ML_CGI_OK);
  }
  
  errorCode = mlCgiGetFormStringNoNewLines ("homeNumber", userData.address.homeNumber, MAX_LENGTH_HOME_NUMBER);
  if (errorCode == ML_CGI_FORM_FIELD_NOT_FOUND)
    userData.address.homeNumber[0] = EOS;
  if (errorCode != ML_CGI_OK)
  {
    mlCgiEndHttpHeader ();
    mlCgiFreeResources ();
    if (errorCode == ML_CGI_INVALID_FORM_LENGTH)
      showHtmlErrorPage (INVALID_FORM_HOME_NUMBER_LENGTH);
    exit (ML_CGI_OK);
  }
  
  errorCode = mlCgiGetFormStringNoNewLines ("complement", userData.address.complement, MAX_LENGTH_COMPLEMENT);
  if (errorCode == ML_CGI_FORM_FIELD_NOT_FOUND)
    userData.address.complement[0] = EOS;
  if (errorCode != ML_CGI_OK)
  {
    mlCgiEndHttpHeader ();
    mlCgiFreeResources ();
    if (errorCode == ML_CGI_INVALID_FORM_LENGTH)
      showHtmlErrorPage (INVALID_FORM_COMPLEMENT_LENGTH);
    exit (ML_CGI_OK);
  }
  
  errorCode = mlCgiGetFormStringNoNewLines ("district", userData.address.district, MAX_LENGTH_DISTRICT);
  if (errorCode == ML_CGI_FORM_FIELD_NOT_FOUND)
    userData.address.district[0] = EOS;
  if (errorCode != ML_CGI_OK)
  {
    mlCgiEndHttpHeader ();
    mlCgiFreeResources ();
    if (errorCode == ML_CGI_INVALID_FORM_LENGTH)
      showHtmlErrorPage (INVALID_FORM_DISTRICT_LENGTH);
    exit (ML_CGI_OK);
  }
  
  errorCode = mlCgiGetFormStringNoNewLines ("city", userData.address.city, MAX_LENGTH_CITY);
  if (errorCode == ML_CGI_FORM_FIELD_NOT_FOUND)
    userData.address.city[0] = EOS;
  if (errorCode != ML_CGI_OK)
  {
    mlCgiEndHttpHeader ();
    mlCgiFreeResources ();
    if (errorCode == ML_CGI_INVALID_FORM_LENGTH)
      showHtmlErrorPage (INVALID_FORM_CITY_LENGTH);
    exit (ML_CGI_OK);
  }
  
  errorCode = mlCgiGetFormStringNoNewLines ("state", userData.address.state, MAX_LENGTH_STATE);
  if (errorCode == ML_CGI_FORM_FIELD_NOT_FOUND)
    userData.address.homeNumber[0] = EOS;
  if (errorCode != ML_CGI_OK)
  {
    mlCgiEndHttpHeader ();
    mlCgiFreeResources ();
    if (errorCode == ML_CGI_INVALID_FORM_LENGTH)
      showHtmlErrorPage (INVALID_FORM_STATE_LENGTH);
    exit (ML_CGI_OK);
  }
  
  errorCode = mlCgiGetFormStringNoNewLines ("country", userData.address.country, MAX_LENGTH_COUNTRY);
  if (errorCode == ML_CGI_FORM_FIELD_NOT_FOUND)
    userData.address.country[0] = EOS;
  if (errorCode != ML_CGI_OK)
  {
    mlCgiEndHttpHeader ();
    mlCgiFreeResources ();
    if (errorCode == ML_CGI_INVALID_FORM_LENGTH)
      showHtmlErrorPage (INVALID_FORM_COUNTRY_LENGTH);
    exit (ML_CGI_OK);
  }
  
  errorCode = mlCgiGetFormStringNoNewLines ("zipCode", userData.address.zipCode, MAX_LENGTH_ZIP_CODE);
  if (errorCode == ML_CGI_FORM_FIELD_NOT_FOUND)
    userData.address.zipCode[0] = EOS;
  if (errorCode != ML_CGI_OK)
  {
    mlCgiEndHttpHeader ();
    mlCgiFreeResources ();
    if (errorCode == ML_CGI_INVALID_FORM_LENGTH)
      showHtmlErrorPage (INVALID_FORM_ZIP_CODE_LENGTH);
    exit (ML_CGI_OK);
  }
  
  errorCode = mlCgiGetFormStringNoNewLines ("telNumber", userData.telNumber, MAX_LENGTH_TEL_NUMBER);
  if (errorCode == ML_CGI_FORM_FIELD_NOT_FOUND)
    userData.telNumber[0] = EOS;
  if (errorCode != ML_CGI_OK)
  {
    mlCgiEndHttpHeader ();
    mlCgiFreeResources ();
    if (errorCode == ML_CGI_INVALID_FORM_LENGTH)
      showHtmlErrorPage (INVALID_FORM_TEL_NUMBER_LENGTH);
    exit (ML_CGI_OK);
  }
  
  errorCode = mlCgiGetFormStringNoNewLines ("cellNumber", userData.cellNumber, MAX_LENGTH_CELL_NUMBER);
  if (errorCode == ML_CGI_FORM_FIELD_NOT_FOUND)
    userData.cellNumber[0] = EOS;
  if (errorCode != ML_CGI_OK)
  {
    mlCgiEndHttpHeader ();
    mlCgiFreeResources ();
    if (errorCode == ML_CGI_INVALID_FORM_LENGTH)
      showHtmlErrorPage (INVALID_FORM_CELL_NUMBER_LENGTH);
    exit (ML_CGI_OK);
  }
  
  errorCode = mlCgiGetFormStringNoNewLines ("gender", temp, 10);
  if (errorCode == ML_CGI_FORM_FIELD_NOT_FOUND)
    userData.gender = notAnswered;
  if (errorCode != ML_CGI_OK)
  {
    mlCgiEndHttpHeader ();
    mlCgiFreeResources ();
    if (errorCode == ML_CGI_INVALID_FORM_LENGTH)
      showHtmlErrorPage (INVALID_FORM_GENDER_LENGTH);
    exit (ML_CGI_OK);
  }
  if (!strcmp (temp, "male"))
    userData.gender = male;
  else if
    (!strcmp (temp, "female"))
      userData.gender = female;
  else
    userData.gender = notAnswered;

  errorCode = mlCgiGetFormStringNoNewLines ("relationshipStatus", temp, 10);
  if (errorCode == ML_CGI_FORM_FIELD_NOT_FOUND)
    userData.relationshipStatus = notGiven;
  if (errorCode != ML_CGI_OK)
  {
    mlCgiEndHttpHeader ();
    mlCgiFreeResources ();
    if (errorCode == ML_CGI_INVALID_FORM_LENGTH)
      showHtmlErrorPage (INVALID_FORM_RELATIONSHIP_STATUS_LENGTH);
    exit (ML_CGI_OK);
  }
  if (!strcmp (temp, "single"))
    userData.relationshipStatus = single;
  else if
    (!strcmp (temp, "married"))
      userData.relationshipStatus = married;
  else if
    (!strcmp (temp, "widowed"))
      userData.relationshipStatus = widowed;
  else
    userData.relationshipStatus = notGiven;

  if ((errorCode = mlCgiGetFormStringNoNewLines ("birthday", userData.birthday, MAX_LENGTH_BIRTHDAY)) != ML_CGI_OK)
  {
    mlCgiEndHttpHeader ();
    mlCgiFreeResources ();
    if (errorCode == ML_CGI_FORM_FIELD_NOT_FOUND)
      showHtmlErrorPage (FORM_BIRTHDAY_NOT_FOUND);
    if (errorCode == ML_CGI_INVALID_FORM_LENGTH)
      showHtmlErrorPage (INVALID_FORM_BIRTHDAY_LENGTH);
    exit (ML_CGI_OK);
  }
  
  errorCode = mlCgiGetFormStringNoNewLines ("description", userData.description, MAX_LENGTH_DESCRIPTION);
  if (errorCode == ML_CGI_FORM_FIELD_NOT_FOUND)
    userData.description[0] = EOS;
  if (errorCode != ML_CGI_OK)
  {
    mlCgiEndHttpHeader ();
    mlCgiFreeResources ();
    if (errorCode == ML_CGI_INVALID_FORM_LENGTH)
      showHtmlErrorPage (INVALID_FORM_DESCRIPTION_LENGTH);
    exit (ML_CGI_OK);
  }
  
  mlCgiEndHttpHeader();
  mlCgiFreeResources ();

  if (userData.category == relative)
  {
    userData.userName[0] = EOS;
	userData.plainPass[0] = EOS;
	userData.encryptedPass[0] = EOS;
  }
  else
  {
    strcpy (userData.plainPass, "noPass");
	if ((errorCode = encodePassword (userData.plainPass, userData.encryptedPass)) != OK)
	{
      showHtmlErrorPage (errorCode);
	  exit (ML_CGI_OK);
	}
  }		  
  
  if ((errorCode = editUserData (&userData)) != OK)
    showHtmlErrorPage (errorCode);
  else
    showHtmlOKPage ();    
        
  exit (ML_CGI_OK);
}