|
1
|
|
|
#!/usr/bin/env php |
|
2
|
|
|
<?php |
|
3
|
|
|
/** |
|
4
|
|
|
* Setup - Command line interface |
|
5
|
|
|
* |
|
6
|
|
|
* @link http://www.egroupware.org |
|
7
|
|
|
* @package setup |
|
8
|
|
|
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de> |
|
9
|
|
|
* @copyright (c) 2006-19 by Ralf Becker <RalfBecker-AT-outdoor-training.de> |
|
10
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
use EGroupware\Api; |
|
14
|
|
|
|
|
15
|
|
|
chdir(dirname(__FILE__)); // to enable our relative pathes to work |
|
16
|
|
|
|
|
17
|
|
|
if (php_sapi_name() !== 'cli') // security precaution: forbit calling setup-cli as web-page |
|
18
|
|
|
{ |
|
19
|
|
|
die('<h1>setup-cli.php must NOT be called as web-page --> exiting !!!</h1>'); |
|
20
|
|
|
} |
|
21
|
|
|
error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT); |
|
22
|
|
|
|
|
23
|
|
|
$dry_run = false; |
|
24
|
|
|
array_shift($_SERVER['argv']); |
|
25
|
|
|
|
|
26
|
|
|
if ($_SERVER['argv']) |
|
27
|
|
|
{ |
|
28
|
|
|
if ($_SERVER['argv'][0] == '--dry-run') |
|
29
|
|
|
{ |
|
30
|
|
|
$dry_run = true; |
|
31
|
|
|
array_shift($_SERVER['argv']); |
|
32
|
|
|
} |
|
33
|
|
|
$arguments = $_SERVER['argv']; |
|
34
|
|
|
$action = array_shift($arguments); |
|
35
|
|
|
if (isset($arguments[0])) list($_POST['FormDomain']) = explode(',',$arguments[0]); // header include needs that to detects the right domain |
|
36
|
|
|
} |
|
37
|
|
|
else |
|
38
|
|
|
{ |
|
39
|
|
|
$action = '--version'; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
// setting the language from the enviroment |
|
43
|
|
|
$_POST['ConfigLang'] = get_lang($charset); |
|
44
|
|
|
create_http_enviroment(); // guessing the docroot etc. |
|
45
|
|
|
|
|
46
|
|
|
if (ini_get('session.save_handler') == 'files' && !is_writable(ini_get('session.save_path')) && is_dir('/tmp') && is_writable('/tmp')) |
|
47
|
|
|
{ |
|
48
|
|
|
ini_set('session.save_path','/tmp'); // regular users may have no rights to apache's session dir |
|
49
|
|
|
} |
|
50
|
|
|
// check if date.timezone is set, report it and set something if not, as it gives tons of errors in install log |
|
51
|
|
|
if (!ini_get('date.timezone')) |
|
52
|
|
|
{ |
|
53
|
|
|
if (!($tz = date_default_timezone_get())) $tz = 'UTC'; |
|
54
|
|
|
echo "No default timezone (php.ini date.timezone) set, we temporary set '$tz'. You should fix that permanent!\n"; |
|
55
|
|
|
ini_set('date.timezone',$tz); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
// setting up the $GLOBALS['egw_setup'] object AND including the header.inc.php if it exists |
|
59
|
|
|
include('inc/functions.inc.php'); |
|
60
|
|
|
$GLOBALS['egw_info']['flags']['no_exception_handler'] = 'cli'; // inc/functions.inc.php does NOT set it |
|
61
|
|
|
$GLOBALS['egw_setup']->system_charset = $charset; |
|
62
|
|
|
|
|
63
|
|
|
if ((float) PHP_VERSION < $GLOBALS['egw_setup']->required_php_version) |
|
64
|
|
|
{ |
|
65
|
|
|
throw new Api\Exception\WrongUserinput(lang('You are using PHP version %1. EGroupware now requires %2 or later, recommended is PHP %3.',PHP_VERSION,$GLOBALS['egw_setup']->required_php_version,$GLOBALS['egw_setup']->recommended_php_version),98); |
|
|
|
|
|
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
switch($action) |
|
69
|
|
|
{ |
|
70
|
|
|
case '--version': |
|
71
|
|
|
case '--check': |
|
72
|
|
|
setup_cmd::check_installed($arguments[0],0,true); |
|
73
|
|
|
break; |
|
74
|
|
|
|
|
75
|
|
|
case '--create-header': |
|
76
|
|
|
case '--edit-header': |
|
77
|
|
|
case '--upgrade-header': |
|
78
|
|
|
case '--update-header': |
|
79
|
|
|
do_header($action == '--create-header',$arguments); |
|
80
|
|
|
break; |
|
81
|
|
|
|
|
82
|
|
|
case '--install': |
|
83
|
|
|
do_install($arguments); |
|
84
|
|
|
break; |
|
85
|
|
|
|
|
86
|
|
|
case '--config': |
|
87
|
|
|
do_config($arguments); |
|
88
|
|
|
break; |
|
89
|
|
|
|
|
90
|
|
|
case '--admin': |
|
91
|
|
|
do_admin($arguments[0]); |
|
92
|
|
|
break; |
|
93
|
|
|
|
|
94
|
|
|
case '--update': |
|
95
|
|
|
do_update($arguments[0]); |
|
96
|
|
|
break; |
|
97
|
|
|
|
|
98
|
|
|
case '--register-hooks': |
|
99
|
|
|
case '--register-all-hooks': |
|
100
|
|
|
do_hooks($arguments[0]); |
|
101
|
|
|
break; |
|
102
|
|
|
|
|
103
|
|
|
case '--backup': |
|
104
|
|
|
do_backup($arguments[0]); |
|
105
|
|
|
break; |
|
106
|
|
|
|
|
107
|
|
|
case '--languages': |
|
108
|
|
|
echo html_entity_decode(file_get_contents('lang/languages'),ENT_COMPAT,'utf-8'); |
|
109
|
|
|
break; |
|
110
|
|
|
|
|
111
|
|
|
case '--charsets': |
|
112
|
|
|
echo html_entity_decode(implode("\n",$GLOBALS['egw_setup']->translation->get_charsets(false)),ENT_COMPAT,'utf-8')."\n"; |
|
113
|
|
|
break; |
|
114
|
|
|
|
|
115
|
|
|
case '--exit-codes': |
|
116
|
|
|
list_exit_codes(); |
|
117
|
|
|
break; |
|
118
|
|
|
|
|
119
|
|
|
case '-h': |
|
120
|
|
|
case '--help': |
|
121
|
|
|
case '--usage': |
|
122
|
|
|
do_usage($arguments[0]); |
|
123
|
|
|
break; |
|
124
|
|
|
|
|
125
|
|
|
default: |
|
126
|
|
|
// we allow to call admin_cmd classes directly, if they define the constant SETUP_CLI_CALLABLE |
|
127
|
|
|
if (substr($action,0,2) == '--' && class_exists($class = str_replace('-','_',substr($action,2))) && |
|
128
|
|
|
is_subclass_of($class,'admin_cmd') && @constant($class.'::SETUP_CLI_CALLABLE')) |
|
129
|
|
|
{ |
|
130
|
|
|
$args = array(); |
|
131
|
|
|
list($args['domain']) = explode(',', array_shift($arguments)); // domain must be first argument, to ensure right domain get's selected in header-include |
|
132
|
|
|
foreach($arguments as $arg) |
|
133
|
|
|
{ |
|
134
|
|
|
// remove quotes from arguments eg. 'db_host=db', in case it does not happen by shell (eg. debuging in Netbeans) |
|
135
|
|
|
if (in_array($arg[0], ["'", '"']) && substr($arg, -1) === $arg[0]) |
|
136
|
|
|
{ |
|
137
|
|
|
$arg = substr($arg, 1, -1); |
|
138
|
|
|
} |
|
139
|
|
|
list($name,$value) = explode('=',$arg,2); |
|
140
|
|
|
if(property_exists('admin_cmd',$name)) // dont allow to overwrite admin_cmd properties |
|
141
|
|
|
{ |
|
142
|
|
|
throw new Api\Exception\WrongUserinput(lang("Invalid argument '%1' !!!",$arg),90); |
|
143
|
|
|
} |
|
144
|
|
|
if (substr($name,-1) == ']') // allow 1-dim. arrays |
|
145
|
|
|
{ |
|
146
|
|
|
list($name,$sub) = explode('[',substr($name,0,-1),2); |
|
147
|
|
|
$args[$name][$sub] = $value; |
|
148
|
|
|
} |
|
149
|
|
|
else |
|
150
|
|
|
{ |
|
151
|
|
|
$args[$name] = $value; |
|
152
|
|
|
} |
|
153
|
|
|
} |
|
154
|
|
|
$cmd = new $class($args); |
|
155
|
|
|
$msg = $cmd->run($time=null, $set_modifier=true, $skip_checks=false, $check_only=$dry_run); |
|
156
|
|
|
if (is_array($msg)) $msg = print_r($msg,true); |
|
157
|
|
|
echo "$msg\n"; |
|
158
|
|
|
break; |
|
159
|
|
|
} |
|
160
|
|
|
throw new Api\Exception\WrongUserinput(lang("Unknown option '%1' !!!",$action),90); |
|
161
|
|
|
} |
|
162
|
|
|
exit(0); |
|
163
|
|
|
|
|
164
|
|
|
/** |
|
165
|
|
|
* Configure EGroupware |
|
166
|
|
|
* |
|
167
|
|
|
* @param array $args domain(default),[config user(admin)],password,[,name=value,...] --files-dir --backup-dir --mailserver |
|
168
|
|
|
*/ |
|
169
|
|
|
function do_config($args) |
|
170
|
|
|
{ |
|
171
|
|
|
$arg0 = explode(',',array_shift($args)); |
|
172
|
|
|
if (!($domain = @array_shift($arg0))) $domain = 'default'; |
|
173
|
|
|
$user = @array_shift($arg0); |
|
174
|
|
|
$password = @array_shift($arg0); |
|
175
|
|
|
_fetch_user_password($user,$password); |
|
176
|
|
|
|
|
177
|
|
|
if ($arg0) // direct assignments (name=value,...) left |
|
178
|
|
|
{ |
|
179
|
|
|
array_unshift($args,implode(',',$arg0)); |
|
180
|
|
|
array_unshift($args,'--config'); |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
|
|
$cmd = new setup_cmd_config($domain,$user,$password,$args,true); |
|
184
|
|
|
echo $cmd->run()."\n\n"; |
|
185
|
|
|
|
|
186
|
|
|
$cmd->get_config(true); |
|
187
|
|
|
} |
|
188
|
|
|
|
|
189
|
|
|
/** |
|
190
|
|
|
* Register all hooks |
|
191
|
|
|
* |
|
192
|
|
|
* @param array $arg domain(default),[config user(admin)],password |
|
193
|
|
|
*/ |
|
194
|
|
|
function do_hooks($arg) |
|
195
|
|
|
{ |
|
196
|
|
|
list($domain,$user,$password) = explode(',',$arg); |
|
197
|
|
|
_fetch_user_password($user,$password); |
|
198
|
|
|
|
|
199
|
|
|
$domains = $GLOBALS['egw_domain']; |
|
200
|
|
|
if ($domain && $domain != 'all') |
|
201
|
|
|
{ |
|
202
|
|
|
$domains = array($domain => $GLOBALS['egw_domain'][$domain]); |
|
203
|
|
|
} |
|
204
|
|
|
|
|
205
|
|
|
foreach(array_keys($domains) as $domain) |
|
206
|
|
|
{ |
|
207
|
|
|
$cmd = new setup_cmd_hooks($domain,$user,$password); |
|
208
|
|
|
echo "$domain: ".$cmd->run()."\n"; |
|
209
|
|
|
} |
|
210
|
|
|
echo "\n"; |
|
211
|
|
|
} |
|
212
|
|
|
|
|
213
|
|
|
/** |
|
214
|
|
|
* Create an admin account |
|
215
|
|
|
* |
|
216
|
|
|
* @param string $arg domain(default),[config user(admin)],password,username,password,[first name],[last name],[email],[lang] |
|
217
|
|
|
*/ |
|
218
|
|
|
function do_admin($arg) |
|
219
|
|
|
{ |
|
220
|
|
|
list($domain,$user,$password,$admin,$pw,$first,$last,$email,$lang) = explode(',',$arg); |
|
221
|
|
|
_fetch_user_password($user,$password); |
|
222
|
|
|
|
|
223
|
|
|
$cmd = new setup_cmd_admin($domain,$user,$password,$admin,$pw,$first,$last,$email,array(),$lang); |
|
224
|
|
|
echo $cmd->run()."\n"; |
|
225
|
|
|
} |
|
226
|
|
|
|
|
227
|
|
|
/** |
|
228
|
|
|
* Backup one or all domains |
|
229
|
|
|
* |
|
230
|
|
|
* @param string $arg domain(all),[config user(admin)],password,[backup-file, 'no' for no backup or empty for default name] |
|
231
|
|
|
* @param boolean $quite_check quiten the call to _check_auth_config |
|
232
|
|
|
*/ |
|
233
|
|
|
function do_backup($arg,$quite_check=false) |
|
234
|
|
|
{ |
|
235
|
|
|
list($domain,,,$backup) = $options = explode(',',$arg); |
|
236
|
|
|
|
|
237
|
|
|
$domains = $GLOBALS['egw_domain']; |
|
238
|
|
|
if ($domain && $domain != 'all') |
|
239
|
|
|
{ |
|
240
|
|
|
$domains = array($domain => $GLOBALS['egw_domain'][$domain]); |
|
241
|
|
|
} |
|
242
|
|
|
foreach(array_keys($domains) as $domain) |
|
243
|
|
|
{ |
|
244
|
|
|
$options[0] = $domain; |
|
245
|
|
|
|
|
246
|
|
|
if ($quite_check) ob_start(); |
|
247
|
|
|
_check_auth_config(implode(',',$options),14); |
|
248
|
|
|
if ($quite_check) ob_end_clean(); |
|
249
|
|
|
|
|
250
|
|
|
if ($backup == 'no') |
|
251
|
|
|
{ |
|
252
|
|
|
echo lang('Backup skipped!')."\n"; |
|
253
|
|
|
} |
|
254
|
|
|
else |
|
255
|
|
|
{ |
|
256
|
|
|
$db_backup = new Api\Db\Backup(); |
|
257
|
|
|
if (is_resource($f = $db_backup->fopen_backup($backup))) |
|
258
|
|
|
{ |
|
259
|
|
|
echo lang('Backup started, this might take a few minutes ...')."\n"; |
|
260
|
|
|
$db_backup->backup($f); |
|
261
|
|
|
echo lang('Backup finished')."\n"; |
|
262
|
|
|
} |
|
263
|
|
|
else // backup failed ==> dont start the upgrade |
|
264
|
|
|
{ |
|
265
|
|
|
throw new Api\Exception\WrongUserinput(lang('Backup failed').': '.$f,50); |
|
266
|
|
|
} |
|
267
|
|
|
} |
|
268
|
|
|
} |
|
269
|
|
|
} |
|
270
|
|
|
|
|
271
|
|
|
/** |
|
272
|
|
|
* Update one or all domains, optional install a given app |
|
273
|
|
|
* |
|
274
|
|
|
* @param string $arg domain(all),[config user(admin)],password,[backup-file, 'no' for no backup or empty for default name],[app to install or uppdate] |
|
275
|
|
|
*/ |
|
276
|
|
|
function do_update($arg) |
|
277
|
|
|
{ |
|
278
|
|
|
list($domain,$user,$password,$backup,$app) = explode(',',$arg); |
|
279
|
|
|
_fetch_user_password($user,$password); |
|
280
|
|
|
|
|
281
|
|
|
$domains = $GLOBALS['egw_domain']; |
|
282
|
|
|
if ($domain && $domain != 'all') |
|
283
|
|
|
{ |
|
284
|
|
|
$domains = array($domain => $GLOBALS['egw_domain'][$domain]); |
|
285
|
|
|
} |
|
286
|
|
|
foreach($domains as $domain => $data) |
|
287
|
|
|
{ |
|
288
|
|
|
$arg = "$domain,$user,$password,$backup"; |
|
289
|
|
|
|
|
290
|
|
|
_check_auth_config($arg,14); |
|
291
|
|
|
|
|
292
|
|
|
if ($GLOBALS['egw_info']['setup']['stage']['db'] != 4 && |
|
293
|
|
|
(!$app || !in_array($app, setup_cmd::$apps_to_install) && !in_array($app, setup_cmd::$apps_to_upgrade)) && |
|
294
|
|
|
!setup_cmd::check_autoinstall()) |
|
295
|
|
|
{ |
|
296
|
|
|
echo lang('No update necessary, domain %1(%2) is up to date.',$domain,$data['db_type'])."\n"; |
|
|
|
|
|
|
297
|
|
|
} |
|
298
|
|
|
else |
|
299
|
|
|
{ |
|
300
|
|
|
do_backup($arg,true); |
|
301
|
|
|
|
|
302
|
|
|
$cmd = new setup_cmd_update($domain,$user,$password,$backup,false,$app); |
|
303
|
|
|
echo $cmd->run()."\n"; |
|
304
|
|
|
} |
|
305
|
|
|
} |
|
306
|
|
|
} |
|
307
|
|
|
|
|
308
|
|
|
/** |
|
309
|
|
|
* Check if EGw is installed according to $stop and we have the necessary authorization for config |
|
310
|
|
|
* |
|
311
|
|
|
* The password can be specified as parameter, via the enviroment variable EGW_CLI_PASSWORD or |
|
312
|
|
|
* querier from the user. Specifying it as parameter can be security problem! |
|
313
|
|
|
* |
|
314
|
|
|
* We allow the config user/pw of the domain OR the header admin user/pw! |
|
315
|
|
|
* |
|
316
|
|
|
* @param string $arg [domain(default)],[user(admin)],password |
|
317
|
|
|
* @param int $stop see setup_cmd::check_installed |
|
318
|
|
|
* @param boolean $set_lang =true set our charset, overwriting the charset of the EGw installation, default true |
|
319
|
|
|
* @return array with unprocessed arguments from $arg |
|
320
|
|
|
*/ |
|
321
|
|
|
function _check_auth_config($arg,$stop,$set_lang=true) |
|
322
|
|
|
{ |
|
323
|
|
|
$options = explode(',',$arg); |
|
324
|
|
|
if (!($domain = array_shift($options))) $domain = 'default'; |
|
325
|
|
|
$user = array_shift($options); |
|
326
|
|
|
$password = array_shift($options); |
|
327
|
|
|
_fetch_user_password($user,$password); |
|
328
|
|
|
|
|
329
|
|
|
setup_cmd::check_installed($domain,$stop,true); |
|
330
|
|
|
|
|
331
|
|
|
// reset charset for the output to the charset used by the OS |
|
332
|
|
|
if ($set_lang) $GLOBALS['egw_setup']->system_charset = $GLOBALS['charset']; |
|
333
|
|
|
|
|
334
|
|
|
setup_cmd::check_setup_auth($user,$password,$domain); |
|
335
|
|
|
|
|
336
|
|
|
return $options; |
|
337
|
|
|
} |
|
338
|
|
|
|
|
339
|
|
|
/** |
|
340
|
|
|
* Install EGroupware |
|
341
|
|
|
* |
|
342
|
|
|
* @param array $args array(0 => "domain,[config user(admin)],password,[backup-file],[charset],[lang]", "name=value", ...) |
|
343
|
|
|
*/ |
|
344
|
|
|
function do_install($args) |
|
345
|
|
|
{ |
|
346
|
|
|
list($domain,$user,$password,$backup,$charset,$lang) = explode(',',array_shift($args)); |
|
347
|
|
|
_fetch_user_password($user,$password); |
|
348
|
|
|
|
|
349
|
|
|
$config = array(); |
|
350
|
|
|
foreach($args as $arg) |
|
351
|
|
|
{ |
|
352
|
|
|
list($name,$value) = explode('=',$arg,2); |
|
353
|
|
|
$config[$name] = $value; |
|
354
|
|
|
} |
|
355
|
|
|
$cmd = new setup_cmd_install($domain,$user,$password,$backup,$charset,true,$config,$lang); |
|
356
|
|
|
echo $cmd->run()."\n"; |
|
357
|
|
|
} |
|
358
|
|
|
|
|
359
|
|
|
/** |
|
360
|
|
|
* Set defaults for user and password or queries the password from the user |
|
361
|
|
|
* |
|
362
|
|
|
* @param string &$user |
|
363
|
|
|
* @param string &$password |
|
364
|
|
|
*/ |
|
365
|
|
|
function _fetch_user_password(&$user,&$password) |
|
366
|
|
|
{ |
|
367
|
|
|
// read password from enviroment or query it from user, if not given |
|
368
|
|
|
if (!$user) $user = 'admin'; |
|
369
|
|
|
if (!$password && !($password = $_SERVER['EGW_CLI_PASSWORD'])) |
|
370
|
|
|
{ |
|
371
|
|
|
echo lang('Admin password to header manager').' '; |
|
372
|
|
|
$password = trim(fgets($f = fopen('php://stdin','rb'))); |
|
373
|
|
|
fclose($f); |
|
374
|
|
|
} |
|
375
|
|
|
} |
|
376
|
|
|
|
|
377
|
|
|
/** |
|
378
|
|
|
* Create, edit or update the header.inc.php |
|
379
|
|
|
* |
|
380
|
|
|
* @param boolean $create true = create new header, false = edit (or update) existing header |
|
381
|
|
|
* @param array $arguments |
|
382
|
|
|
* @return int |
|
383
|
|
|
*/ |
|
384
|
|
|
function do_header($create,&$arguments) |
|
385
|
|
|
{ |
|
386
|
|
|
if (!$create) |
|
387
|
|
|
{ |
|
388
|
|
|
// read password from enviroment or query it from user, if not given |
|
389
|
|
|
$options = explode(',',@$arguments[0]); |
|
390
|
|
|
_fetch_user_password($options[1],$options[0]); |
|
391
|
|
|
$arguments[0] = implode(',',$options); |
|
392
|
|
|
} |
|
393
|
|
|
array_unshift($arguments,$create ? '--create-header' : '--edit-header'); |
|
394
|
|
|
|
|
395
|
|
|
$cmd = new setup_cmd_header($create?'create':'edit',$arguments); |
|
396
|
|
|
echo $cmd->run()."\n"; |
|
397
|
|
|
} |
|
398
|
|
|
|
|
399
|
|
|
/** |
|
400
|
|
|
* Reads the users language from the enviroment |
|
401
|
|
|
* |
|
402
|
|
|
* @param string &$charset charset set in LANG enviroment variable or the default utf-8 |
|
403
|
|
|
* @return string 2 or 5 digit language code used in EGw |
|
404
|
|
|
*/ |
|
405
|
|
|
function get_lang(&$charset) |
|
406
|
|
|
{ |
|
407
|
|
|
@list($lang,$nation,$charset) = preg_split("/[_.]/",strtolower($_SERVER['LANG'])); |
|
408
|
|
|
|
|
409
|
|
|
foreach(file('lang/languages') as $line) |
|
410
|
|
|
{ |
|
411
|
|
|
list($code,$language) = explode("\t",$line); |
|
412
|
|
|
$languages[$code] = $language; |
|
413
|
|
|
} |
|
414
|
|
|
if (isset($languages[$lang.'-'.$nation])) return $lang.'-'.$nation; |
|
415
|
|
|
|
|
416
|
|
|
if (isset($languages[$lang])) return $lang; |
|
417
|
|
|
|
|
418
|
|
|
return 'en'; |
|
419
|
|
|
} |
|
420
|
|
|
|
|
421
|
|
|
/** |
|
422
|
|
|
* Try guessing the document root of the webserver, should work for RH, SuSE, debian and plesk |
|
423
|
|
|
*/ |
|
424
|
|
|
function create_http_enviroment() |
|
425
|
|
|
{ |
|
426
|
|
|
$_SERVER['SCRIPT_FILENAME'] = __FILE__; |
|
427
|
|
|
|
|
428
|
|
|
foreach(array('httpsdocs','httpdocs','htdocs','html','www') as $docroottop) |
|
429
|
|
|
{ |
|
430
|
|
|
$parts = explode($docroottop,__FILE__); |
|
431
|
|
|
if (count($parts) == 2) |
|
432
|
|
|
{ |
|
433
|
|
|
$_SERVER['DOCUMENT_ROOT'] = $parts[0].$docroottop; |
|
434
|
|
|
$_SERVER['PHP_SELF'] = str_replace('\\','/',$parts[1]); |
|
435
|
|
|
break; |
|
436
|
|
|
} |
|
437
|
|
|
} |
|
438
|
|
|
//print_r($_SERVER); exit; |
|
439
|
|
|
} |
|
440
|
|
|
|
|
441
|
|
|
/** |
|
442
|
|
|
* Echos usage message |
|
443
|
|
|
*/ |
|
444
|
|
|
function do_usage($what='') |
|
445
|
|
|
{ |
|
446
|
|
|
echo lang('Usage: %1 command [additional options]',basename($_SERVER['argv'][0]))."\n\n"; |
|
|
|
|
|
|
447
|
|
|
|
|
448
|
|
|
if (!$what) |
|
449
|
|
|
{ |
|
450
|
|
|
echo '--check '.lang('checks EGroupware\'s installed, it\'s versions and necessary upgrads (return values see --exit-codes)')."\n"; |
|
451
|
|
|
echo '--install '.lang('domain(default),[config user(admin)],password,[backup to install],[charset(default depends on language)]')."\n"; |
|
452
|
|
|
} |
|
453
|
|
|
if (!$what || $what == 'config') |
|
454
|
|
|
{ |
|
455
|
|
|
echo '--config '.lang('domain(default),[config user(admin)],password,[name=value,...] sets config values beside:')."\n"; |
|
456
|
|
|
if (!$what) echo ' --help config '.lang('gives further options')."\n"; |
|
457
|
|
|
} |
|
458
|
|
|
if ($what == 'config') |
|
459
|
|
|
{ |
|
460
|
|
|
echo ' --files-dir, --backup-dir, --temp-dir '.lang('path to various directories: have to exist and be writeable by the webserver')."\n"; |
|
461
|
|
|
echo ' --webserver-url '.lang('eg. /egroupware or http://domain.com/egroupware, default: %1',str_replace('/setup/setup-cli.php','',$_SERVER['PHP_SELF']))."\n"; |
|
462
|
|
|
echo ' --mailserver '.lang('host,port(143),[domain],[{standard(default)|vmailmgr = add domain for mailserver login}]').',[starttls|ssl|tls]'."\n"; |
|
463
|
|
|
echo ' --smtpserver '.lang('host,[smtp port],[smtp user],[smtp password],[auth session user/pw=yes|no],[starttls|ssl|tls],[account user editable=yes|no],[further identities=yes|no]')."\n"; |
|
464
|
|
|
echo ' --smtp '.lang('MTA (with LDAP): [yes(user edit forwarding)],emailadmin_smtp(|_sql|_ldap|_ads|_qmail|_mandriva|_dbmailuser|_suse)')."\n"; |
|
465
|
|
|
echo ' --imap '.lang('IMAP: Admin user,Password,emailadmin_imap(|_cyrus|_dovecot)')."\n"; |
|
466
|
|
|
echo ' --sieve '.lang('Sieve: Host[,Port(4190)]').',[starttls|ssl|tls]'."\n"; |
|
467
|
|
|
echo ' --folder '.lang('Folders: Sent,Trash,Drafts,Templates,Junk')."\n"; |
|
468
|
|
|
echo ' --account-auth '.lang('account repository{sql(default) | ldap | ads},[authentication{sql | ldap | ads | mail | http | ...}],[sql encrypttion{md5 | blowfish_crypt | md5_crypt | crypt}],[check save password{ (default)|True}],[allow cookie auth{ (default)|True}]')."\n"; |
|
469
|
|
|
echo ' --ldap-host --ldap-root-dn --ldap-root-pw --ldap-context --ldap-group-context'."\n"; |
|
470
|
|
|
echo ' --ads-host --ads-domain --ads-admin-user --ads-admin-pw --ads-connection (ssl|tls) --ads-context'."\n"; |
|
471
|
|
|
} |
|
472
|
|
|
if (!$what) |
|
473
|
|
|
{ |
|
474
|
|
|
echo '--admin '.lang('creates an admin user: domain(default),[config user(admin)],password,username,password,[first name],[last name],[email]')."\n"; |
|
475
|
|
|
echo '--backup '.lang('domain(all),[config user(admin)],password,[file-name(default: backup-dir/db_backup-YYYYMMDDHHii)]')."\n"; |
|
476
|
|
|
echo '--update '.lang('run a database schema update (if necessary): domain(all),[config user(admin)],password').'[,[no = no backup][,app to install]]'."\n"; |
|
477
|
|
|
echo '--register-hooks '.lang('Find and Register all Application Hooks').": domain(all),[config user(admin)],password\n"; |
|
478
|
|
|
echo lang('You can use the header user and password for every domain too. If the password is not set via the commandline, it is read from the enviroment variable EGW_CLI_PASSWORD or queried from the user.')."\n"; |
|
479
|
|
|
} |
|
480
|
|
|
if (!$what || $what == 'header') |
|
481
|
|
|
{ |
|
482
|
|
|
echo lang('Create or edit the EGroupware configuration file: header.inc.php:')."\n"; |
|
483
|
|
|
echo '--create-header '.lang('header-password[,header-user(admin)]')."\n"; |
|
484
|
|
|
echo '--edit-header '.lang('[header-password],[header-user],[new-password],[new-user]')."\n"; |
|
485
|
|
|
if (!$what) echo ' --help header '.lang('gives further options')."\n"; |
|
486
|
|
|
} |
|
487
|
|
|
if ($what == 'header') |
|
488
|
|
|
{ |
|
489
|
|
|
echo "\n".lang('Additional options and there defaults (in brackets)')."\n"; |
|
490
|
|
|
echo '--server-root '.lang('path of EGroupware install directory (default auto-detected)')."\n"; |
|
491
|
|
|
echo '--session-type '.lang('{db | php(default) | php-restore}')."\n"; |
|
492
|
|
|
echo '--limit-access '.lang('comma separated ip-addresses or host-names, default access to setup from everywhere')."\n"; |
|
493
|
|
|
echo '--mcrypt '.lang('use mcrypt to crypt session-data: {off(default) | on},[mcrypt-init-vector(default randomly generated)],[mcrypt-version]')."\n"; |
|
494
|
|
|
echo '--db-persistent '.lang('use persistent db connections: {on(default) | off}')."\n"; |
|
495
|
|
|
echo '--domain-selectbox '.lang('{off(default) | on}')."\n"; |
|
496
|
|
|
|
|
497
|
|
|
echo "\n".lang('Adding, editing or deleting an EGroupware domain / database instance:')."\n"; |
|
498
|
|
|
echo '--domain '.lang('add or edit a domain: [domain-name(default)],[db-name(egroupware)],[db-user(egroupware)],db-password,[db-type(mysql)],[db-host(localhost)],[db-port(db specific)],[config-user(as header)],[config-passwd(as header)]')."\n"; |
|
499
|
|
|
echo '--delete-domain '.lang('domain-name')."\n"; |
|
500
|
|
|
} |
|
501
|
|
|
if (!$what) |
|
502
|
|
|
{ |
|
503
|
|
|
echo '--help list '.lang('List availible values')."\n"; |
|
504
|
|
|
} |
|
505
|
|
|
if ($what == 'list') |
|
506
|
|
|
{ |
|
507
|
|
|
echo lang('List availible values').":\n"; |
|
508
|
|
|
echo '--languages '.lang('list of availible translations')."\n"; |
|
509
|
|
|
echo '--charsets '.lang('charsets used by the different languages')."\n"; |
|
510
|
|
|
echo '--exit-codes '.lang('all exit codes of the command line interface')."\n"; |
|
511
|
|
|
} |
|
512
|
|
|
if (!$what || !in_array($what,array('config','header','list'))) |
|
513
|
|
|
{ |
|
514
|
|
|
echo '--help|-h [config|header|list] '.lang('gives further options')."\n"; |
|
515
|
|
|
} |
|
516
|
|
|
} |
|
517
|
|
|
|
|
518
|
|
|
/** |
|
519
|
|
|
* List all exit codes used by the command line interface |
|
520
|
|
|
* |
|
521
|
|
|
* The list is generated by "greping" this file for thrown exceptions. |
|
522
|
|
|
* Exceptions have to be in one line, to be recogniced! |
|
523
|
|
|
*/ |
|
524
|
|
|
function list_exit_codes() |
|
525
|
|
|
{ |
|
526
|
|
|
error_reporting(error_reporting() & ~E_NOTICE); |
|
527
|
|
|
|
|
528
|
|
|
$codes = array('Ok'); |
|
529
|
|
|
$setup_dir = EGW_SERVER_ROOT.'/setup/'; |
|
530
|
|
|
//$files = array('setup-cli.php'); |
|
531
|
|
|
foreach(scandir($setup_dir.'/inc') as $file) |
|
532
|
|
|
{ |
|
533
|
|
|
if (substr($file,0,strlen('class.setup_cmd')) == 'class.setup_cmd') |
|
534
|
|
|
{ |
|
535
|
|
|
$files[] = 'inc/'.$file; |
|
536
|
|
|
} |
|
537
|
|
|
} |
|
538
|
|
|
foreach($files as $file) |
|
539
|
|
|
{ |
|
540
|
|
|
$content = file_get_contents($setup_dir.'/'.$file); |
|
541
|
|
|
|
|
542
|
|
|
$matches = null; |
|
543
|
|
|
if (preg_match_all('/throw new (Api\\\\Exception[\\\\a-z_]*)\((.*),([0-9]+)\);/mi',$content,$matches)) |
|
544
|
|
|
{ |
|
545
|
|
|
//echo $file.":\n"; print_r($matches); |
|
546
|
|
|
foreach($matches[3] as $key => $code) |
|
547
|
|
|
{ |
|
548
|
|
|
//if (isset($codes[$code])) echo "$file redifines #$code: {$codes[$code]}\n"; |
|
549
|
|
|
|
|
550
|
|
|
$src = preg_replace('/self::\$[a-z_>-]+/i', "''", $matches[2][$key]); // gives fatal error otherwise |
|
551
|
|
|
@eval($src='$codes['.$code.'] = '.$src.';'); |
|
|
|
|
|
|
552
|
|
|
//echo "- codes[$code] => '{$codes[$code]}'\n"; |
|
553
|
|
|
} |
|
554
|
|
|
//echo $file.":\n"; print_r($codes); |
|
555
|
|
|
} |
|
556
|
|
|
} |
|
557
|
|
|
ksort($codes,SORT_NUMERIC); |
|
558
|
|
|
foreach($codes as $num => $msg) |
|
559
|
|
|
{ |
|
560
|
|
|
echo $num."\t".str_replace("\n","\n\t",$msg)."\n"; |
|
561
|
|
|
} |
|
562
|
|
|
} |
|
563
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.