ajout heimdall
This commit is contained in:
106
heimdall/config/www/SupportedApps/Nextcloud/Nextcloud.php
Executable file
106
heimdall/config/www/SupportedApps/Nextcloud/Nextcloud.php
Executable file
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
|
||||
namespace App\SupportedApps\Nextcloud;
|
||||
|
||||
class Nextcloud extends \App\SupportedApps implements \App\EnhancedApps
|
||||
{
|
||||
public $config;
|
||||
|
||||
//protected $login_first = true; // Uncomment if api requests need to be authed first
|
||||
//protected $method = 'POST'; // Uncomment if requests to the API should be set by POST
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
//$this->jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set
|
||||
}
|
||||
|
||||
public function getHeaders()
|
||||
{
|
||||
$username = $this->config->username;
|
||||
$password = $this->config->password;
|
||||
|
||||
$attrs["headers"] = [
|
||||
"Authorization" =>
|
||||
"Basic " . base64_encode($username . ":" . $password),
|
||||
"OCS-APIRequest" => "true",
|
||||
];
|
||||
return $attrs;
|
||||
}
|
||||
|
||||
public function test()
|
||||
{
|
||||
$username = $this->config->username;
|
||||
|
||||
$test = parent::appTest(
|
||||
$this->url("/ocs/v1.php/cloud/users/" . $username . "?format=json"),
|
||||
$this->getHeaders()
|
||||
);
|
||||
echo $test->status;
|
||||
}
|
||||
|
||||
public function livestats()
|
||||
{
|
||||
$status = "inactive";
|
||||
|
||||
$username = $this->config->username;
|
||||
$res = parent::execute(
|
||||
$this->url("/ocs/v1.php/cloud/users/" . $username . "?format=json"),
|
||||
$this->getHeaders()
|
||||
);
|
||||
$details = json_decode($res->getBody());
|
||||
|
||||
$data = ["visiblestats" => []];
|
||||
|
||||
if ($details) {
|
||||
foreach ($this->config->availablestats as $stat) {
|
||||
if (!isset(self::getAvailableStats()[$stat])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$newstat = new \stdClass();
|
||||
$newstat->title = self::getAvailableStats()[$stat];
|
||||
$newstat->value = self::formatNumberUsingStat(
|
||||
$stat,
|
||||
$details->ocs->data->quota->{$stat}
|
||||
);
|
||||
|
||||
$data["visiblestats"][] = $newstat;
|
||||
}
|
||||
}
|
||||
|
||||
return parent::getLiveStats($status, $data);
|
||||
}
|
||||
public function url($endpoint)
|
||||
{
|
||||
$api_url = parent::normaliseurl($this->config->url);
|
||||
return $api_url . $endpoint;
|
||||
}
|
||||
|
||||
public static function getAvailableStats()
|
||||
{
|
||||
return [
|
||||
"relative" => "Usage",
|
||||
"used" => "Used Space",
|
||||
"free" => "Free Space",
|
||||
"total" => "Total Space",
|
||||
];
|
||||
}
|
||||
|
||||
private static function formatNumberUsingStat($stat, $number)
|
||||
{
|
||||
if (!isset($number)) {
|
||||
return "N/A";
|
||||
}
|
||||
|
||||
switch ($stat) {
|
||||
case "free":
|
||||
case "used":
|
||||
case "total":
|
||||
return format_bytes($number, false, "<span>", "</span>");
|
||||
case "relative":
|
||||
return number_format($number, 1) . "<span>%</span>";
|
||||
default:
|
||||
return number_format($number);
|
||||
}
|
||||
}
|
||||
}
|
||||
32
heimdall/config/www/SupportedApps/Nextcloud/app.json
Executable file
32
heimdall/config/www/SupportedApps/Nextcloud/app.json
Executable file
@@ -0,0 +1,32 @@
|
||||
{
|
||||
"appid": "f2baa52d02ca888455ce47823f47bf372d5eecb3",
|
||||
"name": "Nextcloud",
|
||||
"website": "https://nextcloud.com",
|
||||
"license": "GNU Affero General Public License v3.0 only",
|
||||
"description": "Nextcloud is an open source, self-hosted file share and communication platform. Access and sync your files, contacts, calendars and communicate and collaborate across your devices.",
|
||||
"enhanced": true,
|
||||
"tile_background": "light",
|
||||
"icon": "nextcloud.svg",
|
||||
"config": {
|
||||
"type": "basic_auth",
|
||||
"additional_headers": {
|
||||
"OCS-APIRequest": "true"
|
||||
},
|
||||
"stat1": {
|
||||
"name": "Total",
|
||||
"url": ":url:ocs/v1.php/cloud/users/:username:?format=json",
|
||||
"key": "ocs.data.quota.total",
|
||||
"filter": "size",
|
||||
"updateOnChange": "No",
|
||||
"suffix": ""
|
||||
},
|
||||
"stat2": {
|
||||
"name": "Used",
|
||||
"url": ":url:ocs/v1.php/cloud/users/:username:?format=json",
|
||||
"key": "ocs.data.quota.used",
|
||||
"filter": "size",
|
||||
"updateOnChange": "No",
|
||||
"suffix": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
23
heimdall/config/www/SupportedApps/Nextcloud/config.blade.php
Executable file
23
heimdall/config/www/SupportedApps/Nextcloud/config.blade.php
Executable file
@@ -0,0 +1,23 @@
|
||||
<h2>{{ __('app.apps.config') }} ({{ __('app.optional') }}) @include('items.enable')</h2>
|
||||
<div class="items">
|
||||
<div class="input">
|
||||
<label>{{ strtoupper(__('app.url')) }}</label>
|
||||
{!! Form::text('config[override_url]', isset($item) ? $item->getconfig()->override_url : null, ['placeholder' => __('app.apps.override'), 'id' => 'override_url', 'class' => 'form-control']) !!}
|
||||
</div>
|
||||
<div class="input">
|
||||
<label>{{ __('app.apps.username') }}</label>
|
||||
{!! Form::text('config[username]', isset($item) ? $item->getconfig()->username : null, ['placeholder' => __('app.apps.username'), 'data-config' => 'username', 'class' => 'form-control config-item']) !!}
|
||||
</div>
|
||||
<div class="input">
|
||||
<label>{{ __('app.apps.password') }}</label>
|
||||
{!! Form::input('password', 'config[password]', '', ['placeholder' => __('app.apps.password'), 'data-config' => 'password', 'class' => 'form-control config-item']) !!}
|
||||
<small>Security » App Password</small>
|
||||
</div>
|
||||
<div class="input">
|
||||
<label>Stats to show</label>
|
||||
{!! Form::select('config[availablestats][]', App\SupportedApps\Nextcloud\Nextcloud::getAvailableStats(), isset($item) ? $item->getConfig()->availablestats ?? null : null, ['multiple' => 'multiple']) !!}
|
||||
</div>
|
||||
<div class="input">
|
||||
<button style="margin-top: 32px;" class="btn test" id="test_config">Test</button>
|
||||
</div>
|
||||
</div>
|
||||
8
heimdall/config/www/SupportedApps/Nextcloud/livestats.blade.php
Executable file
8
heimdall/config/www/SupportedApps/Nextcloud/livestats.blade.php
Executable file
@@ -0,0 +1,8 @@
|
||||
<ul class="livestats">
|
||||
@foreach ($visiblestats as $stat)
|
||||
<li>
|
||||
<span class="title">{!! $stat->title !!}</span>
|
||||
<strong>{!! $stat->value !!}</strong>
|
||||
</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
BIN
heimdall/config/www/SupportedApps/Nextcloud/nextcloud.png
Executable file
BIN
heimdall/config/www/SupportedApps/Nextcloud/nextcloud.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 6.0 KiB |
Reference in New Issue
Block a user