'\/', '.' => '\.'])."/i", $res['Location'], $n)) { $protocol = $n[1]; $host = $n[2]; } return false; } $rCode = 0; return false; }; $res = DB::Aowow()->selectCol('SELECT `key` AS ARRAY_KEY, value FROM ?_config WHERE `key` IN ("site_host", "static_host", "force_ssl")'); $prot = $res['force_ssl'] ? 'https://' : 'http://'; $cases = array( 'site_host' => [$prot, $res['site_host'], '/README.md'], 'static_host' => [$prot, $res['static_host'], '/css/aowow.css'] ); foreach ($cases as $conf => list($protocol, $host, $testFile)) { if ($host) { if (!$test($protocol, $host, $testFile, $resp)) { if ($resp == 301 || $resp == 302) { CLI::write('self test received status '.CLI::bold($resp).' (page moved) for '.$conf.', pointing to: '.$protocol.$host.$testFile, CLI::LOG_WARN); $inp = ['x' => ['should '.CLI::bold($conf).' be set to '.CLI::bold($host).' and force_ssl be updated?', true, '/y|n/i']]; if (!CLI::readInput($inp, true) || !$inp || strtolower($inp['x']) == 'n') $error[] = ' * could not access '.$protocol.$host.$testFile.' ['.$resp.']'; else { DB::Aowow()->query('UPDATE ?_config SET `value` = ? WHERE `key` = ?', $host, $conf); DB::Aowow()->query('UPDATE ?_config SET `value` = ?d WHERE `key` = "force_ssl"', intVal($protocol == 'https://')); } CLI::write(); } else $error[] = ' * could not access '.$protocol.$host.$testFile.' ['.$resp.']'; } } else $error[] = ' * '.strtoupper($conf).' is empty'; } return empty($error); } function testAcc(&$error) { $error = []; return !!DB::Aowow()->selectCell('SELECT id FROM ?_account WHERE userPerms = 1'); } function endSetup() { return DB::Aowow()->query('UPDATE ?_config SET value = 0 WHERE `key` = "maintenance"'); } /********************/ /* get current step */ /********************/ $startStep = 0; if (file_exists('cache/firstrun')) { $rows = file('cache/firstrun'); if ((int)$rows[0] == AOWOW_REVISION) $startStep = (int)$rows[1]; } if ($startStep) { CLI::write('Found firstrun progression info. (Halted on subscript '.($steps[$startStep][1] ?: $steps[$startStep][0]).')', CLI::LOG_INFO); $inp = ['x' => ['continue setup? (y/n)', true, '/y|n/i']]; $msg = ''; if (!CLI::readInput($inp, true) || !$inp || strtolower($inp['x']) == 'n') { $msg = 'Starting setup from scratch...'; $startStep = 0; } else $msg = 'Resuming setup from step '.$startStep.'...'; CLI::write(); CLI::write($msg); sleep(1); } /*******/ /* run */ /*******/ foreach ($steps as $idx => $step) { if ($startStep > $idx) continue; if (!strpos($step[0], '::') && !is_callable($step[0])) require_once 'setup/tools/clisetup/'.$step[0].'.func.php'; if ($step[3]) { CLI::write($step[3]); $inp = ['x' => ['Press any key to continue', true]]; if (!CLI::readInput($inp, true)) // we don't actually care about the input return; } while (true) { $res = call_user_func($step[0], $step[1]); // check script result if ($step[2]) { if (!$step[2]($errors)) { CLI::write($step[4], CLI::LOG_ERROR); foreach ($errors as $e) CLI::write($e); } else { $saveProgress($idx); break; } } else if ($res !== false) { $saveProgress($idx); break; } $inp = ['x' => ['['.CLI::bold('c').']ontinue anyway? ['.CLI::bold('r').']etry? ['.CLI::bold('a').']bort?', true, '/c|r|a/i']]; if (CLI::readInput($inp, true) && $inp) { CLI::write(); switch(strtolower($inp['x'])) { case 'c': $saveProgress($idx); break 2; case 'r': break; case 'a': return; } } else { CLI::write(); return; } } } unlink('cache/firstrun'); CLI::write('setup finished', CLI::LOG_OK); } ?>