margin-top: 2em;
font-size: 2vw;
color: #600;
+ background-color: #FCC;
+ width: 100%;
}
h3 {
- margin-top: 3em;
+ margin-top: 1.5em;
+ margin-bottom:-0.6em;
+ }
+
+ table {
+ margin-left: 10%;
+ width: 80%;
+ }
+
+ td {
+ width: auto;
}
input {
- width: 60%;
+ width: 100%;
}
label {
font-weight: bold;
color: red;
}
+
+ span.pass {
+ margin-left: 1em;
+ font-weight: bold;
+ color: green;
+ }
</STYLE>
<SCRIPT>
var states = [
var option = document.createElement("option");
option.innerText = states[i].name;
option.value = states[i].name;
+ if(select.getAttribute("value") == option.value) {
+ option.setAttribute("selected", "true");
+ }
select.appendChild(option);
}
if( isset($_POST['baseurl']) ) {
$baseurl= $_POST['baseurl'];
+ $adminuser = $_POST['adminuser'];
+ $adminpass = $_POST['adminpass'];
+ $state = $_POST['state'];
+ $lat = $_POST['lat'];
+ $lon = $_POST['lon'];
// Database
$dbuser = $_POST['dbuser'];
$dbtres = "";
$dbcres = "";
- try {
- $dbh = new PDO("mysql:host=localhost;dbname=".$dbbase, $dbuser, $dbpass);
- print_r($dbh);
- print_r($dbh->errorInfo());
- } catch(Exception $ex) {
- $dbtres = $ex->errorInfo[2];
+ if($dbuser == "") {
+ $dbtres = "Please enter a username";
+ $dbcres = "error";
+ } else if($dbpass == "") {
+ $dbtres = "Please enter a password";
+ $dbcres = "error";
+ } else if($dbbase == "") {
+ $dbtres = "Please enter a database name";
$dbcres = "error";
+ } else {
+ try {
+ $dbh = new PDO("mysql:host=localhost;dbname=".$dbbase, $dbuser, $dbpass);
+
+ if( !isset($dbh->errorInfo[2]) ) {
+ $dbtres = '<input type="submit" name="dbinstall" value="Install!" />';
+ $dbcres = "pass";
+ } else {
+ $dbtres = $dbh->errorInfo[2];
+ $dbcres = "error";
+ }
+ } catch(Exception $ex) {
+ $dbtres = $ex->errorInfo[2];
+ $dbcres = "error";
+ }
}
+ if( isset($_POST['dbinstall']) && $dbcres == "pass") {
+ echo "WRITING CONFIGURATION...<br/>".PHP_EOL;
+ $filename = dirname(__FILE__)."/config.php";
+ $fh = fopen($filename, "w") or die("Unable to open ".$filename." for writing!");;
+ $content = <<<EOF
+ <?php
+ define("CCCP_BASEURL", "$baseurl");
+ define("CCCP_BASELAT", "$lat");
+ define("CCCP_BASELON", "$lon");
+ define("CCCP_STATE", "$state");
-}
+ \$options = [
+ PDO::ATTR_EMULATE_PREPARES => false, // Disable emulation mode for "real" prepared statements
+ PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, // Make the default fetch be an associative array
+ ];
+ \$dbh = new PDO("mysql:host=localhost;dbname=$dbbase", "$dbuser", "$dbpass", \$options);
+ ?>
+ EOF;
+ fwrite($fh, $content);
+ fclose($fh);
+
+ echo "INSTALLING DATABASE...<br/>".PHP_EOL;
+ $filename = dirname(__FILE__)."/install.sql";
+ if( !file_exists($filename) ) {
+ echo "ERROR: File does not exist: ".$filename;
+ die();
+ }
+ $query = "source ".$filename.";";
+ $stmt = $dbh->prepare($query);
+ $stmt->execute();
+
+ echo "CONFIGURING ADMIN USERS...<br/>".PHP_EOL;
+ $query = "INSERT INTO users(username, passhash) VALUES(?,?);";
+ $params= Array($adminuser, password_hash($adminpass, PASSWORD_DEFAULT));
+ $stmt = $dbh->prepare($query);
+ $stmt->execute($params);
-print_r($_POST);
+ echo "Installation complete.<br/>".PHP_EOL;
+ echo "<a href='./login.php'>Click here to continue</a>".PHP_EOL;
+ die();
+ }
+}
+
?>
<H1>Welcome to the CCCP<br/>Installer!</H1>
<form action="install.php" method="POST" >
<H2>THE BASICS</H2>
+ <H3>Domain Name</H3>
<p>Please enter the root domain name and directory of this server.</p>
- <label for="baseurl">Base URL:</label>
- <input type="text" name="baseurl" id="baseurl" value="<?php echo $baseurl; ?>"></input>
+ <table>
+ <tr><td><label for="baseurl">Base URL:</label></td>
+ <td><input type="text" name="baseurl" id="baseurl" value="<?php echo $baseurl; ?>"></input></td></tr>
+ </table>
+
+ <H3>Admin Account</H3>
+ <p>Please enter a username and password for your admin account. Try not to forget this.</p>
+ <table>
+ <tr><td><label for="adminuser">Username:</label></td>
+ <td><input type="text" name="adminuser" id="adminuser" value="<?php echo $adminuser;?>"></input></td></tr>
+ <tr><td><label for="adminpass">Password:</label></td>
+ <td><input type="password" name="adminpass" id="adminpass" value="<?php echo $adminpass;?>"></input></td></tr>
+ </table>
+ <H3>Location</H3>
<p>Please enter your current location (this will be used as the default center for displaying maps)</p>
- <label for="state">State:</label>
- <select id="state" name="state" onchange="javascript: stateSelect();">
- <option></option>
- </select><br/>
- <label for="lat">Latitude: </label>
- <input type="text" name="lat" id="lat"></input><br/>
- <label for="lon">Latitude: </label>
- <input type="text" name="lon" id="lon"></input>
- <input type="submit" />
+ <table>
+ <tr><td><label for="state">State:</label></td>
+ <td><select id="state" name="state" onchange="javascript: stateSelect();" value="<?php echo $state; ?>">
+ <option></option>
+ </select></td></tr>
+ <tr><td><label for="lat">Latitude: </label></td>
+ <td><input type="text" name="lat" id="lat" value="<?php echo $lat; ?>"></input></td></tr>
+ <tr><td><label for="lon">Latitude: </label></td>
+ <td><input type="text" name="lon" id="lon" value="<?php echo $lon; ?>"></input></td></tr>
+ </table>
<H2>DATABASE</H2>
<p>Please ensure the server has a MariaDB database configured and enter the connection details below.
Please ensure this file is not externally accessible.
(I recommend not allowing the database to be externally accessible either.)</p>
- <input type="hidden" name="section" value="database" />
- <label for="dbuser">Username:</label>
- <input type="text" name="dbuser" id="dbuser" value="<?php echo $dbuser;?>"></input><br/>
- <label for="dbpass">Username:</label>
- <input type="password" name="dbpass" id="dbpass" value="<?php echo $dbpass;?>"></input><br/>
- <label for="dbbase">Database Name:</label>
- <input type="text" name="dbbase" id="dbbase" value="<?php echo $dbbase;?>"></input>
- <input type="submit" value="Save and Test" name="dbsubmit" />
- <span class="dbtres <?php echo $dbcres; ?>"><?php echo $dbtres; ?></span>
+ <table>
+ <tr><td><label for="dbuser">Username:</label></td>
+ <td><input type="text" name="dbuser" id="dbuser" value="<?php echo $dbuser;?>"></input></td></tr>
+ <tr><td><label for="dbpass">Password:</label></td>
+ <td><input type="password" name="dbpass" id="dbpass" value="<?php echo $dbpass;?>"></input></td></tr>
+ <tr><td><label for="dbbase">Database Name:</label></td>
+ <td><input type="text" name="dbbase" id="dbbase" value="<?php echo $dbbase;?>"></input></td></tr>
+ <tr><td><input type="submit" value="Save and Test" name="dbsubmit" /></td>
+ <td><span class="dbtres <?php echo $dbcres; ?>"><?php echo $dbtres; ?></span></td></tr>
+ </table>
</form>
<H2>WEB SERVER</H2>