Unverified Kaydet (Commit) 67d3a066 authored tarafından Mert ÇELEN's avatar Mert ÇELEN Kaydeden (comit) GitHub

Merge pull request #68 from mertcelen/1-dev

Fixes for dispatch job structure.
...@@ -11,6 +11,21 @@ class PHPSandbox implements Sandbox ...@@ -11,6 +11,21 @@ class PHPSandbox implements Sandbox
{ {
private $path = "/liman/sandbox/php/index.php"; private $path = "/liman/sandbox/php/index.php";
private $fileExtension = ".blade.php"; private $fileExtension = ".blade.php";
private $server,$extension,$user,$request;
public function __construct($server = null, $extension = null, $user = null,$request = null)
{
$this->server = ($server) ? $server : server();
$this->extension = ($extension) ? $extension : extension();
$this->user = ($user) ? $user : user();
$this->request = ($request) ? $request : request()->except([
"permissions",
"extension",
"server",
"script",
"server_id",
]);
}
public function getPath() public function getPath()
{ {
...@@ -27,17 +42,17 @@ class PHPSandbox implements Sandbox ...@@ -27,17 +42,17 @@ class PHPSandbox implements Sandbox
$combinerFile = $this->path; $combinerFile = $this->path;
$settings = UserSettings::where([ $settings = UserSettings::where([
"user_id" => user()->id, "user_id" => $this->user->id,
"server_id" => server()->id, "server_id" => $this->server->id,
]); ]);
if ($extensionDb == null) { if ($extensionDb == null) {
$extensionDb = []; $extensionDb = [];
foreach ($settings->get() as $setting) { foreach ($settings->get() as $setting) {
$key = $key =
env('APP_KEY') . env('APP_KEY') .
user()->id . $this->user->id .
extension()->id . $this->extension->id .
server()->id; $this->server->id;
$decrypted = openssl_decrypt( $decrypted = openssl_decrypt(
$setting->value, $setting->value,
'aes-256-cfb8', 'aes-256-cfb8',
...@@ -50,34 +65,27 @@ class PHPSandbox implements Sandbox ...@@ -50,34 +65,27 @@ class PHPSandbox implements Sandbox
$extensionDb = json_encode($extensionDb); $extensionDb = json_encode($extensionDb);
} }
$request = request()->except([ $request = json_encode($this->request);
"permissions",
"extension",
"server",
"script",
"server_id",
]);
$request = json_encode($request);
$apiRoute = route('extension_server', [ $apiRoute = route('extension_server', [
"extension_id" => extension()->id, "extension_id" => $this->extension->id,
"city" => server()->city, "city" => $this->server->city,
"server_id" => server()->id, "server_id" => $this->server->id,
]); ]);
$navigationRoute = route('extension_server', [ $navigationRoute = route('extension_server', [
"server_id" => server()->id, "server_id" => $this->server->id,
"extension_id" => extension()->id, "extension_id" => $this->extension->id,
"city" => server()->city, "city" => $this->server->city,
]); ]);
$token = Token::create(user()->id); $token = Token::create($this->user->id);
if (!user()->isAdmin()) { if (!$this->user->isAdmin()) {
$extensionJson = json_decode( $extensionJson = json_decode(
file_get_contents( file_get_contents(
"/liman/extensions/" . "/liman/extensions/" .
strtolower(extension()->name) . strtolower($this->extension->name) .
DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR .
"db.json" "db.json"
), ),
...@@ -88,10 +96,10 @@ class PHPSandbox implements Sandbox ...@@ -88,10 +96,10 @@ class PHPSandbox implements Sandbox
foreach ($extensionJson["functions"] as $item) { foreach ($extensionJson["functions"] as $item) {
if ( if (
Permission::can( Permission::can(
user()->id, $this->user->id,
"function", "function",
"name", "name",
strtolower(extension()->name), strtolower($this->extension->name),
$item["name"] $item["name"]
) || ) ||
$item["isActive"] != "true" $item["isActive"] != "true"
...@@ -106,18 +114,18 @@ class PHPSandbox implements Sandbox ...@@ -106,18 +114,18 @@ class PHPSandbox implements Sandbox
} }
$userData = [ $userData = [
"id" => user()->id, "id" => $this->user->id,
"name" => user()->name, "name" => $this->user->name,
"email" => user()->email, "email" => $this->user->email,
]; ];
$functionsPath = $functionsPath =
"/liman/extensions/" . "/liman/extensions/" .
strtolower(extension()->name) . strtolower($this->extension->name) .
"/views/functions.php"; "/views/functions.php";
$publicPath = route('extension_public_folder', [ $publicPath = route('extension_public_folder', [
"extension_id" => extension()->id, "extension_id" => $this->extension->id,
"path" => "", "path" => "",
]); ]);
...@@ -125,8 +133,8 @@ class PHPSandbox implements Sandbox ...@@ -125,8 +133,8 @@ class PHPSandbox implements Sandbox
$array = [ $array = [
$functionsPath, $functionsPath,
$function, $function,
server()->toArray(), $this->server->toArray(),
extension()->toArray(), $this->extension->toArray(),
$extensionDb, $extensionDb,
$request, $request,
$apiRoute, $apiRoute,
...@@ -146,19 +154,19 @@ class PHPSandbox implements Sandbox ...@@ -146,19 +154,19 @@ class PHPSandbox implements Sandbox
'cat ' . 'cat ' .
'/liman/keys' . '/liman/keys' .
DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR .
extension()->id $this->extension->id
), ),
0, 0,
Str::random() Str::random()
); );
$keyPath = '/liman/keys' . DIRECTORY_SEPARATOR . extension()->id; $keyPath = '/liman/keys' . DIRECTORY_SEPARATOR . $this->extension->id;
$soPath = "/liman/extensions/" . strtolower(extension()->name) . "/liman.so"; $soPath = "/liman/extensions/" . strtolower($this->extension->name) . "/liman.so";
$extra = is_file($soPath) ? "-dextension=$soPath ": ""; $extra = is_file($soPath) ? "-dextension=$soPath ": "";
return "sudo runuser " . return "sudo runuser " .
cleanDash(extension()->id) . cleanDash($this->extension->id) .
" -c 'timeout 30 /usr/bin/php $extra-d display_errors=on $combinerFile $keyPath $encrypted'"; " -c 'timeout 30 /usr/bin/php $extra-d display_errors=on $combinerFile $keyPath $encrypted'";
} }
......
...@@ -11,6 +11,21 @@ class PythonSandbox implements Sandbox ...@@ -11,6 +11,21 @@ class PythonSandbox implements Sandbox
{ {
private $path = "/liman/sandbox/python/index.py"; private $path = "/liman/sandbox/python/index.py";
private $fileExtension = ".html.ninja"; private $fileExtension = ".html.ninja";
private $server,$extension,$user,$request;
public function __construct($server = null, $extension = null, $user = null,$request = null)
{
$this->server = ($server) ? $server : server();
$this->extension = ($extension) ? $extension : extension();
$this->user = ($user) ? $user : user();
$this->request = ($request) ? $request : request()->except([
"permissions",
"extension",
"server",
"script",
"server_id",
]);
}
public function getPath() public function getPath()
{ {
...@@ -27,48 +42,41 @@ class PythonSandbox implements Sandbox ...@@ -27,48 +42,41 @@ class PythonSandbox implements Sandbox
$combinerFile = $this->path; $combinerFile = $this->path;
$settings = UserSettings::where([ $settings = UserSettings::where([
"user_id" => user()->id, "user_id" => $this->user->id,
"server_id" => server()->id, "server_id" => $this->server->id,
]); ]);
$extensionDb = []; $extensionDb = [];
foreach ($settings->get() as $setting) { foreach ($settings->get() as $setting) {
$key = env('APP_KEY') . user()->id . extension()->id . server()->id; $key = env('APP_KEY') . $this->user->id . $this->extension->id . $this->server->id;
$decrypted = openssl_decrypt($setting->value, 'aes-256-cfb8', $key); $decrypted = openssl_decrypt($setting->value, 'aes-256-cfb8', $key);
$stringToDecode = substr($decrypted, 16); $stringToDecode = substr($decrypted, 16);
$extensionDb[$setting->name] = base64_decode($stringToDecode); $extensionDb[$setting->name] = base64_decode($stringToDecode);
} }
$extensionDb = json_encode($extensionDb); $extensionDb = json_encode($extensionDb);
$request = request()->except([ $request = json_encode($this->request);
"permissions",
"extension",
"server",
"script",
"server_id",
]);
$request = json_encode($request);
$apiRoute = route('extension_server', [ $apiRoute = route('extension_server', [
"extension_id" => extension()->id, "extension_id" => $this->extension->id,
"city" => server()->city, "city" => $this->server->city,
"server_id" => server()->id, "server_id" => $this->server->id,
]); ]);
$navigationRoute = route('extension_server', [ $navigationRoute = route('extension_server', [
"server_id" => server()->id, "server_id" => $this->server->id,
"extension_id" => extension()->id, "extension_id" => $this->extension->id,
"city" => server()->city, "city" => $this->server->city,
]); ]);
$token = Token::create(user()->id); $token = Token::create($this->user->id);
if (!user()->isAdmin()) { if (!$this->user->isAdmin()) {
$extensionJson = json_decode( $extensionJson = json_decode(
file_get_contents( file_get_contents(
"/liman/extensions/" . "/liman/extensions/" .
strtolower(extension()->name) . strtolower($this->extension->name) .
DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR .
"db.json" "db.json"
), ),
...@@ -79,10 +87,10 @@ class PythonSandbox implements Sandbox ...@@ -79,10 +87,10 @@ class PythonSandbox implements Sandbox
foreach ($extensionJson["functions"] as $item) { foreach ($extensionJson["functions"] as $item) {
if ( if (
Permission::can( Permission::can(
user()->id, $this->user->id,
"function", "function",
"name", "name",
strtolower(extension()->name), strtolower($this->extension->name),
$item["name"] $item["name"]
) || ) ||
$item["isActive"] != "true" $item["isActive"] != "true"
...@@ -97,18 +105,18 @@ class PythonSandbox implements Sandbox ...@@ -97,18 +105,18 @@ class PythonSandbox implements Sandbox
} }
$userData = [ $userData = [
"id" => user()->id, "id" => $this->user->id,
"name" => user()->name, "name" => $this->user->name,
"email" => user()->email, "email" => $this->user->email,
]; ];
$functionsPath = $functionsPath =
"/liman/extensions/" . "/liman/extensions/" .
strtolower(extension()->name) . strtolower($this->extension->name) .
"/views/functions.py"; "/views/functions.py";
$publicPath = route('extension_public_folder', [ $publicPath = route('extension_public_folder', [
"extension_id" => extension()->id, "extension_id" => $this->extension->id,
"path" => "", "path" => "",
]); ]);
...@@ -116,8 +124,8 @@ class PythonSandbox implements Sandbox ...@@ -116,8 +124,8 @@ class PythonSandbox implements Sandbox
$array = [ $array = [
$functionsPath, $functionsPath,
$function, $function,
server()->toArray(), $this->server->toArray(),
extension()->toArray(), $this->extension->toArray(),
$extensionDb, $extensionDb,
$request, $request,
$apiRoute, $apiRoute,
...@@ -130,14 +138,14 @@ class PythonSandbox implements Sandbox ...@@ -130,14 +138,14 @@ class PythonSandbox implements Sandbox
$isAjax, $isAjax,
]; ];
$keyPath = '/liman/keys' . DIRECTORY_SEPARATOR . extension()->id; $keyPath = '/liman/keys' . DIRECTORY_SEPARATOR . $this->extension->id;
$combinerFile = $combinerFile =
"/liman/extensions/" . "/liman/extensions/" .
strtolower(extension()->name) . strtolower($this->extension->name) .
"/views/functions.py"; "/views/functions.py";
$encrypted = base64_encode(json_encode($array)); $encrypted = base64_encode(json_encode($array));
return "sudo -u " . return "sudo -u " .
cleanDash(extension()->id) . cleanDash($this->extension->id) .
" bash -c 'export PYTHONPATH=\$PYTHONPATH:/liman/sandbox/python; timeout 30 /usr/bin/python3 $combinerFile $keyPath $encrypted 2>&1'"; " bash -c 'export PYTHONPATH=\$PYTHONPATH:/liman/sandbox/python; timeout 30 /usr/bin/python3 $combinerFile $keyPath $encrypted 2>&1'";
} }
......
...@@ -3,7 +3,9 @@ ...@@ -3,7 +3,9 @@
namespace App\Classes\Sandbox; namespace App\Classes\Sandbox;
interface Sandbox interface Sandbox
{ {
public function __construct($server = null, $extension = null, $user = null,$request = null);
public function getPath(); public function getPath();
public function getFileExtension(); public function getFileExtension();
......
...@@ -12,7 +12,7 @@ use App\Permission; ...@@ -12,7 +12,7 @@ use App\Permission;
use App\Server; use App\Server;
use App\ServerLog; use App\ServerLog;
use App\Token; use App\Token;
use Illuminate\Contracts\Events\Dispatcher; use Illuminate\Contracts\Bus\Dispatcher;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Str; use Illuminate\Support\Str;
......
...@@ -58,7 +58,7 @@ class MainController extends Controller ...@@ -58,7 +58,7 @@ class MainController extends Controller
system_log(7, "EXTENSION_RENDER_PAGE", [ system_log(7, "EXTENSION_RENDER_PAGE", [
"extension_id" => extension()->id, "extension_id" => extension()->id,
"server_id" => server()->id, "server_id" => server()->id,
"view" => "", "view" => $page,
]); ]);
if (trim($output) == "") { if (trim($output) == "") {
abort(504, "İstek zaman aşımına uğradı!"); abort(504, "İstek zaman aşımına uğradı!");
......
...@@ -24,6 +24,7 @@ class ExtensionJob implements ShouldQueue ...@@ -24,6 +24,7 @@ class ExtensionJob implements ShouldQueue
$request, $request,
$session, $session,
$cookie, $cookie,
$sandbox,
$history; $history;
/** /**
...@@ -46,9 +47,10 @@ class ExtensionJob implements ShouldQueue ...@@ -46,9 +47,10 @@ class ExtensionJob implements ShouldQueue
$this->function = $function; $this->function = $function;
$this->parameters = $parameters; $this->parameters = $parameters;
$this->session = session()->all(); $this->session = session()->all();
$this->cookie = isset($_COOKIE["liman_session"]) foreach ($parameters as $key => $param) {
? $_COOKIE["liman_session"] request()->request->add([$key => $param]);
: ''; }
$this->sandbox = sandbox();
} }
/** /**
...@@ -58,22 +60,10 @@ class ExtensionJob implements ShouldQueue ...@@ -58,22 +60,10 @@ class ExtensionJob implements ShouldQueue
*/ */
public function handle() public function handle()
{ {
$request = []; $command = $this->sandbox->command($this->function);
$parameters = json_decode($this->parameters);
foreach ($parameters as $key => $param) {
$request[$key] = $param;
}
$this->request = $request;
$command = self::sandbox(
$this->server,
$this->extension,
$this->extension->id,
$this->user->id,
"null",
"null",
$this->function
);
$output = shell_exec($command); $output = shell_exec($command);
system_log(7, "EXTENSION_BACKGROUND_RUN", [ system_log(7, "EXTENSION_BACKGROUND_RUN", [
"extension_id" => $this->extension->id, "extension_id" => $this->extension->id,
"server_id" => $this->server->id, "server_id" => $this->server->id,
......
1.0.4 1.0.5
\ No newline at end of file \ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment