1
0
mirror of https://github.com/cydrobolt/polr.git synced 2024-09-19 23:21:47 +02:00

[setup] Various cleanups

* config file code more readable
* success/fail messages formatted
* fclose unclosed file-handle
This commit is contained in:
Tarulia 2015-09-25 21:26:59 +02:00
parent 64714b8b64
commit e56fd23b39

View File

@ -81,51 +81,54 @@
} }
$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 .= '?>'; $data .= "\n?>";
$file = "config.php"; $handle = fopen("config.php", 'w');
$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) { if (strlen($path) > 2) { // why 2? Is a folder like /r possible?
$data = "<IfModule mod_rewrite.c> $data = "<IfModule mod_rewrite.c>
RewriteEngine On RewriteEngine On
RewriteBase $path RewriteBase $path
@ -140,8 +143,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
@ -162,15 +170,19 @@
location $path/t { location $path/t {
rewrite ^$path/t-([a-zA-Z0-9]+)/?$ $path/r.php?u=t-$1; rewrite ^$path/t-([a-zA-Z0-9]+)/?$ $path/r.php?u=t-$1;
} }
}"; }";
$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,