Kaydet (Commit) b9608533 authored tarafından mertcelen's avatar mertcelen

WIP > Job dispatch added to the sandbox.

üst b50c90e6
......@@ -18,7 +18,7 @@ CACHE_DRIVER=array
SESSION_DRIVER=file
SESSION_LIFETIME=120
QUEUE_DRIVER=sync
QUEUE_DRIVER=database
SERVER_CONNECTION_TIMEOUT=5000
USER_WIDGET_COUNT=10
......
......@@ -20,6 +20,7 @@ use Illuminate\Support\Facades\DB;
use Illuminate\View\View;
use Illuminate\Support\Str;
use App\ServerLog;
use App\Jobs\ExtensionJob;
/**
* Class OneController
......@@ -172,6 +173,72 @@ class OneController extends Controller
return response($output, $code);
}
public function internalAddJob()
{
if ($_SERVER['SERVER_ADDR'] != $_SERVER['REMOTE_ADDR']) {
system_log(5,"EXTENSION_INTERNAL_NO_PERMISSION",[
"extension_id" => extension()->id,
]);
abort(403, 'Not Allowed');
}
$token = Token::where('token', request('token'))->first() or abort(403, "Token gecersiz");
$server = Server::find(request('server_id')) or abort(404, 'Sunucu Bulunamadi');
if (!Permission::can($token->user_id, 'server','id', $server->id)) {
system_log(7,"EXTENSION_NO_PERMISSION_SERVER",[
"extension_id" => extension()->id,
"server_id" => request('server_id')
]);
return "Sunucu icin yetkiniz yok.";
}
$extension = Extension::find(request('extension_id')) or abort(404, 'Eklenti Bulunamadi');
if (!Permission::can($token->user_id, 'extension','id', $extension->id)) {
system_log(7,"EXTENSION_NO_PERMISSION_SERVER",[
"extension_id" => extension()->id,
"server_id" => request('server_id')
]);
return "Eklenti için yetkiniz yok.";
}
ExtensionJob::dispatch($server,$extension,user(),request('function_name'),request('parameters'))->onQueue('extension_queue');
return "ok";
}
public function internalJobsList()
{
if ($_SERVER['SERVER_ADDR'] != $_SERVER['REMOTE_ADDR']) {
system_log(5,"EXTENSION_INTERNAL_NO_PERMISSION",[
"extension_id" => extension()->id,
]);
abort(403, 'Not Allowed');
}
$token = Token::where('token', request('token'))->first() or abort(403, "Token gecersiz");
$server = Server::find(request('server_id')) or abort(404, 'Sunucu Bulunamadi');
if (!Permission::can($token->user_id, 'server','id', $server->id)) {
system_log(7,"EXTENSION_NO_PERMISSION_SERVER",[
"extension_id" => extension()->id,
"server_id" => request('server_id')
]);
return "Sunucu icin yetkiniz yok.";
}
$extension = Extension::find(request('extension_id')) or abort(404, 'Eklenti Bulunamadi');
if (!Permission::can($token->user_id, 'extension','id', $extension->id)) {
system_log(7,"EXTENSION_NO_PERMISSION_SERVER",[
"extension_id" => extension()->id,
"server_id" => request('server_id')
]);
return "Eklenti icin yetkiniz yok.";
}
$job = (new ExtensionJob($server,$extension,user(),request('function_name')));
$id = dispatch($job);
return $id;
}
public function internalExtensionApi()
{
if ($_SERVER['SERVER_ADDR'] != $_SERVER['REMOTE_ADDR']) {
......
......@@ -352,12 +352,12 @@ function generateSandboxCommand($serverObj, $extensionObj, $extension_id, $user_
$request = json_encode($request);
$apiRoute = route('extension_function_api', [
"extension_id" => extension()->id
"extension_id" => $extension_id
]);
$navigationRoute = route('extension_server_route', [
"server_id" => $serverObj->id,
"extension_id" => extension()->id,
"extension_id" => $extension_id,
"city" => $serverObj->city
]);
......
......@@ -25,6 +25,7 @@ class VerifyCsrfToken extends Middleware
"/lmn/private/getFileApi",
"/lmn/private/runScriptApi",
"/lmn/private/putSession",
"/lmn/private/reverseProxyRequest"
"/lmn/private/reverseProxyRequest",
"/lmn/private/dispatchJob"
];
}
<?php
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class ExtensionJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public $extension,$server,$user,$function,$parameters;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($server,$extension,$user,$function,$parameters)
{
$this->extension = $extension;
$this->server = $server;
$this->user = $user;
$this->function = $function;
$this->parameters = $parameters;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
$parameters = json_decode($this->parameters);
foreach($parameters as $key=>$param){
request()->add([$key=>$param]);
}
$command = generateSandboxCommand($this->server, $this->extension, $this->extension->id,$this->user->id, "null", "null", $this->function);
$output = shell_exec($command);
system_log(7,"EXTENSION_BACKGROUND_RUN",[
"extension_id" => $this->extension->id,
"server_id" => $this->server->id,
"target_name" => $this->function
]);
$code = 200;
try{
$json = json_decode($output,true);
if(array_key_exists("status",$json)){
$code = intval($json["status"]);
}
}catch (\Exception $exception){};
if(strval($code) == "200" && $json["message"] != ""){
return true;
}else{
return false;
}
}
}
......@@ -8,7 +8,7 @@ use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
use Illuminate\Notifications\Messages\BroadcastMessage;
class NotificationSent extends Notification
class NotificationSent extends Notification implements ShouldQueue
{
use Queueable;
......
......@@ -687,27 +687,26 @@
},
{
"name": "egulias/email-validator",
"version": "2.1.12",
"version": "2.1.13",
"source": {
"type": "git",
"url": "https://github.com/egulias/EmailValidator.git",
"reference": "a6255605af39f2db7f5cb62e672bd8a7bad8d208"
"reference": "834593d5900615639208417760ba6a17299e2497"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/egulias/EmailValidator/zipball/a6255605af39f2db7f5cb62e672bd8a7bad8d208",
"reference": "a6255605af39f2db7f5cb62e672bd8a7bad8d208",
"url": "https://api.github.com/repos/egulias/EmailValidator/zipball/834593d5900615639208417760ba6a17299e2497",
"reference": "834593d5900615639208417760ba6a17299e2497",
"shasum": ""
},
"require": {
"doctrine/lexer": "^1.0.1",
"php": ">= 5.5"
"php": ">=5.5"
},
"require-dev": {
"dominicsayers/isemail": "dev-master",
"phpunit/phpunit": "^4.8.35||^5.7||^6.0",
"satooshi/php-coveralls": "^1.0.1",
"symfony/phpunit-bridge": "^4.4@dev"
"dominicsayers/isemail": "^3.0.7",
"phpunit/phpunit": "^4.8.36|^7.5.15",
"satooshi/php-coveralls": "^1.0.1"
},
"suggest": {
"ext-intl": "PHP Internationalization Libraries are required to use the SpoofChecking validation"
......@@ -741,20 +740,20 @@
"validation",
"validator"
],
"time": "2019-12-20T12:49:39+00:00"
"time": "2019-12-30T08:14:25+00:00"
},
{
"name": "erusev/parsedown",
"version": "1.7.3",
"version": "1.7.4",
"source": {
"type": "git",
"url": "https://github.com/erusev/parsedown.git",
"reference": "6d893938171a817f4e9bc9e86f2da1e370b7bcd7"
"reference": "cb17b6477dfff935958ba01325f2e8a2bfa6dab3"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/erusev/parsedown/zipball/6d893938171a817f4e9bc9e86f2da1e370b7bcd7",
"reference": "6d893938171a817f4e9bc9e86f2da1e370b7bcd7",
"url": "https://api.github.com/repos/erusev/parsedown/zipball/cb17b6477dfff935958ba01325f2e8a2bfa6dab3",
"reference": "cb17b6477dfff935958ba01325f2e8a2bfa6dab3",
"shasum": ""
},
"require": {
......@@ -787,7 +786,7 @@
"markdown",
"parser"
],
"time": "2019-03-17T18:48:37+00:00"
"time": "2019-12-30T22:54:17+00:00"
},
{
"name": "evenement/evenement",
......@@ -1349,16 +1348,16 @@
},
{
"name": "league/flysystem",
"version": "1.0.61",
"version": "1.0.62",
"source": {
"type": "git",
"url": "https://github.com/thephpleague/flysystem.git",
"reference": "4fb13c01784a6c9f165a351e996871488ca2d8c9"
"reference": "14dd5d7dff5fbc29ca9a2a53ff109760e40d91a0"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/thephpleague/flysystem/zipball/4fb13c01784a6c9f165a351e996871488ca2d8c9",
"reference": "4fb13c01784a6c9f165a351e996871488ca2d8c9",
"url": "https://api.github.com/repos/thephpleague/flysystem/zipball/14dd5d7dff5fbc29ca9a2a53ff109760e40d91a0",
"reference": "14dd5d7dff5fbc29ca9a2a53ff109760e40d91a0",
"shasum": ""
},
"require": {
......@@ -1429,7 +1428,7 @@
"sftp",
"storage"
],
"time": "2019-12-08T21:46:50+00:00"
"time": "2019-12-29T14:46:55+00:00"
},
{
"name": "monolog/monolog",
......@@ -1690,16 +1689,16 @@
},
{
"name": "paragonie/sodium_compat",
"version": "v1.12.1",
"version": "v1.12.2",
"source": {
"type": "git",
"url": "https://github.com/paragonie/sodium_compat.git",
"reference": "063cae9b3a7323579063e7037720f5b52b56c178"
"reference": "3b953109fdfc821c1979bc829c8b7421721fef82"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/paragonie/sodium_compat/zipball/063cae9b3a7323579063e7037720f5b52b56c178",
"reference": "063cae9b3a7323579063e7037720f5b52b56c178",
"url": "https://api.github.com/repos/paragonie/sodium_compat/zipball/3b953109fdfc821c1979bc829c8b7421721fef82",
"reference": "3b953109fdfc821c1979bc829c8b7421721fef82",
"shasum": ""
},
"require": {
......@@ -1768,7 +1767,7 @@
"secret-key cryptography",
"side-channel resistant"
],
"time": "2019-11-07T17:07:24+00:00"
"time": "2019-12-30T03:11:08+00:00"
},
{
"name": "phpoption/phpoption",
......@@ -4685,16 +4684,16 @@
},
{
"name": "filp/whoops",
"version": "2.5.1",
"version": "2.7.0",
"source": {
"type": "git",
"url": "https://github.com/filp/whoops.git",
"reference": "ee9699e79d8fcdd15c107e035d7b965e4fa854ac"
"reference": "4c97f814aa2f0dd4d5bedc89181c10ef12c004c5"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/filp/whoops/zipball/ee9699e79d8fcdd15c107e035d7b965e4fa854ac",
"reference": "ee9699e79d8fcdd15c107e035d7b965e4fa854ac",
"url": "https://api.github.com/repos/filp/whoops/zipball/4c97f814aa2f0dd4d5bedc89181c10ef12c004c5",
"reference": "4c97f814aa2f0dd4d5bedc89181c10ef12c004c5",
"shasum": ""
},
"require": {
......@@ -4703,8 +4702,8 @@
},
"require-dev": {
"mockery/mockery": "^0.9 || ^1.0",
"phpunit/phpunit": "^4.8.35 || ^5.7",
"symfony/var-dumper": "^2.6 || ^3.0 || ^4.0"
"phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.0",
"symfony/var-dumper": "^2.6 || ^3.0 || ^4.0 || ^5.0"
},
"suggest": {
"symfony/var-dumper": "Pretty print complex values better with var-dumper available",
......@@ -4713,7 +4712,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.2-dev"
"dev-master": "2.6-dev"
}
},
"autoload": {
......@@ -4742,7 +4741,7 @@
"throwable",
"whoops"
],
"time": "2019-12-21T10:00:00+00:00"
"time": "2019-12-29T10:00:00+00:00"
},
{
"name": "fzaninotto/faker",
......@@ -4995,23 +4994,22 @@
},
{
"name": "mockery/mockery",
"version": "1.3.0",
"version": "1.3.1",
"source": {
"type": "git",
"url": "https://github.com/mockery/mockery.git",
"reference": "5571962a4f733fbb57bede39778f71647fae8e66"
"reference": "f69bbde7d7a75d6b2862d9ca8fab1cd28014b4be"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/mockery/mockery/zipball/5571962a4f733fbb57bede39778f71647fae8e66",
"reference": "5571962a4f733fbb57bede39778f71647fae8e66",
"url": "https://api.github.com/repos/mockery/mockery/zipball/f69bbde7d7a75d6b2862d9ca8fab1cd28014b4be",
"reference": "f69bbde7d7a75d6b2862d9ca8fab1cd28014b4be",
"shasum": ""
},
"require": {
"hamcrest/hamcrest-php": "~2.0",
"lib-pcre": ">=7.0",
"php": ">=5.6.0",
"sebastian/comparator": "^1.2.4|^3.0"
"php": ">=5.6.0"
},
"require-dev": {
"phpunit/phpunit": "~5.7.10|~6.5|~7.0|~8.0"
......@@ -5019,7 +5017,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.2.x-dev"
"dev-master": "1.3.x-dev"
}
},
"autoload": {
......@@ -5057,7 +5055,7 @@
"test double",
"testing"
],
"time": "2019-11-24T07:54:50+00:00"
"time": "2019-12-26T09:49:15+00:00"
},
{
"name": "myclabs/deep-copy",
......@@ -5379,16 +5377,16 @@
},
{
"name": "phpdocumentor/reflection-docblock",
"version": "4.3.3",
"version": "4.3.4",
"source": {
"type": "git",
"url": "https://github.com/phpDocumentor/ReflectionDocBlock.git",
"reference": "2ecaa9fef01634c83bfa8dc1fe35fb5cef223a62"
"reference": "da3fd972d6bafd628114f7e7e036f45944b62e9c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/2ecaa9fef01634c83bfa8dc1fe35fb5cef223a62",
"reference": "2ecaa9fef01634c83bfa8dc1fe35fb5cef223a62",
"url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/da3fd972d6bafd628114f7e7e036f45944b62e9c",
"reference": "da3fd972d6bafd628114f7e7e036f45944b62e9c",
"shasum": ""
},
"require": {
......@@ -5400,6 +5398,7 @@
"require-dev": {
"doctrine/instantiator": "^1.0.5",
"mockery/mockery": "^1.0",
"phpdocumentor/type-resolver": "0.4.*",
"phpunit/phpunit": "^6.4"
},
"type": "library",
......@@ -5426,7 +5425,7 @@
}
],
"description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.",
"time": "2019-12-20T13:40:23+00:00"
"time": "2019-12-28T18:55:12+00:00"
},
{
"name": "phpdocumentor/type-resolver",
......@@ -5792,16 +5791,16 @@
},
{
"name": "phpunit/phpunit",
"version": "8.5.0",
"version": "8.5.1",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/phpunit.git",
"reference": "3ee1c1fd6fc264480c25b6fb8285edefe1702dab"
"reference": "7870c78da3c5e4883eaef36ae47853ebb3cb86f2"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/3ee1c1fd6fc264480c25b6fb8285edefe1702dab",
"reference": "3ee1c1fd6fc264480c25b6fb8285edefe1702dab",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/7870c78da3c5e4883eaef36ae47853ebb3cb86f2",
"reference": "7870c78da3c5e4883eaef36ae47853ebb3cb86f2",
"shasum": ""
},
"require": {
......@@ -5871,7 +5870,7 @@
"testing",
"xunit"
],
"time": "2019-12-06T05:41:38+00:00"
"time": "2019-12-25T14:49:39+00:00"
},
{
"name": "psy/psysh",
......
......@@ -35,10 +35,10 @@ return [
],
'database' => [
'driver' => 'sync',
'table' => 'jobs',
'queue' => 'default',
'expire' => 60,
'driver' => 'database',
'table' => 'jobs',
'queue' => 'default',
'retry_after' => 90,
],
'beanstalkd' => [
......
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateJobsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('jobs', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('queue')->index();
$table->longText('payload');
$table->unsignedTinyInteger('attempts');
$table->unsignedInteger('reserved_at')->nullable();
$table->unsignedInteger('available_at');
$table->unsignedInteger('created_at');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('jobs');
}
}
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateFailedJobsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('failed_jobs', function (Blueprint $table) {
$table->bigIncrements('id');
$table->text('connection');
$table->text('queue');
$table->longText('payload');
$table->longText('exception');
$table->timestamp('failed_at')->useCurrent();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('failed_jobs');
}
}
......@@ -115,6 +115,8 @@ Route::post('/lmn/private/putSession','Extension\OneController@internalPutSessio
Route::post('/lmn/private/reverseProxyRequest','Extension\OneController@internalAddProxyConfig')->middleware(['auth', 'permissions']);
Route::post('/lmn/private/dispatchJob','Extension\OneController@internalAddJob')->middleware(['auth', 'permissions']);
Route::any('/upload/{any?}', function () {
$server = app('tus-server');
$extension_id = request("extension_id");
......
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