<?php
session_start();

require_once("include/sql.inc.php");
require_once("include/db.config.inc.php");


$step = isset($_GET['step']) ? abs((int)$_GET['step']) : 0;

if ((!isset($_SESSION['authok']) && $step != 1) || !$step)
	die();

switch ($step)
{
	case 1:
		if (!isset($_GET['login']) ||
			!isset($_GET['password']) ||
			$_GET['login'] != $config->db_user ||
			$_GET['password'] != $config->db_pass)
		{
			echo json_encode(array('result' => false, 'message' => 'Invalid auth data!'));
			break;
		}
		else
		{
			$_SESSION['authok'] = true;
			echo json_encode(array('result' => true, 'message' => 'Auth ok!'));
			break;
		}
	case 2:
		$error = '';
		$config->db_host=@gethostbyname($config->db_host);
		$mysql = @mysql_connect($config->db_host,$config->db_user,$config->db_pass);
		if (!$mysql)
			$error = mysql_error();
		else
		{
			$resource = @mysql_select_db($config->db_db);
			if (!$resource)
				$error = mysql_error();
			else
			{
				mysql_query('ALTER TABLE  `amx_amxadmins` ADD  `icq` INT( 9 ) NULL DEFAULT NULL AFTER  `steamid`;');
				mysql_query('ALTER TABLE  `amx_amxadmins` CHANGE  `password`  `password` VARCHAR( 50 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL;');
			}
		}
		if (!$error)
			echo json_encode(array('result' => true, 'message' => 'Upgrade ok!'));
		else
			echo json_encode(array('result' => false, 'message' => $error));
		break;
}

?>