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 ($_SESSION['dbcollation'] == '') {
150:         prntln(i18n('You did not specify a database collation!', 'setup'));
151:         $fine = false;
152:     }
153:     if ($cfg['db']['connection']['database'] == '') {
154:         prntln(i18n('You did not specify a database name!', 'setup'));
155:         $fine = false;
156:     }
157:     if ($_SESSION['dbprefix'] == '') {
158:         prntln(i18n('You did not specify a database prefix!', 'setup'));
159:         $fine = false;
160:     }
161: 
162:     
163:     if (!(substr($_SESSION['override_root_http_path'], -strlen("/")) === "/")) {
164:         $_SESSION['override_root_http_path'] = $_SESSION['override_root_http_path'] . "/";
165:     }
166:     if ($_SESSION['override_root_http_path'] == '') {
167:         prntln(i18n('You did not specify an http root path!', 'setup'));
168:         $fine = false;
169:     }
170:     if ($_SESSION['clientmode'] == '') {
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['clientmode'] == "CLIENTEXAMPLES" || $_SESSION['clientmode'] == "CLIENTMODULES" || $_SESSION['clientmode'] == "NOCLIENT")) {
175:         prntln(i18n('You did not specify if you want to install the example client or not!', 'setup'));
176:         $fine = false;
177:     }
178:     if ($_SESSION['adminpass'] == '') {
179:         prntln(i18n('You did not specify an admin password!', 'setup'));
180:         $fine = false;
181:     }
182:     if ($_SESSION['adminmail'] == '') {
183:         prntln(i18n('You did not specify an admin email!', 'setup'));
184:         $fine = false;
185:     }
186: 
187:     return $fine;
188: }
189: 
190: 191: 192: 193: 194: 
195: function getArgs() {
196:     $args = $_SERVER['argv'];
197: 
198:     $out = array();
199:     $last_arg = null;
200: 
201:     for ($i = 1, $il = sizeof($args); $i < $il; $i++) {
202:         if (preg_match("/^--(.+)/", $args[$i], $match)) {
203:             $parts = explode("=", $match[1]);
204:             $key = preg_replace("/[^a-z0-9]+/", "", $parts[0]);
205: 
206:             if (isset($parts[1])) {
207:                 $out[$key] = $parts[1];
208:             } else {
209:                 $out[$key] = true;
210:             }
211:             $last_arg = $key;
212:         } else if (preg_match("/^-([a-zA-Z0-9]+)/", $args[$i], $match)) {
213:             for ($j = 0, $jl = strlen($match[1]); $j < $jl; $j++) {
214:                 $key = $match[1]{$j};
215:                 $out[$key] = true;
216:             }
217:             $last_arg = $key;
218:         } else if ($last_arg !== null) {
219:             $out[$last_arg] = $args[$i];
220:         }
221:     }
222:     return $out;
223: }
224: 
225: 226: 227: 
228: function printHelpText() {
229:     prntln("\r" . i18n('CONTENIDO setup script', 'setup'));
230:     prntln(i18n('This script will install CONTENIDO to your computer', 'setup'));
231:     prntln();
232:     prntln(i18n("CONTENIDO can be installed using the interactive mode or a non-interactive mode.", 'setup'));
233:     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'));
234:     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'));
235:     prntln(i18n("In case the ini file can not be found, the script will wait for user input\non all relevant information.", 'setup'));
236:     prntln();
237:     prntln('--interactive, -i');
238:     prntln(i18n("Forces the script to be interactive and wait for user input even if the\n\tautoinstall.ini file is present.", 'setup'), 1);
239:     prntln('--non-interactive');
240:     prntln(i18n("Will prevent all waiting for user input. The script will abort\n\tin case of any errors", 'setup'), 1);
241:     prntln('--file [' . i18n('file', 'setup') . ']');
242:     prntln(i18n('Use [file] instead of the default autoinstall.ini.', 'setup'), 1);
243:     prntln('--locale [' . i18n('language code', 'setup') . ']');
244:     prntln(i18n("Provide a country and language code to use. Defaults to \"en_US\"", 'setup'), 1);
245:     prntln('--help, -h');
246:     prntln(i18n('Prints this help text', 'setup'), 1);
247:     prntln();
248:     prntln(i18n("Furthermore, you can use parameters to overwrite setup settings.\nUse \"--[ini-group].[ini-name]=\"value\" (e.g. --db.host=\"localhost\")", 'setup'));
249:     prntln();
250:     prntln('CONTENIDO version ' . CON_SETUP_VERSION);
251: }
252: 
253: ?>
254: