2018-10-18 09:37:18 +00:00
|
|
|
<?php namespace App;
|
|
|
|
|
|
|
|
use GuzzleHttp\Exception\GuzzleException;
|
|
|
|
use GuzzleHttp\Client;
|
|
|
|
|
|
|
|
abstract class SupportedApps
|
|
|
|
{
|
|
|
|
|
2018-10-28 10:59:59 +00:00
|
|
|
protected $jar = false;
|
|
|
|
protected $method = 'GET';
|
|
|
|
|
|
|
|
public function appTest($url, $attrs = [])
|
2018-10-18 09:37:18 +00:00
|
|
|
{
|
2018-10-28 10:59:59 +00:00
|
|
|
$res = $this->execute($url, $attrs);
|
2018-10-21 12:23:23 +00:00
|
|
|
switch($res->getStatusCode()) {
|
|
|
|
case 200:
|
2018-10-28 10:59:59 +00:00
|
|
|
$status = 'Successfully communicated with the API';
|
2018-10-21 12:23:23 +00:00
|
|
|
break;
|
|
|
|
case 401:
|
2018-10-28 10:59:59 +00:00
|
|
|
$status = 'Failed: Invalid credentials';
|
2018-10-21 12:23:23 +00:00
|
|
|
break;
|
|
|
|
case 404:
|
2018-10-28 10:59:59 +00:00
|
|
|
$status = 'Failed: Please make sure your URL is correct and that there is a trailing slash';
|
2018-10-21 12:23:23 +00:00
|
|
|
break;
|
|
|
|
default:
|
2018-10-28 10:59:59 +00:00
|
|
|
$status = 'Something went wrong... Code: '.$res->getStatusCode();
|
2018-10-21 12:23:23 +00:00
|
|
|
break;
|
|
|
|
}
|
2018-10-28 10:59:59 +00:00
|
|
|
return (object)[
|
|
|
|
'code' => $res->getStatusCode(),
|
|
|
|
'status' => $status,
|
|
|
|
'response' => $res->getBody(),
|
|
|
|
];
|
2018-10-18 09:37:18 +00:00
|
|
|
}
|
|
|
|
|
2018-10-28 10:59:59 +00:00
|
|
|
public function execute($url, $attrs = [])
|
2018-10-18 09:37:18 +00:00
|
|
|
{
|
2018-10-28 10:59:59 +00:00
|
|
|
$vars = [
|
|
|
|
'http_errors' => false,
|
|
|
|
'timeout' => 15,
|
|
|
|
'connect_timeout' => 15,
|
|
|
|
];
|
|
|
|
$client = new Client($vars);
|
|
|
|
|
|
|
|
try {
|
|
|
|
return $client->request($this->method, $url, $attrs);
|
|
|
|
} catch (\GuzzleHttp\Exception\ServerException $e) {
|
|
|
|
echo (string) $e->getResponse()->getBody();
|
|
|
|
}
|
2018-10-18 09:37:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function login()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function apiRequest($url)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-10-21 11:39:12 +00:00
|
|
|
|
|
|
|
public function getLiveStats($status, $data)
|
|
|
|
{
|
|
|
|
$className = get_class($this);
|
|
|
|
$explode = explode('\\', $className);
|
|
|
|
$name = end($explode);
|
|
|
|
|
|
|
|
$html = view('SupportedApps::'.$name.'.livestats', $data)->with('data', $data)->render();
|
|
|
|
return json_encode(['status' => $status, 'html' => $html]);
|
|
|
|
//return
|
|
|
|
}
|
|
|
|
|
2018-10-20 23:17:36 +00:00
|
|
|
public static function getList()
|
|
|
|
{
|
|
|
|
$list_url = 'https://apps.heimdall.site/list';
|
|
|
|
$client = new Client(['http_errors' => false, 'timeout' => 15, 'connect_timeout' => 15]);
|
2018-10-28 20:41:46 +00:00
|
|
|
return $client->request('GET', $list_url);
|
2018-10-20 23:17:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function getFiles($app)
|
|
|
|
{
|
|
|
|
$zipurl = $app->files;
|
|
|
|
$client = new Client(['http_errors' => false, 'timeout' => 60, 'connect_timeout' => 15]);
|
2018-10-28 20:41:46 +00:00
|
|
|
$res = $client->request('GET', $zipurl);
|
2018-10-20 23:17:36 +00:00
|
|
|
|
2018-10-23 14:53:56 +00:00
|
|
|
if(!file_exists(app_path('SupportedApps'))) {
|
|
|
|
mkdir(app_path('SupportedApps'), 0777, true);
|
|
|
|
}
|
|
|
|
|
2018-10-29 15:12:47 +00:00
|
|
|
$src = app_path('SupportedApps/'.className($app->name).'.zip');
|
2018-10-20 23:17:36 +00:00
|
|
|
file_put_contents($src, $res->getBody());
|
|
|
|
|
|
|
|
$zip = new \ZipArchive();
|
|
|
|
$x = $zip->open($src); // open the zip file to extract
|
|
|
|
if ($x === true) {
|
|
|
|
$zip->extractTo(app_path('SupportedApps')); // place in the directory with same name
|
|
|
|
$zip->close();
|
|
|
|
unlink($src); //Deleting the Zipped file
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function saveApp($details, $app)
|
|
|
|
{
|
2018-10-29 15:12:47 +00:00
|
|
|
$img_src = app_path('SupportedApps/'.className($details->name).'/'.$details->icon);
|
2018-10-29 15:24:47 +00:00
|
|
|
$img_dest = public_path('storage/supportedapps/'.$details->icon);
|
2018-10-23 14:53:56 +00:00
|
|
|
//die("i: ".$img_src);
|
2018-10-20 23:17:36 +00:00
|
|
|
copy($img_src, $img_dest);
|
|
|
|
|
2018-10-25 13:42:14 +00:00
|
|
|
$app->appid = $details->appid;
|
2018-10-20 23:17:36 +00:00
|
|
|
$app->name = $details->name;
|
2018-10-25 13:42:14 +00:00
|
|
|
$app->sha = $details->sha ?? null;
|
2018-10-21 11:39:12 +00:00
|
|
|
$app->icon = 'supportedapps/'.$details->icon;
|
2018-10-20 23:17:36 +00:00
|
|
|
$app->website = $details->website;
|
|
|
|
$app->license = $details->license;
|
|
|
|
$app->description = $details->description;
|
2018-10-21 11:39:12 +00:00
|
|
|
|
|
|
|
$appclass = $app->class();
|
|
|
|
$application = new $appclass;
|
|
|
|
$enhanced = (bool)($application instanceof \App\EnhancedApps);
|
|
|
|
|
|
|
|
$app->enhanced = $enhanced;
|
2018-10-20 23:17:36 +00:00
|
|
|
$app->tile_background = $details->tile_background;
|
|
|
|
$app->save();
|
|
|
|
}
|
|
|
|
|
2018-10-18 09:37:18 +00:00
|
|
|
}
|