2018-10-18 09:37:18 +00:00
|
|
|
<?php namespace App;
|
|
|
|
|
|
|
|
use GuzzleHttp\Exception\GuzzleException;
|
|
|
|
use GuzzleHttp\Client;
|
|
|
|
|
|
|
|
abstract class SupportedApps
|
|
|
|
{
|
|
|
|
|
2018-10-21 12:23:23 +00:00
|
|
|
public function appTest($url, $requiresLoginFirst=false)
|
2018-10-18 09:37:18 +00:00
|
|
|
{
|
2018-10-21 12:23:23 +00:00
|
|
|
$res = $this->execute($url, $requiresLoginFirst);
|
|
|
|
switch($res->getStatusCode()) {
|
|
|
|
case 200:
|
|
|
|
echo 'Successfully connected to the API';
|
|
|
|
break;
|
|
|
|
case 401:
|
|
|
|
echo 'Failed: Invalid credentials';
|
|
|
|
break;
|
|
|
|
case 404:
|
|
|
|
echo 'Failed: Please make sure your URL is correct and that there is a trailing slash';
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
echo 'Something went wrong... Code: '.$res->getStatusCode();
|
|
|
|
break;
|
|
|
|
}
|
2018-10-18 09:37:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function execute($url, $requiresLoginFirst=false)
|
|
|
|
{
|
2018-10-21 11:39:12 +00:00
|
|
|
if($requiresLoginFirst) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$client = new Client(['http_errors' => false, 'timeout' => 15, 'connect_timeout' => 15]);
|
|
|
|
return $client->request('GET', $url);
|
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]);
|
|
|
|
return $client->request('GET', $list_url);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function getFiles($app)
|
|
|
|
{
|
|
|
|
$zipurl = $app->files;
|
|
|
|
$client = new Client(['http_errors' => false, 'timeout' => 60, 'connect_timeout' => 15]);
|
|
|
|
$res = $client->request('GET', $zipurl);
|
|
|
|
|
|
|
|
$src = app_path('SupportedApps/'.$app->name.'.zip');
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
$img_src = app_path('SupportedApps/'.$details->name.'/'.$details->icon);
|
|
|
|
$img_dest = public_path('storage/supportedapps/'.$details->icon);
|
|
|
|
copy($img_src, $img_dest);
|
|
|
|
|
|
|
|
$app->name = $details->name;
|
|
|
|
$app->sha = $details->sha;
|
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
|
|
|
}
|