Skip to content

Commit 8c2008d

Browse files
committed
fix $app->system-> calls in system/ but not interface/
1 parent de80006 commit 8c2008d

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

interface/lib/classes/functions.inc.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -472,15 +472,16 @@ public function generate_ssh_key($client_id, $username = ''){
472472
global $app;
473473

474474
// generate the SSH key pair for the client
475-
$app->system->exec_safe('mktemp -dt id_rsa.XXXXXXXX');
476-
$tmpdir = $app->system->last_exec_out();
475+
if (! $tmpdir = $app->system->exec_safe('mktemp -dt id_rsa.XXXXXXXX')) {
476+
$app->log("mktemp failed, cannot create SSH keypair for ".$username, LOGLEVEL_WARN);
477+
}
477478
$id_rsa_file = $tmpdir . uniqid('',true);
478479
$id_rsa_pub_file = $id_rsa_file.'.pub';
479480
if(file_exists($id_rsa_file)) unset($id_rsa_file);
480481
if(file_exists($id_rsa_pub_file)) unset($id_rsa_pub_file);
481482
if(!file_exists($id_rsa_file) && !file_exists($id_rsa_pub_file)) {
482483
$app->system->exec_safe('ssh-keygen -t rsa -C ? -f ? -N ""', $username.'-rsa-key-'.time(), $id_rsa_file);
483-
$app->db->query("UPDATE client SET created_at = UNIX_TIMESTAMP(), id_rsa = ?, ssh_rsa = ? WHERE client_id = ?", $app->system->file_get_contents($id_rsa_file), $app->system->file_get_contents($id_rsa_pub_file), $client_id);
484+
$app->db->query("UPDATE client SET created_at = UNIX_TIMESTAMP(), id_rsa = ?, ssh_rsa = ? WHERE client_id = ?", @file_get_contents($id_rsa_file), @file_get_contents($id_rsa_pub_file), $client_id);
484485
$app->system->rmdir($tmpdir, true);
485486
} else {
486487
$app->log("Failed to create SSH keypair for ".$username, LOGLEVEL_WARN);

interface/lib/classes/system.inc.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,32 @@ public function is_blacklisted_web_path($path) {
7979
return false;
8080
}
8181

82+
function rmdir($path, $recursive=false) {
83+
// Disallow operating on root directory
84+
if(realpath($path) == '/') {
85+
$app->log("rmdir: afraid I might delete root: $path", LOGLEVEL_WARN);
86+
return false;
87+
}
88+
89+
$path = rtrim($path, '/');
90+
if (is_dir($path) && !is_link($path)) {
91+
$objects = array_diff(scandir($path), array('.', '..'));
92+
foreach ($objects as $object) {
93+
if ($recursive) {
94+
if (is_dir("$path/$object") && !is_link("$path/$object")) {
95+
$this->rmdir("$path/$object", $recursive);
96+
} else {
97+
unlink ("$path/$object");
98+
}
99+
} else {
100+
$app->log("rmdir: invoked non-recursive, not removing $path (expect rmdir failure)", LOGLEVEL_DEBUG);
101+
}
102+
}
103+
return rmdir($path);
104+
}
105+
return false;
106+
}
107+
82108
public function last_exec_out() {
83109
return $this->_last_exec_out;
84110
}

0 commit comments

Comments
 (0)