#include <stdio.h>
#include <stdlib.h>  /* for exit */
#include <time.h>
#include <dirent.h>
#include <string.h>

#include <sys/stat.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_cs_util.h"
#include "manhat-lib/shared_super_menu.h"

void
lock_server( const char *key)
{
       char tmp_dir[MAX_PATH +1];
       FILE *fp;

       snprintf(tmp_dir, MAX_PATH +1, "%s%s",  TMP_PATH, MAINTENANCE_LOCK);
       fp = fopen(tmp_dir, "w");
       if(!fp)
	       cs_critical_error(ERR_FOPEN_WRITE_FAILED, "");
       fprintf(fp, "Server is locked");   /* you don't really have to write anything at all to this file */
       fclose(fp);
	
}

int
main ()
{

	char key[MAX_KEY + 1];
        SESSION user;

	cs_cgi_init();
        read_param( key);
        validate_super_key(key, &user);
	set_admin_page(&user, key, 0, "super_lock");  /* shared_super_menu.c */
        lock_server( key);
	cs_cgi_display("super_lock", 1);
	cs_cgi_destroy();
	 return 0;
}

