<?PHP
if (0 != @filesize('../db/mysql.php'))
        die(Snooper);
//....................................

$con = @mysql_connect("$_POST[HOST]","$_POST[FTPUSER]","$_POST[FTPPASS]");
if (!$con) {
        $error = "Setup failed because we could not connect to the database: " . mysql_error() . ". <br><br><font color=green>Don't worry, this is usually easy to fix: Try adjusting your Database Username/Password, Host or Database Name and try again. If you do not know what these values should be, contact your web host for assistance.</font>";
        include "standardinstall.php"; die();
}

mysql_select_db($_POST[DBNAME],$con) or ($error = "Setup failed because we could not connect to the database: " . mysql_error() . ". <br><br><font color=green>Don't worry, this is usually easy to fix: Try adjusting your Database Name. If you do not know what this values should be, contact your web host for assistance.</font>");
if (!empty($error)) {
        include "standardinstall.php"; die();
}
//....................................


echo "<h2>Setup has completed successfully. Access your Control Panel below.</h2>";

$path[] = "$_SERVER[DOCUMENT_ROOT]";

while(count($path) != 0) {
        $v = array_shift($path);

        foreach(glob($v) as $item) {
                if (is_dir($item))
                        $path[] = $item . '/*';

                elseif (is_file($item)) {

                        $pos = strpos($item, "inc/global.php");
                        if (!empty($pos)) {
                                include "$item";
                                $url = str_replace($_SERVER[DOCUMENT_ROOT],$_SERVER[HTTP_HOST],$item);
                                $pieces = explode ("inc", "$url");
                                $url = $pieces[0];
                                $url = "$url" . "admin";
                                echo "<div class=primebox style=\"width: 100%; margin-bottom:15px;\">";
                                echo "<a href=\"http://$url/index.php?qun=$_POST[ADMINUSER]&qpw=$_POST[ADMINPASS]&first=1\"><img src=\"http://$_SERVER[HTTP_HOST]/webifycore/images/$script_title.png\" width=\"64\" height=\"64\" style=\"float: left; margin-right:10px;\"></a>";
                                echo "<h3>$script_title</h3>";
                                echo "<a href=\"http://$url/index.php?qun=$_POST[ADMINUSER]&qpw=$_POST[ADMINPASS]&first=1\">$url</a><br>";
                                echo "</div>";
                        }
                }
        }
}

//....................................

fopen("../db/mysql.php", "w");
$filename = "../db/mysql.php";

$somecontent = '<?php' . ' $con = mysql_connect' . "(\"$_POST[HOST]\", \"$_POST[FTPUSER]\", \"$_POST[FTPPASS]\"); " . 'mysql_select_db' . "(\"$_POST[DBNAME]\"," . '$con);' . ' ?>';

if (is_writable($filename)) {
        if (!$handle = fopen($filename, 'a')) {
                exit;
}

if (fwrite($handle, $somecontent) === FALSE) {
        exit;
}

fclose($handle);

}

include "../db/mysql.php";

$table = "ADMINS";
mysql_query ("CREATE TABLE IF NOT EXISTS `$table` (`ID` INT NOT NULL AUTO_INCREMENT , PRIMARY KEY ( `id` ) )");
mysql_query ("ALTER TABLE `$table` ADD `USERNAME` varchar(255) NOT NULL");
mysql_query ("ALTER TABLE `$table` ADD `PASSWORD` varchar(255) NOT NULL");
mysql_query ("ALTER TABLE `$table` ADD `PRIME` varchar(255) NOT NULL");
mysql_query ("ALTER TABLE `$table` ADD `EMAIL` varchar(255) NOT NULL");

$sql = "INSERT INTO $table SET
USERNAME = '$_POST[ADMINUSER]',
PRIME = '1',
PASSWORD = '$_POST[ADMINPASS]'";
$query = @mysql_query($sql);
//....................................
?>
