Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: ccf03dd65c
Fetching contributors…

Cannot retrieve contributors at this time

file 154 lines (137 sloc) 5.761 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
<?php
/************************************************************************
* Call of Cthulhu Character Generator
* Copyright (C) 2011 Brian Turchyn, Glen Conolly, Tyler Omichinski
* All references to commercial items copyright their respective owners.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
************************************************************************/

error_reporting(0);
ini_set('display_errors','Off');

require_once 'classes/sqli.php';

define('CFG_FILE', "../config.php");
define('INS_LOCK', "install.lock");

function bufferflush (){
    echo(str_repeat(' ',256));
    // check that buffer is actually set before flushing
    if (ob_get_length()){
        @ob_flush();
        @flush();
        @ob_end_flush();
    }
    @ob_start();
}
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

<title>CoC Chargen Installer</title>
<style type='text/css'>
body {background:#8CA2D5;font-family: Verdana;font-size:10px;margin: 0;padding: 0;}
.header {width: 100%; margin: 0; padding: 0;border: 0; background: #5D75AB;}
.header h1 {text-align:right;margin: 0 0 25px 0;padding:25px;}
.container {margin: auto; width: 400px;padding: 10px;background:#A0B0D5;position:relative;
-moz-border-radius: 20px;
-webkit-border-radius: 20px;
-khtml-border-radius: 20px;
border-radius: 20px;
behaviour: url(border-radius.htc);
border: 1px solid #EEF;}
.label {width: 200px;text-align: right;float:left;height:20px;vertical-align:bottom;padding-top:5px;}
.input {width: 200px;text-align: left; float:left;height:25px;}
.status {text-align:center;font-size: 12px;}
.success {color: green;}
.failure {color: red;}
</style>
</head>

<body>
<div class="header"><h1>CoC Chargen Installer</h1></div>
<div class="container">
<?php

if(file_exists(INS_LOCK)) {
?>
<p class="status failed">The installer has been locked. Remove install.lock to reinstall.</p>
<?php
}
elseif(file_exists(CFG_FILE)) {
?>
<p class="status failed">The configuration file currently exists. Remove the configuration file to continue.</p>
<?php
}
// Check if we'll be able to write the config file
elseif(!file_exists(CFG_FILE) && !(touch(CFG_FILE) && unlink(CFG_FILE))) {
?>
<p class="status failed">Unable to write the config file. Check folder permissions.</p>
<?php
}
// Check if we'll be able to write the install lock
elseif(!file_exists(INS_LOCK) && !(touch(INS_LOCK) && unlink(INS_LOCK))) {
?>
<p class="status failed">Unable to write the installer lock. Check folder permissions.</p>
<?php
}
elseif(isset($_POST['coc_install'])) {
$sql = new SQLiInstall($_POST['coc_host'], $_POST['coc_user'], $_POST['coc_password'], $_POST['coc_database'], $_POST['coc_prefix']);
echo "Successfully connected to " . $sql->host_info . "<br />";

$failed = false;

// Get the SQL files
$dir = 'tabledata';
$files = scandir($dir, 0);
// Iterate through each file
foreach($files as $key => $value) {
if(preg_match("/.sql$/", $value)) {
// Output the current query being run, and flush the buffer
echo preg_replace("/.sql$/", "", $value) . " ==> ";
bufferflush();

// Run the query
$res = $sql->runQueryFromFile($value);

// Display the result
if($res == null) {
echo "<span style=\"color: green\">Passed</span><br />\n";
} else {
echo "<span style=\"color: red\">FAILED</span><br />\n";
$failed = true;
}
}
}

// Only write the config and lock the installer if we've succeeded
if(!$failed) {
// TODO: Write the configuration file out
echo (touch(CFG_FILE) ? "Config created" : "Config creation failed!");

// Lock the installer
echo (touch(INS_LOCK) ? "Lock created" : "Lock creation failed!");
}

// Display the overall result
if(!$failed) {
echo "<p class='status success'>Completed successfully!</p>";
} else {
echo "<p class='status failed'>One or more install queries failed. Your installation of CoC Chargen may not function properly!</p>";
}

} else {
?>
<form method='POST'>
<div class='label'><label for='coc_host'>Database host:</label></div> <div class='input'><input type="text" name="coc_host" /></div>
<div class='label'><label for='coc_user'>Database username:</label></div> <div class='input'><input type="text" name="coc_user" /></div>
<div class='label'><label for='coc_password'>Database password:</label></div> <div class='input'><input type="text" name="coc_password" /></div>
<div class='label'><label for='coc_database'>Database name:</label></div> <div class='input'><input type="text" name="coc_database" /></div>
<div class='label'><label for='coc_prefix'>Table prefix:</label></div> <div class='input'><input type="text" name="coc_prefix" /></div>
<div style='text-align:center'><input type="submit" name="coc_install" value="Install Database" /></div>
</form>
<?php
}
?>
</div>
</body>
</html>
Something went wrong with that request. Please try again.