mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-01 05:56:16 +00:00
Fix .env Files for Isolated Users (#496)
This commit is contained in:
@ -2,19 +2,20 @@
|
||||
|
||||
namespace App\Actions\Site;
|
||||
|
||||
use App\Exceptions\SSHUploadFailed;
|
||||
use App\Exceptions\SSHError;
|
||||
use App\Models\Site;
|
||||
|
||||
class UpdateEnv
|
||||
{
|
||||
/**
|
||||
* @throws SSHUploadFailed
|
||||
* @throws SSHError
|
||||
*/
|
||||
public function update(Site $site, array $input): void
|
||||
{
|
||||
$site->server->os()->editFile(
|
||||
$site->server->os()->editFileAs(
|
||||
$site->path.'/.env',
|
||||
$input['env']
|
||||
$site->user,
|
||||
trim($input['env']),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -112,7 +112,9 @@ public function exec(string $command, string $log = '', ?int $siteId = null, ?bo
|
||||
|
||||
try {
|
||||
if ($this->asUser) {
|
||||
$command = 'sudo su - '.$this->asUser.' -c '.'"'.addslashes($command).'"';
|
||||
$command = addslashes($command);
|
||||
$command = str_replace('\\\'', '\'', $command);
|
||||
$command = 'sudo su - '.$this->asUser.' -c '.'"'.trim($command).'"';
|
||||
}
|
||||
|
||||
$this->connection->setTimeout(0);
|
||||
|
@ -198,16 +198,34 @@ public function editFile(string $path, ?string $content = null): void
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws SSHError
|
||||
*/
|
||||
public function editFileAs(string $path, string $user, ?string $content = null): void
|
||||
{
|
||||
$sudo = $user === 'root';
|
||||
$actualUser = $sudo ? $this->server->getSshUser() : $user;
|
||||
|
||||
$this->server->ssh($actualUser)->exec(
|
||||
view('ssh.os.edit-file', [
|
||||
'path' => $path,
|
||||
'content' => $content,
|
||||
'sudo' => $sudo,
|
||||
]),
|
||||
'edit-file'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws SSHError
|
||||
*/
|
||||
public function readFile(string $path): string
|
||||
{
|
||||
return $this->server->ssh()->exec(
|
||||
return trim($this->server->ssh()->exec(
|
||||
view('ssh.os.read-file', [
|
||||
'path' => $path,
|
||||
])
|
||||
);
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user