Skip to content

Commit

Permalink
Merge pull request #78 from mertcelen/1.2-dev
Browse files Browse the repository at this point in the history
Liman'ın Yetkilerinin Kısıtlanması
  • Loading branch information
mertcelen authored Jul 23, 2020
2 parents 40f4a33 + 11b6adc commit 67cacfc
Show file tree
Hide file tree
Showing 56 changed files with 841 additions and 528 deletions.
2 changes: 1 addition & 1 deletion app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use App\Models\AdminNotification;
use App\Models\Notification;
use App\Models\User;
use App\User;
use App\Http\Controllers\MarketController;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
Expand Down
38 changes: 38 additions & 0 deletions app/Events/ExtensionRendered.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace App\Events;

use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class ExtensionRendered implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;

public $output;

/**
* Create a new event instance.
*
* @return void
*/
public function __construct($output)
{
$this->output = $output;
}

/**
* Get the channels the event should broadcast on.
*
* @return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
{
return new PrivateChannel('channel-name');
}
}
2 changes: 1 addition & 1 deletion app/Http/Controllers/Auth/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Carbon\Carbon;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;
use App\Models\User;
use App\User;
use App\Models\RoleMapping;
use App\Models\RoleUser;
use Illuminate\Support\Facades\Event;
Expand Down
99 changes: 18 additions & 81 deletions app/Http/Controllers/Extension/MainController.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function upload()
} catch (\Exception $exception) {
return respond("Lütfen geçerli bir eklenti giriniz.", 201);
}

$verify = false;
$zipFile = request()->file('extension');
if (
endsWith(
Expand Down Expand Up @@ -146,7 +146,7 @@ public function upload()
);
}
}
list($error, $new) = self::setupNewExtension($zipFile);
list($error, $new) = self::setupNewExtension($zipFile,$verify);

if ($error) {
return $error;
Expand All @@ -159,7 +159,7 @@ public function upload()
return respond("Eklenti Başarıyla yüklendi.", 200);
}

public function setupNewExtension($zipFile)
public function setupNewExtension($zipFile, $verify = false)
{
// Initialize Zip Archive Object to use it later.
$zip = new ZipArchive();
Expand Down Expand Up @@ -199,7 +199,7 @@ public function setupNewExtension($zipFile)
];
}

if (isset($verify)) {
if ($verify) {
$json["issuer"] = explode(" ", $verify, 4)[3];
} else {
$json["issuer"] = "";
Expand All @@ -223,55 +223,21 @@ public function setupNewExtension($zipFile)
}
$new->fill($json);
$new->save();

$system = rootSystem();

// Add User if not exists
if (
intval(
shell_exec("grep -c '^" . cleanDash($new->id) . "' /etc/passwd")
)
? false
: true
) {
shell_exec('sudo useradd -r -s /bin/sh ' . cleanDash($new->id));
}
$system->userAdd($new->id);

$extension_folder = "/liman/extensions/" . strtolower($json["name"]);
$passPath = '/liman/keys' . DIRECTORY_SEPARATOR . $new->id;
file_put_contents($passPath, Str::random(32));

shell_exec(
"
sudo chown liman:" .
cleanDash($new->id) .
" $passPath;
sudo chmod 640 $passPath;
sudo mkdir -p $extension_folder;
sudo cp -r " .
$path .
"/* " .
$extension_folder .
DIRECTORY_SEPARATOR .
";
sudo chown " .
cleanDash($new->id) .
":liman $extension_folder;
sudo chmod 770 $extension_folder;
sudo chown -R " .
cleanDash($new->id) .
":liman $extension_folder;
sudo chmod -R 770 $extension_folder;
sudo chown liman:" .
cleanDash($new->id) .
" " .
$extension_folder .
DIRECTORY_SEPARATOR .
"db.json;
sudo chmod 640 " .
$extension_folder .
DIRECTORY_SEPARATOR .
"db.json;
"
);
$extension_folder = "/liman/extensions/" . strtolower($json["name"]);

`mkdir -p $extension_folder`;
`cp -r $path/* $extension_folder/.`;

$system->fixExtensionPermissions($new->id, $new->name);

return [null, $new];
}

Expand Down Expand Up @@ -338,26 +304,12 @@ public function newExtension()
json_encode($json, JSON_PRETTY_PRINT)
);

if (
intval(
shell_exec("grep -c '^" . cleanDash($ext->id) . "' /etc/passwd")
)
? false
: true
) {
shell_exec('sudo useradd -r -s /bin/sh ' . cleanDash($ext->id));
}
$system = rootSystem();

$system->userAdd($ext->id);

$passPath = '/liman/keys' . DIRECTORY_SEPARATOR . $ext->id;
file_put_contents($passPath, Str::random(32));
shell_exec(
"
sudo chown liman:" .
cleanDash($ext->id) .
" $passPath;
sudo chmod 640 $passPath;
"
);

request()->request->add(['server' => "none"]);
request()->request->add(['extension_id' => $ext->id]);
Expand All @@ -366,22 +318,7 @@ public function newExtension()
touch($folder . "/views/$file");
}

shell_exec(
"
sudo chown -R " .
cleanDash($ext->id) .
":liman $folder;
sudo chmod -R 770 $folder;
sudo chown liman:" .
cleanDash($ext->id) .
" $folder" .
DIRECTORY_SEPARATOR .
"db.json;
sudo chmod 640 $folder" .
DIRECTORY_SEPARATOR .
"db.json;
"
);
$system->fixExtensionPermissions($ext->id, $ext->name);

system_log(6, "EXTENSION_CREATE", [
"extension_id" => $ext->id,
Expand Down
17 changes: 3 additions & 14 deletions app/Http/Controllers/Extension/OneController.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function serverSettings()
$extension["verification"],
$extensionDb
);
$output = shell_exec($command);
$output = rootSystem()->runCommand($command);
if (isJson($output)) {
$message = json_decode($output);
if (isset($message->message)) {
Expand Down Expand Up @@ -251,26 +251,15 @@ public function remove()
hook('extension_delete_attempt', extension());
try {
shell_exec(
"sudo rm -r " .
"rm -rf " .
"/liman/extensions/" .
strtolower(extension()->name)
);
} catch (\Exception $exception) {
}

try {
shell_exec(
"
sudo userdel " .
cleanDash(extension()->id) .
";
rm " .
'/liman/keys/' .
DIRECTORY_SEPARATOR .
extension()->id .
";
"
);
rootSystem()->userRemove(extension()->id);
extension()->delete();
} catch (\Exception $exception) {
}
Expand Down
10 changes: 2 additions & 8 deletions app/Http/Controllers/Extension/Sandbox/InternalController.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,14 +271,8 @@ public function getFile()
);

// Update Permissions
shell_exec("sudo chmod 770 " . request('localPath'));
shell_exec(
"sudo chown " .
cleanDash(extension()->id) .
":liman " .
request('localPath')
);

rootSystem()->fixExtensionPermissions(extension()->id, extension()->name);

system_log(7, "EXTENSION_INTERNAL_RECEIVE_FILE", [
"extension_id" => extension()->id,
"server_id" => server()->id,
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Extension/Sandbox/MainController.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ private function executeSandbox($function)
$command = $this->sandbox->command($function);

$before = Carbon::now();
$output = shell_exec($command);
$output = rootSystem()->runCommand($command);
return [$output, $before->diffInMilliseconds(Carbon::now()) / 1000];
}

Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use App\Models\LimanRequest;
use App\Models\Server;
use App\Models\User;
use App\User;
use App\Models\UserSettings;
use App\Models\Extension;
use App\Models\Widget;
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Notification/MainController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use App\Models\Notification;
use App\Http\Controllers\Controller;
use App\Notifications\NotificationSent;
use App\Models\User;
use App\User;

class MainController extends Controller
{
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Permission/MainController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use App\Models\LimanRequest;
use App\Models\Notification;
use App\Models\User;
use App\User;
use App\Http\Controllers\Controller;

class MainController extends Controller
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Server/OneController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use App\Models\Extension;
use App\Http\Controllers\Controller;
use App\Models\Notification;
use App\Models\User;
use App\User;
use App\Models\Permission;
use Carbon\Carbon;
use Exception;
Expand Down
31 changes: 13 additions & 18 deletions app/Http/Controllers/Settings/MainController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use App\Models\Extension;
use App\Models\Permission;
use App\Models\Server;
use App\Models\User;
use App\User;
use App\Models\Role;
use App\Http\Controllers\Controller;
use App\Models\AdminNotification;
Expand Down Expand Up @@ -69,7 +69,7 @@ public function one(User $user)
public function getUserList()
{
return view('l.table', [
"value" => \App\Models\User::all(),
"value" => \App\User::all(),
"title" => ["Kullanıcı Adı", "Email", "*hidden*"],
"display" => ["name", "email", "id:user_id"],
"menu" => [
Expand Down Expand Up @@ -611,35 +611,30 @@ public function getDNSServers()
{
$data = `grep nameserver /etc/resolv.conf | grep -v "#" | grep nameserver`;
$arr = explode("\n", $data);
$arr = array_filter($arr);
$clean = [];
foreach ($arr as $ip) {
if ($ip == "") {
continue;
}
$foo = explode(" ", trim($ip));
if (count($foo) == 1) {
continue;
}
array_push($clean, $foo[1]);
}
return respond($clean);
}

public function setDNSServers()
{
`sudo chattr -i /etc/resolv.conf`;
$str = "
options rotate timeout:1 retries:1
";
foreach ([request('dns1'), request('dns2'), request('dns3')] as $ip) {
if ($ip == null) {
continue;
}
$str .= "nameserver $ip
";
}
$str = trim($str);
$output = `echo "$str" | sudo tee /etc/resolv.conf`;
$compare = trim(`cat /etc/resolv.conf`) == $str ? true : false;
if ($compare) {
`sudo chattr +i /etc/resolv.conf`;
$system = rootSystem();
$flag = $system->dnsUpdate(
request('dns1'),
request('dns2'),
request('dns3')
);
if ($flag) {
return respond("DNS Ayarları güncellendi!");
} else {
return respond("DNS Ayarları güncellenemedi!", 201);
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use App\Models\Permission;
use App\Models\RoleUser;
use App\Models\User;
use App\User;
use App\Models\UserSettings;
use App\Models\AccessToken;
use App\Models\Server;
Expand Down
Loading

0 comments on commit 67cacfc

Please sign in to comment.