예제 #1
0
tarErrorType TarCgiShowLicense ( tarLanguageType tarLanguageMain )
{
  /* Variables Definitions */
  environmentType tarEnvironment ;
  char tarNickname [TAR_NICKNAME_MAX_LENGTH + 1] ;
  char tarPassword [TAR_PASSWORD_MAX_LENGTH + 1] ;

/*  tarUserInterfaceMessageNumberType tarCgiMainUserInterface ; */

/* Check if the Librarie "mlcgi.h" has been initialized successfully */
  if (mlCgiInitialize (&tarEnvironment))
    return (tarErrorCgi) ;
/* Check the Environment Types */
  if (tarEnvironment == commandLine)
  {
    printf ("%s\n" , "Esse programa so pode ser executado via web" );
    exit (tarInvalidExecutionEnvironment);
  }

  mlCgiBeginHttpHeader ("text/html") ;
  mlCgiEndHttpHeader () ;

  /* Begin the Forms */
  /* Usar codigo de retorno ?? */
  mlCgiGetFormStringNoNewLines ("Login" , tarNickname , TAR_NICKNAME_MAX_LENGTH ) ;

  /* Program has been executed successfully */
  mlCgiFreeResources ();
  return (tarOK) ;
  /* return tarOK ; */
}
int
main (int argc, char **argv)
{
  environmentType ambiente;
  char languageString [COMPRIMENTO_MAXIMO_LINGUA + 1];
  guLanguageType language;
  unsigned codigoRetorno;


  if (mlCgiInitialize (&ambiente))
    exit (ML_CGI_OK);

  if (ambiente == commandLine)
  {
    printf ("Este programa só pode ser executado via web\n");
    exit (AMBIENTE_EXECUCAO_INVALIDO);
  }

  mlCgiBeginHttpHeader ("text/html");
  mlCgiEndHttpHeader ();

  codigoRetorno = mlCgiGetFormStringNoNewLines ("guLanguage", 
                                                languageString, 
                                                COMPRIMENTO_MAXIMO_LINGUA);
  if (codigoRetorno != ML_CGI_OK)
  {
    printf ("Erro obtendo o valor do campo numero - Erro #%i\n", codigoRetorno);
    mlCgiFreeResources ();
    exit (ML_CGI_OK);
  }

  language = GuGetLanguageIndex(languageString);


  printf ("<html>\n");
  printf ("  <head>\n");
  printf ("    <title>\n");
  printf ("      %s\n",
                 GuGetWebUserInterfaceMessage(guWelcomeMessage,language));
  printf ("    </title>\n");
  printf ("  </head>\n");
  printf ("  <body bgcolor=\"white\">\n");
  printf ("    <h1 style=\"text-align: center;\">"
              "<span style=\"color: #cc99ff;\">GNUber</span></h1>\n");
  printf ("    <form style=\"text-align: center;\""
              " action=\"guRequestPasswordReset.cgi\">\n");
  printf ("      Username:<br/> \n");
  printf ("      <input name=\"guNickname\" type=\"text\""
                "maxlength=\"%u\"/>\n",GU_MAX_NICKNAME_LENGTH);
  printf ("      <br/> Email:<br/>\n");
  printf ("      <input name=\"guEmail\""
                "type=\"text\" maxlength=\"%u\"/><br><br>\n",
                 GU_MAX_EMAIL_LENGTH);
  printf ("      <input type=\"submit\" value=\"Reset Password\">");
  printf ("      <input type=\"hidden\" name=\"guLanguage\""
          "      value=\"%s\">\n",languageString);
  printf ("    </form>\n");

  printf ("  </body>\n");
  printf ("</html>\n");

  mlCgiFreeResources ();
  return ML_CGI_OK;
}
int main (int argc, char **argv)
{
	thcUserDataType data;
	environmentType enviro;
	thcErrorType errorCode;
	thcLanguageType language = THC_DEFAULT_LANGUAGE;
	char email   [THC_EMAIL_MAXIMUM_LENGHT+1];
	char confirm [THC_EMAIL_MAXIMUM_LENGHT+1];
	char nickname[THC_NICKNAME_MAXIMUM_LENGHT+1];
	char cookieName[THC_COOKIE_NAME_LENGHT+1];
	char user [THC_NICKNAME_MAXIMUM_LENGHT + 1];


	/*Clears trash from data*/
	memset(&data,0x00,sizeof(thcUserDataType));

	if (mlCgiInitialize (&enviro))
		exit (THC_OK);

	if (enviro == commandLine) /* programa executado via CLI */
	{
		thcGetTextErrorMessage(THC_DEFAULT_LANGUAGE, THC_ERROR_INVALID_INTERFACE);
		mlCgiFreeResources();
		exit (THC_OK);
	}

	/* programa executado via web */
	mlCgiBeginHttpHeader ("text/html");
	
	errorCode = mlCgiGetFormStringNoNewLines ("thcCookieName",cookieName,THC_COOKIE_NAME_LENGHT);
	if (errorCode != ML_CGI_OK)
	{
		mlCgiEndHttpHeader ();
		thcGetHtmlErrorMessage(language, THC_ERROR_ON_WEB_FORM);
		mlCgiFreeResources ();
		exit(THC_OK);		
	}
	

	errorCode = mlCgiGetFormStringNoNewLines ("thcEmail", email, THC_FULL_NAME_MAXIMUM_LENGHT);
	if (errorCode != ML_CGI_OK)
	{
		mlCgiEndHttpHeader ();
		thcGetHtmlErrorMessage(language, THC_ERROR_ON_WEB_FORM);
		mlCgiFreeResources ();
		exit(THC_OK);		
	}
	
	errorCode = mlCgiGetFormStringNoNewLines ("thcConfirm", confirm, THC_FULL_NAME_MAXIMUM_LENGHT);
	if (errorCode != ML_CGI_OK)
	{
		mlCgiEndHttpHeader ();
		thcGetHtmlErrorMessage(language, THC_ERROR_ON_WEB_FORM);
		mlCgiFreeResources ();
		exit(THC_OK);		
	}

	errorCode = mlCgiGetFormStringNoNewLines ("thcNickname", nickname, THC_NICKNAME_MAXIMUM_LENGHT);
	if (errorCode != ML_CGI_OK)
	{
		mlCgiEndHttpHeader ();
		thcGetHtmlErrorMessage(language, THC_ERROR_ON_WEB_FORM);
		mlCgiFreeResources ();
		exit(THC_OK);		
	}

	

	errorCode = thcRenewCookie(cookieName, &language);
	if (errorCode != THC_OK)
	{
		mlCgiEndHttpHeader();
		thcGetHtmlErrorMessage(language, errorCode);
		mlCgiFreeResources();
		exit(THC_OK);
	}	

	/* mlCgiBeginHttpHeader (NULL); */
	mlCgiEndHttpHeader ();
	
	/*Check for e-mail*/
	if (strcmp(email,confirm) != 0)
	{
		thcGetTextErrorMessage(language,THC_INVALID_ARGUMENT);
		exit(THC_OK);
		
	}
	
	if (strlen(email) == 0)
	{
		thcGetTextErrorMessage(language,THC_INVALID_ARGUMENT);
		exit(THC_OK);	
		
	}
    
    errorCode = thcSearchUser(nickname,&data);
    if (errorCode != THC_OK)
    {
		thcGetTextErrorMessage(language,errorCode);
		mlCgiFreeResources();
		exit (THC_OK);
	}
 
	
	data.UID = (unsigned long long)language;
	strcpy(data.email,email);
	
	errorCode = thcChangeUserEmail(&data);
	if (errorCode != THC_OK)
    {
		thcGetTextErrorMessage(language,errorCode);
		mlCgiFreeResources();
		exit (THC_OK);
	}
	
	/*Get the nickname*/
	errorCode = thcCookieNameToNickname (cookieName, user);
	if (errorCode != THC_OK)
	{
		thcGetTextErrorMessage(language,errorCode);
		mlCgiFreeResources();
		exit (THC_OK);
	}
	
	thcWebShowHeader();
	
	printf("<body>                                         \n");
	printf("<div class='content'>                          \n");
	printf("                                               \n");
	printf("%s<br>                                         \n",menssages[0][language]);
	printf("%s<br>                                         \n",menssages[1][language]);
	printf("<a href='thcHome.cgi?thcNickname='%s>%s</a>    \n",user,menssages[2][language]);
	printf("</div>                                         \n");
	printf("                                               \n");


	
	thcWebShowFooter();

	mlCgiFreeResources();
	return THC_OK;
}
int main (int argc, char **argv)
{
  unsigned errorCode;	

  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");
  mlCgiEndHttpHeader();
  mlCgiFreeResources ();
  
  #ifdef ENGLISH
    printf ("<HTML>\n");
    printf ("  <HEAD>\n");
    printf ("    <TITLE>Relationship System - Form to new user login</TITLE>\n");
    printf ("  </HEAD>\n");
    printf ("  <BODY BACKGROUND = \"http://www2.del.ufrj.br/~marceloddm/computacao_ii/pf/images/zertxtr.gif\" BGCOLOR = \"#000000\" TEXT = \"#FFFFFF\" LINK = \"#6699CC\" VLINK = \"#669966\" ALINK = \"#999999\">\n");
    printf ("    <DIV ALIGN = \"CENTER\"><STRONG><FONT FACE = \"Courier New\" SIZE = \"5\" COLOR = \"#FFFFFF\">RELATIONSHIP SYSTEM</FONT></STRONG></DIV>\n");
    printf ("    <HR>\n");
    printf ("    <CENTER><STRONG><FONT FACE = \"Courier New\" SIZE = \"4\" COLOR = \"#FFFFFF\">FORM TO NEW USER LOGIN</FONT></STRONG><CENTER>\n");
    printf ("    <HR>\n");
    printf ("    <BR><BR>\n");
    printf ("    <TABLE BORDER=\"1\" ALIGN = \"center\">\n");
    printf ("    <FORM ACTION=\"http://www2.del.ufrj.br/~marceloddm/computacao_ii/pf/cgi/showNewUserForm.cgi\" METHOD=\"post\">\n");
    printf ("       <TR><TD>Email: </TD>        <TD><INPUT TYPE=\"text\"     NAME=\"email\"      SIZE=\"40\"  ></TD></TR>\n");
    printf ("       <TR><TD>Password: </TD>     <TD><INPUT TYPE=\"password\"     NAME=\"password\"   SIZE=\"40\"  ></TD></TR>\n");
    printf ("       <TR><TD>Accept the invitation: </TD><TD><INPUT TYPE=\"radio\" NAME=\"option\" VALUE=\"accept\" checked</TD></TR>\n");
    printf ("       <TR><TD>Reject the invitation: </TD><TD><INPUT TYPE=\"radio\" NAME=\"option\" VALUE=\"reject\" </TD></TR>\n");
    printf ("    </TABLE>\n");  	
    printf ("    <BR><BR>\n");
    printf ("                      <INPUT TYPE=\"submit\"   VALUE=\"Submit\">\n");
    printf ("                      <INPUT TYPE=\"reset\"    VALUE=\"Clear\">\n");
    printf ("    </FORM>\n");
    printf ("    <BR><BR><BR>\n");
    printf ("<P ALIGN=\"left\"><A HREF=\"javascript:window.history.go(-1)\" TARGET=\"_self\">GO BACK</a></p>\n");
    printf ("    <HR>\n");
    printf ("    <DIV ALIGN = \"RIGHT\"><FONT FACE = \"Courier New\" SIZE = \"2\"><U>Authors:</U>\n");
    printf ("    <I> Carlo Fragni and Marcelo Duffles Donato Moreira\n");
    printf ("    <BR>\n");
    printf ("    Last update: 17/02/05</I></FONT>\n");
    printf ("    </DIV></FONT>\n");
    printf ("  <BODY>\n");
    printf ("</HTML>\n");
  #elif PORTUGUESE
    printf ("<HTML>\n");
    printf ("  <HEAD>\n");
    printf ("    <TITLE>Sistema de Relacionamentos - Formul&aacute;rio para login de novo usu&aacute;rio</TITLE>\n");
    printf ("  </HEAD>\n");
    printf ("  <BODY BACKGROUND = \"http://www2.del.ufrj.br/~marceloddm/computacao_ii/pf/images/zertxtr.gif\" BGCOLOR = \"#000000\" TEXT = \"#FFFFFF\" LINK = \"#6699CC\" VLINK = \"#669966\" ALINK = \"#999999\">\n");
    printf ("    <DIV ALIGN = \"CENTER\"><STRONG><FONT FACE = \"Courier New\" SIZE = \"5\" COLOR = \"#FFFFFF\">SISTEMA DE RELACIONAMENTOS</FONT></STRONG></DIV>\n");
    printf ("    <HR>\n");
    printf ("    <CENTER><STRONG><FONT FACE = \"Courier New\" SIZE = \"4\" COLOR = \"#FFFFFF\">FORMUL&Aacute;RIO PARA LOGIN DE NOVO USU&Aacute;RIO</FONT></STRONG><CENTER>\n");
    printf ("    <HR>\n");
    printf ("    <BR><BR>\n");
    printf ("    <TABLE BORDER=\"1\" ALIGN = \"center\">\n");
    printf ("    <FORM ACTION=\"http://www2.del.ufrj.br/~marceloddm/computacao_ii/pf/cgi/showNewUserForm.cgi\" METHOD=\"post\">\n");
    printf ("       <TR><TD>Email: </TD>      <TD><INPUT TYPE=\"text\"     NAME=\"email\"     SIZE=\"40\"  ></TD></TR>\n"); 
    printf ("       <TR><TD>Senha: </TD>      <TD><INPUT TYPE=\"password\"     NAME=\"password\"   SIZE=\"40\"  ></TD></TR>\n");
    printf ("       <TR><TD>Aceitar o convite: </TD><TD><INPUT TYPE=\"radio\" NAME=\"option\" VALUE=\"accept\" checked</TD></TR>\n");
    printf ("       <TR><TD>Rejeitar o convite: </TD><TD><INPUT TYPE=\"radio\" NAME=\"option\" VALUE=\"reject\" </TD></TR>\n");
    printf ("    </TABLE>\n");  	
    printf ("    <BR><BR>\n");
    printf ("                      <INPUT TYPE=\"submit\"   VALUE=\"Submeter\">\n");
    printf ("                      <INPUT TYPE=\"reset\"    VALUE=\"Apagar\">\n");
    printf ("    </FORM>\n");
    printf ("    <BR><BR><BR>\n");
    printf ("<P ALIGN=\"left\"><A HREF=\"javascript:window.history.go(-1)\" TARGET=\"_self\">VOLTAR</a></p>\n");
    printf ("    <HR>\n");
    printf ("    <DIV ALIGN = \"RIGHT\"><FONT FACE = \"Courier New\" SIZE = \"2\"><U>Autores:</U>\n");
    printf ("    <I> Carlo Fragni e Marcelo Duffles Donato Moreira\n");
    printf ("    <BR>\n");
    printf ("    &Uacute;ltima Atualiza&ccedil;&atilde;o: 17/02/05</I></FONT>\n");
    printf ("    </DIV></FONT>\n");
    printf ("  <BODY>\n");
    printf ("</HTML>\n");
  #endif

  exit (ML_CGI_OK);
}
int main (int argc, char **argv)
{
	environmentType enviro;
	thcUserDataType data;   
	thcLanguageType language = THC_DEFAULT_LANGUAGE;         
	char password [THC_PASSWORD_MAXIMUM_LENGHT + 1];
	char passwordConfirm [THC_PASSWORD_MAXIMUM_LENGHT + 1];
	char nickname[THC_NICKNAME_MAXIMUM_LENGHT+1];
	char user [THC_NICKNAME_MAXIMUM_LENGHT + 1];
	char cookieName [THC_COOKIE_NAME_LENGHT + 1];
	thcErrorType errorCode;
	

	/*Initiate and check environment*/
	if (mlCgiInitialize (&enviro))
		exit (THC_OK);

	if (enviro == commandLine) 
	{
		printf ("%s\n",errorMensages[0][0]);
		exit (THC_OK);
	}

	/*Web interface*/
	mlCgiBeginHttpHeader ("text/html");
	
	errorCode = mlCgiGetFormStringNoNewLines ("thcNickname", nickname , THC_NICKNAME_MAXIMUM_LENGHT);
	if (errorCode != ML_CGI_OK)
	{
		mlCgiEndHttpHeader();
		thcGetHtmlErrorMessage(language, THC_ERROR_ON_WEB_FORM);
		mlCgiFreeResources ();	
		exit(THC_OK);
	}
	
	errorCode = mlCgiGetFormStringNoNewLines ("thcCookieName", cookieName , THC_COOKIE_NAME_LENGHT);
	if (errorCode != ML_CGI_OK)
	{
		mlCgiEndHttpHeader();
		thcGetHtmlErrorMessage(language, THC_ERROR_ON_WEB_FORM);
		mlCgiFreeResources ();	
		exit(THC_OK);
	}
	
	errorCode = mlCgiGetFormStringNoNewLines ("thcPassword", password, THC_PASSWORD_MAXIMUM_LENGHT);
	if (errorCode != ML_CGI_OK)
	{
		mlCgiEndHttpHeader();
		thcGetHtmlErrorMessage(language, THC_ERROR_ON_WEB_FORM);
		mlCgiFreeResources ();	
		exit(THC_OK);		
	}
	
	errorCode = mlCgiGetFormStringNoNewLines ("thcConfirm", passwordConfirm, THC_PASSWORD_MAXIMUM_LENGHT);
	if (errorCode != ML_CGI_OK)
	{
		mlCgiEndHttpHeader();
		thcGetHtmlErrorMessage(language, THC_ERROR_ON_WEB_FORM);
		mlCgiFreeResources ();	
		exit(THC_OK);		
	}
	
	errorCode = thcRenewCookie (cookieName, &language);
	mlCgiEndHttpHeader ();
	
	if (errorCode != THC_OK)
	{
		thcGetHtmlErrorMessage(language, errorCode);
		mlCgiFreeResources ();	
		exit(THC_OK);		
	}
	
	/*Check if password match*/
	if (strcmp(password, passwordConfirm) != 0)
	{
		thcGetHtmlErrorMessage(language, THC_INCORRECT_PASSWORD);
		mlCgiFreeResources ();	
		exit(THC_OK);		
	}
	
	errorCode = thcSearchUser(nickname,&data);	
	if (errorCode != THC_OK)
	{
		thcGetHtmlErrorMessage(language, errorCode);
		mlCgiFreeResources ();	
		exit(THC_OK);
	}
	
	strcpy(data.codedPassword,password);
	
	/*Change user password*/
	errorCode = thcChangeUserPassword(&data);
	if (errorCode != THC_OK)
	{
		thcGetHtmlErrorMessage(language, errorCode);
		mlCgiFreeResources ();	
		exit(THC_OK);
	}
	
	/*Get username*/
	errorCode = thcCookieNameToNickname(cookieName, user);
	if (errorCode != THC_OK)
	{
		thcGetHtmlErrorMessage(language, errorCode);
		mlCgiFreeResources ();	
		exit(THC_OK);
	}
	
	thcWebShowHeader();
	printf("<body>                                         \n");
	printf("<div class='content'>                          \n");
	printf("                                               \n");
	printf("%s<br>                                         \n",menssage[0][language]);
	printf("<a href='thcHome.cgi?thcNickname='%s>%s</a>    \n",user,menssage[1][language]);
	printf("</div>                                         \n");

	thcWebShowFooter();

	mlCgiFreeResources ();
	return THC_OK;
}
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[20 +1];
  userIdType callerOfProgramId, givenId, givenId2, givenId3, givenId4;

  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", temp, 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);
  }
  givenId           = strtoul (temp,       NULL, 10);
  callerOfProgramId = strtoul (cookieName, NULL, 10); 
  
  if ((errorCode = mlCgiGetFormStringNoNewLines ("userId2", temp, 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);
  }
  givenId2 = strtoul (temp, NULL, 10);
  
  if ((errorCode = mlCgiGetFormStringNoNewLines ("userId3", temp, 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);
  }
  givenId3 = strtoul (temp, NULL, 10);

  if ((errorCode = mlCgiGetFormStringNoNewLines ("userId4", temp, 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);
  }
  givenId2 = strtoul (temp, NULL, 10);
  
  if ((callerOfProgramId != 0) && (givenId != callerOfProgramId) && (givenId2 != callerOfProgramId) && (givenId3 != callerOfProgramId) && (givenId4 != callerOfProgramId))
  {
    mlCgiEndHttpHeader ();
    mlCgiFreeResources ();
    showHtmlErrorPage (YOU_CAN_ONLY_EDIT_YOUR_PARENT_RELATIONSHIP);
    exit (ML_CGI_OK);
  }
  
  mlCgiEndHttpHeader();
  mlCgiFreeResources ();
  
  if ((errorCode = editParentRelationship (givenId, givenId2, givenId3, givenId4)) != OK)
    showHtmlErrorPage (errorCode);
  else
    showHtmlOKPage ();    
        
  exit (ML_CGI_OK);
}
int main (int argc, char **argv)
{
	environmentType enviro;
	thcUserDataType data;       
	char cookieName [THC_COOKIE_NAME_LENGHT + 1];      
	char username [THC_NICKNAME_MAXIMUM_LENGHT + 1];
	char password [THC_PASSWORD_MAXIMUM_LENGHT + 1];
	thcErrorType errorCode;
	char cookieContent [THC_COOKIE_CONTENT_LENGHT+1];
	time_t expiration;
	char languageString[THC_LANGUAGE_MAXIMUM_LENGHT+1];
	thcLanguageType language = THC_DEFAULT_LANGUAGE;

	/*Initiate and check environment*/
	if (mlCgiInitialize (&enviro))
		exit (THC_OK);

	if (enviro == commandLine) 
	{
		thcGetTextErrorMessage(language, THC_ERROR_INVALID_INTERFACE);
		exit (THC_OK);
	}

	/*Web interface*/
	mlCgiBeginHttpHeader ("text/html");
	
	errorCode = mlCgiGetFormStringNoNewLines ("thcLanguage",languageString,THC_LANGUAGE_MAXIMUM_LENGHT);
	if (errorCode == ML_CGI_OK)
	{
		if (strcmp(languageString,"br") == 0) language = portuguese;
		if (strcmp(languageString,"en") == 0) language = english;	
	}
	
	
	errorCode = mlCgiGetFormStringNoNewLines ("thcUsername", username, THC_NICKNAME_MAXIMUM_LENGHT);
	if (errorCode != ML_CGI_OK)
	{
		thcGetHtmlErrorMessage(language, THC_ERROR_ON_WEB_FORM);
		exit(THC_OK);
	}
	
	errorCode = mlCgiGetFormStringNoNewLines ("thcPassword", password, THC_PASSWORD_MAXIMUM_LENGHT);
	if (errorCode != ML_CGI_OK)
	{
		thcGetHtmlErrorMessage(language, THC_ERROR_ON_WEB_FORM);
		exit(THC_OK);	
	}
	
	
	
	errorCode = thcUserLogin(username,password,&data);
	if (errorCode != THC_OK)
	{
		mlCgiEndHttpHeader ();
		thcGetHtmlErrorMessage(language,errorCode);
		exit(THC_OK);
	}	
	
	
	
	/*Login correct*/
	
	/*Generate the cookie content*/
	errorCode = thcGenerateCookieContent(cookieContent);
	if (errorCode != THC_OK)
	{
		mlCgiEndHttpHeader ();
		thcGetHtmlErrorMessage(language,errorCode);
		exit(THC_OK);		
	}
	
	/*send language information to cookie*/
	if (language == english) cookieContent[0] = 'e';
	if (language == portuguese) cookieContent[0] = 'b';
	
	/*Generate cookie name using the user ID*/
	if (sprintf(cookieName,THC_COOKIE_NAME_PRINTF_FORMAT,data.UID) != THC_COOKIE_NAME_LENGHT)
	{
		mlCgiEndHttpHeader ();
		thcGetHtmlErrorMessage(language,THC_ERROR_GENERATING_COOKIE_NAME);
		exit(THC_OK);			
	}
	
	
	/*send cookie*/
	expiration = time(NULL) + THC_COOKIE_EXPIRATION;
	
	errorCode = thcGenerateCookie(cookieName, &expiration, cookieContent, THC_DEFAULT_COOKIE_IP);
	if (errorCode != THC_OK)
	{
		mlCgiEndHttpHeader ();
		thcGetHtmlErrorMessage(language,errorCode);
		exit(THC_OK);		
	}
	
	/*Sends the cookie to user*/
	mlCgiSetCookie(cookieName, cookieContent, THC_COOKIE_EXPIRATION, NULL, NULL, NULL);
	mlCgiEndHttpHeader ();
	
	if (data.flag == abeyance)
	{
		
		thcWebShowHeader();
		     
		
		printf("<body>                                                                \n");          
		printf("  <div class=\"content\">                                             \n");                               
		printf("	<h1>%s</h1>                                                       \n",menssage[1][language]);                                                       
		printf("    <a href='thcCgiShowChangePasswordForm.cgi?thcNickname=%s'>%s</a>  \n",data.nickname,menssage[0][language]);
		printf("  </div>	                                                          \n");               
		printf("</body>                                                               \n");
		
			
		exit(THC_OK);
	}
	
	if (data.flag == passwordReset)
	{
		
		thcWebShowHeader();
		     
		
		printf("<body>                                                                \n");          
		printf("  <div class=\"content\">                                             \n");                               
		printf("	<h1>%s</h1>                                                       \n",menssage[1][language]);                                                       
		printf("    <a href='thcCgiShowChangePasswordForm.cgi?thcNickname=%s'>%s</a>  \n",data.nickname,menssage[2][language]);
		printf("  </div>	                                                          \n");               
		printf("</body>                                                               \n");
		
			
		exit(THC_OK);
	}
	
	
	/*Prints header*/		
	
	thcWebShowHeader();
	
	printf("	<body>                          \n");          
	printf("		<div class=\"content\">     \n");                               
	printf("			<h1>%s</h1>             \n",menssage[1][language]);                                                                                            
	printf("		</div>	                    \n");               
	printf("                                    \n");
	
	/*Prints menu*/
	thcWebShowMenu(language,data);
	                                                                                                                            
	/*Prints footer*/
	thcWebShowFooter();

	mlCgiFreeResources ();
	return THC_OK;
}
int main (int argc, char **argv)
{
	environmentType enviro;
	thcErrorType errorCode;
	thcLanguageType language = english;
	char languageString[THC_LANGUAGE_MAXIMUM_LENGHT + 1];
	
		
	if (mlCgiInitialize (&enviro))
		exit (THC_OK);

	if (enviro == commandLine)
	{
		thcGetTextErrorMessage(language,THC_ERROR_INVALID_INTERFACE);
		mlCgiFreeResources();
		exit (THC_OK);
	}
	
	/*Start header*/
	mlCgiBeginHttpHeader("text/html");
	mlCgiEndHttpHeader();

	errorCode = mlCgiGetFormStringNoNewLines ("thcLanguage",languageString,THC_LANGUAGE_MAXIMUM_LENGHT);
	if (errorCode != ML_CGI_OK)
	{
		mlCgiEndHttpHeader ();
		thcGetHtmlErrorMessage(language,THC_ERROR_ON_WEB_FORM);
		mlCgiFreeResources();
		exit(THC_OK);
	}
	
	if (strcmp(languageString,"en") == 0 ) language = english;
	if (strcmp(languageString,"br") == 0 ) language = portuguese;

	if (language == english)
	{
		thcWebShowHeader();
		
		printf("<body>                                                                                  \n");
		printf("    <h1><center>Tree High CloudDropper </center></h1><br>                               \n");
		printf("    <h2><center>V 4.2.0</center></h2><br>                                               \n");
		printf("    Help Session:<br>                                                                   \n");
		printf("    &nbsp;&nbsp;&nbsp;&nbsp;Invite User: <br>                                           \n");
		printf("    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;->This will invite a new user to join the system, he will receive an e-mail with login and temporary password to be able to use the system<br><br>\n");
		printf("                                                                                        \n");
		printf("    &nbsp;&nbsp;&nbsp;&nbsp;Change Passowrd: <br>\n");
		printf("    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;->This will change your password to a new one<br><br>\n");
		printf("                                                                                        \n");
		printf("    &nbsp;&nbsp;&nbsp;&nbsp;Change e-mail: <br>                                    \n");
		printf("    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;->This will change your e-mail, you will receive a confirmation e-mail to the new adress and a cancel e-mail to the old adress<br><br>\n");
		printf("                                                                                        \n");
		printf("    &nbsp;&nbsp;&nbsp;&nbsp;Change Username: <br>                      \n");
		printf("    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;->This will change your username and generate a new nickname based on the new name<br><br>\n");
		printf("                                                                                        \n");
		printf("    &nbsp;&nbsp;&nbsp;&nbsp;Change User group (admin only): <br>   \n");
		printf("    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;->This will change a selected user to the selected group <br><br>\n");
		printf("                                                                                        \n");
		printf("    &nbsp;&nbsp;&nbsp;&nbsp;Add User to group (admin only): <br>             \n");
		printf("    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;->This will add a user to a selected group, e.g. if the he is a user and you add to owner group he will be user & owner<br><br>\n");
		printf("                                                                                        \n");
		printf("    &nbsp;&nbsp;&nbsp;&nbsp;Remove Account<br>                                         \n");
		printf("    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;->This will remove a user account from the system and will delete all of his data<br><br>\n");
		printf("                                                                                        \n");
		printf("    &nbsp;&nbsp;&nbsp;&nbsp;Help: <br>                                           \n");
		printf("    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;->Show this very informative screen in the selected language<br><br>\n");
		printf("                                                                                        \n");
		printf("    &nbsp;&nbsp;&nbsp;&nbsp;Contact: <br>                                           \n");
		printf("    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;->Send an e-mail to sistem admin<br><br>\n");
		printf("                                                                                        \n");
		printf("    &nbsp;&nbsp;&nbsp;&nbsp;Logout: <br>                                           \n");
		printf("    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;->Finish user session and return to initial screen<br><br>\n");
		printf("                                                                                        \n");
		printf("</body>");
	}
	
	if (language == portuguese)
	{
		thcWebShowHeader();
		
		printf("<body>                                                                                  \n");
		printf("    <h1><center>Tree High CloudDropper </center></h1><br>                               \n");
		printf("    <h2><center>V 4.2.0</center></h2><br>                                               \n");
		printf("    Sessão de ajuda :<br>                                                  \n");
		printf("    &nbsp;&nbsp;&nbsp;&nbsp;Convidar um amigo: <br>                                  \n");
		printf("    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;->Essa opção convida um novo usuario para entrar no sistema, ele irá receber um e-mail de confirmação com o login e a senha temporária<br><br>\n");
		printf("                                                                                        \n");
		printf("    &nbsp;&nbsp;&nbsp;&nbsp;Trocar Senha: <br>\n");
		printf("    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;->Essa opção troca a senha do usuário por uma nova<br><br>\n");
		printf("                                                                                        \n");
		printf("    &nbsp;&nbsp;&nbsp;&nbsp;Trocar e-mail: <br>                                    \n");
		printf("    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;->Essa opção muda seu e-mail, você receberá um e-mail de confirmação no endereço novo e um e-mail para cancelar operação no endereço antigo<br><br>\n");
		printf("                                                                                        \n");
		printf("    &nbsp;&nbsp;&nbsp;&nbsp;Alterar Nome: <br>                      \n");
		printf("    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;->Essa função altera o nome de um usuário e gera um novo nickname baseado no novo nome<br><br>\n");
		printf("                                                                                        \n");
		printf("    &nbsp;&nbsp;&nbsp;&nbsp;Trocar Grupo de Usuário (apenas administradores): <br>   \n");
		printf("    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;->Essa opção troca um usuário para o grupo selecionado<br><br>\n");
		printf("                                                                                        \n");
		printf("    &nbsp;&nbsp;&nbsp;&nbsp;Adicionar Usuario ao Grupo (apenas administradores): <br>             \n");
		printf("    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;->Essa opção ira adicionar um usuário ao grupo selecionado, ex: caso ele seja usuario e seja adicionado ao grupo de proprietários, ele exercerá ambas as funções<br><br>\n");
		printf("                                                                                        \n");
		printf("    &nbsp;&nbsp;&nbsp;&nbsp;Remover Conta<br>                                         \n");
		printf("    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;->Essa opção irá remover um usuário e todos os seu dados do sistema<br><br>\n");
		printf("                                                                                        \n");
		printf("    &nbsp;&nbsp;&nbsp;&nbsp;Ajuda: <br>                                           \n");
		printf("    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;->Exibe essa tela super informativa<br><br>\n");
		printf("                                                                                        \n");
		printf("    &nbsp;&nbsp;&nbsp;&nbsp;Contato: <br>                                           \n");
		printf("    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;->Envia um e-mail para o administrador do sistema<br><br>\n");
		printf("                                                                                        \n");
		printf("    &nbsp;&nbsp;&nbsp;&nbsp;Sair: <br>                                           \n");
		printf("    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;->Finaliza a sessão e volta para a página inicial<br><br>\n");
		printf("                                                                                        \n");
		printf("</body>");

	}
	return THC_OK;
}
예제 #9
0
int
main (int argc, char **argv)
{
  environmentType ambiente;
  char languageString [COMPRIMENTO_MAXIMO_LINGUA + 1];
  guLanguageType language;
  unsigned codigoRetorno;


  if (mlCgiInitialize (&ambiente))
    exit (ML_CGI_OK);

  if (ambiente == commandLine)
  {
    printf ("Este programa só pode ser executado via web\n");
    exit (AMBIENTE_EXECUCAO_INVALIDO);
  }

  mlCgiBeginHttpHeader ("text/html");
  mlCgiEndHttpHeader ();

  codigoRetorno = mlCgiGetFormStringNoNewLines ("guLanguage", 
                                                languageString, 
                                                COMPRIMENTO_MAXIMO_LINGUA);
  if (codigoRetorno != ML_CGI_OK)
  {
    printf ("Erro obtendo o valor do campo numero - Erro #%i\n", codigoRetorno);
    mlCgiFreeResources ();
    exit (ML_CGI_OK);
  }

  language = GuGetLanguageIndex(languageString);


  printf ("<html>\n");
  printf ("  <head>\n");
  printf ("    <title>\n");
  printf ("      %s\n",
                 GuGetWebUserInterfaceMessage(guWelcomeMessage,language));
  printf ("    </title>\n");
  printf ("  </head>\n");
  printf ("  <body bgcolor=\"white\">\n");
  printf ("    <h1 style=\"text-align: center;\">"
               "<span style=\"color: #cc99ff;\">GNUber</span></h1>\n");
  printf ("    <p style=\"text-align: center;\">\n");
  printf ("    <span style=\"color: #cc99ff;\">\n");
  printf ("    <span style=\"color: #000000;\">\n");
  printf ("    %s&nbsp;\n",
               GuGetWebUserInterfaceMessage(guByMessage,language));
  printf ("    <a title=\"Author\""
               " href=\"mailto:[email protected]\"" 
               "target=\"_blank\">Carlos Felipe D. e Oliveira</a>"
               "</span>&nbsp;</span></p>\n");
  printf ("    <form style=\"text-align: center;\""
               " action=\"./CGIs/guLogin.cgi\">\n");
  printf ("      %s:<br/> \n",
                 GuGetWebUserInterfaceMessage(guUsernameMessage,language));
  printf ("      <input name=\"guNickname\" type=\"text\"" 
                "maxlength=\"%u\"/>\n",GU_MAX_NICKNAME_LENGTH); 
  printf ("      <br/> %s:<br/>\n",
                 GuGetWebUserInterfaceMessage(guPasswordMessage,language)); 
  printf ("      <input name=\"guPassword\"" 
                "type=\"password\" maxlength=\"%u\"/><br><br>\n",
                 GU_MAX_PASSWORD_LENGTH); 
  printf ("      <input type=\"submit\" value=\"%s\">",
                 GuGetWebUserInterfaceMessage(guLoginMessage,language));
  printf ("      <input type=\"hidden\" name=\"guLanguage\"" 
          "      value=\"%s\">\n",languageString);
  printf ("    </form>\n");
  printf ("    <p style=\"text-align:center;\">%s"
          "    <a href=\"%s?guLanguage=%s\">%s</a>&nbsp;%s</p>\n",
               GuGetWebUserInterfaceMessage(guSignUpMessage1,language),
               GU_REGISTER_FORM_URL, languageString,
               GuGetWebUserInterfaceMessage(guSignUpMessage2,language),
               GuGetWebUserInterfaceMessage(guSignUpMessage3,language));
  printf ("    <p style=\"text-align: center;\">"
              "<a href=\"%s?guLanguage=%s\">%s</a></p>\n",
               GU_LOST_PW_FORM_URL, languageString,
               GuGetWebUserInterfaceMessage(guLostPWMessage,language));
  printf ("    <p style=\"text-align: center;\">"
              "<a href=\"%s?guLanguage=%s\">%s</a></p>\n",
               GU_HELP_URL, languageString,
               GuGetWebUserInterfaceMessage(guHelpMessage,language));
  printf ("    <p style=\"text-align: center;\">"
              "<a href=\"%s?guLanguage=%s\">%s</a></p>\n",
               GU_LICENSE_URL, languageString,
               GuGetWebUserInterfaceMessage(guLicenseMessage,language));
  printf ("  </body>\n");
  printf ("</html>\n");

  mlCgiFreeResources ();
  return ML_CGI_OK;
}
예제 #10
0
int main (int argc, char **argv)
{
  unsigned ret;	
  char cookieName[COOKIE_NAME_LENGTH +1];
  char cookieValue[COOKIE_VALUE_LENGTH +1];
  char *cookieFileName;

  if ((ret = mlCgiInitialize ()) != ML_CGI_OK)
  {
    showHtmlErrorPage (E_SHOW_WELCOME_PAGE);
    exit (ML_CGI_OK);
  }

  if (!isCgi)
  {
    log_msg (error_messages[E_IS_NOT_CGI]);
    exit (ML_CGI_OK);
  }
	
	  
  mlCgiBeginHttpHeader ("text/html");
    
  if ((ret = mlCgiGetFormStringNoNewLines ("cookieName", cookieName, COOKIE_NAME_LENGTH)) != ML_CGI_OK)
  {
    mlCgiEndHttpHeader ();
    mlCgiFreeResources ();
    showHtmlErrorPage (E_SHOW_WELCOME_PAGE);
    exit (ML_CGI_OK);
  }

  if ((ret = mlCgiGetSpecificCookie (cookieName, COOKIE_NAME_LENGTH, cookieValue, COOKIE_VALUE_LENGTH)) != ML_CGI_OK)
  {
    mlCgiEndHttpHeader();
    mlCgiFreeResources ();
    showHtmlErrorPage (E_SHOW_WELCOME_PAGE);
    exit (ML_CGI_OK); 
  }
  
  if ((ret = validateCookie (cookieName, cookieValue, mlCgiEnvironmentVariablesValues[ML_CGI_REMOTE_ADDRESS])) != OK)
  {
    if (ret != E_COOKIE_FILE_DOES_NOT_EXIST)
    {
      if ((ret = getCookieValue (cookieName, cookieValue)) != OK)
      {
        mlCgiEndHttpHeader ();
        mlCgiFreeResources ();
        showHtmlErrorPage (ret);
        exit (ML_CGI_OK);
      }
      if ((ret = mlCgiSetCookie (cookieName, cookieValue, 0, NULL, NULL, NULL)) != ML_CGI_OK)
      {
        mlCgiEndHttpHeader();
        mlCgiFreeResources ();
        showHtmlErrorPage (E_SET_COOKIE);
        exit (ML_CGI_OK); 
      }
      if ((cookieFileName = getLongFilename (COOKIES_DIR, cookieName)) == NULL)
      {
        mlCgiEndHttpHeader();
        mlCgiFreeResources ();
        showHtmlErrorPage (E_SHOW_WELCOME_PAGE);
        exit (ML_CGI_OK); 
      }
      remove (cookieFileName); 
    }
    mlCgiEndHttpHeader();
    mlCgiFreeResources ();
    showHtmlErrorPage (ret);
    exit (ML_CGI_OK); 
  }

  mlCgiEndHttpHeader();
  mlCgiFreeResources ();

  showHtmlWelcomePage (cookieName);

  exit (ML_CGI_OK);
}
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);
}
int main (int argc, char **argv)
{
	environmentType enviro;
	thcErrorType errorCode;
	thcLanguageType language = THC_DEFAULT_LANGUAGE;
	thcUserDataType data;
	char nickname [THC_NICKNAME_MAXIMUM_LENGHT+1];
	char cookieName [THC_COOKIE_NAME_LENGHT + 1];
	
		
	if (mlCgiInitialize (&enviro))
		exit (THC_OK);

	if (enviro == commandLine)
	{
		thcGetTextErrorMessage(language,THC_ERROR_INVALID_INTERFACE);
		mlCgiFreeResources();
		exit (THC_OK);
	}
	
	/*Start header*/
	mlCgiBeginHttpHeader("text/html");
	
	/*Get nickname*/
	errorCode = mlCgiGetFormStringNoNewLines ("thcNickname",nickname,THC_NICKNAME_MAXIMUM_LENGHT);
	if (errorCode != ML_CGI_OK)
	{
		mlCgiEndHttpHeader();
		thcGetHtmlErrorMessage(language, THC_ERROR_ON_WEB_FORM);
		mlCgiFreeResources();
		exit(THC_OK);
	}
	
	/*Get the cookie name*/
	errorCode = thcSearchUser(nickname,&data);
	if (errorCode != THC_OK)
	{
		mlCgiEndHttpHeader ();
		thcGetHtmlErrorMessage(language, errorCode);
		mlCgiFreeResources();
		exit(THC_OK);
	}

	if (sprintf(cookieName,THC_COOKIE_NAME_PRINTF_FORMAT,data.UID) != THC_COOKIE_NAME_LENGHT)
	{
		mlCgiEndHttpHeader ();
		thcGetHtmlErrorMessage(language,THC_ERROR_GENERATING_COOKIE_NAME);
		mlCgiFreeResources();
		exit(THC_OK);			
	}	
	
	errorCode = thcRenewCookie(cookieName,&language);
	
	mlCgiEndHttpHeader();
	if (errorCode != THC_OK)
	{
		thcGetHtmlErrorMessage(language, errorCode);
		mlCgiFreeResources();
		exit(THC_OK);
	}
	
	
	/*Check for admin member*/
	if ((data.group != administrador) && (data.group != userAdmin) && (data.group != ownerAdmin) &&(data.group != root))
	{
		/*Show the user form*/
		thcWebShowHeader();
		
		printf("	<body>                                                                                          \n");
		printf("		<ul class=\"table\">                                                                        \n");
		printf("		     %s <br>                                                                                \n",menssages[1][language]);
		printf("			<form action='thcRemoveUser.cgi' method='post'><br>                                     \n");
		printf("				<input type='radio' name='thcConfirm' value='yes'>%s<br>                            \n",menssages[2][language]);  
		printf("                <input type='radio' name='thcConfirm' value='no' checked>%s<br>                     \n",menssages[3][language]);
		printf("				<input type=\"hidden\" name=\"thcNickname\" value=\"%s\">	                        \n",nickname);
		printf("				<input type=\"hidden\" name=\"thcCookieName\" value=\"%s\">	                        \n",cookieName);
		printf("				<input type=\"submit\" value=\"enter\">                                             \n");
		printf("			</form>                                                                                 \n");
		printf("		</ul>                                                                                       \n");
		
		thcWebShowFooter();
	}
	
	
	/*Show the admin form*/
	thcWebShowHeader();
		
	printf("	<body>                                                                                          \n");
	printf("		<ul class=\"table\">                                                                        \n");
	printf("		     %s <br>                                                                                \n",menssages[1][language]);
	printf("			<form action='thcRemoveUser.cgi' method='post'>                                         \n");
	printf("				%s<br><input type=\"text\" name=\"thcNickname\" value=\"%s\"><br>                   \n",menssages[0][language],nickname);
	printf("				<input type='radio' name='thcConfirm' value='yes'>%s<br>                            \n",menssages[2][language]);  
	printf("                <input type='radio' name='thcConfirm' value='no' checked>%s<br>                     \n",menssages[3][language]);
	printf("				<input type=\"hidden\" name=\"thcCookieName\" value=\"%s\">	                        \n",cookieName);
	printf("				<input type=\"submit\" value=\"enter\">                                             \n");
	printf("			</form>                                                                                 \n");
	printf("		</ul>                                                                                       \n");
	
	thcWebShowFooter();
	
	
	return THC_OK;
}
int main (int argc, char **argv)
{
	thcUserDataType data;
	environmentType enviro;
	thcErrorType errorCode;
	thcLanguageType language = THC_DEFAULT_LANGUAGE;
	time_t localTime;
	char nickname[THC_NICKNAME_MAXIMUM_LENGHT+1];
	char cookieName [THC_COOKIE_NAME_LENGHT + 1];
	char cookieContent [THC_COOKIE_CONTENT_LENGHT + 1];

	if (mlCgiInitialize (&enviro))
		exit (THC_OK);

	if (enviro == commandLine)
	{
		thcGetTextErrorMessage(language,THC_ERROR_INVALID_INTERFACE);
		mlCgiFreeResources();
		exit (THC_OK);
	}
	
	/*Start header*/
	mlCgiBeginHttpHeader("text/html");
	
	/*Get nickname*/
	errorCode = mlCgiGetFormStringNoNewLines ("thcNickname",nickname,THC_NICKNAME_MAXIMUM_LENGHT);
	if (errorCode != ML_CGI_OK)
	{
		mlCgiEndHttpHeader();
		thcGetHtmlErrorMessage(language, THC_ERROR_ON_WEB_FORM);
		mlCgiFreeResources();
		exit(THC_OK);
	}
	
	/*Get the cookie name*/
	errorCode = thcSearchUser(nickname,&data);
	if (errorCode != THC_OK)
	{
		mlCgiEndHttpHeader ();
		thcGetHtmlErrorMessage(language, errorCode);
		mlCgiFreeResources();
		exit(THC_OK);
	}

	if (sprintf(cookieName,THC_COOKIE_NAME_PRINTF_FORMAT,data.UID) != THC_COOKIE_NAME_LENGHT)
	{
		mlCgiEndHttpHeader ();
		thcGetHtmlErrorMessage(language,THC_ERROR_GENERATING_COOKIE_NAME);
		exit(THC_OK);			
	}	
	
	/*Send cookie with expiration time 0*/
	mlCgiGetSpecificCookie (cookieName,THC_NICKNAME_MAXIMUM_LENGHT,cookieContent,THC_COOKIE_CONTENT_LENGHT);
	mlCgiSetCookie(cookieName,cookieContent,0,NULL,NULL,NULL);
	mlCgiEndHttpHeader();
	
	localTime = time(NULL);
	thcGenerateCookie(cookieName, &localTime, cookieContent, THC_DEFAULT_COOKIE_IP);	
	
	printf("<head>       \n");
	if (cookieContent[0] == 'e')
		printf("<meta HTTP-EQUIV='REFRESH' content='0; url=%s'>  ",THC_WEB_SERVER_URL);
	if (cookieContent[0] == 'b')
		printf("<meta HTTP-EQUIV='REFRESH' content='0; url=%s'>  ",THC_WEB_SERVER_URL_BR);
	printf("</head>      \n");
	

	mlCgiFreeResources();
	return THC_OK;
}
int main (int argc, char **argv)
{
  unsigned errorCode;	
  char email[MAX_LENGTH_EMAIL +1];
  char password[MAX_LENGTH_PLAIN_PASS +1];
  char option[10 +1];
  char name[MAX_LENGTH_NAME +1];
  char filename[MAX_LENGTH_LONG_FILENAME +1];
  char encryptedPass[ENCRYPTED_PASS_LENGTH +1];
  FILE *tempFile;

  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 ("email", email, MAX_LENGTH_EMAIL)) != 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 = mlCgiGetFormStringNoNewLines ("password", password, MAX_LENGTH_PLAIN_PASS)) != ML_CGI_OK)
  {
    mlCgiEndHttpHeader ();
    mlCgiFreeResources ();
    if (errorCode == ML_CGI_FORM_FIELD_NOT_FOUND)
      showHtmlErrorPage (FORM_PLAIN_PASS_NOT_FOUND);
    if (errorCode == ML_CGI_INVALID_FORM_LENGTH)
      showHtmlErrorPage (INVALID_FORM_PLAIN_PASS_LENGTH);
    exit (ML_CGI_OK);
  }
  
  if ((errorCode = mlCgiGetFormStringNoNewLines ("option", option, 10)) != 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);
  }

  mlCgiEndHttpHeader();
  mlCgiFreeResources ();
  
  if (!strcmp (option, "reject"))
  {
    remove (email);
    showHtmlErrorPage (USER_HAS_REJECTED_THE_INVITATION);
    exit (ML_CGI_OK);
  }
  
  if ((errorCode = getLongFilename (DATA_DIR, email, filename)) != OK)
  {
    showHtmlErrorPage (errorCode);
    exit (ML_CGI_OK);
  }
    
  if ((tempFile = fopen (filename, "r")) == NULL)
  {
    if (errno != ENOENT)
    {
      showHtmlErrorPage (ERROR_OPENING_TEMPORARY_FILE_FOR_READING);
      exit (ML_CGI_OK);
    }
    showHtmlErrorPage (TEMPORARY_FILE_DOES_NOT_EXIST);
    exit (ML_CGI_OK);
  } 
  
  if ((errorCode = getString (tempFile, MIN_LENGTH_NAME, MAX_LENGTH_NAME, name)) != OK)
  {
    fclose (tempFile);
    showHtmlErrorPage (errorCode);
    exit (ML_CGI_OK);
  }
  if ((errorCode = getString (tempFile, ENCRYPTED_PASS_LENGTH, ENCRYPTED_PASS_LENGTH, encryptedPass)) != OK)
  {
    fclose (tempFile);
    showHtmlErrorPage (errorCode);
    exit (ML_CGI_OK);
  }
  fclose (tempFile);
  
  if ((errorCode = checkPassword (encryptedPass, password)) != OK)
  {
    showHtmlErrorPage (errorCode);
    exit (ML_CGI_OK);
  }
  remove (filename);
  
  #ifdef ENGLISH
    printf ("<HTML>\n");
    printf ("  <HEAD>\n");
    printf ("    <TITLE>Relationship System - Form to add a new user to the system </TITLE>\n");
    printf ("  </HEAD>\n");
    printf ("  <BODY BACKGROUND = \"http://www2.del.ufrj.br/~marceloddm/computacao_ii/pf/images/zertxtr.gif\" BGCOLOR = \"#000000\" TEXT = \"#FFFFFF\" LINK = \"#6699CC\" VLINK = \"#669966\" ALINK = \"#999999\">\n");
    printf ("    <DIV ALIGN = \"CENTER\"><STRONG><FONT FACE = \"Courier New\" SIZE = \"5\" COLOR = \"#FFFFFF\">RELATIONSHIP SYSTEM</FONT></STRONG></DIV>\n");
    printf ("    <HR>\n");
    printf ("    <CENTER><STRONG><FONT FACE = \"Courier New\" SIZE = \"4\" COLOR = \"#FFFFFF\">FORM TO ADD A NEW USER TO THE SYSTEM</FONT></STRONG><CENTER>\n");
    printf ("    <HR>\n");
    printf ("    <BR><BR>\n");
    printf ("    <TABLE BORDER=\"1\" ALIGN = \"center\">\n");
    printf ("    <FORM ACTION=\"http://www2.del.ufrj.br/~marceloddm/computacao_ii/pf/cgi/newUser.cgi\" METHOD=\"post\">\n");
    printf ("       <TR><TD>Username: </TD>     <TD><INPUT TYPE=\"text\"     NAME=\"username\"   SIZE=\"%i\"  ></TD></TR>\n", MAX_LENGTH_USERNAME);
    printf ("       <TR><TD>Password: </TD>     <TD><INPUT TYPE=\"password\" NAME=\"password\"   SIZE=\"%i\" VALUE=\"%s\" ></TD></TR>\n", MAX_LENGTH_PLAIN_PASS, password);
    printf ("       <TR><TD>Web user: </TD>     <TD><INPUT TYPE=\"radio\"    NAME=\"category\" VALUE=\"webUser\" CHECKED></TD></TR>\n");
    printf ("       <TR><TD>Relative: </TD>     <TD><INPUT TYPE=\"radio\"    NAME=\"category\" VALUE=\"relative\"></TD></TR>\n"); 
    printf ("       <TR><TD>Full name: </TD>    <TD><INPUT TYPE=\"text\"     NAME=\"name\"       SIZE=\"40\" VALUE=\"%s\"></TD></TR>\n", name);  
    printf ("       <TR><TD>Email: </TD>        <TD><INPUT TYPE=\"text\"     NAME=\"email\"      SIZE=\"40\" VALUE=\"%s\"></TD></TR>\n", email);
    printf ("       <TR><TD>Homepage: </TD>     <TD><INPUT TYPE=\"text\"     NAME=\"homepage\"   SIZE=\"40\"  ></TD></TR>\n");
    printf ("       <TR><TD>Street: </TD>       <TD><INPUT TYPE=\"text\"     NAME=\"street\"     SIZE=\"40\"  ></TD></TR>\n");  					
    printf ("       <TR><TD>Home number: </TD>  <TD><INPUT TYPE=\"text\"     NAME=\"homeNumber\" SIZE=\"%i\"  ></TD></TR>\n", MAX_LENGTH_HOME_NUMBER);
    printf ("       <TR><TD>Complement: </TD>   <TD><INPUT TYPE=\"text\"     NAME=\"complement\" SIZE=\"40\"  ></TD></TR>\n");   
    printf ("       <TR><TD>District: </TD>     <TD><INPUT TYPE=\"text\"     NAME=\"district\"   SIZE=\"40\"  ></TD></TR>\n"); 
    printf ("       <TR><TD>City: </TD>         <TD><INPUT TYPE=\"text\"     NAME=\"city\"       SIZE=\"40\"  ></TD></TR>\n"); 
    printf ("       <TR><TD>State: </TD>        <TD><INPUT TYPE=\"text\"     NAME=\"state\"      SIZE=\"40\"  ></TD></TR>\n"); 
    printf ("       <TR><TD>Country: </TD>      <TD><INPUT TYPE=\"text\"     NAME=\"country\"    SIZE=\"40\"  ></TD></TR>\n");
    printf ("       <TR><TD>ZIP CODE: </TD>     <TD><INPUT TYPE=\"text\"     NAME=\"zipCode\"    SIZE=\"%i\"  ></TD></TR>\n", MAX_LENGTH_ZIP_CODE);   				
    printf ("       <TR><TD>Telphone: </TD>     <TD><INPUT TYPE=\"text\"     NAME=\"telNumber\"  SIZE=\"%i\"  ></TD></TR>\n", MAX_LENGTH_TEL_NUMBER);
    printf ("       <TR><TD>Cellphone: </TD>    <TD><INPUT TYPE=\"text\"     NAME=\"cellNumber\" SIZE=\"%i\"  ></TD></TR>\n", MAX_LENGTH_CELL_NUMBER);
    printf ("       <TR><TD>Male: </TD>         <TD><INPUT TYPE=\"radio\"    NAME=\"gender\" VALUE=\"male\"  ></TD></TR>\n");
    printf ("       <TR><TD>Female: </TD>       <TD><INPUT TYPE=\"radio\"    NAME=\"gender\" VALUE=\"female\"></TD></TR>\n");
    printf ("       <TR><TD>Single: </TD>       <TD><INPUT TYPE=\"radio\"    NAME=\"relationshipStatus\" VALUE=\"single\"></TD></TR>\n");
    printf ("       <TR><TD>Married: </TD>      <TD><INPUT TYPE=\"radio\"    NAME=\"relationshipStatus\" VALUE=\"married\"></TD></TR>\n");
    printf ("       <TR><TD>Widowed: </TD>      <TD><INPUT TYPE=\"radio\"    NAME=\"relationshipStatus\" VALUE=\"widowed\"></TD></TR>\n");        
    printf ("       <TR><TD>Date of birth: </TD><TD><INPUT TYPE=\"text\"     NAME=\"birthday\"      SIZE=\"8\"> (DDMMYYYY)</TD></TR>\n"); 
    printf ("       <TR><TD>Description: </TD>  <TD><INPUT TYPE=\"text\"     NAME=\"description\"   SIZE=\"40\"  ></TD></TR>\n");  
    printf ("    </TABLE>\n");  	
    printf ("    <BR><BR>\n");
    printf ("                      <INPUT TYPE=\"submit\"   VALUE=\"Submit\">\n");
    printf ("                      <INPUT TYPE=\"reset\"    VALUE=\"Clear\">\n");
    printf ("    </FORM>\n");
    printf ("    <BR><BR><BR>\n");
    printf ("<P ALIGN=\"left\"><A HREF=\"javascript:window.history.go(-1)\" TARGET=\"_self\">GO BACK</a></p>\n");
    printf ("    <HR>\n");
    printf ("    <DIV ALIGN = \"RIGHT\"><FONT FACE = \"Courier New\" SIZE = \"2\"><U>Authors:</U>\n");
    printf ("    <I> Carlo Fragni and Marcelo Duffles Donato Moreira\n");
    printf ("    <BR>\n");
    printf ("    Last update: 13/02/05</I></FONT>\n");
    printf ("    </DIV></FONT>\n");
    printf ("  <BODY>\n");
    printf ("</HTML>\n");
  #elif PORTUGUESE
    printf ("<HTML>\n");
    printf ("  <HEAD>\n");
    printf ("    <TITLE>Sistema de Relacionamentos - Formul&aacute;rio para adicionar novo usu&aacute;rio ao sistema</TITLE>\n");
    printf ("  </HEAD>\n");
    printf ("  <BODY BACKGROUND = \"http://www2.del.ufrj.br/~marceloddm/computacao_ii/pf/images/zertxtr.gif\" BGCOLOR = \"#000000\" TEXT = \"#FFFFFF\" LINK = \"#6699CC\" VLINK = \"#669966\" ALINK = \"#999999\">\n");
    printf ("    <DIV ALIGN = \"CENTER\"><STRONG><FONT FACE = \"Courier New\" SIZE = \"5\" COLOR = \"#FFFFFF\">SISTEMA DE RELACIONAMENTOS</FONT></STRONG></DIV>\n");
    printf ("    <HR>\n");
    printf ("    <CENTER><STRONG><FONT FACE = \"Courier New\" SIZE = \"4\" COLOR = \"#FFFFFF\">FORMUL&Aacute;RIO PARA ADICIONAR NOVO USU&Aacute;RIO AO SISTEMA</FONT></STRONG><CENTER>\n");
    printf ("    <HR>\n");
    printf ("    <BR><BR>\n");
    printf ("    <TABLE BORDER=\"1\" ALIGN = \"center\">\n");
    printf ("    <FORM ACTION=\"http://www2.del.ufrj.br/~marceloddm/computacao_ii/pf/cgi/newUser.cgi\" METHOD=\"post\">\n");
    printf ("       <TR><TD>Username: </TD>     <TD><INPUT TYPE=\"text\"     NAME=\"username\"   SIZE=\"%i\"  ></TD></TR>\n", MAX_LENGTH_USERNAME);
    printf ("       <TR><TD>Senha: </TD>        <TD><INPUT TYPE=\"password\" NAME=\"password\"   SIZE=\"%i\" VALUE=\"%s\"></TD></TR>\n", MAX_LENGTH_PLAIN_PASS, password);
    printf ("       <TR><TD>Usuário web: </TD>  <TD><INPUT TYPE=\"radio\"    NAME=\"category\" VALUE=\"webUser\" CHECKED></TD></TR>\n");
    printf ("       <TR><TD>Parente: </TD>      <TD><INPUT TYPE=\"radio\"    NAME=\"category\" VALUE=\"relative\"></TD></TR>\n"); 
    printf ("       <TR><TD>Nome completo: </TD><TD><INPUT TYPE=\"text\"     NAME=\"name\"       SIZE=\"40\" VALUE=\"%s\"></TD></TR>\n", name);  
    printf ("       <TR><TD>Email: </TD>        <TD><INPUT TYPE=\"text\"     NAME=\"email\"      SIZE=\"40\" VALUE=\"%s\"></TD></TR>\n", email);
    printf ("       <TR><TD>Homepage: </TD>     <TD><INPUT TYPE=\"text\"     NAME=\"homepage\"   SIZE=\"40\"  ></TD></TR>\n");
    printf ("       <TR><TD>Rua: </TD>          <TD><INPUT TYPE=\"text\"     NAME=\"street\"     SIZE=\"40\"  ></TD></TR>\n");  					
    printf ("       <TR><TD>Número: </TD>       <TD><INPUT TYPE=\"text\"     NAME=\"homeNumber\" SIZE=\"%i\"  ></TD></TR>\n", MAX_LENGTH_HOME_NUMBER);
    printf ("       <TR><TD>Complemento: </TD>  <TD><INPUT TYPE=\"text\"     NAME=\"complement\" SIZE=\"40\"></TD></TR>\n");   
    printf ("       <TR><TD>Bairro: </TD>       <TD><INPUT TYPE=\"text\"     NAME=\"district\"   SIZE=\"40\"  ></TD></TR>\n"); 
    printf ("       <TR><TD>Cidade: </TD>       <TD><INPUT TYPE=\"text\"     NAME=\"city\"       SIZE=\"40\"  ></TD></TR>\n"); 
    printf ("       <TR><TD>Estado: </TD>       <TD><INPUT TYPE=\"text\"     NAME=\"state\"      SIZE=\"40\"  ></TD></TR>\n"); 
    printf ("       <TR><TD>País: </TD>         <TD><INPUT TYPE=\"text\"     NAME=\"country\"    SIZE=\"40\"  ></TD></TR>\n");
    printf ("       <TR><TD>CEP: </TD>          <TD><INPUT TYPE=\"text\"     NAME=\"zipCode\"    SIZE=\"%i\"  ></TD></TR>\n", MAX_LENGTH_ZIP_CODE);   				
    printf ("       <TR><TD>Telefone: </TD>     <TD><INPUT TYPE=\"text\"     NAME=\"telNumber\"  SIZE=\"%i\"  ></TD></TR>\n", MAX_LENGTH_TEL_NUMBER);
    printf ("       <TR><TD>Celular: </TD>      <TD><INPUT TYPE=\"text\"     NAME=\"cellNumber\" SIZE=\"%i\"  ></TD></TR>\n", MAX_LENGTH_CELL_NUMBER);
    printf ("       <TR><TD>Masculino: </TD>    <TD><INPUT TYPE=\"radio\"    NAME=\"gender\" VALUE=\"male\"  ></TD></TR>\n");
    printf ("       <TR><TD>Feminino: </TD>     <TD><INPUT TYPE=\"radio\"    NAME=\"gender\" VALUE=\"female\"></TD></TR>\n");
    printf ("       <TR><TD>Solteiro(a): </TD>  <TD><INPUT TYPE=\"radio\"    NAME=\"relationshipStatus\" VALUE=\"single\"></TD></TR>\n");
    printf ("       <TR><TD>Casado(a): </TD>    <TD><INPUT TYPE=\"radio\"    NAME=\"relationshipStatus\" VALUE=\"married\"></TD></TR>\n");
    printf ("       <TR><TD>Viuvo(a): </TD>     <TD><INPUT TYPE=\"radio\"    NAME=\"relationshipStatus\" VALUE=\"widowed\"></TD></TR>\n");        
    printf ("       <TR><TD>Data de nascimento: </TD><TD><INPUT TYPE=\"text\"     NAME=\"birthday\"      SIZE=\"8\"> (DDMMYYYY)</TD></TR>\n"); 
    printf ("       <TR><TD>Descrição: </TD>    <TD><INPUT TYPE=\"text\"     NAME=\"description\"   SIZE=\"40\"  ></TD></TR>\n");  
    printf ("    </TABLE>\n");  	
    printf ("    <BR><BR>\n");
    printf ("                      <INPUT TYPE=\"submit\"   VALUE=\"Submeter\">\n");
    printf ("                      <INPUT TYPE=\"reset\"    VALUE=\"Apagar\">\n");
    printf ("    </FORM>\n");
    printf ("    <BR><BR><BR>\n");
    printf ("<P ALIGN=\"left\"><A HREF=\"javascript:window.history.go(-1)\" TARGET=\"_self\">VOLTAR</a></p>\n");
    printf ("    <HR>\n");
    printf ("    <DIV ALIGN = \"RIGHT\"><FONT FACE = \"Courier New\" SIZE = \"2\"><U>Autores:</U>\n");
    printf ("    <I> Carlo Fragni e Marcelo Duffles Donato Moreira\n");
    printf ("    <BR>\n");
    printf ("    &Uacute;ltima Atualiza&ccedil;&atilde;o: 13/02/05</I></FONT>\n");
    printf ("    </DIV></FONT>\n");
    printf ("  <BODY>\n");
    printf ("</HTML>\n");
  #endif

        
  exit (ML_CGI_OK);
}