Skip to content

Commit aa77b18

Browse files
committed
Update Shell/Cron PHP code
Fix PHP 8.2 warnings
1 parent c344f48 commit aa77b18

File tree

2 files changed

+37
-38
lines changed

2 files changed

+37
-38
lines changed

server/plugins-available/cron_jailkit_plugin.inc.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class cron_jailkit_plugin {
3636
var $class_name = 'cron_jailkit_plugin';
3737
var $parent_domain = array();
3838

39+
3940
//* This function is called during ispconfig installation to determine
4041
// if a symlink shall be created for this plugin.
4142
function onInstall() {
@@ -91,9 +92,9 @@ function insert($event_name, $data) {
9192
}
9293

9394

94-
$this->parent_domain = $parent_domain;
95+
//$this->parent_domain = $parent_domain;
9596

96-
$this->cronjob_id = $data['new']['id'];
97+
//$this->cronjob_id = $data['new']['id'];
9798

9899
$app->uses('system');
99100

@@ -166,14 +167,7 @@ function update($event_name, $data) {
166167

167168
$app->uses('system');
168169

169-
$this->parent_domain = $parent_domain;
170-
171-
$this->cronjob_id = $data['new']['id'];
172-
173170
if($app->system->is_user($parent_domain['system_user'])) {
174-
175-
176-
177171
/**
178172
* Setup Jailkit Chroot System If Enabled
179173
*/
@@ -407,7 +401,7 @@ function _setup_php_jailkit() {
407401
}
408402

409403
if(!file_exists($this->parent_domain['document_root'] . '/' . $this->parent_domain['php_cli_binary'])) {
410-
$app->log("The PHP cli binary " . $this->parent_domain['php_cli_binary'] . " is not available in the jail of the web " . $this->parent_domain['domain'] . " / cronjob_id: " . $this->cronjob_id . ". Check your Jailkit setup!", LOGLEVEL_DEBUG);
404+
$app->log("The PHP cli binary " . $this->parent_domain['php_cli_binary'] . " is not available in the jail of the web " . $this->parent_domain['domain'] . " / cronjob_id: " . $this->data['new']['id'] . ". Check your Jailkit setup!", LOGLEVEL_DEBUG);
411405
$tpl->setVar('use_php_path', false);
412406
$tpl->setVar('use_php_alias', false);
413407
if(is_link($this->parent_domain['document_root'] . '/etc/alternatives/php'))

server/plugins-available/shelluser_jailkit_plugin.inc.php

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class shelluser_jailkit_plugin {
3636
var $min_uid = 499;
3737
var $data = array();
3838
var $jailkit_config = array();
39+
var $web = array();
3940

4041
//* This function is called during ispconfig installation to determine
4142
// if a symlink shall be created for this plugin.
@@ -87,8 +88,6 @@ function insert($event_name, $data) {
8788

8889
$this->web = $web;
8990

90-
$this->username = $data['new']['username'];
91-
9291
if(!$app->system->is_allowed_user($data['new']['username'], false, false)
9392
|| !$app->system->is_allowed_user($data['new']['puser'], true, true)
9493
|| !$app->system->is_allowed_group($data['new']['pgroup'], true, true)) {
@@ -202,8 +201,7 @@ function update($event_name, $data) {
202201
$web = $app->db->queryOneRecord("SELECT * FROM web_domain LEFT JOIN server_php ON web_domain.server_php_id = server_php.server_php_id WHERE `domain_id` = ?", $data["new"]["parent_domain_id"]);
203202

204203
$this->web = $web;
205-
206-
$this->username = $data['new']['username'];
204+
$username = $data['new']['username'];
207205

208206
// Get the UID of the parent user
209207
$uid = intval($app->system->getuid($data['new']['puser']));
@@ -346,7 +344,7 @@ function _setup_jailkit_chroot()
346344

347345
$web = $app->db->queryOneRecord("SELECT `domain`, `last_jailkit_hash`, `php_cli_binary` FROM web_domain
348346
LEFT JOIN server_php ON web_domain.server_php_id = server_php.server_php_id
349-
WHERE `domain_id` = ?", $data["new"]["parent_domain_id"]);
347+
WHERE `domain_id` = ?", $this->data["new"]["parent_domain_id"]);
350348

351349

352350
$last_updated = preg_split('/[\s,]+/', $this->jailkit_config['jailkit_chroot_app_sections']
@@ -686,20 +684,11 @@ private function _delete_jailkit_if_unused($parent_domain_id) {
686684
function _setup_php_jailkit() {
687685
global $app;
688686

689-
$app->uses('system');
690-
691687
// Create .bashrc file
692688
$app->load('tpl');
693689

694690
$tpl = new tpl();
695691

696-
// Predefine some template vars
697-
$tpl->setVar('jailkit_chroot', 'y');
698-
$tpl->setVar('domain', $this->web['domain']);
699-
$tpl->setVar('home_dir', $this->_get_home_dir(""));
700-
$tpl->setVar('use_php_path', false);
701-
$tpl->setVar('use_php_alias', false);
702-
703692
if($app->system->get_os_type() == "debian" || $app->system->get_os_type() == "ubuntu") {
704693
$tpl->newTemplate("bashrc_user_deb.master");
705694
} elseif($app->system->get_os_type() == "redhat") {
@@ -708,26 +697,45 @@ function _setup_php_jailkit() {
708697
$tpl->newTemplate("bashrc_user_generic.master");
709698
}
710699

700+
// Predefine some template vars
701+
$tpl->setVar('jailkit_chroot', 'y');
702+
$tpl->setVar('domain', $this->web['domain']);
703+
$tpl->setVar('home_dir', $this->_get_home_dir(""));
704+
705+
$tpl->setVar('use_php_path', false);
706+
$tpl->setVar('use_php_alias', false);
711707

712708
$php_bin_dir = dirname($this->web['php_cli_binary']);
713709

714710
if(($this->web['server_php_id'] > 0) && !empty($this->web['php_cli_binary'])) {
715-
if($app->system->get_os_type() != "debian" || $app->system->get_os_type() != "ubuntu") {
716-
if(preg_match('/^(\/usr\/(s)?bin|\/(s)?bin)/', $php_bin_dir)) {
717-
$tpl->setVar('use_php_path', false);
718-
$tpl->setVar('use_php_alias', true);
719-
$tpl->setVar('php_alias', $this->web['php_cli_binary']);
720-
} else {
721-
$tpl->setVar('use_php_path', true);
722-
$tpl->setVar('use_php_alias', false);
723-
$tpl->setVar('php_bin_dir', $php_bin_dir);
724-
}
711+
if(preg_match('/^(\/usr\/(s)?bin|\/(s)?bin)/', $php_bin_dir)) {
712+
$tpl->setVar('use_php_path', false);
713+
$tpl->setVar('use_php_alias', true);
714+
$tpl->setVar('php_alias', $this->web['php_cli_binary']);
715+
} else {
716+
$tpl->setVar('use_php_path', true);
717+
$tpl->setVar('use_php_alias', false);
718+
$tpl->setVar('php_bin_dir', $php_bin_dir);
725719
}
726720

727721
if(!file_exists($this->web['document_root'] . '/' . $this->web['php_cli_binary'])) {
728-
$app->log("The PHP cli binary " . $this->web['php_cli_binary'] . " is not available in the jail of the web " . $this->web['domain'] . " / SSH/SFTP user: " . $this->username . ". Check your Jailkit setup!", LOGLEVEL_DEBUG);
722+
$app->log("The PHP cli binary " . $this->web['php_cli_binary'] . " is not available in the jail of the web " . $this->web['domain'] . " / SSH/SFTP user: " . $this->data['new']['username'] . ". Check your Jailkit setup!", LOGLEVEL_DEBUG);
729723
$tpl->setVar('use_php_path', false);
730724
$tpl->setVar('use_php_alias', false);
725+
if(is_link($this->web['document_root'] . '/etc/alternatives/php'))
726+
{
727+
unlink($this->web['document_root'] . '/etc/alternatives/php');
728+
}
729+
} else {
730+
if($app->system->get_os_type() == "debian" || $app->system->get_os_type() == "ubuntu") {
731+
if(is_link($this->web['document_root'] . '/etc/alternatives/php') || is_file($this->web['document_root'] . '/etc/alternatives/php'))
732+
{
733+
unlink($this->web['document_root'] . '/etc/alternatives/php');
734+
symlink($this->web['php_cli_binary'], $this->web['document_root'] . '/etc/alternatives/php');
735+
} else {
736+
symlink($this->web['php_cli_binary'], $this->web['document_root'] . '/etc/alternatives/php');
737+
}
738+
}
731739
}
732740
}
733741

@@ -742,9 +750,6 @@ function _setup_php_jailkit() {
742750

743751
unset($tpl);
744752

745-
746-
747-
748753
}
749754

750755
} // end class

0 commit comments

Comments
 (0)