diff options
Diffstat (limited to 'common/install.php')
-rwxr-xr-x | common/install.php | 170 |
1 files changed, 28 insertions, 142 deletions
diff --git a/common/install.php b/common/install.php index 3a3eae7..86e1123 100755 --- a/common/install.php +++ b/common/install.php @@ -1,6 +1,6 @@ <?php -require_once dirname(__FILE__) . '/app/app.php'; +require_once __DIR__ . '/app/app.php'; // This is an helper function returning an html table row to avoid code duplication function installStatus($str, $msg, $result) { @@ -8,31 +8,32 @@ function installStatus($str, $msg, $result) { return '<tr><td>' . $str . '</td><td class="' . $class . '">' . $msg . '</td></tr>'; } -// If the password and config files exist, moonmoon is already installed -if (file_exists(dirname(__FILE__) . '/custom/config.yml') - && file_exists(dirname(__FILE__) . '/admin/inc/pwd.inc.php')) { +// If the config file exists and the auth variables are set, moonmoon is already installed +if (is_installed()) { $status = 'installed'; -} elseif (isset($_REQUEST['url'])) { +} elseif (isset($_POST['url'])) { + + // Do no try to use the file of an invalid locale + if (strstr($_POST['locale'], '..') !== false + || !file_exists(__DIR__ . "/app/l10n/${_REQUEST['locale']}.lang")) { + $_POST['locale'] = 'en'; + } + $save = array(); //Save config file - $config = array( - 'url' => filter_var($_REQUEST['url'], FILTER_SANITIZE_ENCODED), - 'name' => filter_var($_REQUEST['title'], FILTER_SANITIZE_SPECIAL_CHARS), - 'locale' => filter_var($_REQUEST['locale'], FILTER_SANITIZE_SPECIAL_CHARS), - 'items' => 10, - 'shuffle' => 0, - 'refresh' => 240, - 'cache' => 10, - 'nohtml' => 0, - 'postmaxlength' => 0, - 'cachedir' => './cache' - ); + $config = array_merge(PlanetConfig::$defaultConfig, [ + 'url' => $_POST['url'], + 'name' => filter_var($_POST['title'], FILTER_SANITIZE_SPECIAL_CHARS), + 'locale' => $_POST['locale'], + ]); $CreatePlanetConfig = new PlanetConfig($config); - $save['config'] = file_put_contents(dirname(__FILE__).'/custom/config.yml', $CreatePlanetConfig->toYaml()); + $save['config'] = file_put_contents(custom_path('config.yml'), $CreatePlanetConfig->toYaml()); + + OpmlManager::save(new Opml(), custom_path('people.opml')); //Save password - $save['password'] = file_put_contents(dirname(__FILE__).'/admin/inc/pwd.inc.php', '<?php $login="admin"; $password="'.md5($_REQUEST['password']).'"; ?>'); + $save['password'] = file_put_contents(admin_path('inc/pwd.inc.php'), '<?php $login="admin"; $password="'.md5($_POST['password']).'"; ?>'); if (0 != ($save['config'] + $save['password'])) { $status = 'installed'; @@ -40,12 +41,12 @@ if (file_exists(dirname(__FILE__) . '/custom/config.yml') } else { // We start by malking sure we have PHP5 as a base requirement - if(phpversion() >= 5) { - $strInstall = installStatus('Server is running PHP5', 'OK',true); + if(version_compare(PHP_VERSION, '5.6.0') >= 0) { + $strInstall = installStatus('Server is running at least PHP 5.6', 'OK',true); $strRecommendation = ''; } else { - $strInstall = installStatus('Server is running PHP5', 'FAIL',false); - $strRecommendation = '<li>Check your server documentation to activate PHP5</li>'; + $strInstall = installStatus('Server is running at least PHP 5.6', 'FAIL',false); + $strRecommendation = '<li>Check your server documentation to activate at least PHP 5.6</li>'; } // Writable file requirements @@ -56,10 +57,11 @@ if (file_exists(dirname(__FILE__) . '/custom/config.yml') '/cache', ); - // We now test that all required files are writable + // We now test that all required files and directories are writable. foreach ($tests as $v) { - if(is_writable(dirname(__FILE__) . $v)) { + if(touch(__DIR__ . $v)) { $strInstall .= installStatus("<code>$v</code> is writable", 'OK', true); + unlink(__DIR__.$v); } else { $strInstall .= installStatus("<code>$v</code> is writable", 'FAIL',false); $strRecommendation .= "<li>Make <code>$v</code> writable with CHMOD</li>"; @@ -70,121 +72,5 @@ if (file_exists(dirname(__FILE__) . '/custom/config.yml') $status = ($strRecommendation != '') ? 'error' : 'install'; } -?> -<!DOCTYPE html> -<html lang="en"> -<meta charset="utf-8"> -<head> - <title><?=_g('moonmoon installation')?></title> - <style> - body { - font: normal 1em sans-serif; - width: 500px; - margin: 0 auto; - } - - /* Error */ - td.ok { - color: #090; - } - - td.fail { - color: #900; - font-weight: bold; - } - th { - text-align: left; - } - - /* Install */ - .field label { - display: block; - } - - .submit { - font-size: 2em; - } - - </style> -</head> - -<body> - <h1><?=_g('moonmoon installation')?></h1> - - <?php if ($status == 'error') : ?> - <div id="compatibility"> - <h2>Sorry, your server is not compatible with moonmoon.</h2> - - <h3>Your server does not fulfill the requirements</h3> - <table> - <thead> - <tr> - <th>Test</th> - <th>Result</th> - </tr> - </thead> - <tbody> - <?php echo $strInstall ?> - </tbody> - </table> - - <h3>Troubleshooting</h3> - <p>To install moonmoon, try the following changes:</p> - <ul> - <?php echo $strRecommendation; ?> - </ul> - </div> - - <?php elseif ($status == 'install') : ?> - <div> - <form method="post" action=""> - <fieldset> - <input type="hidden" id="url" name="url" value="" readonly="readonly"/> - <script> - <!-- - document.forms[0].elements[1].value = document.URL.replace('install.php',''); - --> - </script> - - <p class="field"> - <label for="title">Title:</label> - <input type="text" id="title" name="title" value="My website"/> - </p> - <!-- - <p class="field"> - <label>Administrator login:</label> <code>admin</code> - </p> - --> - <p class="field"> - <label for="password">Administrator password:</label> - <input type="text" id="password" name="password" class="text password" value="admin" /> - </p> - <p class="field"> - <label for="locale">Language:</label> - <select name="locale" id="locale"> - <option selected="selected" value="en">English</option> - <option value="fr">Français</option> - </select> - </p> - <p> - <input type="submit" class="submit" value="Install"/> - </p> - </fieldset> - </form> - </div> - - <?php elseif ($status =='installed'): ?> - <p><?=_g('Congratulations! Your moonmoon is ready.')?></p> - <h3><?=_g("What's next?")?></h3> - <ol> - <li> - <?=_g('<strong>Delete</strong> <code>install.php</code> with your FTP software.')?> - </li> - <li> - <?=_g('Use your password to go to the <a href="./admin/">administration panel</a>')?> - </li> - </ol> - <?php endif; ?> -</body> -</html> +require_once views_path('install.tpl.php');
\ No newline at end of file |