Skip to content

Commit 86c6e7e

Browse files
author
Till Brehm
committed
Merge branch '6639-ispconfig-cli-command' into 'develop'
Resolve "ISPConfig CLI command" Closes #6639 See merge request ispconfig/ispconfig3!1847
2 parents c3b4a84 + 1f1ded4 commit 86c6e7e

File tree

11 files changed

+641
-0
lines changed

11 files changed

+641
-0
lines changed

install/dist/lib/fedora.lib.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,6 +1076,12 @@ public function install_ispconfig()
10761076
if(!is_link('/usr/local/bin/ispconfig_update_from_dev.sh')) exec('ln -s /usr/local/ispconfig/server/scripts/ispconfig_update.sh /usr/local/bin/ispconfig_update_from_dev.sh');
10771077
if(!is_link('/usr/local/bin/ispconfig_update.sh')) exec('ln -s /usr/local/ispconfig/server/scripts/ispconfig_update.sh /usr/local/bin/ispconfig_update.sh');
10781078

1079+
// Install ISPConfig cli command
1080+
if(is_file('/usr/local/bin/ispc')) unlink('/usr/local/bin/ispc');
1081+
chown($install_dir.'/server/cli/ispc', 'root');
1082+
chmod($install_dir.'/server/cli/ispc', 0700);
1083+
symlink($install_dir.'/server/cli/ispc', '/usr/local/bin/ispc');
1084+
10791085
// set the fast cgi starter script to executable
10801086
// exec('chmod 755 '.$install_dir.'/interface/bin/php-fcgi');
10811087

