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