Textpattern | PHP Cross Reference | Content Management Systems |
1 <?php 2 3 /* 4 * Textpattern Content Management System 5 * https://textpattern.com/ 6 * 7 * Copyright (C) 2020 The Textpattern Development Team 8 * 9 * This file is part of Textpattern. 10 * 11 * Textpattern is free software; you can redistribute it and/or 12 * modify it under the terms of the GNU General Public License 13 * as published by the Free Software Foundation, version 2. 14 * 15 * Textpattern is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU General Public License for more details. 19 * 20 * You should have received a copy of the GNU General Public License 21 * along with Textpattern. If not, see <https://www.gnu.org/licenses/>. 22 */ 23 24 if (@php_sapi_name() != 'cli') { 25 exit; 26 } 27 28 $params = getopt('', array('config:', 'debug::', 'force::')); 29 30 if (! $file = @$params['config']) { 31 exit(<<<EOF 32 Usage: php setup.php --config="my-setup-config.json" 33 Other options: 34 --force - overwrite existing 'config.php' file. 35 --debug - debug output to STDOUT. 36 37 EOF 38 ); 39 } 40 41 $cfg = json_decode(file_get_contents($file), true); 42 43 if (empty($cfg)) { 44 msg("Error json config file", MSG_ERROR); 45 } 46 47 define("txpinterface", "admin"); 48 49 if (!defined('txpath')) { 50 define("txpath", dirname(dirname(__FILE__))); 51 } 52 53 define('MSG_OK', '[OK]'); 54 define('MSG_ALERT', '[WARNING]'); 55 define('MSG_ERROR', '[ERROR]'); 56 57 error_reporting(E_ALL | E_STRICT); 58 @ini_set("display_errors", "1"); 59 60 include_once txpath.'/lib/class.trace.php'; 61 $trace = new Trace(); 62 include_once txpath.'/lib/constants.php'; 63 include_once txpath.'/lib/txplib_misc.php'; 64 include_once txpath.'/lib/txplib_admin.php'; 65 include_once txpath.'/vendors/Textpattern/Loader.php'; 66 67 $loader = new \Textpattern\Loader(txpath.'/vendors'); 68 $loader->register(); 69 70 $loader = new \Textpattern\Loader(txpath.'/lib'); 71 $loader->register(); 72 73 include_once txpath.'/lib/txplib_html.php'; 74 include_once txpath.'/lib/txplib_forms.php'; 75 include_once txpath.'/include/txp_auth.php'; 76 include_once txpath.'/setup/setup_lib.php'; 77 78 assert_system_requirements(); 79 setup_load_lang(@$cfg['site']['language_code']); 80 81 if (!isset($params['force']) && file_exists(txpath.'/config.php')) { 82 msg(gTxt('already_installed'), MSG_ERROR); 83 } 84 85 setup_connect(); 86 $cfg_php = setup_makeConfig($cfg); 87 88 if (@file_put_contents(txpath.'/config.php', $cfg_php) === false) { 89 msg(gTxt('config_php_write_error'), MSG_ERROR); 90 } 91 92 @include txpath.'/config.php'; 93 94 if (empty($cfg['user']['login_name'])) { 95 msg(gTxt('name_required'), MSG_ERROR); 96 } 97 98 if (empty($cfg['user']['password'])) { 99 msg(gTxt('pass_required'), MSG_ERROR); 100 } 101 102 if (!is_valid_email($cfg['user']['email'])) { 103 msg(gTxt('email_required'), MSG_ERROR); 104 } 105 106 setup_db($cfg); 107 msg(gTxt('that_went_well')); 108 109 setup_die(0); 110 111 function msg($msg, $class = MSG_OK, $back = false) 112 { 113 echo "$class\t".strip_tags($msg)."\n"; 114 if ($class == MSG_ERROR) { 115 setup_die(128); 116 } 117 } 118 119 function setup_die($code = 0) 120 { 121 global $trace, $params; 122 123 if (isset($params['debug'])) { 124 echo $trace->summary(); 125 echo $trace->result(); 126 } 127 128 exit((int)$code); 129 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
title