install/dist/lib/gentoo.lib.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1511,6 +1511,12 @@ public function install_ispconfig() {
15111511
if(!is_link('/usr/local/bin/ispconfig_update_from_dev.sh')) symlink($install_dir.'/server/scripts/ispconfig_update.sh', '/usr/local/bin/ispconfig_update_from_dev.sh');
15121512
if(!is_link('/usr/local/bin/ispconfig_update.sh')) symlink($install_dir.'/server/scripts/ispconfig_update.sh', '/usr/local/bin/ispconfig_update.sh');
15131513

1514+
// Install ISPConfig cli command
1515+
if(is_file('/usr/local/bin/ispc')) unlink('/usr/local/bin/ispc');
1516+
chown($install_dir.'/server/cli/ispc', 'root');
1517+
chmod($install_dir.'/server/cli/ispc', 0700);
1518+
symlink($install_dir.'/server/cli/ispc', '/usr/local/bin/ispc');
1519+
15141520
// Make executable then unlink and symlink letsencrypt pre, post and renew hook scripts
15151521
chown($install_dir.'/server/scripts/letsencrypt_pre_hook.sh', 'root');
15161522
chown($install_dir.'/server/scripts/letsencrypt_post_hook.sh', 'root');

install/lib/installer_base.lib.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3823,6 +3823,12 @@ public function install_ispconfig() {
38233823
if(!is_link('/usr/local/bin/ispconfig_update_from_dev.sh')) symlink($install_dir.'/server/scripts/ispconfig_update.sh', '/usr/local/bin/ispconfig_update_from_dev.sh');
38243824
if(!is_link('/usr/local/bin/ispconfig_update.sh')) symlink($install_dir.'/server/scripts/ispconfig_update.sh', '/usr/local/bin/ispconfig_update.sh');
38253825

3826+
// Install ISPConfig cli command
3827+
if(is_file('/usr/local/bin/ispc')) unlink('/usr/local/bin/ispc');
3828+
chown($install_dir.'/server/cli/ispc', 'root');
3829+
chmod($install_dir.'/server/cli/ispc', 0700);
3830+
symlink($install_dir.'/server/cli/ispc', '/usr/local/bin/ispc');
3831+
38263832
// Make executable then unlink and symlink letsencrypt pre, post and renew hook scripts
38273833
chown($install_dir.'/server/scripts/letsencrypt_pre_hook.sh', 'root');
38283834
chown($install_dir.'/server/scripts/letsencrypt_post_hook.sh', 'root');

server/cli/ispc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
3+
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/X11R6/bin
4+
5+
. /etc/profile
6+
7+
if [ -f /usr/local/ispconfig/server/lib/php.ini ]; then
8+
PHPINIOWNER=`stat -c %U /usr/local/ispconfig/server/lib/php.ini`
9+
if [ $PHPINIOWNER == 'root' ] || [ $PHPINIOWNER == 'ispconfig' ]; then
10+
export PHPRC=/usr/local/ispconfig/server/lib
11+
fi
12+
fi
13+
14+
cd /usr/local/ispconfig/server/cli
15+
$(which php) -q \
16+
-d disable_classes= \
17+
-d disable_functions= \
18+
-d open_basedir= \
19+
/usr/local/ispconfig/server/cli/ispc.php "$@";
20+
RET=$? ;
21+
22+
exit $RET ;

server/cli/ispc.php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
/*
4+
Copyright (c) 2024, Till Brehm, ISPConfig UG
5+
All rights reserved.
6+
7+
Redistribution and use in source and binary forms, with or without modification,
8+
are permitted provided that the following conditions are met:
9+
10+
* Redistributions of source code must retain the above copyright notice,
11+
this list of conditions and the following disclaimer.
12+
* Redistributions in binary form must reproduce the above copyright notice,
13+
this list of conditions and the following disclaimer in the documentation
14+
and/or other materials provided with the distribution.
15+
* Neither the name of ISPConfig nor the names of its contributors
16+
may be used to endorse or promote products derived from this software without
17+
specific prior written permission.
18+
19+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22+
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24+
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
26+
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
*/
30+
31+
if(posix_getuid() != 0) {
32+
die("This command must be run as root user\n");
33+
}
34+
35+
//define('SCRIPT_PATH', dirname($_SERVER["SCRIPT_FILENAME"]));
36+
require "../lib/config.inc.php";
37+
require "../lib/app.inc.php";
38+
39+
$app->setCaller('server');
40+
$app->load('cli');
41+
42+
//* Check input
43+
$module = $argv[1];
44+
if($module == '-h' || $module == '--help') $module = 'help';
45+
if(!preg_match("/[a-z0-9]{3,20}/",$module)) die("Invalid commandline option\n");
46+
//* Check if cli module exists and run it
47+
if(is_file('modules/'.$module.'.inc.php')) {
48+
include_once 'modules/'.$module.'.inc.php';
49+
$class = $module.'_cli';
50+
$m = new $class;
51+
$m->process($argv);
52+
} else {
53+
include_once 'modules/help.inc.php';
54+
$m = new help_cli;
55+
$m->errorShowHelp($argv);
56+
}
57+
58+
59+

server/cli/modules/help.inc.php

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
3+
/*
4+
Copyright (c) 2024, Till Brehm, ISPConfig UG
5+
All rights reserved.
6+
7+
Redistribution and use in source and binary forms, with or without modification,
8+
are permitted provided that the following conditions are met:
9+
10+
* Redistributions of source code must retain the above copyright notice,
11+
this list of conditions and the following disclaimer.
12+
* Redistributions in binary form must reproduce the above copyright notice,
13+
this list of conditions and the following disclaimer in the documentation
14+
and/or other materials provided with the distribution.
15+
* Neither the name of ISPConfig nor the names of its contributors
16+
may be used to endorse or promote products derived from this software without
17+
specific prior written permission.
18+
19+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22+
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24+
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
26+
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
*/
30+
31+
class help_cli extends cli {
32+
33+
function __construct() {
34+
$cmd_opt = [];
35+
$cmd_opt['help'] = 'showHelp';
36+
$cmd_opt['-h'] = 'showHelp';
37+
$cmd_opt['--help'] = 'showHelp';
38+
$this->addCmdOpt($cmd_opt);
39+
}
40+
41+
public function errorShowHelp($arg) {
42+
global $conf;
43+
44+
$this->swriteln("\nError: Unknown Commandline Option\n");
45+
$this->showHelp($arg);
46+
}
47+
48+
public function showHelp($arg) {
49+
global $conf;
50+
51+
$this->swriteln("---------------------------------");
52+
$this->swriteln("- Available commandline modules -");
53+
$this->swriteln("---------------------------------");
54+
55+
$module_dir = dirname(__FILE__);
56+
57+
// loop trough modules
58+
$files = glob($module_dir . '/*.inc.php');
59+
foreach ($files as $file) {
60+
$filename = basename($file);
61+
$filename = str_replace('.inc.php', '', $filename);
62+
$this->swriteln("\033[1m\033[31mispc ".$filename."\033[0m");
63+
}
64+
65+
$this->swriteln("---------------------------------");
66+
$this->swriteln();
67+
68+
69+
}
70+
71+
}
72+

server/cli/modules/php.inc.php

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
/*
4+
Copyright (c) 2024, Till Brehm, ISPConfig UG
5+
All rights reserved.
6+
7+
Redistribution and use in source and binary forms, with or without modification,
8+
are permitted provided that the following conditions are met:
9+
10+
* Redistributions of source code must retain the above copyright notice,
11+
this list of conditions and the following disclaimer.
12+
* Redistributions in binary form must reproduce the above copyright notice,
13+
this list of conditions and the following disclaimer in the documentation
14+
and/or other materials provided with the distribution.
15+
* Neither the name of ISPConfig nor the names of its contributors
16+
may be used to endorse or promote products derived from this software without
17+
specific prior written permission.
18+
19+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22+
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24+
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
26+
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
*/
30+
31+
class php_cli extends cli {
32+
33+
function __construct() {
34+
$cmd_opt = [];
35+
$cmd_opt['php:version'] = 'showPHPVersion';
36+
$cmd_opt['php:help'] = 'showHelp';
37+
$this->addCmdOpt($cmd_opt);
38+
}
39+
40+
public function showPHPVersion($arg) {
41+
global $conf;
42+
$this->swriteln("PHP CLI version: ".shell_exec('php --version'));
43+
}
44+
45+
public function showHelp($arg) {
46+
global $conf;
47+
48+
$this->swriteln("---------------------------------");
49+
$this->swriteln("- Available commandline options -");
50+
$this->swriteln("---------------------------------");
51+
$this->swriteln("ispc php version - Show the commandline PHP version.");
52+
$this->swriteln("---------------------------------");
53+
$this->swriteln();
54+
}
55+
56+
}
57+

server/cli/modules/update.inc.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
/*
4+
Copyright (c) 2024, Till Brehm, ISPConfig UG
5+
All rights reserved.
6+
7+
Redistribution and use in source and binary forms, with or without modification,
8+
are permitted provided that the following conditions are met:
9+
10+
* Redistributions of source code must retain the above copyright notice,
11+
this list of conditions and the following disclaimer.
12+
* Redistributions in binary form must reproduce the above copyright notice,
13+
this list of conditions and the following disclaimer in the documentation
14+
and/or other materials provided with the distribution.
15+
* Neither the name of ISPConfig nor the names of its contributors
16+
may be used to endorse or promote products derived from this software without
17+
specific prior written permission.
18+
19+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22+
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24+
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
26+
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
*/
30+
31+
class update_cli extends cli {
32+
33+
function __construct() {
34+
$cmd_opt = [];
35+
$cmd_opt['update'] = 'ispconfigUpdate';
36+
$this->addCmdOpt($cmd_opt);
37+
}
38+
39+
public function ispconfigUpdate($arg) {
40+
global $conf;
41+
passthru('/usr/local/bin/ispconfig_update.sh');
42+
}
43+
44+
public function showHelp($arg) {
45+
global $conf;
46+
47+
$this->swriteln("---------------------------------");
48+
$this->swriteln("- Available commandline options -");
49+
$this->swriteln("---------------------------------");
50+
$this->swriteln("ispc update - Start ISPConfig update.");
51+
$this->swriteln("---------------------------------");
52+
$this->swriteln();
53+
}
54+
55+
}
56+

0 commit comments

Comments
 (0)