1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
14:
15: 16: 17: 18: 19: 20:
21: function prnt($str = '', $tab = 0) {
22: for ($i = 0; $i < $tab; $i++) {
23: echo("\t");
24: }
25: echo($str);
26: }
27:
28: 29: 30: 31: 32: 33:
34: function prntln($str = '', $tab = 0) {
35: prnt($str . "\n\r", $tab);
36: }
37:
38: 39: 40: 41: 42:
43: function prntst($str = '') {
44: echo($str . "\r");
45: }
46:
47: 48: 49: 50: 51: 52: 53: 54: 55:
56: function passwordPrompt($title, $tab = 0) {
57: if (cString::toUpperCase(cString::getPartOfString(PHP_OS, 0, 3)) === 'WIN') {
58: prntln(i18n('Be careful! The password will be readable in the console window!', 'setup'), $tab);
59: }
60: prnt($title . ': ', $tab);
61: $line = trim(fgets(STDIN));
62: if (!(cString::toUpperCase(cString::getPartOfString(PHP_OS, 0, 3)) === 'WIN')) {
63: echo("\033[1A");
64: prnt($title . ': ', $tab);
65: for ($i = 0; $i < cString::getStringLength($line); $i++) {
66: echo("*");
67: }
68: echo("\r\n");
69: }
70: return $line;
71: }
72:
73: 74: 75: 76: 77: 78:
79: function progressBar($width, $filled) {
80: echo("\r");
81: echo("|");
82: $i = 0;
83: for ($i = 0; $i <= $filled / 100 * $width; $i++) {
84: echo("#");
85: }
86: for ($j = $i; $j <= $width; $j++) {
87: echo(" ");
88: }
89: echo("| ");
90: prnt(round($filled) . "%");
91: }
92:
93: 94: 95:
96: function initializeVariables() {
97: global $cfg, $_SESSION;
98:
99: $cfg['db'] = array(
100: 'connection' => array(
101: 'host' => '',
102: 'user' => '',
103: 'password' => '',
104: 'charset' => '',
105: 'database' => ''
106: ),
107: 'haltBehavior' => 'report',
108: 'haltMsgPrefix' => (isset($_SERVER['REQUEST_URI'])) ? $_SERVER['REQUEST_URI'] . ' ' : '',
109: 'enableProfiling' => false
110: );
111: $_SESSION['setuptype'] = 'setup';
112: $_SESSION['dbname'] = '';
113: $_SESSION['configmode'] = 'save';
114: $_SESSION["override_root_http_path"] = '';
115: $_SESSION['clientmode'] = '';
116: $_SESSION['adminpass'] = '';
117: $_SESSION['adminmail'] = '';
118: $_SESSION['dbprefix'] = '';
119: }
120:
121: 122: 123: 124: 125:
126: function checkInstallationSettings() {
127: global $cfg, $_SESSION;
128:
129: $fine = true;
130:
131: if ($cfg['db']['connection']['host'] == '') {
132: prntln(i18n('You did not specify a database host!', 'setup'));
133: $fine = false;
134: }
135: if ($cfg['db']['connection']['user'] == '') {
136: prntln(i18n('You did not specify a database user!', 'setup'));
137: $fine = false;
138: }
139: if ($cfg['db']['connection']['password'] == '') {
140: prntln(i18n('You did not specify a database password!', 'setup'));
141: $fine = false;
142: }
143: if ($cfg['db']['connection']['charset'] == '') {
144: prntln(i18n('You did not specify a database charset!', 'setup'));
145: $fine = false;
146: }
147: if ($_SESSION['dbcollation'] == '') {
148: prntln(i18n('You did not specify a database collation!', 'setup'));
149: $fine = false;
150: }
151: if ($cfg['db']['connection']['database'] == '') {
152: prntln(i18n('You did not specify a database name!', 'setup'));
153: $fine = false;
154: }
155: if ($_SESSION['dbprefix'] == '') {
156: prntln(i18n('You did not specify a database prefix!', 'setup'));
157: $fine = false;
158: }
159:
160:
161: if (!(cString::getPartOfString($_SESSION['override_root_http_path'], -cString::getStringLength("/")) === "/")) {
162: $_SESSION['override_root_http_path'] = $_SESSION['override_root_http_path'] . "/";
163: }
164: if ($_SESSION['override_root_http_path'] == '') {
165: prntln(i18n('You did not specify an http root path!', 'setup'));
166: $fine = false;
167: }
168: if ($_SESSION['clientmode'] == '') {
169: prntln(i18n('You did not specify if you want to install the example client or not!', 'setup'));
170: $fine = false;
171: }
172: if (!($_SESSION['clientmode'] == "CLIENTEXAMPLES" || $_SESSION['clientmode'] == "CLIENTMODULES" || $_SESSION['clientmode'] == "NOCLIENT")) {
173: prntln(i18n('You did not specify if you want to install the example client or not!', 'setup'));
174: $fine = false;
175: }
176: if ($_SESSION['adminpass'] == '') {
177: prntln(i18n('You did not specify an admin password!', 'setup'));
178: $fine = false;
179: }
180: if ($_SESSION['adminmail'] == '') {
181: prntln(i18n('You did not specify an admin email!', 'setup'));
182: $fine = false;
183: }
184:
185: return $fine;
186: }
187:
188: 189: 190: 191: 192:
193: function getArgs() {
194: $args = $_SERVER['argv'];
195:
196: $out = array();
197: $last_arg = null;
198:
199: for ($i = 1, $il = sizeof($args); $i < $il; $i++) {
200: if (preg_match("/^--(.+)/", $args[$i], $match)) {
201: $parts = explode("=", $match[1]);
202: $key = preg_replace("/[^a-z0-9]+/", "", $parts[0]);
203:
204: if (isset($parts[1])) {
205: $out[$key] = $parts[1];
206: } else {
207: $out[$key] = true;
208: }
209: $last_arg = $key;
210: } else if (preg_match("/^-([a-zA-Z0-9]+)/", $args[$i], $match)) {
211: for ($j = 0, $jl = cString::getStringLength($match[1]); $j < $jl; $j++) {
212: $key = $match[1]{$j};
213: $out[$key] = true;
214: }
215: $last_arg = $key;
216: } else if ($last_arg !== null) {
217: $out[$last_arg] = $args[$i];
218: }
219: }
220: return $out;
221: }
222:
223: 224: 225:
226: function printHelpText() {
227: prntln("\r" . i18n('CONTENIDO setup script', 'setup'));
228: prntln(i18n('This script will install CONTENIDO to your computer', 'setup'));
229: prntln();
230: prntln(i18n("CONTENIDO can be installed using the interactive mode or a non-interactive mode.", 'setup'));
231: prntln(i18n("If the script is executed without any parameters it will look for the\nautoinstall.ini file (or any other file specified with \"--file\").", 'setup'));
232: prntln(i18n("If that file is present, the non-interactive mode will be used. The script will\nask for user input in the case of errors though.\nIf you want to prevent the script from ever waiting for user input use\n\"--non-interactive\".", 'setup'));
233: prntln(i18n("In case the ini file can not be found, the script will wait for user input\non all relevant information.", 'setup'));
234: prntln();
235: prntln('--interactive, -i');
236: prntln(i18n("Forces the script to be interactive and wait for user input even if the\n\tautoinstall.ini file is present.", 'setup'), 1);
237: prntln('--non-interactive');
238: prntln(i18n("Will prevent all waiting for user input. The script will abort\n\tin case of any errors", 'setup'), 1);
239: prntln('--file [' . i18n('file', 'setup') . ']');
240: prntln(i18n('Use [file] instead of the default autoinstall.ini.', 'setup'), 1);
241: prntln('--locale [' . i18n('language code', 'setup') . ']');
242: prntln(i18n("Provide a country and language code to use. Defaults to \"en_US\"", 'setup'), 1);
243: prntln('--help, -h');
244: prntln(i18n('Prints this help text', 'setup'), 1);
245: prntln();
246: prntln(i18n("Furthermore, you can use parameters to overwrite setup settings.\nUse \"--[ini-group].[ini-name]=\"value\" (e.g. --db.host=\"localhost\")", 'setup'));
247: prntln();
248: prntln('CONTENIDO version ' . CON_SETUP_VERSION);
249: }
250:
251: ?>
252: