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

Auto updates enabled.

üst 1c7be4be
......@@ -5,6 +5,7 @@ namespace App\Console;
use App\AdminNotification;
use App\Notification;
use App\User;
use App\Http\Controllers\MarketController;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
use Illuminate\Support\Facades\DB;
......@@ -60,21 +61,33 @@ class Kernel extends ConsoleKernel
//Check Package Update Every 30 Min
$schedule
->call(function () {
shell_exec("sudo apt update");
$output = shell_exec("apt list --upgradable");
if (!strpos($output, "liman")) {
$controller = new MarketController();
if (!env('MARKET_ACCESS_TOKEN')) {
return;
}
$client = $controller->getClient();
try {
$response = $client->post(
env("MARKET_URL") . '/api/users/me'
);
} catch (\Exception $e) {
return;
}
AdminNotification::where('type', 'liman_update')->delete();
AdminNotification::create([
"title" => "Liman Güncellemesi Mevcut!",
"type" => "liman_update",
"message" =>
"Yeni bir liman sürümü mevcut ayrıntılı bilgi için tıklayınız.",
"level" => 3,
]);
$array = $controller->checkMarketUpdates(true);
$collection = collect($array);
if (!$collection->where("updateAvailable", 1)->count()) {
AdminNotification::where('type', 'liman_update')->delete();
AdminNotification::create([
"title" => "Liman Güncellemesi Mevcut!",
"type" => "liman_update",
"message" =>
"Yeni bir sistem güncellemesi mevcut, ayrıntılı bilgi için tıklayınız.",
"level" => 3,
]);
}
})
->everyThirtyMinutes()
->everyMinute()
->name('Update Check');
}
......
......@@ -4,6 +4,7 @@ namespace App\Http\Controllers;
use Illuminate\Http\Request;
use GuzzleHttp\Client;
use App\Extension;
use App\Jobs\ExtensionUpdaterJob;
use GuzzleHttp\Exception\BadResponseException;
use Illuminate\Contracts\Bus\Dispatcher;
......@@ -12,16 +13,16 @@ class MarketController extends Controller
{
public function verifyMarketConnection()
{
if(!env('MARKET_ACCESS_TOKEN')){
return respond("Market'e bağlanmak için bir anahtarınız yok!",201);
if (!env('MARKET_ACCESS_TOKEN')) {
return respond("Market'e bağlanmak için bir anahtarınız yok!", 201);
}
$client = self::getClient();
try{
try {
$response = $client->post(env("MARKET_URL") . '/api/users/me');
}catch(\Exception $e){
return respond("Anahtarınız ile Market'e bağlanılamadı!",201);
} catch (\Exception $e) {
return respond("Anahtarınız ile Market'e bağlanılamadı!", 201);
}
return respond("Market Bağlantısı Başarıyla Sağlandı.");
}
......@@ -38,22 +39,22 @@ class MarketController extends Controller
);
}
public function checkMarketUpdates()
public function checkMarketUpdates($returnRaw = false)
{
$client = self::getClient();
$params = [];
$limanCode = trim(file_get_contents(storage_path('VERSION_CODE')));
array_push($params,[
array_push($params, [
"packageName" => "Liman.Core",
"versionCode" => intval($limanCode),
"currentVersion" => getVersion(),
"extension_id" => null
"extension_id" => null,
]);
foreach(extensions() as $extension){
$extensions = Extension::all();
foreach ($extensions as $extension) {
$obj = json_decode(
file_get_contents(
"/liman/extensions/" .
......@@ -63,75 +64,98 @@ class MarketController extends Controller
),
true
);
array_push($params,[
array_push($params, [
"packageName" => "Liman." . $obj["name"],
"versionCode" => array_key_exists("version_code",$obj) ? $obj["version_code"] : 0,
"versionCode" => array_key_exists("version_code", $obj)
? $obj["version_code"]
: 0,
"currentVersion" => $obj["version"],
"extension_id" => $extension->id
"extension_id" => $extension->id,
]);
}
try{
$response = $client->get(env("MARKET_URL") . '/api/application/check_version',[
"json" => $params
]);
}catch(\Exception $e){
return respond($e->getMessage(),201);
try {
$response = $client->get(
env("MARKET_URL") . '/api/application/check_version',
[
"json" => $params,
]
);
} catch (\Exception $e) {
return respond($e->getMessage(), 201);
}
$json = json_decode((string) $response->getBody());
$collection = collect($json);
$fileToWrite = [];
for($i=0; $i < count($params); $i++){
$obj = $collection->where('packageName',$params[$i]["packageName"])->first();
if(!$obj){
for ($i = 0; $i < count($params); $i++) {
$obj = $collection
->where('packageName', $params[$i]["packageName"])
->first();
if (!$obj) {
$params[$i]["status"] = "Güncel";
}else{
$obj = json_decode(json_encode($obj),true);
$params[$i]["status"] = $obj["version"]["versionName"] . " sürümü mevcut";
if($params[$i]["extension_id"] != null && count($obj["platforms"])){
$params[$i]["updateAvailable"] = 0;
} else {
$obj = json_decode(json_encode($obj), true);
$params[$i]["status"] =
$obj["version"]["versionName"] . " sürümü mevcut";
$params[$i]["updateAvailable"] = 1;
if (
$params[$i]["extension_id"] != null &&
count($obj["platforms"])
) {
$job = (new ExtensionUpdaterJob(
$params[$i]["extension_id"],
$obj["version"]["versionCode"],
$obj["platforms"][0]["downloadLink"]
))->onQueue('system_updater');
// Dispatch job right away.
$job_id = app(Dispatcher::class)->dispatch($job);
array_push($fileToWrite,[
"name" => substr($params[$i]["packageName"],6),
array_push($fileToWrite, [
"name" => substr($params[$i]["packageName"], 6),
"currentVersion" => $params[$i]["currentVersion"],
"newVersion" => $obj["version"]["versionName"],
"downloadLink" => $obj["platforms"][0]["downloadLink"],
"versionCode" => $obj["version"]["versionCode"],
"changeLog" => $obj["version"]["versionDescription"],
"extension_id" => $params[$i]["extension_id"]
"extension_id" => $params[$i]["extension_id"],
]);
}
}
}
if(count($fileToWrite)){
file_put_contents(storage_path("extension_updates"),json_encode($fileToWrite),JSON_PRETTY_PRINT);
if (count($fileToWrite)) {
file_put_contents(
storage_path("extension_updates"),
json_encode($fileToWrite),
JSON_PRETTY_PRINT
);
}
if ($returnRaw) {
return $params;
}
return respond($params);
}
private function getClient()
public function getClient()
{
if(!self::checkAccess(parse_url(env("MARKET_URL"))["host"])){
if(env("MARKET_URL") == null){
abort(504,"Market bağlantısı ayarlanmamış.");
if (!self::checkAccess(parse_url(env("MARKET_URL"))["host"])) {
if (env("MARKET_URL") == null) {
abort(504, "Market bağlantısı ayarlanmamış.");
}
abort(504,env("MARKET_URL") . " adresindeki markete bağlanılamadı!");
abort(
504,
env("MARKET_URL") . " adresindeki markete bağlanılamadı!"
);
}
return new Client([
"headers" => [
"Accept" => "application/json",
"Authorization" => "Bearer " . env("MARKET_ACCESS_TOKEN")
"Authorization" => "Bearer " . env("MARKET_ACCESS_TOKEN"),
],
"verify" => false
"verify" => false,
]);
}
}
......@@ -6266,16 +6266,16 @@
},
{
"name": "myclabs/deep-copy",
"version": "1.10.0",
"version": "1.10.1",
"source": {
"type": "git",
"url": "https://github.com/myclabs/DeepCopy.git",
"reference": "5796d127b0c4ff505b77455148ea9d5269d99758"
"reference": "969b211f9a51aa1f6c01d1d2aef56d3bd91598e5"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/5796d127b0c4ff505b77455148ea9d5269d99758",
"reference": "5796d127b0c4ff505b77455148ea9d5269d99758",
"url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/969b211f9a51aa1f6c01d1d2aef56d3bd91598e5",
"reference": "969b211f9a51aa1f6c01d1d2aef56d3bd91598e5",
"shasum": ""
},
"require": {
......@@ -6316,7 +6316,7 @@
"type": "tidelift"
}
],
"time": "2020-06-28T07:02:41+00:00"
"time": "2020-06-29T13:22:24+00:00"
},
{
"name": "nikic/php-parser",
......
......@@ -17,12 +17,12 @@
@case('error')
@case('health_problem')
@case('liman_update')
<a href="/bildirim/{{$notification->id}}" class="dropdown-item" style="color: #f56954;width: 100%">
<a onclick="partialPageRequest('/bildirim/{{$notification->id}}'); return false;" href="/bildirim/{{$notification->id}}" class="dropdown-item" style="color: #f56954;width: 100%">
{{$notification->title}}
</a>
@break
@default
<a href="/bildirim/{{$notification->id}}" class="dropdown-item" style="color: #00a65a;width: 100%">
<a onclick="partialPageRequest('/bildirim/{{$notification->id}}'); return false;" href="/bildirim/{{$notification->id}}" class="dropdown-item" style="color: #00a65a;width: 100%">
{{$notification->title}}
</a>
@break
......
......@@ -44,7 +44,7 @@
localStorage.displayedNots = JSON.stringify(displayedNots);
$(toastElement).click(function(){
partialPageRequest("/bildirim/" + data.id);
window.location.href = "/bildirim/" + data.id;
});
}
checkNotifications(data ? data.id : null);
......
<?php
$notification = \App\AdminNotification::where('id',(request('notification_id')))->first();
if(!$notification){
header("Location: /", true);
$notification = \App\AdminNotification::where(
'id',
request('notification_id')
)->first();
if (!$notification) {
header("Location: /", true);
exit();
}
switch ($notification->type) {
case "cert_request":
list($hostname, $port, $server_id) = explode(
":",
$notification->message
);
$url =
route('certificate_add_page') .
"?notification_id=$notification->id&hostname=$hostname&port=$port&server_id=$server_id";
header("Location: $url", true);
exit();
}
switch ($notification->type){
case "cert_request":
list($hostname, $port, $server_id) = explode(":",$notification->message);
$url = route('certificate_add_page') . "?notification_id=$notification->id&hostname=$hostname&port=$port&server_id=$server_id";
header("Location: $url", true);
exit();
break;
case "liman_update":
$url = route('settings') . "#update";
$notification->update([
"read" => "true"
]);
header("Location: $url", true);
exit();
break;
case "health_problem":
$url = route('settings') . "#health";
$notification->update([
"read" => "true"
]);
header("Location: $url", true);
exit();
break;
case "new_module":
$url = route('modules_index');
$notification->update([
"read" => "true"
]);
header("Location: $url", true);
exit();
break;
case "extension_update":
$url = route('settings') . "#extensions";
$notification->update([
"read" => "true"
]);
header("Location: $url", true);
exit();
break;
default:
break;
}
break;
case "liman_update":
$url = route('settings') . "#limanMarket";
$notification->update([
"read" => "true",
]);
header("Location: $url", true);
exit();
break;
case "health_problem":
$url = route('settings') . "#health";
$notification->update([
"read" => "true",
]);
header("Location: $url", true);
exit();
break;
case "new_module":
$url = route('modules_index');
$notification->update([
"read" => "true",
]);
header("Location: $url", true);
exit();
break;
case "extension_update":
$url = route('settings') . "#extensions";
$notification->update([
"read" => "true",
]);
header("Location: $url", true);
exit();
break;
default:
break;
}
?>
@extends('layouts.app')
......
......@@ -192,7 +192,7 @@
]).draw().node();
});
table.draw();
status.html("Güncellemeler başarıyla kontrol edildi...");
status.html("Güncellemeler başarıyla kontrol edildi");
status.attr("class","alert alert-success");
$("#marketLoading").fadeOut(0);
$("#marketTableWrapper").fadeIn(0);
......
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