Skip to content

Commit

Permalink
ilk
Browse files Browse the repository at this point in the history
  • Loading branch information
orhan osmanağaoğlu authored Sep 10, 2021
0 parents commit 5b7fe42
Show file tree
Hide file tree
Showing 51 changed files with 2,203 additions and 0 deletions.
10 changes: 10 additions & 0 deletions app/App.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
namespace App;

class App
{
public function init()
{
//will be called when extension init
}
}
10 changes: 10 additions & 0 deletions app/Controllers/HomeController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
namespace App\Controllers;

class HomeController
{
public function index()
{
return view('index');
}
}
27 changes: 27 additions & 0 deletions app/Controllers/HostnameController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
namespace App\Controllers;

use Liman\Toolkit\Shell\Command;

class HostnameController
{
public function get()
{
$deger = Command::runSudo("ls -la");

return respond($deger, 200);
}

public function set()
{
validate([
'hostname' => 'required|string'
]);

$deger = Command::run("echo ", [
"degiskenIsmi" => request("hostname")
]);


}
}
41 changes: 41 additions & 0 deletions app/Controllers/RunScriptController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
namespace App\Controllers;

class RunScriptController
{
public function run()
{
// runScript function
// 1st parameter: filename under scripts folder STRING
// 2nd parameter: parameters STRING
// 3nd parameter: run as sudo BOOL
$script = runScript("example.py", "", false);

return $script;
}

public function test()
{
validate([
'testJavascriptVerisi' => 'required|string|max:255'
]);

checkPort("10.0.0.100", 22);

$istekVerisi = request("testJavascriptVerisi");

server()->name;
server()->ip_address;

user()->name;
user()->email;

respond($istekVerisi, 201);

view("alert", [
"type" => "danger",
"title" => "Örnek Alert",
"message" => "Mesajınızı buraya yazabilirsiniz."
]);
}
}
30 changes: 30 additions & 0 deletions app/Controllers/SystemInfoController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
namespace App\Controllers;

use Liman\Toolkit\Shell\Command;

class SystemInfoController
{
public function get()
{
$systeminfo = Command::runSudo('lshw -html');
return respond($systeminfo, strlen($systeminfo) ? 200 : 404);
}

public function install()
{
return respond(
view('taskview.task', [
'onFail' => 'onTaskFail',
'onSuccess' => 'onTaskSuccess',
'tasks' => [
0 => [
'name' => 'Lshw',
'attributes' => []
]
]
]),
200
);
}
}
22 changes: 22 additions & 0 deletions app/Controllers/TaskController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace App\Controllers;

use Liman\Toolkit\RemoteTask\TaskManager;

class TaskController
{
public function runTask()
{
$taskName = request('name');
$attributes = (array) json_decode(request('attributes'));
return respond(TaskManager::get($taskName, $attributes)->run());
}

public function checkTask()
{
$taskName = request('name');
$attributes = (array) json_decode(request('attributes'));
return respond(TaskManager::get($taskName, $attributes)->check());
}
}
145 changes: 145 additions & 0 deletions app/Controllers/TaskManagerController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
<?php
namespace App\Controllers;

use Liman\Toolkit\Shell\Command;

