Browse Source

template.php install.php: handle cache directory being a symlink

dockerize
Zankaria 1 month ago
parent
commit
177de81550
  1. 31
      inc/template.php
  2. 139
      install.php

31
inc/template.php

@ -14,12 +14,17 @@ $twig = false;
function load_twig() { function load_twig() {
global $twig, $config; global $twig, $config;
$cache_dir = "{$config['dir']['template']}/cache";
if (is_link($cache_dir)) {
$cache_dir = realpath($cache_dir);
}
$loader = new Twig\Loader\FilesystemLoader($config['dir']['template']); $loader = new Twig\Loader\FilesystemLoader($config['dir']['template']);
$loader->setPaths($config['dir']['template']); $loader->setPaths($config['dir']['template']);
$twig = new Twig\Environment($loader, array( $twig = new Twig\Environment($loader, array(
'autoescape' => false, 'autoescape' => false,
'cache' => is_writable('templates') || (is_dir('templates/cache') && is_writable('templates/cache')) ? 'cache' => is_writable('templates/') || (is_dir($cache_dir) && is_writable($cache_dir)) ?
new Twig_Cache_TinyboardFilesystem("{$config['dir']['template']}/cache") : false, new Twig_Cache_TinyboardFilesystem($cache_dir) : false,
'debug' => $config['debug'], 'debug' => $config['debug'],
'auto_reload' => $config['twig_auto_reload'] 'auto_reload' => $config['twig_auto_reload']
)); ));
@ -31,17 +36,17 @@ function load_twig() {
function Element($templateFile, array $options) { function Element($templateFile, array $options) {
global $config, $debug, $twig, $build_pages; global $config, $debug, $twig, $build_pages;
if (!$twig) if (!$twig)
load_twig(); load_twig();
if (function_exists('create_pm_header') && ((isset($options['mod']) && $options['mod']) || isset($options['__mod'])) && !preg_match('!^mod/!', $templateFile)) { if (function_exists('create_pm_header') && ((isset($options['mod']) && $options['mod']) || isset($options['__mod'])) && !preg_match('!^mod/!', $templateFile)) {
$options['pm'] = create_pm_header(); $options['pm'] = create_pm_header();
} }
if (isset($options['body']) && $config['debug']) { if (isset($options['body']) && $config['debug']) {
$_debug = $debug; $_debug = $debug;
if (isset($debug['start'])) { if (isset($debug['start'])) {
$_debug['time']['total'] = '~' . round((microtime(true) - $_debug['start']) * 1000, 2) . 'ms'; $_debug['time']['total'] = '~' . round((microtime(true) - $_debug['start']) * 1000, 2) . 'ms';
$_debug['time']['init'] = '~' . round(($_debug['start_debug'] - $_debug['start']) * 1000, 2) . 'ms'; $_debug['time']['init'] = '~' . round(($_debug['start_debug'] - $_debug['start']) * 1000, 2) . 'ms';
@ -59,15 +64,15 @@ function Element($templateFile, array $options) {
str_replace("\n", '<br/>', utf8tohtml(print_r($_debug, true))) . str_replace("\n", '<br/>', utf8tohtml(print_r($_debug, true))) .
'</pre>'; '</pre>';
} }
// Read the template file // Read the template file
if (@file_get_contents("{$config['dir']['template']}/${templateFile}")) { if (@file_get_contents("{$config['dir']['template']}/${templateFile}")) {
$body = $twig->render($templateFile, $options); $body = $twig->render($templateFile, $options);
if ($config['minify_html'] && preg_match('/\.html$/', $templateFile)) { if ($config['minify_html'] && preg_match('/\.html$/', $templateFile)) {
$body = trim(preg_replace("/[\t\r\n]/", '', $body)); $body = trim(preg_replace("/[\t\r\n]/", '', $body));
} }
return $body; return $body;
} else { } else {
throw new Exception("Template file '${templateFile}' does not exist or is empty in '{$config['dir']['template']}'!"); throw new Exception("Template file '${templateFile}' does not exist or is empty in '{$config['dir']['template']}'!");
@ -106,7 +111,7 @@ class Tinyboard extends Twig\Extension\AbstractExtension
new Twig\TwigFilter('cloak_mask', 'cloak_mask'), new Twig\TwigFilter('cloak_mask', 'cloak_mask'),
); );
} }
/** /**
* Returns a list of functions to add to the existing list. * Returns a list of functions to add to the existing list.
* *
@ -126,7 +131,7 @@ class Tinyboard extends Twig\Extension\AbstractExtension
new Twig\TwigFunction('link_for', 'link_for') new Twig\TwigFunction('link_for', 'link_for')
); );
} }
/** /**
* Returns the name of the extension. * Returns the name of the extension.
* *
@ -162,7 +167,7 @@ function twig_hasPermission_filter($mod, $permission, $board = null) {
function twig_extension_filter($value, $case_insensitive = true) { function twig_extension_filter($value, $case_insensitive = true) {
$ext = mb_substr($value, mb_strrpos($value, '.') + 1); $ext = mb_substr($value, mb_strrpos($value, '.') + 1);
if($case_insensitive) if($case_insensitive)
$ext = mb_strtolower($ext); $ext = mb_strtolower($ext);
return $ext; return $ext;
} }
@ -187,7 +192,7 @@ function twig_filename_truncate_filter($value, $length = 30, $separator = '…')
$value = strrev($value); $value = strrev($value);
$array = array_reverse(explode(".", $value, 2)); $array = array_reverse(explode(".", $value, 2));
$array = array_map("strrev", $array); $array = array_map("strrev", $array);
$filename = &$array[0]; $filename = &$array[0];
$extension = isset($array[1]) ? $array[1] : false; $extension = isset($array[1]) ? $array[1] : false;

139
install.php

@ -1,6 +1,6 @@
<?php <?php
// Installation/upgrade file // Installation/upgrade file
define('VERSION', '5.1.3'); define('VERSION', '5.1.3');
if (fopen('inc/instance-config.php' , 'a') === false) { if (fopen('inc/instance-config.php' , 'a') === false) {
@ -39,41 +39,41 @@ function checkGifsicle() {
} }
if (file_exists($config['has_installed'])) { if (file_exists($config['has_installed'])) {
// Check the version number // Check the version number
$version = trim(file_get_contents($config['has_installed'])); $version = trim(file_get_contents($config['has_installed']));
if (empty($version)) if (empty($version))
$version = 'v0.9.1'; $version = 'v0.9.1';
function __query($sql) { function __query($sql) {
sql_open(); sql_open();
if (mysql_version() >= 50503) if (mysql_version() >= 50503)
return query($sql); return query($sql);
else else
return query(str_replace('utf8mb4', 'utf8', $sql)); return query(str_replace('utf8mb4', 'utf8', $sql));
} }
$boards = listBoards(); $boards = listBoards();
switch ($version) { switch ($version) {
case 'v0.9': case 'v0.9':
case 'v0.9.1': case 'v0.9.1':
// Upgrade to v0.9.2-dev // Upgrade to v0.9.2-dev
foreach ($boards as &$_board) { foreach ($boards as &$_board) {
// Add `capcode` field after `trip` // Add `capcode` field after `trip`
query(sprintf("ALTER TABLE `posts_%s` ADD `capcode` VARCHAR( 50 ) NULL AFTER `trip`", $_board['uri'])) or error(db_error()); query(sprintf("ALTER TABLE `posts_%s` ADD `capcode` VARCHAR( 50 ) NULL AFTER `trip`", $_board['uri'])) or error(db_error());
// Resize `trip` to 15 characters // Resize `trip` to 15 characters
query(sprintf("ALTER TABLE `posts_%s` CHANGE `trip` `trip` VARCHAR( 15 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL", $_board['uri'])) or error(db_error()); query(sprintf("ALTER TABLE `posts_%s` CHANGE `trip` `trip` VARCHAR( 15 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL", $_board['uri'])) or error(db_error());
} }
case 'v0.9.2-dev': case 'v0.9.2-dev':
// Upgrade to v0.9.2-dev-1 // Upgrade to v0.9.2-dev-1
// New table: `theme_settings` // New table: `theme_settings`
query("CREATE TABLE IF NOT EXISTS `theme_settings` ( `name` varchar(40) NOT NULL, `value` text, UNIQUE KEY `name` (`name`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;") or error(db_error()); query("CREATE TABLE IF NOT EXISTS `theme_settings` ( `name` varchar(40) NOT NULL, `value` text, UNIQUE KEY `name` (`name`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;") or error(db_error());
// New table: `news` // New table: `news`
query("CREATE TABLE IF NOT EXISTS `news` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` text NOT NULL, `time` int(11) NOT NULL, `subject` text NOT NULL, `body` text NOT NULL, UNIQUE KEY `id` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;") or error(db_error()); query("CREATE TABLE IF NOT EXISTS `news` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` text NOT NULL, `time` int(11) NOT NULL, `subject` text NOT NULL, `body` text NOT NULL, UNIQUE KEY `id` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;") or error(db_error());
case 'v0.9.2.1-dev': case 'v0.9.2.1-dev':
@ -81,7 +81,7 @@ if (file_exists($config['has_installed'])) {
// Fix broken version number/mistake // Fix broken version number/mistake
$version = 'v0.9.2-dev-1'; $version = 'v0.9.2-dev-1';
// Upgrade to v0.9.2-dev-2 // Upgrade to v0.9.2-dev-2
foreach ($boards as &$_board) { foreach ($boards as &$_board) {
// Increase field sizes // Increase field sizes
query(sprintf("ALTER TABLE `posts_%s` CHANGE `subject` `subject` VARCHAR( 50 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL", $_board['uri'])) or error(db_error()); query(sprintf("ALTER TABLE `posts_%s` CHANGE `subject` `subject` VARCHAR( 50 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL", $_board['uri'])) or error(db_error());
@ -89,7 +89,7 @@ if (file_exists($config['has_installed'])) {
} }
case 'v0.9.2-dev-2': case 'v0.9.2-dev-2':
// Upgrade to v0.9.2-dev-3 (v0.9.2) // Upgrade to v0.9.2-dev-3 (v0.9.2)
foreach ($boards as &$_board) { foreach ($boards as &$_board) {
// Add `custom_fields` field // Add `custom_fields` field
query(sprintf("ALTER TABLE `posts_%s` ADD `embed` TEXT NULL", $_board['uri'])) or error(db_error()); query(sprintf("ALTER TABLE `posts_%s` ADD `embed` TEXT NULL", $_board['uri'])) or error(db_error());
@ -97,7 +97,7 @@ if (file_exists($config['has_installed'])) {
case 'v0.9.2-dev-3': // v0.9.2-dev-3 == v0.9.2 case 'v0.9.2-dev-3': // v0.9.2-dev-3 == v0.9.2
case 'v0.9.2': case 'v0.9.2':
// Upgrade to v0.9.3-dev-1 // Upgrade to v0.9.3-dev-1
// Upgrade `theme_settings` table // Upgrade `theme_settings` table
query("TRUNCATE TABLE `theme_settings`") or error(db_error()); query("TRUNCATE TABLE `theme_settings`") or error(db_error());
query("ALTER TABLE `theme_settings` ADD `theme` VARCHAR( 40 ) NOT NULL FIRST") or error(db_error()); query("ALTER TABLE `theme_settings` ADD `theme` VARCHAR( 40 ) NOT NULL FIRST") or error(db_error());
@ -129,7 +129,7 @@ if (file_exists($config['has_installed'])) {
foreach ($boards as &$board) { foreach ($boards as &$board) {
$tables[] = "posts_{$board['uri']}"; $tables[] = "posts_{$board['uri']}";
} }
foreach ($tables as &$table) { foreach ($tables as &$table) {
query("ALTER TABLE `{$table}` ENGINE = MYISAM DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci") or error(db_error()); query("ALTER TABLE `{$table}` ENGINE = MYISAM DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci") or error(db_error());
} }
@ -153,10 +153,10 @@ if (file_exists($config['has_installed'])) {
query("ALTER TABLE `boards` DROP PRIMARY KEY") or error(db_error()); query("ALTER TABLE `boards` DROP PRIMARY KEY") or error(db_error());
query("ALTER TABLE `reports` DROP INDEX `id`") or error(db_error()); query("ALTER TABLE `reports` DROP INDEX `id`") or error(db_error());
query("ALTER TABLE `boards` DROP INDEX `uri`") or error(db_error()); query("ALTER TABLE `boards` DROP INDEX `uri`") or error(db_error());
query("ALTER IGNORE TABLE `robot` ADD PRIMARY KEY (`hash`)") or error(db_error()); query("ALTER IGNORE TABLE `robot` ADD PRIMARY KEY (`hash`)") or error(db_error());
query("ALTER TABLE `bans` ADD FULLTEXT (`ip`)") or error(db_error()); query("ALTER TABLE `bans` ADD FULLTEXT (`ip`)") or error(db_error());
query("ALTER TABLE `ip_notes` ADD INDEX (`ip`)") or error(db_error()); query("ALTER TABLE `ip_notes` ADD INDEX (`ip`)") or error(db_error());
query("ALTER TABLE `modlogs` ADD INDEX (`time`)") or error(db_error()); query("ALTER TABLE `modlogs` ADD INDEX (`time`)") or error(db_error());
query("ALTER TABLE `boards` ADD PRIMARY KEY(`uri`)") or error(db_error()); query("ALTER TABLE `boards` ADD PRIMARY KEY(`uri`)") or error(db_error());
query("ALTER TABLE `mutes` ADD INDEX (`ip`)") or error(db_error()); query("ALTER TABLE `mutes` ADD INDEX (`ip`)") or error(db_error());
@ -174,9 +174,9 @@ if (file_exists($config['has_installed'])) {
<p style="text-align:center"> <p style="text-align:center">
<a href="?confirm=1">I have read and understood the agreement. Proceed to upgrading.</a> <a href="?confirm=1">I have read and understood the agreement. Proceed to upgrading.</a>
</p>'; </p>';
file_write($config['has_installed'], 'v0.9.4-dev-2'); file_write($config['has_installed'], 'v0.9.4-dev-2');
break; break;
} }
case 'v0.9.4-dev-3': case 'v0.9.4-dev-3':
@ -194,14 +194,14 @@ if (file_exists($config['has_installed'])) {
} }
query("CREATE TABLE IF NOT EXISTS `cites` ( `board` varchar(8) NOT NULL, `post` int(11) NOT NULL, `target_board` varchar(8) NOT NULL, `target` int(11) NOT NULL, KEY `target` (`target_board`,`target`), KEY `post` (`board`,`post`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;") or error(db_error()); query("CREATE TABLE IF NOT EXISTS `cites` ( `board` varchar(8) NOT NULL, `post` int(11) NOT NULL, `target_board` varchar(8) NOT NULL, `target` int(11) NOT NULL, KEY `target` (`target_board`,`target`), KEY `post` (`board`,`post`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;") or error(db_error());
case 'v0.9.5-dev-2': case 'v0.9.5-dev-2':
query("ALTER TABLE `boards` query("ALTER TABLE `boards`
CHANGE `uri` `uri` VARCHAR( 15 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL, CHANGE `uri` `uri` VARCHAR( 15 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
CHANGE `title` `title` VARCHAR( 40 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL, CHANGE `title` `title` VARCHAR( 40 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
CHANGE `subtitle` `subtitle` VARCHAR( 120 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL") or error(db_error()); CHANGE `subtitle` `subtitle` VARCHAR( 120 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL") or error(db_error());
case 'v0.9.5-dev-3': case 'v0.9.5-dev-3':
// v0.9.5 // v0.9.5
case 'v0.9.5': case 'v0.9.5':
query("ALTER TABLE `boards` query("ALTER TABLE `boards`
CHANGE `uri` `uri` VARCHAR( 50 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL, CHANGE `uri` `uri` VARCHAR( 50 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
CHANGE `title` `title` TINYTEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL, CHANGE `title` `title` TINYTEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
CHANGE `subtitle` `subtitle` TINYTEXT CHARACTER SET utf8 COLLATE utf8_general_ci NULL") or error(db_error()); CHANGE `subtitle` `subtitle` TINYTEXT CHARACTER SET utf8 COLLATE utf8_general_ci NULL") or error(db_error());
@ -228,12 +228,12 @@ if (file_exists($config['has_installed'])) {
$query->bindValue(':newboard', $board['uri']); $query->bindValue(':newboard', $board['uri']);
$query->bindValue(':oldboard', $board['id']); $query->bindValue(':oldboard', $board['id']);
$query->execute() or error(db_error($query)); $query->execute() or error(db_error($query));
$query = prepare("UPDATE `modlogs` SET `board` = :newboard WHERE `board` = :oldboard"); $query = prepare("UPDATE `modlogs` SET `board` = :newboard WHERE `board` = :oldboard");
$query->bindValue(':newboard', $board['uri']); $query->bindValue(':newboard', $board['uri']);
$query->bindValue(':oldboard', $board['id']); $query->bindValue(':oldboard', $board['id']);
$query->execute() or error(db_error($query)); $query->execute() or error(db_error($query));
$query = prepare("UPDATE `reports` SET `board` = :newboard WHERE `board` = :oldboard"); $query = prepare("UPDATE `reports` SET `board` = :newboard WHERE `board` = :oldboard");
$query->bindValue(':newboard', $board['uri']); $query->bindValue(':newboard', $board['uri']);
$query->bindValue(':oldboard', $board['id']); $query->bindValue(':oldboard', $board['id']);
@ -271,10 +271,10 @@ if (file_exists($config['has_installed'])) {
if (strlen($user['password']) == 40) { if (strlen($user['password']) == 40) {
mt_srand(microtime(true) * 100000 + memory_get_usage(true)); mt_srand(microtime(true) * 100000 + memory_get_usage(true));
$salt = md5(uniqid(mt_rand(), true)); $salt = md5(uniqid(mt_rand(), true));
$user['salt'] = $salt; $user['salt'] = $salt;
$user['password'] = hash('sha256', $user['salt'] . $user['password']); $user['password'] = hash('sha256', $user['salt'] . $user['password']);
$_query = prepare("UPDATE `mods` SET `password` = :password, `salt` = :salt WHERE `id` = :id"); $_query = prepare("UPDATE `mods` SET `password` = :password, `salt` = :salt WHERE `id` = :id");
$_query->bindValue(':id', $user['id']); $_query->bindValue(':id', $user['id']);
$_query->bindValue(':password', $user['password']); $_query->bindValue(':password', $user['password']);
@ -306,7 +306,7 @@ if (file_exists($config['has_installed'])) {
CHANGE `embed` `embed` TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL, CHANGE `embed` `embed` TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,
DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;", $board['uri'])) or error(db_error()); DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;", $board['uri'])) or error(db_error());
} }
__query("ALTER TABLE `antispam` __query("ALTER TABLE `antispam`
CHANGE `board` `board` VARCHAR( 120 ) CHARACTER SET ASCII COLLATE ascii_general_ci NOT NULL , CHANGE `board` `board` VARCHAR( 120 ) CHARACTER SET ASCII COLLATE ascii_general_ci NOT NULL ,
CHANGE `hash` `hash` CHAR( 40 ) CHARACTER SET ASCII COLLATE ascii_bin NOT NULL , CHANGE `hash` `hash` CHAR( 40 ) CHARACTER SET ASCII COLLATE ascii_bin NOT NULL ,
@ -466,44 +466,44 @@ if (file_exists($config['has_installed'])) {
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT=1") or error(db_error()); ) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT=1") or error(db_error());
$listquery = query("SELECT * FROM ``bans`` ORDER BY `id`") or error(db_error()); $listquery = query("SELECT * FROM ``bans`` ORDER BY `id`") or error(db_error());
while ($ban = $listquery->fetch(PDO::FETCH_ASSOC)) { while ($ban = $listquery->fetch(PDO::FETCH_ASSOC)) {
$query = prepare("INSERT INTO ``bans_new_temp`` VALUES $query = prepare("INSERT INTO ``bans_new_temp`` VALUES
(NULL, :ipstart, :ipend, :created, :expires, :board, :creator, :reason, :seen, NULL)"); (NULL, :ipstart, :ipend, :created, :expires, :board, :creator, :reason, :seen, NULL)");
$range = Bans::parse_range($ban['ip']); $range = Bans::parse_range($ban['ip']);
if ($range === false) { if ($range === false) {
// Invalid retard ban; just skip it. // Invalid retard ban; just skip it.
continue; continue;
} }
$query->bindValue(':ipstart', $range[0]); $query->bindValue(':ipstart', $range[0]);
if ($range[1] !== false && $range[1] != $range[0]) if ($range[1] !== false && $range[1] != $range[0])
$query->bindValue(':ipend', $range[1]); $query->bindValue(':ipend', $range[1]);
else else
$query->bindValue(':ipend', null, PDO::PARAM_NULL); $query->bindValue(':ipend', null, PDO::PARAM_NULL);
$query->bindValue(':created', $ban['set']); $query->bindValue(':created', $ban['set']);
if ($ban['expires']) if ($ban['expires'])
$query->bindValue(':expires', $ban['expires']); $query->bindValue(':expires', $ban['expires']);
else else
$query->bindValue(':expires', null, PDO::PARAM_NULL); $query->bindValue(':expires', null, PDO::PARAM_NULL);
if ($ban['board']) if ($ban['board'])
$query->bindValue(':board', $ban['board']); $query->bindValue(':board', $ban['board']);
else else
$query->bindValue(':board', null, PDO::PARAM_NULL); $query->bindValue(':board', null, PDO::PARAM_NULL);
$query->bindValue(':creator', $ban['mod']); $query->bindValue(':creator', $ban['mod']);
if ($ban['reason']) if ($ban['reason'])
$query->bindValue(':reason', $ban['reason']); $query->bindValue(':reason', $ban['reason']);
else else
$query->bindValue(':reason', null, PDO::PARAM_NULL); $query->bindValue(':reason', null, PDO::PARAM_NULL);
$query->bindValue(':seen', $ban['seen']); $query->bindValue(':seen', $ban['seen']);
$query->execute() or error(db_error($query)); $query->execute() or error(db_error($query));
} }
// Drop old bans table // Drop old bans table
query("DROP TABLE ``bans``") or error(db_error()); query("DROP TABLE ``bans``") or error(db_error());
// Replace with new table // Replace with new table
@ -535,9 +535,9 @@ if (file_exists($config['has_installed'])) {
<p style="text-align:center"> <p style="text-align:center">
<a href="?confirm2=1">I have read and understood the agreement. Proceed to upgrading.</a> <a href="?confirm2=1">I have read and understood the agreement. Proceed to upgrading.</a>
</p>'; </p>';
file_write($config['has_installed'], '4.4.97'); file_write($config['has_installed'], '4.4.97');
break; break;
} }
case '4.4.98-pre': case '4.4.98-pre':
@ -553,9 +553,9 @@ if (file_exists($config['has_installed'])) {
<p style="text-align:center"> <p style="text-align:center">
<a href="?confirm3=1">I have read and understood the warning. Proceed to upgrading.</a> <a href="?confirm3=1">I have read and understood the warning. Proceed to upgrading.</a>
</p>'; </p>';
file_write($config['has_installed'], '4.5.2'); file_write($config['has_installed'], '4.5.2');
break; break;
} }
@ -614,7 +614,7 @@ if (file_exists($config['has_installed'])) {
// Update version number // Update version number
file_write($config['has_installed'], VERSION); file_write($config['has_installed'], VERSION);
$page['title'] = 'Upgraded'; $page['title'] = 'Upgraded';
$page['body'] = '<p style="text-align:center">Successfully upgraded from ' . $version . ' to <strong>' . VERSION . '</strong>.</p>'; $page['body'] = '<p style="text-align:center">Successfully upgraded from ' . $version . ' to <strong>' . VERSION . '</strong>.</p>';
break; break;
@ -626,8 +626,8 @@ if (file_exists($config['has_installed'])) {
$page['title'] = 'Already installed'; $page['title'] = 'Already installed';
$page['body'] = '<p style="text-align:center">It appears that vichan is already installed (' . $version . ') and there is nothing to upgrade! Delete <strong>' . $config['has_installed'] . '</strong> to reinstall.</p>'; $page['body'] = '<p style="text-align:center">It appears that vichan is already installed (' . $version . ') and there is nothing to upgrade! Delete <strong>' . $config['has_installed'] . '</strong> to reinstall.</p>';
break; break;
} }
die(Element('page.html', $page)); die(Element('page.html', $page));
} }
@ -659,11 +659,11 @@ if ($step == 0) {
<p style="text-align:center"> <p style="text-align:center">
<a href="?step=1">I have read and understood the agreement. Proceed to installation.</a> <a href="?step=1">I have read and understood the agreement. Proceed to installation.</a>
</p>'; </p>';
echo Element('page.html', $page); echo Element('page.html', $page);
} elseif ($step == 1) { } elseif ($step == 1) {
$page['title'] = 'Pre-installation test'; $page['title'] = 'Pre-installation test';
$can_exec = true; $can_exec = true;
if (!function_exists('shell_exec')) if (!function_exists('shell_exec'))
$can_exec = false; $can_exec = false;
@ -673,12 +673,12 @@ if ($step == 0) {
$can_exec = false; $can_exec = false;
elseif (trim(shell_exec('echo "TEST"')) !== 'TEST') elseif (trim(shell_exec('echo "TEST"')) !== 'TEST')
$can_exec = false; $can_exec = false;
if (!defined('PHP_VERSION_ID')) { if (!defined('PHP_VERSION_ID')) {
$version = explode('.', PHP_VERSION); $version = explode('.', PHP_VERSION);
define('PHP_VERSION_ID', ($version[0] * 10000 + $version[1] * 100 + $version[2])); define('PHP_VERSION_ID', ($version[0] * 10000 + $version[1] * 100 + $version[2]));
} }
// Required extensions // Required extensions
$extensions = array( $extensions = array(
'PDO' => array( 'PDO' => array(
@ -818,14 +818,14 @@ if ($step == 0) {
array( array(
'category' => 'File permissions', 'category' => 'File permissions',
'name' => getcwd() . '/templates/cache', 'name' => getcwd() . '/templates/cache',
'result' => is_writable('templates') || (is_dir('templates/cache') && is_writable('templates/cache')), 'result' => is_dir('templates/cache/') && is_writable('templates/cache/'),
'required' => true, 'required' => true,
'message' => 'You must give vichan permission to create (and write to) the <code>templates/cache</code> directory or performance will be drastically reduced.' 'message' => 'You must give vichan permission to create (and write to) the <code>templates/cache</code> directory or performance will be drastically reduced.'
), ),
array( array(
'category' => 'File permissions', 'category' => 'File permissions',
'name' => getcwd() . '/tmp/cache', 'name' => getcwd() . '/tmp/cache',
'result' => is_dir('tmp/cache') && is_writable('tmp/cache'), 'result' => is_dir('tmp/cache/') && is_writable('tmp/cache/'),
'required' => true, 'required' => true,
'message' => 'You must give vichan permission to write to the <code>tmp/cache</code> directory.' 'message' => 'You must give vichan permission to write to the <code>tmp/cache</code> directory.'
), ),
@ -854,7 +854,7 @@ if ($step == 0) {
); );
$config['font_awesome'] = true; $config['font_awesome'] = true;
$additional_config = array(); $additional_config = array();
foreach ($tests as $test) { foreach ($tests as $test) {
if ($test['result'] && isset($test['effect'])) { if ($test['result'] && isset($test['effect'])) {
@ -877,10 +877,10 @@ if ($step == 0) {
} elseif ($step == 2) { } elseif ($step == 2) {
// Basic config // Basic config
$page['title'] = 'Configuration'; $page['title'] = 'Configuration';
$config['cookies']['salt'] = substr(base64_encode(sha1(rand())), 0, 30); $config['cookies']['salt'] = substr(base64_encode(sha1(rand())), 0, 30);
$config['secure_trip_salt'] = substr(base64_encode(sha1(rand())), 0, 30); $config['secure_trip_salt'] = substr(base64_encode(sha1(rand())), 0, 30);
echo Element('page.html', array( echo Element('page.html', array(
'body' => Element('installer/config.html', array( 'body' => Element('installer/config.html', array(
'config' => $config, 'config' => $config,
@ -893,7 +893,7 @@ if ($step == 0) {
$more = $_POST['more']; $more = $_POST['more'];
unset($_POST['more']); unset($_POST['more']);
$instance_config = $instance_config =
'<'.'?php '<'.'?php
/* /*
@ -905,13 +905,13 @@ if ($step == 0) {
*/ */
'; ';
create_config_from_array($instance_config, $_POST); create_config_from_array($instance_config, $_POST);
$instance_config .= "\n"; $instance_config .= "\n";
$instance_config .= $more; $instance_config .= $more;
$instance_config .= "\n"; $instance_config .= "\n";
if (@file_put_contents('inc/instance-config.php', $instance_config)) { if (@file_put_contents('inc/instance-config.php', $instance_config)) {
header('Location: ?step=4', true, $config['redirect_http']); header('Location: ?step=4', true, $config['redirect_http']);
} else { } else {
@ -928,22 +928,22 @@ if ($step == 0) {
} }
} elseif ($step == 4) { } elseif ($step == 4) {
// SQL installation // SQL installation
buildJavascript(); buildJavascript();
$sql = @file_get_contents('install.sql') or error("Couldn't load install.sql."); $sql = @file_get_contents('install.sql') or error("Couldn't load install.sql.");
sql_open(); sql_open();
$mysql_version = mysql_version(); $mysql_version = mysql_version();
// This code is probably horrible, but what I'm trying // This code is probably horrible, but what I'm trying
// to do is find all of the SQL queires and put them // to do is find all of the SQL queires and put them
// in an array. // in an array.
preg_match_all("/(^|\n)((SET|CREATE|INSERT).+)\n\n/msU", $sql, $queries); preg_match_all("/(^|\n)((SET|CREATE|INSERT).+)\n\n/msU", $sql, $queries);
$queries = $queries[2]; $queries = $queries[2];
$queries[] = Element('posts.sql', array('board' => 'b')); $queries[] = Element('posts.sql', array('board' => 'b'));
$sql_errors = ''; $sql_errors = '';
foreach ($queries as $query) { foreach ($queries as $query) {
if ($mysql_version < 50503) if ($mysql_version < 50503)
@ -952,10 +952,10 @@ if ($step == 0) {
if (!query($query)) if (!query($query))
$sql_errors .= '<li>' . db_error() . '</li>'; $sql_errors .= '<li>' . db_error() . '</li>';
} }
$page['title'] = 'Installation complete'; $page['title'] = 'Installation complete';
$page['body'] = '<p style="text-align:center">Thank you for using vichan. Please remember to report any bugs you discover. <a href="http://tinyboard.org/docs/?p=Config">How do I edit the config files?</a></p>'; $page['body'] = '<p style="text-align:center">Thank you for using vichan. Please remember to report any bugs you discover. <a href="http://tinyboard.org/docs/?p=Config">How do I edit the config files?</a></p>';
if (!empty($sql_errors)) { if (!empty($sql_errors)) {
$page['body'] .= '<div class="ban"><h2>SQL errors</h2><p>SQL errors were encountered when trying to install the database. This may be the result of using a database which is already occupied with a vichan installation; if so, you can probably ignore this.</p><p>The errors encountered were:</p><ul>' . $sql_errors . '</ul><p><a href="?step=5">Ignore errors and complete installation.</a></p></div>'; $page['body'] .= '<div class="ban"><h2>SQL errors</h2><p>SQL errors were encountered when trying to install the database. This may be the result of using a database which is already occupied with a vichan installation; if so, you can probably ignore this.</p><p>The errors encountered were:</p><ul>' . $sql_errors . '</ul><p><a href="?step=5">Ignore errors and complete installation.</a></p></div>';
} else { } else {
@ -964,29 +964,28 @@ if ($step == 0) {
setupBoard($_board); setupBoard($_board);
buildIndex(); buildIndex();
} }
file_write($config['has_installed'], VERSION); file_write($config['has_installed'], VERSION);
/*if (!file_unlink(__FILE__)) { /*if (!file_unlink(__FILE__)) {
$page['body'] .= '<div class="ban"><h2>Delete install.php!</h2><p>I couldn\'t remove <strong>install.php</strong>. You will have to remove it manually.</p></div>'; $page['body'] .= '<div class="ban"><h2>Delete install.php!</h2><p>I couldn\'t remove <strong>install.php</strong>. You will have to remove it manually.</p></div>';
}*/ }*/
} }
echo Element('page.html', $page); echo Element('page.html', $page);
} elseif ($step == 5) { } elseif ($step == 5) {
$page['title'] = 'Installation complete'; $page['title'] = 'Installation complete';
$page['body'] = '<p style="text-align:center">Thank you for using vichan. Please remember to report any bugs you discover.</p>'; $page['body'] = '<p style="text-align:center">Thank you for using vichan. Please remember to report any bugs you discover.</p>';
$boards = listBoards(); $boards = listBoards();
foreach ($boards as &$_board) { foreach ($boards as &$_board) {
setupBoard($_board); setupBoard($_board);
buildIndex(); buildIndex();
} }
file_write($config['has_installed'], VERSION); file_write($config['has_installed'], VERSION);
if (!file_unlink(__FILE__)) { if (!file_unlink(__FILE__)) {
$page['body'] .= '<div class="ban"><h2>Delete install.php!</h2><p>I couldn\'t remove <strong>install.php</strong>. You will have to remove it manually.</p></div>'; $page['body'] .= '<div class="ban"><h2>Delete install.php!</h2><p>I couldn\'t remove <strong>install.php</strong>. You will have to remove it manually.</p></div>';
} }
echo Element('page.html', $page); echo Element('page.html', $page);
} }

Loading…
Cancel
Save