Kaydet (Commit) db66317a authored tarafından Mert ÇELEN's avatar Mert ÇELEN

Service status added.

üst 5e06a519
...@@ -293,7 +293,14 @@ class OneController extends Controller ...@@ -293,7 +293,14 @@ class OneController extends Controller
"free -t | awk 'NR == 2 {printf($3/$2*100)}'", "free -t | awk 'NR == 2 {printf($3/$2*100)}'",
false false
); );
$cpu = substr(server()->run("grep 'cpu ' /proc/stat | awk '{usage=($2+$4)*100/($2+$4+$5)} END {print usage}'",false),0,7); $cpu = substr(
server()->run(
"grep 'cpu ' /proc/stat | awk '{usage=($2+$4)*100/($2+$4+$5)} END {print usage}'",
false
),
0,
7
);
// $cpu = server()->run("vmstat 1 1|tail -1|awk '{print $15}'", false); // $cpu = server()->run("vmstat 1 1|tail -1|awk '{print $15}'", false);
// $cpu = 100 - intval($cpu); // $cpu = 100 - intval($cpu);
} elseif (server()->type == "windows_powershell") { } elseif (server()->type == "windows_powershell") {
...@@ -570,8 +577,8 @@ class OneController extends Controller ...@@ -570,8 +577,8 @@ class OneController extends Controller
public function serviceList() public function serviceList()
{ {
if(!Permission::can(user()->id,'liman','id','server_services')){ if (!Permission::can(user()->id, 'liman', 'id', 'server_services')) {
return respond("Bu işlemi yapmak için yetkiniz yok!",201); return respond("Bu işlemi yapmak için yetkiniz yok!", 201);
} }
$services = []; $services = [];
if ( if (
...@@ -624,7 +631,11 @@ class OneController extends Controller ...@@ -624,7 +631,11 @@ class OneController extends Controller
"title" => ["Servis Adı", "Aciklamasi", "Durumu"], "title" => ["Servis Adı", "Aciklamasi", "Durumu"],
"display" => ["name", "description", "status"], "display" => ["name", "description", "status"],
"menu" => [ "menu" => [
"Baslat" => [ "Detaylar" => [
"target" => "statusService",
"icon" => "fa-info-circle",
],
"Başlat" => [
"target" => "startService", "target" => "startService",
"icon" => "fa-play", "icon" => "fa-play",
], ],
...@@ -632,7 +643,7 @@ class OneController extends Controller ...@@ -632,7 +643,7 @@ class OneController extends Controller
"target" => "stopService", "target" => "stopService",
"icon" => "fa-stop", "icon" => "fa-stop",
], ],
"Yeniden Baslat" => [ "Yeniden Başlat" => [
"target" => "restartService", "target" => "restartService",
"icon" => "fa-sync-alt", "icon" => "fa-sync-alt",
], ],
...@@ -642,76 +653,98 @@ class OneController extends Controller ...@@ -642,76 +653,98 @@ class OneController extends Controller
public function getLogs() public function getLogs()
{ {
if(!Permission::can(user()->id,'liman','id','view_logs')){ if (!Permission::can(user()->id, 'liman', 'id', 'view_logs')) {
return respond("Sunucu Günlük Kayıtlarını görüntülemek için yetkiniz yok",201); return respond(
"Sunucu Günlük Kayıtlarını görüntülemek için yetkiniz yok",
201
);
} }
$page = request('page') * 10; $page = request('page') * 10;
$query = request('query') ? request('query') : ""; $query = request('query') ? request('query') : "";
$server_id = request('server_id'); $server_id = request('server_id');
$count = intval(trim(`grep --text EXTENSION_RENDER_PAGE /liman/logs/liman.log | grep '"display":"true"'| grep '$query' | grep $server_id | wc -l`)); $count = intval(
trim(
`grep --text EXTENSION_RENDER_PAGE /liman/logs/liman.log | grep '"display":"true"'| grep '$query' | grep $server_id | wc -l`
)
);
$head = $page > $count ? $count % 10 : 10; $head = $page > $count ? $count % 10 : 10;
$data = trim(`grep --text EXTENSION_RENDER_PAGE /liman/logs/liman.log | grep '"display":"true"'| grep '$query' | grep $server_id | tail -$page | head -$head | tac`); $data = trim(
`grep --text EXTENSION_RENDER_PAGE /liman/logs/liman.log | grep '"display":"true"'| grep '$query' | grep $server_id | tail -$page | head -$head | tac`
);
$clean = []; $clean = [];
$knownUsers = []; $knownUsers = [];
$knownExtensions = []; $knownExtensions = [];
if($data == ""){ if ($data == "") {
return respond([ return respond([
"table" => "Bu aramaya göre bir sonuç bulunamadı." "table" => "Bu aramaya göre bir sonuç bulunamadı.",
]); ]);
} }
foreach(explode("\n",$data) as $row){ foreach (explode("\n", $data) as $row) {
$dateEndPos = strposX($row, " ", 2); $dateEndPos = strposX($row, " ", 2);
$date = substr($row,1,$dateEndPos -2); $date = substr($row, 1, $dateEndPos - 2);
$json = substr($row,strpos($row,"{")); $json = substr($row, strpos($row, "{"));
$parsed = json_decode($json,true); $parsed = json_decode($json, true);
$parsed["date"] = $date; $parsed["date"] = $date;
if(!array_key_exists($parsed["extension_id"],$knownExtensions)){ if (!array_key_exists($parsed["extension_id"], $knownExtensions)) {
$extension = Extension::find($parsed["extension_id"]); $extension = Extension::find($parsed["extension_id"]);
if($extension){ if ($extension) {
$knownExtensions[$parsed["extension_id"]] = $extension->display_name; $knownExtensions[$parsed["extension_id"]] =
}else{ $extension->display_name;
$knownExtensions[$parsed["extension_id"]] = $parsed["extension_id"]; } else {
$knownExtensions[$parsed["extension_id"]] =
$parsed["extension_id"];
} }
} }
$parsed["extension_id"] = $knownExtensions[$parsed["extension_id"]]; $parsed["extension_id"] = $knownExtensions[$parsed["extension_id"]];
if(!array_key_exists("log_id",$parsed)){ if (!array_key_exists("log_id", $parsed)) {
$parsed["log_id"] = null; $parsed["log_id"] = null;
} }
if(!array_key_exists($parsed["user_id"],$knownUsers)){ if (!array_key_exists($parsed["user_id"], $knownUsers)) {
$user = User::find($parsed["user_id"]); $user = User::find($parsed["user_id"]);
if($user){ if ($user) {
$knownUsers[$parsed["user_id"]] = $user->name; $knownUsers[$parsed["user_id"]] = $user->name;
}else{ } else {
$knownUsers[$parsed["user_id"]] = $parsed["user_id"]; $knownUsers[$parsed["user_id"]] = $parsed["user_id"];
} }
} }
$parsed["user_id"] = $knownUsers[$parsed["user_id"]]; $parsed["user_id"] = $knownUsers[$parsed["user_id"]];
array_push($clean,$parsed); array_push($clean, $parsed);
} }
$table = view('table',[ $table = view('table', [
"value" => (array) $clean, "value" => (array) $clean,
"startingNumber" => (intval(request('page')) - 1) * 10, "startingNumber" => (intval(request('page')) - 1) * 10,
"title" => ["Eklenti", "Fonksiyon", "Kullanıcı","İşlem Tarihi", "*hidden*"], "title" => [
"display" => ["extension_id", "view", "user_id","date","log_id:id"], "Eklenti",
"onclick" => "getLogDetails" "Fonksiyon",
"Kullanıcı",
"İşlem Tarihi",
"*hidden*",
],
"display" => [
"extension_id",
"view",
"user_id",
"date",
"log_id:id",
],
"onclick" => "getLogDetails",
])->render(); ])->render();
$pagination = view('pagination',[ $pagination = view('pagination', [
"current" => request('page') ? intval(request('page')) : 1, "current" => request('page') ? intval(request('page')) : 1,
"count" => floor($count / 10) + 1, "count" => floor($count / 10) + 1,
"onclick" => "getLogs" "onclick" => "getLogs",
])->render(); ])->render();
return respond([ return respond([
"table" => $table . "<br>" . $pagination "table" => $table . "<br>" . $pagination,
]); ]);
} }
...@@ -719,18 +752,18 @@ class OneController extends Controller ...@@ -719,18 +752,18 @@ class OneController extends Controller
{ {
$query = request('log_id'); $query = request('log_id');
$data = trim(`grep '$query' /liman/logs/extension.log`); $data = trim(`grep '$query' /liman/logs/extension.log`);
if($data == ""){ if ($data == "") {
return respond("Bu loga ait detay bulunamadı",201); return respond("Bu loga ait detay bulunamadı", 201);
} }
$logs = []; $logs = [];
foreach(explode("\n",$data) as $row){ foreach (explode("\n", $data) as $row) {
$dateEndPos = strposX($row, " ", 2); $dateEndPos = strposX($row, " ", 2);
$date = substr($row,1,$dateEndPos -2); $date = substr($row, 1, $dateEndPos - 2);
$json = substr($row,strpos($row,"{")); $json = substr($row, strpos($row, "{"));
$parsed = json_decode($json,true); $parsed = json_decode($json, true);
$parsed["title"] = base64_decode($parsed["title"]); $parsed["title"] = base64_decode($parsed["title"]);
$parsed["message"] = base64_decode($parsed["message"]); $parsed["message"] = base64_decode($parsed["message"]);
array_push($logs,$parsed); array_push($logs, $parsed);
} }
return respond($logs); return respond($logs);
...@@ -749,8 +782,8 @@ class OneController extends Controller ...@@ -749,8 +782,8 @@ class OneController extends Controller
basename($package) . basename($package) .
".txt\" 2>&1 & disown && echo \$!'" ".txt\" 2>&1 & disown && echo \$!'"
); );
system_log(7,"Paket Güncelleme",[ system_log(7, "Paket Güncelleme", [
'package_name' => request("package_name") 'package_name' => request("package_name"),
]); ]);
} elseif (server()->type == "windows_powershell") { } elseif (server()->type == "windows_powershell") {
$raw = ""; $raw = "";
...@@ -807,8 +840,8 @@ class OneController extends Controller ...@@ -807,8 +840,8 @@ class OneController extends Controller
($mode == "update" && $output == "0") || ($mode == "update" && $output == "0") ||
($mode == "install" && $output != "0") ($mode == "install" && $output != "0")
) { ) {
system_log(7,"Paket Güncelleme Başarılı",[ system_log(7, "Paket Güncelleme Başarılı", [
'package_name' => request("package_name") 'package_name' => request("package_name"),
]); ]);
return respond([ return respond([
"status" => __( "status" => __(
...@@ -818,8 +851,8 @@ class OneController extends Controller ...@@ -818,8 +851,8 @@ class OneController extends Controller
"output" => trim($command_output), "output" => trim($command_output),
]); ]);
} else { } else {
system_log(7,"Paket Güncelleme Başarısız",[ system_log(7, "Paket Güncelleme Başarısız", [
'package_name' => request("package_name") 'package_name' => request("package_name"),
]); ]);
return respond([ return respond([
"status" => __(":package_name paketi kurulamadı.", [ "status" => __(":package_name paketi kurulamadı.", [
...@@ -1116,6 +1149,23 @@ class OneController extends Controller ...@@ -1116,6 +1149,23 @@ class OneController extends Controller
return respond("Servis Yeniden Başlatıldı", 200); return respond("Servis Yeniden Başlatıldı", 200);
} }
public function statusService()
{
if (
server()->type == "linux_ssh" ||
server()->type == "linux_certificate"
) {
$command = sudo() . "systemctl status " . request('name');
} else {
return respond(
"Windows Sunucularda yalnızca servis durumu görüntülenmektedir.",
201
);
}
$output = server()->run($command);
return respond($output, 200);
}
public function getOpenPorts() public function getOpenPorts()
{ {
if ( if (
......
...@@ -169,7 +169,6 @@ Route::group(['middleware' => ['server']], function () { ...@@ -169,7 +169,6 @@ Route::group(['middleware' => ['server']], function () {
'Server\OneController@getLogs' 'Server\OneController@getLogs'
)->name('server_get_logs'); )->name('server_get_logs');
Route::post( Route::post(
'/sunucu/gunluk_kayitlari_detay', '/sunucu/gunluk_kayitlari_detay',
'Server\OneController@getLogDetails' 'Server\OneController@getLogDetails'
...@@ -203,6 +202,11 @@ Route::group(['middleware' => ['server']], function () { ...@@ -203,6 +202,11 @@ Route::group(['middleware' => ['server']], function () {
'Server\OneController@restartService' 'Server\OneController@restartService'
)->name('server_restart_service'); )->name('server_restart_service');
Route::post(
'/sunucu/servis/durum',
'Server\OneController@statusService'
)->name('server_service_status');
Route::post( Route::post(
'/sunucu/acikPortlar', '/sunucu/acikPortlar',
'Server\OneController@getOpenPorts' 'Server\OneController@getOpenPorts'
......
...@@ -191,8 +191,11 @@ ...@@ -191,8 +191,11 @@
$key . ":" . $parameter["type"]; $key . ":" . $parameter["type"];
} }
} }
$arr[$extension->display_name . ":" . $extension->id] = $arr[
"extension_id:hidden"; $extension->display_name .
":" .
$extension->id
] = "extension_id:hidden";
$input_extensions[] = [ $input_extensions[] = [
"name" => $extension->display_name, "name" => $extension->display_name,
"id" => $extension->id, "id" => $extension->id,
...@@ -392,7 +395,7 @@ ...@@ -392,7 +395,7 @@
@include('modal',[ @include('modal',[
"id"=>"delete_extensions", "id"=>"delete_extensions",
"title" => "Eklentileri Sil", "title" => "Eklentileri Sil",
"text" => "Secili eklentileri silmek istediginize emin misiniz?", "text" => "Seçili eklentileri silmek istediğinize emin misiniz?",
"type" => "danger", "type" => "danger",
"onsubmit" => "removeExtensionFunc", "onsubmit" => "removeExtensionFunc",
"submit_text" => "Eklentileri Sil" "submit_text" => "Eklentileri Sil"
...@@ -453,21 +456,21 @@ ...@@ -453,21 +456,21 @@
@include('modal',[ @include('modal',[
"id"=>"startService", "id"=>"startService",
"title" => "Servisi Baslat", "title" => "Servisi Başlat",
"text" => "Secili servisi baslatmak istediginize emin misiniz?", "text" => "Seçili servisi başlatmak istediğinize emin misiniz?",
"type" => "danger", "type" => "danger",
"next" => "reload", "next" => "reload",
"inputs" => [ "inputs" => [
"name:-" => "name:hidden", "name:-" => "name:hidden",
], ],
"url" => route('server_start_service'), "url" => route('server_start_service'),
"submit_text" => "Servisi Baslat" "submit_text" => "Servisi Başlat"
]) ])
@include('modal',[ @include('modal',[
"id"=>"stopService", "id"=>"stopService",
"title" => "Servisi Durdur", "title" => "Servisi Durdur",
"text" => "Secili servisi durdurmak istediginize emin misiniz?", "text" => "Seçili servisi durdurmak istediğinize emin misiniz?",
"type" => "danger", "type" => "danger",
"next" => "reload", "next" => "reload",
"inputs" => [ "inputs" => [
...@@ -479,15 +482,15 @@ ...@@ -479,15 +482,15 @@
@include('modal',[ @include('modal',[
"id"=>"restartService", "id"=>"restartService",
"title" => "Servisi Yeniden Baslat", "title" => "Servisi Yeniden Başlat",
"text" => "Secili servisi yeniden baslatmak istediginize emin misiniz?", "text" => "Seçili servisi yeniden başlatmak istediğinize emin misiniz?",
"type" => "danger", "type" => "danger",
"next" => "reload", "next" => "reload",
"inputs" => [ "inputs" => [
"name:-" => "name:hidden", "name:-" => "name:hidden",
], ],
"url" => route('server_restart_service'), "url" => route('server_restart_service'),
"submit_text" => "Servisi Yeniden Baslat" "submit_text" => "Servisi Yeniden Başlat"
]) ])
@include('modal',[ @include('modal',[
...@@ -570,6 +573,13 @@ ...@@ -570,6 +573,13 @@
</div> </div>
@endcomponent @endcomponent
@component('modal-component',[
"id" => "serviceStatusModal",
"title" => "Servis Durumu"
])
<pre id="serviceStatusWrapper"></pre>
@endcomponent
@component('modal-component',[ @component('modal-component',[
"id"=>"logDetailModal", "id"=>"logDetailModal",
"title" => "Log Detayı" "title" => "Log Detayı"
...@@ -890,6 +900,24 @@ ...@@ -890,6 +900,24 @@
}) })
} }
function statusService(element) {
let name = element.querySelector('#name').innerHTML;
showSwal('{{__("Okunuyor...")}}','info');
let form = new FormData();
form.append('name',name);
request('{{route('server_service_status')}}', form, function (response) {
let json = JSON.parse(response);
$("#serviceStatusWrapper").html(json.message);
$("#serviceStatusModal").modal('show');
setTimeout(function () {
Swal.close();
}, 1500);
}, function(response){
let error = JSON.parse(response);
showSwal(error.message,'error',2000);
})
}
$("#logQueryFilter").on('keyup', function (e) { $("#logQueryFilter").on('keyup', function (e) {
if (e.keyCode === 13) { if (e.keyCode === 13) {
getLogs(); getLogs();
......
1.0.12 1.0.13
\ 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