class TaskManagerController
{
function getList()
{
// Komut çalıştırdık
$cmd = Command::runSudo("ps -Ao user,pid,pcpu,stat,unit,pmem,comm --sort=-pcpu");

// Komutu newline ile böldük
$cmd = explode("\n", $cmd);

// İlk satırı attık
array_splice($cmd, 0, 1);

// her satır üzerinde işlem yapalım.
foreach ($cmd as $key => &$process)
{
// fazlalık boşluklarımı sildim
$process = preg_replace('/\s+/', ' ', $process);

// boşluklara göre parçalayalım
$process = explode(" ", $process);

// veriyi formatlayalim
$process = [
"user" => $process[0],
"pid" => $process[1],
"cpu" => $process[2],
"status" => $process[3],
"service" => $process[4],
"ram" => $process[5],
"command" => $process[6]
];
}

return view("table", [
"value" => $cmd,
"display" => ["user", "pid", "cpu", "status", "service", "ram", "command"],
"title" => ["Kullanıcı", "PID", "% İşlemci", "Durum", "Servis", "% Bellek", "İşlem"],
"menu" => [
"Dosya Konumu" => [
"target" => "jsGetFileLocation",
"icon" => "fa-location-arrow"
],
"Servis Durumu" => [
"target" => "jsGetServisDurum",
"icon" => "fa-address-book"
],
"Islem Agaci" => [
"target" => "jsGetIslemAgaci",
"icon" => "fa-address-book"
],
"Calitirma Arguman" => [
"target" => "jsGetCalitirmaArguman",
"icon" => "fa-address-book"
],
"Islem sonlandir" => [
"target" => "jsGetIslemSonlandir",
"icon" => "fa-address-book"
],
"Tum Islem sonlandir" => [
"target" => "jsGetTumIslemSonlandir",
"icon" => "fa-address-book"
],
]
]);
}

function getFileLocation()
{
validate([
"pid" => "required|numeric"
]);

$location = Command::runSudo("readlink -f /proc/@{:pid}/exe", [
"pid" => request("pid")
]);

return respond($location);
}
function getServisDurum()
{
validate([
"service" => "required|string"
]);

$location = Command::runSudo("systemctl status @{:service}", [
"service" => request("service")
]);

return respond($location);
}
function getIslemAgaci()
{
validate([
"pid" => "required|numeric"
]);

$location = Command::runSudo("ps f -g @{:pid}", [
"pid" => request("pid")
]);

return respond($location);
}
function getCalitirmaArguman()
{
validate([
"command" => "required|string"
]);

$location = Command::runSudo("man @{:command}", [
"command" => request("command")
]);

return respond($location);
}
function getIslemSonlandir()
{
validate([
"pid" => "required|numeric"
]);

$location = Command::runSudo("kill @{:pid}", [
"pid" => request("pid")
]);

return respond($location);
}
function getTumIslemSonlandir()
{
validate([
"command" => "required|string"
]);

$location = Command::runSudo("pkill @{:command}", [
"command" => request("command")
]);

return respond($location);
}
}
22 changes: 22 additions & 0 deletions app/Controllers/TaskViewController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
namespace App\Controllers;

class TaskViewController
{
public function run()
{
return respond(
view('taskview.task', [
'onFail' => 'onTaskFail',
'onSuccess' => 'onTaskSuccess',
'tasks' => [
0 => [
'name' => 'Example',
'attributes' => []
]
]
]),
200
);
}
}
57 changes: 57 additions & 0 deletions app/Controllers/dosyaListeControlller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php
namespace App\Controllers;

use Liman\Toolkit\Shell\Command;

class dosyaListeControlller
{
function getList()
{
// Komut çalıştırdık
$cmd = Command::run("ls -la /home/sysadmin/orhan");


// Komutu newline ile böldük
$cmd = explode("\n", $cmd);

// İlk satırı attık
array_splice($cmd, 0, 1);

// her satır üzerinde işlem yapalım.
foreach ($cmd as $key => &$process)
{
// fazlalık boşluklarımı sildim
$process = preg_replace('/\s+/', ' ', $process);

// boşluklara göre parçalayalım
$process = explode(" ", $process);

// veriyi formatlayalim
$process = [
"izinler" => $process[0],
"pid" => $process[1],
"kullanıcı" => $process[2],
"grup" => $process[3],
"boyut" => $process[4],
"tarih" => $process[5].$process[6].$process[7],
"dosyaad" => $process[8]
];
}

return view("table", [
"value" => $cmd,
"display" => ["izinler", "pid", "kullanıcı", "grup", "boyut", "tarih", "dosyaad"],
"title" => ["İzin", "ID", "Oluşturan", "Grup", "Boyut", "Tarih", "Dosya adı"],
"menu" => [
/* "Dosya Konumu" => [
"target" => "jsGetFileLocation",
"icon" => "fa-location-arrow"
],
"Servis Durumu" => [
"target" => "jsGetServisDurum",
"icon" => "fa-address-book"
],*/
]
]);
}
}
19 changes: 19 additions & 0 deletions app/Helpers/Helpers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

if (!function_exists('checkPort')) {
function checkPort($ip, $port)
{
restoreHandler();
if ($port == -1) {
return true;
}
$fp = @fsockopen($ip, $port, $errno, $errstr, 0.1);
setHandler();
if (!$fp) {
return false;
} else {
fclose($fp);
return true;
}
}
}
Loading

0 comments on commit 5b7fe42

Please sign in to comment.