selectCol('SELECT `key` AS ARRAY_KEY, value FROM ?_config WHERE `key` IN ("site_host", "static_host", "force_ssl")'); $prot = $res['force_ssl'] ? 'https://' : 'http://'; if ($res['site_host']) { if (!$test($prot.$res['site_host'].'/README.md', $resp)) $error[] = ' * could not access '.$prot.$res['site_host'].'/README.md ['.$resp.']'; } else $error[] = ' * SITE_HOST is empty'; if ($res['static_host']) { if (!$test($prot.$res['static_host'].'/css/aowow.css', $resp)) $error[] = ' * could not access '.$prot.$res['static_host'].'/css/aowow.css ['.$resp.']'; } else $error[] = ' * STATIC_HOST 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) { CLISetup::log('Found firstrun progression info. (Halted on subscript '.($steps[$startStep][1] ?: $steps[$startStep][0]).')', CLISetup::LOG_INFO); $inp = ['x' => ['continue setup? (y/n)', true, '/y|n/i']]; $msg = ''; if (!CLISetup::readInput($inp, true) || !$inp || strtolower($inp['x']) == 'n') { $msg = 'Starting setup from scratch...'; $startStep = 0; } else $msg = 'Resuming setup from step '.$startStep.'...'; CLISetup::log(); CLISetup::log($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]) { CLISetup::log($step[3]); $inp = ['x' => ['Press any key to continue', true]]; if (!CLISetup::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)) { CLISetup::log($step[4], CLISetup::LOG_ERROR); foreach ($errors as $e) CLISetup::log($e); } else { $saveProgress($idx); break; } } else if ($res !== false) { $saveProgress($idx); break; } $inp = ['x' => ['['.CLISetup::bold('c').']ontinue anyway? ['.CLISetup::bold('r').']etry? ['.CLISetup::bold('a').']bort?', true, '/c|r|a/i']]; if (CLISetup::readInput($inp, true) && $inp) { CLISetup::log(); switch(strtolower($inp['x'])) { case 'c': $saveProgress($idx); break 2; case 'r': break; case 'a': return; } } else { CLISetup::log(); return; } } } unlink('cache/firstrun'); CLISetup::log('setup finished', CLISetup::LOG_OK); } ?>