#include <stdio.h>
#include <string.h>
#include <unistd.h>		


#include "global.h"
#include "custom.h"		/* for date FORMAT strings */

#include "manhat-lib/shared_util.h"
#include "manhat-lib/shared_super_util.h"
#include "manhat-lib/shared_authenticate.h"
#include "manhat-lib/shared_strtrm.h"
#include "manhat-lib/shared_cs_util.h"
#include "manhat-lib/shared_super_menu.h"



/******* do we still need this?????
static void get_melange_password(char *password)
{

FILE *fp;
char line[200];
char *ptr;

  *password = '\0';
  
  fp = fopen(CHAT_CONF_PATH, "r");
  if(!fp)
     return;
     
  if(!fgets(line, 200, fp))
     return;
     
  fclose(fp);

  ptr = strstr(line,"PASSWD");
  if(ptr && (ptr == line))
    {
     ptr += strlen("PASSWD");
     strtrm(ptr);   // shared_strtrm.c
     if(strlen(ptr) <= MAX_PASSWORD)
       strcpy(password, ptr);
    }
    
}       
 
*******/ 
 


static void
set_chat_menu(  const char *key)
{
	
  
  char url[MAX_PATH +1];   

  cs_set_current_time();
  cs_set_value("install_title", INSTALLATION_TITLE);
  cs_set_int_value("port", MELANGE_PORT);

  snprintf (url, MAX_PATH +1, "%s?id=%s", "super_chat_enter", key);
  cs_set_value("chat.0.url",url); 
  
  snprintf (url, MAX_PATH +1, "%s?id=%s", "super_chat_kill", key);
  cs_set_value("chat.1.url",url); 

  snprintf (url, MAX_PATH +1, "%s?id=%s", "super_chat_start", key);
  cs_set_value("chat.2.url",url); 
  
  snprintf (url, MAX_PATH +1, "%s?id=%s", "super_chat_log", key);
  cs_set_value("chat.3.url",url); 

  snprintf (url, MAX_PATH +1, "%s?id=%s", "super_chat_passwd", key);
  cs_set_value("chat.4.url",url); 
  
}





int
main ()
{
  char key[MAX_KEY + 1];	/* from id=? command line */
  SESSION user; 

  cs_cgi_init();
  read_param ( key);
  validate_super_key (key, &user);	/* shared_super_util.c*/
  set_admin_page(&user, key, 0, "super_chat");  /* shared_super_menu.c */

  set_chat_menu ( key);
  cs_cgi_display("super_chat", 1);
  cs_cgi_destroy();
  return 0;			/* exit successfully */

}

