1
0
mirror of https://github.com/cydrobolt/polr.git synced 2024-11-12 21:22:28 +01:00

Merge pull request #103 from mihawk90/setup-write-config

[setup] Various cleanups
This commit is contained in:
Chaoyi Zha 2015-10-14 17:44:18 -04:00
commit 1bede6921f

View File

@ -81,51 +81,59 @@
} }
$nowdate = date('F d Y'); $nowdate = date('F d Y');
$site_theme = $_POST['t']; $ppass = hashpass($_POST['protpass']);
$data = '<?php $hp = sha1(rstr(30));
$host="' . $_POST['dbserver'] . '";' $data = <<<PHP
. '$user="' . $_POST['dbuser'] . '";' \n<?php
. '$passwd="' . $_POST['dbpass'] . '";' \$host = "{$_POST['dbserver']}";
. '$db="' . $_POST['dbname'] . '";' \$user = "{$_POST['dbuser']}";
. '$wsa = "' . $_POST['appurl'] . '";' \$passwd = "{$_POST['dbpass']}";
. '$wsn = "' . $_POST['appname'] . '";' \$db = "{$_POST['dbname']}";
. '$wsb = "' . $nowdate . '";' \$wsa = "{$_POST['appurl']}";
. '$ppass = \'' . hashpass($_POST['protpass']) . '\';' \$wsn = "{$_POST['appname']}";
. '$hp = "' . sha1(rstr(30)) . "\";" \$wsb = "{$nowdate}";
. '$regtype = "' . $_POST['reg'] . "\";" \$ppass = '{$ppass}';
. '$path = "' . $_POST['path'] . "\";" \$hp = "{$hp}";
. '$fpass = ' . $_POST['fpass'] . ";" \$regtype = "{$_POST['reg']}";
. '$li_shorten_only = ' . $_POST['li_shorten_only'] . ";" \$path = "{$_POST['path']}";
. '$theme = "' . $site_theme . "\";" \$fpass = {$_POST['fpass']};
. '$ip = ' . $_POST['ipfetch'] . ";" \$li_shorten_only = {$_POST['li_shorten_only']};
. '$li_show_front = ' . $_POST['li_show_front'] . ";" \$theme = "{$_POST['t']}";
. '$unstr = "' . $rstr . '";'; \$ip = {$_POST['ipfetch']};
\$li_show_front = {$_POST['li_show_front']};
\$unstr = "{$rstr}";
PHP;
if (strlen($_POST['smtp-servers'])>1) { if (strlen($_POST['smtp-servers'])>1) {
$smtpSection = ' $smtpSection = <<<PHP
$smtpCfg = array( \n
"servers" => \''.$_POST['smtp-servers'].'\', \$smtpCfg = array(
"from" => \''.$_POST['smtp-from'].'\', "servers" => "{$_POST['smtp-servers']}",
"username" => \''.$_POST['smtp-username'].'\', "from" => "{$_POST['smtp-from']}",
"password" => \''.$_POST['smtp-password'].'\', "username" => "{$_POST['smtp-username']}",
"password" => "{$_POST['smtp-password']}",
); );
'; PHP;
$data .= $smtpSection; $data .= $smtpSection;
} }
$data .= '?>'; $handle = fopen("config.php", 'w');
$file = "config.php";
$handle = fopen($file, 'a');
if (fwrite($handle, $data) === FALSE) { if (fwrite($handle, $data) === FALSE) {
echo "Can not write to (" . $file . "). Please make sure your file permissions are correct. die("<p class='alert alert-danger'>Could not write to <strong>config.php</strong>. Please make sure your file permissions are correct.
<br />Your webserver's user should have write permissions for the folder. Try looking up <code>chown</code>, <code>chgrp</code> and <code>chmod</code>. <a href='http://linuxcommand.org/lts0070.php'>Helpful link</a>"; <br />Your webserver's user should have write permissions for the folder. Try looking up <code>chown</code>, <code>chgrp</code> and <code>chmod</code>. <a href='http://linuxcommand.org/lts0070.php'>Helpful link</a></p>. <strong>Aborting Setup</strong>");
die(); } else {
echo "<p class='alert alert-success'>Successfully created <strong>config.php</strong> .</p>";
} }
echo "Successfully created config. "; fclose($handle); //config.php
fclose($handle);
require_once('lib-core.php'); require_once('lib-core.php');
$path = $_POST['path']; $path = $_POST['path'];
if (strlen($path) > 2) { // check if path ends with / , validating it for .htaccess
if ( empty( $path ) ) {
echo "<p class='alert alert-success'>Path is empty, no <strong>.htaccess</strong> needs to be written.</p>";
} elseif ( !( ( strlen( $path) > 2) &&
( substr( $path, -1 ) == "/") ) ) {
echo "<p class='alert alert-danger'>Path needs trailing slash (<code>/</code>) and cannot be a slash only.</p>";
} else {
$data = "<IfModule mod_rewrite.c> $data = "<IfModule mod_rewrite.c>
RewriteEngine On RewriteEngine On
RewriteBase $path RewriteBase $path
@ -140,8 +148,13 @@
</IfModule>"; </IfModule>";
$handle = fopen('.htaccess', 'w'); $handle = fopen('.htaccess', 'w');
if (fwrite($handle, $data) === FALSE) { if (fwrite($handle, $data) === FALSE) {
echo "Can not write to (" . $file . ")"; echo "<p class='alert alert-danger'>Could not write to <strong>.htaccess</strong> .</p>";
} else {
echo "<p class='alert alert-success'>Successfully created <strong>.htaccess</strong> .</p>";
} }
fclose($handle); //.htaccess
// .nginx-config
$data = "# Polr experimental nginx configuration. Append this to your nginx config for effect. $data = "# Polr experimental nginx configuration. Append this to your nginx config for effect.
# If you use Apache, ignore this file. # If you use Apache, ignore this file.
# Try `/etc/nginx/config.d/` if you have trouble finding the configuration # Try `/etc/nginx/config.d/` if you have trouble finding the configuration
@ -165,12 +178,16 @@
}"; }";
$handle = fopen('.nginx-config', 'w'); $handle = fopen('.nginx-config', 'w');
if (fwrite($handle, $data) === FALSE) { if (fwrite($handle, $data) === FALSE) {
echo "Can not write to (" . $file . ")"; echo "<p class='alert alert-warning'>Could not write to <strong>.nginx-config</strong></p>";
} else {
echo "<p class='alert alert-success'>Successfully created <strong>.nginx-config</strong> .</p>";
} }
echo "Succesfully created htaccess (custom path) <br />. "; fclose($handle); //.nginx-config
fclose($handle);
} }
// Create Polr tables
// TODO: lib-core.php:95
// return actual result of query and implement Error message here instead of core~
sqlrun(' sqlrun('
CREATE TABLE `api` ( CREATE TABLE `api` (
`valid` tinyint(1) NOT NULL, `valid` tinyint(1) NOT NULL,