The version of vichan running on lainchan.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

848 lines
41KB

  1. <?php
  2. // Installation/upgrade file
  3. define('VERSION', 'v0.9.6-dev-22 + <a href="https://int.vichan.net/devel/">vichan-devel-4.4.97</a>');
  4. require 'inc/functions.php';
  5. $step = isset($_GET['step']) ? round($_GET['step']) : 0;
  6. $page = array(
  7. 'config' => $config,
  8. 'title' => 'Install',
  9. 'body' => '',
  10. 'nojavascript' => true
  11. );
  12. // this breaks the display of licenses if enabled
  13. $config['minify_html'] = false;
  14. if (file_exists($config['has_installed'])) {
  15. // Check the version number
  16. $version = trim(file_get_contents($config['has_installed']));
  17. if (empty($version))
  18. $version = 'v0.9.1';
  19. function __query($sql) {
  20. sql_open();
  21. if (mysql_version() >= 50503)
  22. return query($sql);
  23. else
  24. return query(str_replace('utf8mb4', 'utf8', $sql));
  25. }
  26. $boards = listBoards();
  27. switch ($version) {
  28. case 'v0.9':
  29. case 'v0.9.1':
  30. // Upgrade to v0.9.2-dev
  31. foreach ($boards as &$_board) {
  32. // Add `capcode` field after `trip`
  33. query(sprintf("ALTER TABLE `posts_%s` ADD `capcode` VARCHAR( 50 ) NULL AFTER `trip`", $_board['uri'])) or error(db_error());
  34. // Resize `trip` to 15 characters
  35. 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());
  36. }
  37. case 'v0.9.2-dev':
  38. // Upgrade to v0.9.2-dev-1
  39. // New table: `theme_settings`
  40. 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());
  41. // New table: `news`
  42. 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());
  43. case 'v0.9.2.1-dev':
  44. case 'v0.9.2-dev-1':
  45. // Fix broken version number/mistake
  46. $version = 'v0.9.2-dev-1';
  47. // Upgrade to v0.9.2-dev-2
  48. foreach ($boards as &$_board) {
  49. // Increase field sizes
  50. 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());
  51. query(sprintf("ALTER TABLE `posts_%s` CHANGE `name` `name` VARCHAR( 35 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL", $_board['uri'])) or error(db_error());
  52. }
  53. case 'v0.9.2-dev-2':
  54. // Upgrade to v0.9.2-dev-3 (v0.9.2)
  55. foreach ($boards as &$_board) {
  56. // Add `custom_fields` field
  57. query(sprintf("ALTER TABLE `posts_%s` ADD `embed` TEXT NULL", $_board['uri'])) or error(db_error());
  58. }
  59. case 'v0.9.2-dev-3': // v0.9.2-dev-3 == v0.9.2
  60. case 'v0.9.2':
  61. // Upgrade to v0.9.3-dev-1
  62. // Upgrade `theme_settings` table
  63. query("TRUNCATE TABLE `theme_settings`") or error(db_error());
  64. query("ALTER TABLE `theme_settings` ADD `theme` VARCHAR( 40 ) NOT NULL FIRST") or error(db_error());
  65. query("ALTER TABLE `theme_settings` CHANGE `name` `name` VARCHAR( 40 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL") or error(db_error());
  66. query("ALTER TABLE `theme_settings` DROP INDEX `name`") or error(db_error());
  67. case 'v0.9.3-dev-1':
  68. query("ALTER TABLE `mods` ADD `boards` TEXT NOT NULL") or error(db_error());
  69. query("UPDATE `mods` SET `boards` = '*'") or error(db_error());
  70. case 'v0.9.3-dev-2':
  71. foreach ($boards as &$_board) {
  72. query(sprintf("ALTER TABLE `posts_%s` CHANGE `filehash` `filehash` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL", $_board['uri'])) or error(db_error());
  73. }
  74. case 'v0.9.3-dev-3':
  75. // Board-specifc bans
  76. query("ALTER TABLE `bans` ADD `board` SMALLINT NULL AFTER `reason`") or error(db_error());
  77. case 'v0.9.3-dev-4':
  78. // add ban ID
  79. query("ALTER TABLE `bans` ADD `id` INT NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY ( `id` ), ADD UNIQUE (`id`)");
  80. case 'v0.9.3-dev-5':
  81. foreach ($boards as &$_board) {
  82. // Increase subject field size
  83. query(sprintf("ALTER TABLE `posts_%s` CHANGE `subject` `subject` VARCHAR( 100 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL", $_board['uri'])) or error(db_error());
  84. }
  85. case 'v0.9.3-dev-6':
  86. // change to MyISAM
  87. $tables = array(
  88. 'bans', 'boards', 'ip_notes', 'modlogs', 'mods', 'mutes', 'noticeboard', 'pms', 'reports', 'robot', 'theme_settings', 'news'
  89. );
  90. foreach ($boards as &$board) {
  91. $tables[] = "posts_{$board['uri']}";
  92. }
  93. foreach ($tables as &$table) {
  94. query("ALTER TABLE `{$table}` ENGINE = MYISAM DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci") or error(db_error());
  95. }
  96. case 'v0.9.3-dev-7':
  97. foreach ($boards as &$board) {
  98. query(sprintf("ALTER TABLE `posts_%s` CHANGE `filename` `filename` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL", $board['uri'])) or error(db_error());
  99. }
  100. case 'v0.9.3-dev-8':
  101. foreach ($boards as &$board) {
  102. query(sprintf("ALTER TABLE `posts_%s` ADD INDEX ( `thread` )", $board['uri'])) or error(db_error());
  103. }
  104. case 'v0.9.3-dev-9':
  105. foreach ($boards as &$board) {
  106. query(sprintf("ALTER TABLE `posts_%s`ADD INDEX ( `time` )", $board['uri'])) or error(db_error());
  107. query(sprintf("ALTER TABLE `posts_%s`ADD FULLTEXT (`body`)", $board['uri'])) or error(db_error());
  108. }
  109. case 'v0.9.3-dev-10':
  110. case 'v0.9.3':
  111. query("ALTER TABLE `bans` DROP INDEX `id`") or error(db_error());
  112. query("ALTER TABLE `pms` DROP INDEX `id`") or error(db_error());
  113. query("ALTER TABLE `boards` DROP PRIMARY KEY") or error(db_error());
  114. query("ALTER TABLE `reports` DROP INDEX `id`") or error(db_error());
  115. query("ALTER TABLE `boards` DROP INDEX `uri`") or error(db_error());
  116. query("ALTER IGNORE TABLE `robot` ADD PRIMARY KEY (`hash`)") or error(db_error());
  117. query("ALTER TABLE `bans` ADD FULLTEXT (`ip`)") or error(db_error());
  118. query("ALTER TABLE `ip_notes` ADD INDEX (`ip`)") or error(db_error());
  119. query("ALTER TABLE `modlogs` ADD INDEX (`time`)") or error(db_error());
  120. query("ALTER TABLE `boards` ADD PRIMARY KEY(`uri`)") or error(db_error());
  121. query("ALTER TABLE `mutes` ADD INDEX (`ip`)") or error(db_error());
  122. query("ALTER TABLE `news` ADD INDEX (`time`)") or error(db_error());
  123. query("ALTER TABLE `theme_settings` ADD INDEX (`theme`)") or error(db_error());
  124. case 'v0.9.4-dev-1':
  125. foreach ($boards as &$board) {
  126. query(sprintf("ALTER TABLE `posts_%s` ADD `sage` INT( 1 ) NOT NULL AFTER `locked`", $board['uri'])) or error(db_error());
  127. }
  128. case 'v0.9.4-dev-2':
  129. if (!isset($_GET['confirm'])) {
  130. $page['title'] = 'License Change';
  131. $page['body'] = '<p style="text-align:center">You are upgrading to a version which uses an amended license. The licenses included with Tinyboard distributions prior to this version (v0.9.4-dev-2) are still valid for those versions, but no longer apply to this and newer versions.</p>' .
  132. '<textarea style="width:700px;height:370px;margin:auto;display:block;background:white;color:black" disabled>' . htmlentities(file_get_contents('LICENSE.md')) . '</textarea>
  133. <p style="text-align:center">
  134. <a href="?confirm=1">I have read and understood the agreement. Proceed to upgrading.</a>
  135. </p>';
  136. file_write($config['has_installed'], 'v0.9.4-dev-2');
  137. break;
  138. }
  139. case 'v0.9.4-dev-3':
  140. case 'v0.9.4-dev-4':
  141. case 'v0.9.4':
  142. foreach ($boards as &$board) {
  143. query(sprintf("ALTER TABLE `posts_%s`
  144. CHANGE `subject` `subject` VARCHAR( 100 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL ,
  145. CHANGE `email` `email` VARCHAR( 30 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL ,
  146. CHANGE `name` `name` VARCHAR( 35 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL", $board['uri'])) or error(db_error());
  147. }
  148. case 'v0.9.5-dev-1':
  149. foreach ($boards as &$board) {
  150. query(sprintf("ALTER TABLE `posts_%s` ADD `body_nomarkup` TEXT NULL AFTER `body`", $board['uri'])) or error(db_error());
  151. }
  152. 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());
  153. case 'v0.9.5-dev-2':
  154. query("ALTER TABLE `boards`
  155. CHANGE `uri` `uri` VARCHAR( 15 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  156. CHANGE `title` `title` VARCHAR( 40 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  157. CHANGE `subtitle` `subtitle` VARCHAR( 120 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL") or error(db_error());
  158. case 'v0.9.5-dev-3':
  159. // v0.9.5
  160. case 'v0.9.5':
  161. query("ALTER TABLE `boards`
  162. CHANGE `uri` `uri` VARCHAR( 50 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  163. CHANGE `title` `title` TINYTEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  164. CHANGE `subtitle` `subtitle` TINYTEXT CHARACTER SET utf8 COLLATE utf8_general_ci NULL") or error(db_error());
  165. case 'v0.9.6-dev-1':
  166. query("CREATE TABLE IF NOT EXISTS `antispam` (
  167. `board` varchar(255) NOT NULL,
  168. `thread` int(11) DEFAULT NULL,
  169. `hash` bigint(20) NOT NULL,
  170. `created` int(11) NOT NULL,
  171. `expires` int(11) DEFAULT NULL,
  172. `passed` smallint(6) NOT NULL,
  173. PRIMARY KEY (`hash`),
  174. KEY `board` (`board`,`thread`)
  175. ) ENGINE=MyISAM DEFAULT CHARSET=utf8;") or error(db_error());
  176. case 'v0.9.6-dev-2':
  177. query("ALTER TABLE `boards`
  178. DROP `id`,
  179. CHANGE `uri` `uri` VARCHAR( 120 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL") or error(db_error());
  180. query("ALTER TABLE `bans` CHANGE `board` `board` VARCHAR( 120 ) NULL DEFAULT NULL") or error(db_error());
  181. query("ALTER TABLE `reports` CHANGE `board` `board` VARCHAR( 120 ) NULL DEFAULT NULL") or error(db_error());
  182. query("ALTER TABLE `modlogs` CHANGE `board` `board` VARCHAR( 120 ) NULL DEFAULT NULL") or error(db_error());
  183. foreach ($boards as $board) {
  184. $query = prepare("UPDATE `bans` SET `board` = :newboard WHERE `board` = :oldboard");
  185. $query->bindValue(':newboard', $board['uri']);
  186. $query->bindValue(':oldboard', $board['id']);
  187. $query->execute() or error(db_error($query));
  188. $query = prepare("UPDATE `modlogs` SET `board` = :newboard WHERE `board` = :oldboard");
  189. $query->bindValue(':newboard', $board['uri']);
  190. $query->bindValue(':oldboard', $board['id']);
  191. $query->execute() or error(db_error($query));
  192. $query = prepare("UPDATE `reports` SET `board` = :newboard WHERE `board` = :oldboard");
  193. $query->bindValue(':newboard', $board['uri']);
  194. $query->bindValue(':oldboard', $board['id']);
  195. $query->execute() or error(db_error($query));
  196. }
  197. case 'v0.9.6-dev-3':
  198. query("ALTER TABLE `antispam` CHANGE `hash` `hash` CHAR( 40 ) NOT NULL") or error(db_error());
  199. case 'v0.9.6-dev-4':
  200. query("ALTER TABLE `news` DROP INDEX `id`, ADD PRIMARY KEY ( `id` )") or error(db_error());
  201. case 'v0.9.6-dev-5':
  202. query("ALTER TABLE `bans` CHANGE `id` `id` INT( 11 ) UNSIGNED NOT NULL AUTO_INCREMENT") or error(db_error());
  203. query("ALTER TABLE `mods` CHANGE `id` `id` INT( 11 ) UNSIGNED NOT NULL AUTO_INCREMENT") or error(db_error());
  204. query("ALTER TABLE `news` CHANGE `id` `id` INT( 11 ) UNSIGNED NOT NULL AUTO_INCREMENT") or error(db_error());
  205. query("ALTER TABLE `noticeboard` CHANGE `id` `id` INT( 11 ) UNSIGNED NOT NULL AUTO_INCREMENT") or error(db_error());
  206. query("ALTER TABLE `pms` CHANGE `id` `id` INT( 11 ) UNSIGNED NOT NULL AUTO_INCREMENT") or error(db_error());
  207. query("ALTER TABLE `reports` CHANGE `id` `id` INT( 11 ) UNSIGNED NOT NULL AUTO_INCREMENT") or error(db_error());
  208. foreach ($boards as $board) {
  209. query(sprintf("ALTER TABLE `posts_%s` CHANGE `id` `id` INT( 11 ) UNSIGNED NOT NULL AUTO_INCREMENT", $board['uri'])) or error(db_error());
  210. }
  211. case 'v0.9.6-dev-6':
  212. foreach ($boards as &$_board) {
  213. query(sprintf("CREATE INDEX `thread_id` ON `posts_%s` (`thread`, `id`)", $_board['uri'])) or error(db_error());
  214. query(sprintf("ALTER TABLE `posts_%s` DROP INDEX `thread`", $_board['uri'])) or error(db_error());
  215. }
  216. case 'v0.9.6-dev-7':
  217. case 'v0.9.6-dev-7 + <a href="https://github.com/vichan-devel/Tinyboard/">vichan-devel-4.0-gold</a>':
  218. query("ALTER TABLE `bans` ADD `seen` BOOLEAN NOT NULL") or error(db_error());
  219. case 'v0.9.6-dev-8':
  220. case 'v0.9.6-dev-8 + <a href="https://github.com/vichan-devel/Tinyboard/">vichan-devel-4.0.1</a>':
  221. query("CREATE TABLE IF NOT EXISTS `search_queries` ( `ip` varchar(39) NOT NULL, `time` int(11) NOT NULL, `query` text NOT NULL) ENGINE=MyISAM DEFAULT CHARSET=utf8;") or error(db_error());
  222. case 'v0.9.6-dev-8 + <a href="https://github.com/vichan-devel/Tinyboard/">vichan-devel-4.0.2</a>':
  223. query("ALTER TABLE `mods` CHANGE `password` `password` CHAR( 64 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT 'SHA256'") or error(db_error());
  224. query("ALTER TABLE `mods` ADD `salt` CHAR( 32 ) NOT NULL AFTER `password`") or error(db_error());
  225. $query = query("SELECT `id`,`password` FROM `mods`") or error(db_error());
  226. while ($user = $query->fetch(PDO::FETCH_ASSOC)) {
  227. if (strlen($user['password']) == 40) {
  228. mt_srand(microtime(true) * 100000 + memory_get_usage(true));
  229. $salt = md5(uniqid(mt_rand(), true));
  230. $user['salt'] = $salt;
  231. $user['password'] = hash('sha256', $user['salt'] . $user['password']);
  232. $_query = prepare("UPDATE `mods` SET `password` = :password, `salt` = :salt WHERE `id` = :id");
  233. $_query->bindValue(':id', $user['id']);
  234. $_query->bindValue(':password', $user['password']);
  235. $_query->bindValue(':salt', $user['salt']);
  236. $_query->execute() or error(db_error($_query));
  237. }
  238. }
  239. case 'v0.9.6-dev-9':
  240. case 'v0.9.6-dev-9 + <a href="https://github.com/vichan-devel/Tinyboard/">vichan-devel-4.0.3</a>':
  241. case 'v0.9.6-dev-9 + <a href="https://github.com/vichan-devel/Tinyboard/">vichan-devel-4.0.4-gold</a>':
  242. case 'v0.9.6-dev-9 + <a href="https://github.com/vichan-devel/Tinyboard/">vichan-devel-4.0.5-gold</a>':
  243. foreach ($boards as &$board) {
  244. __query(sprintf("ALTER TABLE `posts_%s`
  245. CHANGE `subject` `subject` VARCHAR(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,
  246. CHANGE `email` `email` VARCHAR(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,
  247. CHANGE `name` `name` VARCHAR(35) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,
  248. CHANGE `trip` `trip` VARCHAR(15) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,
  249. CHANGE `capcode` `capcode` VARCHAR(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,
  250. CHANGE `body` `body` TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
  251. CHANGE `body_nomarkup` `body_nomarkup` TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,
  252. CHANGE `thumb` `thumb` VARCHAR(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,
  253. CHANGE `thumbwidth` `thumbwidth` INT(11) NULL DEFAULT NULL,
  254. CHANGE `thumbheight` `thumbheight` INT(11) NULL DEFAULT NULL,
  255. CHANGE `file` `file` VARCHAR(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,
  256. CHANGE `filename` `filename` TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,
  257. CHANGE `filehash` `filehash` TEXT CHARACTER SET ascii COLLATE ascii_general_ci NULL DEFAULT NULL,
  258. CHANGE `password` `password` VARCHAR(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,
  259. CHANGE `ip` `ip` VARCHAR(39) CHARACTER SET ascii COLLATE ascii_general_ci NOT NULL,
  260. CHANGE `embed` `embed` TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,
  261. DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;", $board['uri'])) or error(db_error());
  262. }
  263. __query("ALTER TABLE `antispam`
  264. CHANGE `board` `board` VARCHAR( 120 ) CHARACTER SET ASCII COLLATE ascii_general_ci NOT NULL ,
  265. CHANGE `hash` `hash` CHAR( 40 ) CHARACTER SET ASCII COLLATE ascii_bin NOT NULL ,
  266. DEFAULT CHARACTER SET ASCII COLLATE ascii_bin;") or error(db_error());
  267. __query("ALTER TABLE `bans`
  268. CHANGE `ip` `ip` VARCHAR( 39 ) CHARACTER SET ASCII COLLATE ascii_general_ci NOT NULL ,
  269. CHANGE `reason` `reason` TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL ,
  270. CHANGE `board` `board` VARCHAR( 120 ) CHARACTER SET ASCII COLLATE ascii_general_ci NULL DEFAULT NULL,
  271. DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;") or error(db_error());
  272. __query("ALTER TABLE `boards`
  273. CHANGE `uri` `uri` VARCHAR( 120 ) CHARACTER SET ASCII COLLATE ascii_general_ci NOT NULL ,
  274. CHANGE `title` `title` TINYTEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL ,
  275. CHANGE `subtitle` `subtitle` TINYTEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,
  276. DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;") or error(db_error());
  277. __query("ALTER TABLE `cites`
  278. CHANGE `board` `board` VARCHAR( 120 ) CHARACTER SET ASCII COLLATE ascii_general_ci NOT NULL ,
  279. CHANGE `target_board` `target_board` VARCHAR( 120 ) CHARACTER SET ASCII COLLATE ascii_general_ci NOT NULL ,
  280. DEFAULT CHARACTER SET ASCII COLLATE ascii_general_ci;") or error(db_error());
  281. __query("ALTER TABLE `ip_notes`
  282. CHANGE `ip` `ip` VARCHAR( 39 ) CHARACTER SET ASCII COLLATE ascii_general_ci NOT NULL ,
  283. CHANGE `body` `body` TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL ,
  284. DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;") or error(db_error());
  285. __query("ALTER TABLE `modlogs`
  286. CHANGE `ip` `ip` VARCHAR( 39 ) CHARACTER SET ASCII COLLATE ascii_general_ci NOT NULL ,
  287. CHANGE `board` `board` VARCHAR( 120 ) CHARACTER SET ASCII COLLATE ascii_general_ci NULL DEFAULT NULL ,
  288. CHANGE `text` `text` TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL ,
  289. DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;") or error(db_error());
  290. __query("ALTER TABLE `mods`
  291. CHANGE `username` `username` VARCHAR( 30 ) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL ,
  292. CHANGE `password` `password` CHAR( 64 ) CHARACTER SET ASCII COLLATE ascii_general_ci NOT NULL COMMENT 'SHA256',
  293. CHANGE `salt` `salt` CHAR( 32 ) CHARACTER SET ASCII COLLATE ascii_general_ci NOT NULL ,
  294. CHANGE `boards` `boards` TEXT CHARACTER SET ASCII COLLATE ascii_general_ci NOT NULL ,
  295. DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;") or error(db_error());
  296. __query("ALTER TABLE `mutes`
  297. CHANGE `ip` `ip` VARCHAR( 39 ) CHARACTER SET ASCII COLLATE ascii_general_ci NOT NULL ,
  298. DEFAULT CHARACTER SET ASCII COLLATE ascii_general_ci;") or error(db_error());
  299. __query("ALTER TABLE `news`
  300. CHANGE `name` `name` TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL ,
  301. CHANGE `subject` `subject` TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL ,
  302. CHANGE `body` `body` TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL ,
  303. DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;") or error(db_error());
  304. __query("ALTER TABLE `noticeboard`
  305. CHANGE `subject` `subject` TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL ,
  306. CHANGE `body` `body` TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL ,
  307. DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;") or error(db_error());
  308. __query("ALTER TABLE `pms`
  309. CHANGE `message` `message` TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL ,
  310. DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;") or error(db_error());
  311. __query("ALTER TABLE `reports`
  312. CHANGE `ip` `ip` VARCHAR( 39 ) CHARACTER SET ASCII COLLATE ascii_general_ci NOT NULL ,
  313. CHANGE `board` `board` VARCHAR( 120 ) CHARACTER SET ASCII COLLATE ascii_general_ci NULL DEFAULT NULL ,
  314. CHANGE `reason` `reason` TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL ,
  315. DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;") or error(db_error());
  316. __query("ALTER TABLE `robot`
  317. CHANGE `hash` `hash` VARCHAR( 40 ) CHARACTER SET ASCII COLLATE ascii_bin NOT NULL COMMENT 'SHA1',
  318. DEFAULT CHARACTER SET ASCII COLLATE ascii_bin;") or error(db_error());
  319. __query("ALTER TABLE `theme_settings`
  320. CHANGE `theme` `theme` VARCHAR( 40 ) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL ,
  321. CHANGE `name` `name` VARCHAR( 40 ) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL ,
  322. CHANGE `value` `value` TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL ,
  323. DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;") or eror(db_error());
  324. case 'v0.9.6-dev-10':
  325. query("ALTER TABLE `antispam`
  326. CHANGE `board` `board` VARCHAR( 58 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL;") or error(db_error());
  327. query("ALTER TABLE `bans`
  328. CHANGE `board` `board` VARCHAR( 58 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL;") or error(db_error());
  329. query("ALTER TABLE `boards`
  330. CHANGE `uri` `uri` VARCHAR( 58 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL;") or error(db_error());
  331. query("ALTER TABLE `cites`
  332. CHANGE `board` `board` VARCHAR( 58 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
  333. CHANGE `target_board` `target_board` VARCHAR( 58 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
  334. DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;") or error(db_error());
  335. query("ALTER TABLE `modlogs`
  336. CHANGE `board` `board` VARCHAR( 58 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL;") or error(db_error());
  337. query("ALTER TABLE `mods`
  338. CHANGE `boards` `boards` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL;") or error(db_error());
  339. query("ALTER TABLE `reports`
  340. CHANGE `board` `board` VARCHAR( 58 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL;") or error(db_error());
  341. case 'v0.9.6-dev-11':
  342. case 'v0.9.6-dev-11 + <a href="https://int.vichan.net/devel/">vichan-devel-4.0.6</a>':
  343. case 'v0.9.6-dev-11 + <a href="https://int.vichan.net/devel/">vichan-devel-4.0.7-gold</a>':
  344. case 'v0.9.6-dev-11 + <a href="https://int.vichan.net/devel/">vichan-devel-4.0.8-gold</a>':
  345. case 'v0.9.6-dev-11 + <a href="https://int.vichan.net/devel/">vichan-devel-4.0.9-gold</a>':
  346. foreach ($boards as &$board) {
  347. __query(sprintf("ALTER TABLE ``posts_%s``
  348. CHANGE `thumb` `thumb` VARCHAR( 255 ) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,
  349. CHANGE `file` `file` VARCHAR( 255 ) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL ;",
  350. $board['uri'])) or error(db_error());
  351. }
  352. case 'v0.9.6-dev-12':
  353. case 'v0.9.6-dev-12 + <a href="https://int.vichan.net/devel/">vichan-devel-4.0.10</a>':
  354. case 'v0.9.6-dev-12 + <a href="https://int.vichan.net/devel/">vichan-devel-4.0.11-gold</a>':
  355. foreach ($boards as &$board) {
  356. query(sprintf("ALTER TABLE ``posts_%s`` ADD INDEX `ip` (`ip`)", $board['uri'])) or error(db_error());
  357. }
  358. case 'v0.9.6-dev-13':
  359. query("ALTER TABLE ``antispam`` ADD INDEX `expires` (`expires`)") or error(db_error());
  360. case 'v0.9.6-dev-14':
  361. case 'v0.9.6-dev-14 + <a href="https://int.vichan.net/devel/">vichan-devel-4.0.12</a>':
  362. foreach ($boards as &$board) {
  363. query(sprintf("ALTER TABLE ``posts_%s``
  364. DROP INDEX `body`,
  365. ADD INDEX `filehash` (`filehash`(40))", $board['uri'])) or error(db_error());
  366. }
  367. query("ALTER TABLE ``modlogs`` ADD INDEX `mod` (`mod`)") or error(db_error());
  368. query("ALTER TABLE ``bans`` DROP INDEX `ip`") or error(db_error());
  369. query("ALTER TABLE ``bans`` ADD INDEX `ip` (`ip`)") or error(db_error());
  370. query("ALTER TABLE ``noticeboard`` ADD INDEX `time` (`time`)") or error(db_error());
  371. query("ALTER TABLE ``pms`` ADD INDEX `to` (`to`, `unread`)") or error(db_error());
  372. case 'v0.9.6-dev-15':
  373. foreach ($boards as &$board) {
  374. query(sprintf("ALTER TABLE ``posts_%s``
  375. ADD INDEX `list_threads` (`thread`, `sticky`, `bump`)", $board['uri'])) or error(db_error());
  376. }
  377. case 'v0.9.6-dev-16':
  378. case 'v0.9.6-dev-16 + <a href="https://int.vichan.net/devel/">vichan-devel-4.0.13</a>':
  379. query("ALTER TABLE ``bans`` ADD INDEX `seen` (`seen`)") or error(db_error());
  380. case 'v0.9.6-dev-17':
  381. query("ALTER TABLE ``ip_notes``
  382. DROP INDEX `ip`,
  383. ADD INDEX `ip_lookup` (`ip`, `time`)") or error(db_error());
  384. case 'v0.9.6-dev-18':
  385. query("CREATE TABLE IF NOT EXISTS ``flood`` (
  386. `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  387. `ip` varchar(39) NOT NULL,
  388. `board` varchar(58) CHARACTER SET utf8 NOT NULL,
  389. `time` int(11) NOT NULL,
  390. `posthash` char(32) NOT NULL,
  391. `filehash` char(32) DEFAULT NULL,
  392. `isreply` tinyint(1) NOT NULL,
  393. PRIMARY KEY (`id`),
  394. KEY `ip` (`ip`),
  395. KEY `posthash` (`posthash`),
  396. KEY `filehash` (`filehash`),
  397. KEY `time` (`time`)
  398. ) ENGINE=MyISAM DEFAULT CHARSET=ascii COLLATE=ascii_bin AUTO_INCREMENT=1 ;") or error(db_error());
  399. case 'v0.9.6-dev-19':
  400. query("UPDATE ``mods`` SET `type` = 10 WHERE `type` = 0") or error(db_error());
  401. query("UPDATE ``mods`` SET `type` = 20 WHERE `type` = 1") or error(db_error());
  402. query("UPDATE ``mods`` SET `type` = 30 WHERE `type` = 2") or error(db_error());
  403. query("ALTER TABLE ``mods`` CHANGE `type` `type` smallint(1) NOT NULL") or error(db_error());
  404. case 'v0.9.6-dev-20':
  405. __query("CREATE TABLE IF NOT EXISTS `bans_new_temp` (
  406. `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  407. `ipstart` varbinary(16) NOT NULL,
  408. `ipend` varbinary(16) DEFAULT NULL,
  409. `created` int(10) unsigned NOT NULL,
  410. `expires` int(10) unsigned DEFAULT NULL,
  411. `board` varchar(58) DEFAULT NULL,
  412. `creator` int(10) NOT NULL,
  413. `reason` text,
  414. `seen` tinyint(1) NOT NULL,
  415. `post` blob,
  416. PRIMARY KEY (`id`),
  417. KEY `expires` (`expires`),
  418. KEY `ipstart` (`ipstart`,`ipend`)
  419. ) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT=1") or error(db_error());
  420. $listquery = query("SELECT * FROM ``bans`` ORDER BY `id`") or error(db_error());
  421. while ($ban = $listquery->fetch(PDO::FETCH_ASSOC)) {
  422. $query = prepare("INSERT INTO ``bans_new_temp`` VALUES
  423. (NULL, :ipstart, :ipend, :created, :expires, :board, :creator, :reason, :seen, NULL)");
  424. $range = Bans::parse_range($ban['ip']);
  425. if ($range === false) {
  426. // Invalid retard ban; just skip it.
  427. continue;
  428. }
  429. $query->bindValue(':ipstart', $range[0]);
  430. if ($range[1] !== false && $range[1] != $range[0])
  431. $query->bindValue(':ipend', $range[1]);
  432. else
  433. $query->bindValue(':ipend', null, PDO::PARAM_NULL);
  434. $query->bindValue(':created', $ban['set']);
  435. if ($ban['expires'])
  436. $query->bindValue(':expires', $ban['expires']);
  437. else
  438. $query->bindValue(':expires', null, PDO::PARAM_NULL);
  439. if ($ban['board'])
  440. $query->bindValue(':board', $ban['board']);
  441. else
  442. $query->bindValue(':board', null, PDO::PARAM_NULL);
  443. $query->bindValue(':creator', $ban['mod']);
  444. if ($ban['reason'])
  445. $query->bindValue(':reason', $ban['reason']);
  446. else
  447. $query->bindValue(':reason', null, PDO::PARAM_NULL);
  448. $query->bindValue(':seen', $ban['seen']);
  449. $query->execute() or error(db_error($query));
  450. }
  451. // Drop old bans table
  452. query("DROP TABLE ``bans``") or error(db_error());
  453. // Replace with new table
  454. query("RENAME TABLE ``bans_new_temp`` TO ``bans``") or error(db_error());
  455. case 'v0.9.6-dev-21':
  456. case 'v0.9.6-dev-21 + <a href="https://int.vichan.net/devel/">vichan-devel-4.4.90</a>':
  457. __query("CREATE TABLE IF NOT EXISTS ``ban_appeals`` (
  458. `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  459. `ban_id` int(10) unsigned NOT NULL,
  460. `time` int(10) unsigned NOT NULL,
  461. `message` text NOT NULL,
  462. `denied` tinyint(1) NOT NULL,
  463. PRIMARY KEY (`id`),
  464. KEY `ban_id` (`ban_id`)
  465. ) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT=1 ;") or error(db_error());
  466. case 'v0.9.6-dev-22':
  467. case 'v0.9.6-dev-22 + <a href="https://int.vichan.net/devel/">vichan-devel-4.4.91</a>':
  468. case 'v0.9.6-dev-22 + <a href="https://int.vichan.net/devel/">vichan-devel-4.4.92</a>':
  469. case 'v0.9.6-dev-22 + <a href="https://int.vichan.net/devel/">vichan-devel-4.4.93</a>':
  470. case 'v0.9.6-dev-22 + <a href="https://int.vichan.net/devel/">vichan-devel-4.4.94</a>':
  471. case 'v0.9.6-dev-22 + <a href="https://int.vichan.net/devel/">vichan-devel-4.4.95</a>':
  472. case 'v0.9.6-dev-22 + <a href="https://int.vichan.net/devel/">vichan-devel-4.4.96</a>':
  473. case false:
  474. // Update version number
  475. file_write($config['has_installed'], VERSION);
  476. $page['title'] = 'Upgraded';
  477. $page['body'] = '<p style="text-align:center">Successfully upgraded from ' . $version . ' to <strong>' . VERSION . '</strong>.</p>';
  478. break;
  479. default:
  480. $page['title'] = 'Unknown version';
  481. $page['body'] = '<p style="text-align:center">Tinyboard was unable to determine what version is currently installed.</p>';
  482. break;
  483. case VERSION:
  484. $page['title'] = 'Already installed';
  485. $page['body'] = '<p style="text-align:center">It appears that Tinyboard is already installed (' . $version . ') and there is nothing to upgrade! Delete <strong>' . $config['has_installed'] . '</strong> to reinstall.</p>';
  486. break;
  487. }
  488. die(Element('page.html', $page));
  489. }
  490. if ($step == 0) {
  491. // Agreeement
  492. $page['body'] = '
  493. <textarea style="width:700px;height:370px;margin:auto;display:block;background:white;color:black" disabled>' . htmlentities(file_get_contents('LICENSE.md')) . '</textarea>
  494. <p style="text-align:center">
  495. <a href="?step=1">I have read and understood the agreement. Proceed to installation.</a>
  496. </p>';
  497. echo Element('page.html', $page);
  498. } elseif ($step == 1) {
  499. $page['title'] = 'Pre-installation test';
  500. $can_exec = true;
  501. if (!function_exists('shell_exec'))
  502. $can_exec = false;
  503. elseif (in_array('shell_exec', array_map('trim', explode(', ', ini_get('disable_functions')))))
  504. $can_exec = false;
  505. elseif (ini_get('safe_mode'))
  506. $can_exec = false;
  507. elseif (trim(shell_exec('echo "TEST"')) !== 'TEST')
  508. $can_exec = false;
  509. if (!defined('PHP_VERSION_ID')) {
  510. $version = explode('.', PHP_VERSION);
  511. define('PHP_VERSION_ID', ($version[0] * 10000 + $version[1] * 100 + $version[2]));
  512. }
  513. // Required extensions
  514. $extensions = array(
  515. 'PDO' => array(
  516. 'installed' => extension_loaded('pdo'),
  517. 'required' => true
  518. ),
  519. 'PDO' => array(
  520. 'installed' => extension_loaded('gd'),
  521. 'required' => true
  522. ),
  523. 'Imagick' => array(
  524. 'installed' => extension_loaded('imagick'),
  525. 'required' => false
  526. )
  527. );
  528. $tests = array(
  529. array(
  530. 'category' => 'PHP',
  531. 'name' => 'PHP &ge; 5.2.5',
  532. 'result' => PHP_VERSION_ID >= 50205,
  533. 'required' => true,
  534. 'message' => 'Tinyboard requires PHP 5.2.5 or better.',
  535. ),
  536. array(
  537. 'category' => 'PHP',
  538. 'name' => 'PHP &ge; 5.3',
  539. 'result' => PHP_VERSION_ID >= 50300,
  540. 'required' => false,
  541. 'message' => 'PHP &ge; 5.3, though not required, is recommended to make the most out of Tinyboard configuration files.',
  542. ),
  543. array(
  544. 'category' => 'PHP',
  545. 'name' => 'mbstring extension installed',
  546. 'result' => extension_loaded('mbstring'),
  547. 'required' => true,
  548. 'message' => 'You must install the PHP <a href="http://www.php.net/manual/en/mbstring.installation.php">mbstring</a> extension.',
  549. ),
  550. array(
  551. 'category' => 'Database',
  552. 'name' => 'PDO extension installed',
  553. 'result' => extension_loaded('pdo'),
  554. 'required' => true,
  555. 'message' => 'You must install the PHP <a href="http://www.php.net/manual/en/intro.pdo.php">PDO</a> extension.',
  556. ),
  557. array(
  558. 'category' => 'Database',
  559. 'name' => 'MySQL PDO driver installed',
  560. 'result' => extension_loaded('pdo') && in_array('mysql', PDO::getAvailableDrivers()),
  561. 'required' => true,
  562. 'message' => 'The required <a href="http://www.php.net/manual/en/ref.pdo-mysql.php">PDO MySQL driver</a> is not installed.',
  563. ),
  564. array(
  565. 'category' => 'Image processing',
  566. 'name' => 'GD extension installed',
  567. 'result' => extension_loaded('gd'),
  568. 'required' => true,
  569. 'message' => 'You must install the PHP <a href="http://www.php.net/manual/en/intro.image.php">GD</a> extension. GD is a requirement even if you have chosen another image processor for thumbnailing.',
  570. ),
  571. array(
  572. 'category' => 'Image processing',
  573. 'name' => 'GD: JPEG',
  574. 'result' => function_exists('imagecreatefromjpeg'),
  575. 'required' => true,
  576. 'message' => 'imagecreatefromjpeg() does not exist. This is a problem.',
  577. ),
  578. array(
  579. 'category' => 'Image processing',
  580. 'name' => 'GD: PNG',
  581. 'result' => function_exists('imagecreatefrompng'),
  582. 'required' => true,
  583. 'message' => 'imagecreatefrompng() does not exist. This is a problem.',
  584. ),
  585. array(
  586. 'category' => 'Image processing',
  587. 'name' => 'GD: GIF',
  588. 'result' => function_exists('imagecreatefromgif'),
  589. 'required' => true,
  590. 'message' => 'imagecreatefromgif() does not exist. This is a problem.',
  591. ),
  592. array(
  593. 'category' => 'Image processing',
  594. 'name' => 'Imagick extension installed',
  595. 'result' => extension_loaded('imagick'),
  596. 'required' => false,
  597. 'message' => '(Optional) The PHP <a href="http://www.php.net/manual/en/imagick.installation.php">Imagick</a> (ImageMagick) extension is not installed. You may not use Imagick for better (and faster) image processing.',
  598. ),
  599. array(
  600. 'category' => 'Image processing',
  601. 'name' => '`convert` (command-line ImageMagick)',
  602. 'result' => $can_exec && shell_exec('which convert'),
  603. 'required' => false,
  604. 'message' => '(Optional) `convert` was not found or executable; command-line ImageMagick image processing cannot be enabled.',
  605. ),
  606. array(
  607. 'category' => 'Image processing',
  608. 'name' => '`identify` (command-line ImageMagick)',
  609. 'result' => $can_exec && shell_exec('which identify'),
  610. 'required' => false,
  611. 'message' => '(Optional) `identify` was not found or executable; command-line ImageMagick image processing cannot be enabled.',
  612. ),
  613. array(
  614. 'category' => 'Image processing',
  615. 'name' => '`gm` (command-line GraphicsMagick)',
  616. 'result' => $can_exec && shell_exec('which gm'),
  617. 'required' => false,
  618. 'message' => '(Optional) `gm` was not found or executable; command-line GraphicsMagick (faster than ImageMagick) cannot be enabled.',
  619. ),
  620. array(
  621. 'category' => 'Image processing',
  622. 'name' => '`gifsicle` (command-line animted GIF thumbnailing)',
  623. 'result' => $can_exec && shell_exec('which gifsicle'),
  624. 'required' => false,
  625. 'message' => '(Optional) `gifsicle` was not found or executable; you may not use `convert+gifsicle` for better animated GIF thumbnailing.',
  626. ),
  627. array(
  628. 'category' => 'File permissions',
  629. 'name' => getcwd(),
  630. 'result' => is_writable('.'),
  631. 'required' => true,
  632. 'message' => 'Tinyboard does not have permission to create directories (boards) here. You will need to <code>chmod</code> (or operating system equivalent) appropriately.'
  633. ),
  634. array(
  635. 'category' => 'File permissions',
  636. 'name' => getcwd() . '/templates/cache',
  637. 'result' => is_writable('templates') && (!is_dir('templates/cache') || is_writable('templates/cache')),
  638. 'required' => true,
  639. 'message' => 'You must give Tinyboard permission to create (and write to) the <code>templates/cache</code> directory or performance will be drastically reduced.'
  640. ),
  641. array(
  642. 'category' => 'File permissions',
  643. 'name' => getcwd() . '/inc/instance-config.php',
  644. 'result' => is_writable('inc/instance-config.php'),
  645. 'required' => false,
  646. 'message' => 'Tinyboard does not have permission to make changes to <code>inc/instance-config.php</code>. To complete the installation, you will be asked to manually copy and paste code into the file instead.'
  647. ),
  648. array(
  649. 'category' => 'Misc',
  650. 'name' => 'Caching available (APC, XCache, Memcached or Redis)',
  651. 'result' => extension_loaded('apc') || extension_loaded('xcache')
  652. || extension_loaded('memcached') || extension_loaded('redis'),
  653. 'required' => false,
  654. 'message' => 'You will not be able to enable the additional caching system, designed to minimize SQL queries and significantly improve performance. <a href="http://php.net/manual/en/book.apc.php">APC</a> is the recommended method of caching, but <a href="http://xcache.lighttpd.net/">XCache</a>, <a href="http://www.php.net/manual/en/intro.memcached.php">Memcached</a> and <a href="http://pecl.php.net/package/redis">Redis</a> are also supported.'
  655. ),
  656. array(
  657. 'category' => 'Misc',
  658. 'name' => 'Tinyboard installed using git',
  659. 'result' => is_dir('.git'),
  660. 'required' => false,
  661. 'message' => 'Tinyboard is still beta software and it\'s not going to come out of beta any time soon. As there are often many months between releases yet changes and bug fixes are very frequent, it\'s recommended to use the git repository to maintain your Tinyboard installation. Using git makes upgrading much easier.'
  662. )
  663. );
  664. $config['font_awesome'] = true;
  665. echo Element('page.html', array(
  666. 'body' => Element('installer/check-requirements.html', array(
  667. 'extensions' => $extensions,
  668. 'tests' => $tests,
  669. 'config' => $config
  670. )),
  671. 'title' => 'Checking environment',
  672. 'config' => $config
  673. ));
  674. } elseif ($step == 2) {
  675. // Basic config
  676. $page['title'] = 'Configuration';
  677. $config['cookies']['salt'] = substr(base64_encode(sha1(rand())), 0, 30);
  678. $config['secure_trip_salt'] = substr(base64_encode(sha1(rand())), 0, 30);
  679. echo Element('page.html', array(
  680. 'body' => Element('installer/config.html', array(
  681. 'config' => $config
  682. )),
  683. 'title' => 'Configuration',
  684. 'config' => $config
  685. ));
  686. } elseif ($step == 3) {
  687. $instance_config =
  688. '<?php
  689. /*
  690. * Instance Configuration
  691. * ----------------------
  692. * Edit this file and not config.php for imageboard configuration.
  693. *
  694. * You can copy values from config.php (defaults) and paste them here.
  695. */
  696. ';
  697. function create_config_from_array(&$instance_config, &$array, $prefix = '') {
  698. foreach ($array as $name => $value) {
  699. if (is_array($value)) {
  700. $instance_config .= "\n";
  701. create_config_from_array($instance_config, $value, $prefix . '[\'' . addslashes($name) . '\']');
  702. $instance_config .= "\n";
  703. } else {
  704. $instance_config .= ' $config' . $prefix . '[\'' . addslashes($name) . '\'] = ';
  705. if (is_numeric($value))
  706. $instance_config .= $value;
  707. else
  708. $instance_config .= "'" . addslashes($value) . "'";
  709. $instance_config .= ";\n";
  710. }
  711. }
  712. }
  713. create_config_from_array($instance_config, $_POST);
  714. $instance_config .= "\n";
  715. if (@file_put_contents('inc/instance-config.php', $instance_config)) {
  716. header('Location: ?step=4', true, $config['redirect_http']);
  717. } else {
  718. $page['title'] = 'Manual installation required';
  719. $page['body'] = '
  720. <p>I couldn\'t write to <strong>inc/instance-config.php</strong> with the new configuration, probably due to a permissions error.</p>
  721. <p>Please complete the installation manually by copying and pasting the following code into the contents of <strong>inc/instance-config.php</strong>:</p>
  722. <textarea style="width:700px;height:370px;margin:auto;display:block;background:white;color:black">' . htmlentities($instance_config) . '</textarea>
  723. <p style="text-align:center">
  724. <a href="?step=4">Once complete, click here to complete installation.</a>
  725. </p>
  726. ';
  727. echo Element('page.html', $page);
  728. }
  729. } elseif ($step == 4) {
  730. // SQL installation
  731. buildJavascript();
  732. $sql = @file_get_contents('install.sql') or error("Couldn't load install.sql.");
  733. sql_open();
  734. $mysql_version = mysql_version();
  735. // This code is probably horrible, but what I'm trying
  736. // to do is find all of the SQL queires and put them
  737. // in an array.
  738. preg_match_all("/(^|\n)((SET|CREATE|INSERT).+)\n\n/msU", $sql, $queries);
  739. $queries = $queries[2];
  740. $queries[] = Element('posts.sql', array('board' => 'b'));
  741. $sql_errors = '';
  742. foreach ($queries as $query) {
  743. if ($mysql_version < 50503)
  744. $query = preg_replace('/(CHARSET=|CHARACTER SET )utf8mb4/', '$1utf8', $query);
  745. $query = preg_replace('/^([\w\s]*)`([0-9a-zA-Z$_\x{0080}-\x{FFFF}]+)`/u', '$1``$2``', $query);
  746. if (!query($query))
  747. $sql_errors .= '<li>' . db_error() . '</li>';
  748. }
  749. $page['title'] = 'Installation complete';
  750. $page['body'] = '<p style="text-align:center">Thank you for using Tinyboard. 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>';
  751. if (!empty($sql_errors)) {
  752. $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 Tinyboard 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>';
  753. } else {
  754. $boards = listBoards();
  755. foreach ($boards as &$_board) {
  756. setupBoard($_board);
  757. buildIndex();
  758. }
  759. file_write($config['has_installed'], VERSION);
  760. if (!file_unlink(__FILE__)) {
  761. $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>';
  762. }
  763. }
  764. echo Element('page.html', $page);
  765. } elseif ($step == 5) {
  766. $page['title'] = 'Installation complete';
  767. $page['body'] = '<p style="text-align:center">Thank you for using Tinyboard. Please remember to report any bugs you discover.</p>';
  768. $boards = listBoards();
  769. foreach ($boards as &$_board) {
  770. setupBoard($_board);
  771. buildIndex();
  772. }
  773. file_write($config['has_installed'], VERSION);
  774. if (!file_unlink(__FILE__)) {
  775. $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>';
  776. }
  777. echo Element('page.html', $page);
  778. }