This repository has been archived by the owner on Nov 25, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change url.shorten hook to make it more versatile.
First implementation of gateway.
- Loading branch information
Showing
7 changed files
with
231 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
<?php | ||
/* | ||
* Copyright 2007-2016 Charles du Jeu - Abstrium SAS <team (at) pyd.io> | ||
* This file is part of Pydio. | ||
* | ||
* Pydio is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Pydio is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with Pydio. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* The latest code can be found at <https://pydio.com>. | ||
*/ | ||
|
||
namespace Pydio\LinkShortener; | ||
|
||
use GuzzleHttp\Exception\RequestException; | ||
use Pydio\Core\Model\ContextInterface; | ||
use GuzzleHttp\Client; | ||
|
||
use Pydio\Core\PluginFramework\Plugin; | ||
use Pydio\Core\Services\ApplicationState; | ||
use Pydio\Share\Model\ShareLink; | ||
use Pydio\Share\View\PublicAccessManager; | ||
|
||
defined('AJXP_EXEC') or die( 'Access not allowed'); | ||
|
||
/** | ||
* FileGateway implementation | ||
* @package Pydio\LinkShortener | ||
*/ | ||
class FileGateway extends Plugin | ||
{ | ||
private $servers = [ | ||
"filesend" => "https://filesend.cc", | ||
"yourshare" => "https://yoursha.re", | ||
]; | ||
|
||
/** | ||
* @param ContextInterface $ctx | ||
* @param ShareLink $shareObject | ||
* @param PublicAccessManager $publicAccessManager | ||
*/ | ||
public function processShortenHook(ContextInterface $ctx, &$shareObject, $publicAccessManager){ | ||
|
||
$server = $this->getContextualOption($ctx, "GATEWAY_SERVER"); | ||
$apiKey = $this->getContextualOption($ctx, "API_KEY"); | ||
$apiSecret = $this->getContextualOption($ctx, "API_SECRET"); | ||
if(empty($server) || empty($apiKey) || empty($apiSecret)){ | ||
return; | ||
} | ||
if(!isSet($this->servers[$server])){ | ||
$this->logError("FileGateway", "Cannot find valid server for key ".$server); | ||
return; | ||
} | ||
|
||
$data = [ | ||
"hash" => $shareObject->getHash(), | ||
"base" => ApplicationState::detectServerURL(true), | ||
"main_endpoint" => "proxy.php?hash={hash}", | ||
"dl_endpoint" => "proxy.php?hash={hash}&dl=true&file={path}", | ||
"shorten_type" => "full", | ||
]; | ||
$headers['Authorization'] = 'Basic '.base64_encode($apiKey.":".$apiSecret); | ||
$client = new Client([]); | ||
$request = $client->createRequest("POST", $this->servers[$server], [ | ||
"timeout" => 5, | ||
"headers" => $headers, | ||
"json" => $data | ||
]); | ||
|
||
try{ | ||
$response = $client->send($request); | ||
}catch (RequestException $r){ | ||
$this->logError("FileGateway", "There was an error while trying to submit a request to the server: ".$r->getMessage()); | ||
return; | ||
} | ||
$body = $response->getBody(); | ||
$json = json_decode($body, true); | ||
if(!empty($json)){ | ||
$newUrl = $json["public_url"]; | ||
$shareObject->setShortFormUrl($newUrl); | ||
$shareObject->save(); | ||
}else{ | ||
$this->logError("FileGateway", "There was an error while trying to decode the server response: ".$body); | ||
} | ||
|
||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
/* | ||
* Copyright 2007-2016 Charles du Jeu - Abstrium SAS <team (at) pyd.io> | ||
* This file is part of Pydio. | ||
* | ||
* Pydio is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Pydio is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with Pydio. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* The latest code can be found at <https://pydio.com>. | ||
*/ | ||
|
||
$mess=array( | ||
"File Gateway" => "File Gateway", | ||
"Shorten links and serve them proxied by Pydio hosted service" => "Shorten links and serve them proxied by Pydio hosted service", | ||
"Api Key" => "Api Key", | ||
"Api Key as provided in your Pydio.com account" => "Api Key as provided in your Pydio.com account", | ||
"Api Secret" => "Api Secret", | ||
"Api Secret, as provided in your Pydio.com account" => "Api Secret, as provided in your Pydio.com account", | ||
"Gateway Server" => "Gateway Server", | ||
"Choose on which server you want the link to be proxied. You may choose depending on your region." => "Choose on which server you want the link to be proxied. You may choose depending on your region.", | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
/* | ||
* Copyright 2007-2016 Charles du Jeu - Abstrium SAS <team (at) pyd.io> | ||
* This file is part of Pydio. | ||
* | ||
* Pydio is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Pydio is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with Pydio. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* The latest code can be found at <https://pydio.com>. | ||
*/ | ||
|
||
$mess=array( | ||
"File Gateway" => "File Gateway", | ||
"Shorten links and serve them proxied by Pydio hosted service" => "Raccourcir les liens et les servir via le service hébergé de proxy de Pydio.", | ||
"Api Key" => "Clé d'API", | ||
"Api Key as provided in your Pydio.com account" => "La clé d'API disponible dans votre compte Pydio.com", | ||
"Api Secret" => "Clé secrète", | ||
"Api Secret, as provided in your Pydio.com account" => "La clé secrète, disponible dans votre compte Pydio.com", | ||
"Gateway Server" => "Serveur FileGateway", | ||
"Choose on which server you want the link to be proxied. You may choose depending on your region." => "Choisir sur quel serveur vous désirez héberger vos liens, en fonction de votre région.", | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ajxp_plugin id="shorten.gateway" enabled="false" label="CONF_MESSAGE[File Gateway]" description="CONF_MESSAGE[Shorten links and serve them proxied by Pydio hosted service]" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="file:../core.ajaxplorer/ajxp_registry.xsd"> | ||
<plugin_info> | ||
<plugin_author>Charles du Jeu</plugin_author> | ||
</plugin_info> | ||
<client_settings> | ||
<resources> | ||
<i18n namespace="gateway_shortener" path="plugins/shorten.gateway/i18n" /> | ||
</resources> | ||
</client_settings> | ||
<server_settings> | ||
<global_param name="API_KEY" type="string" label="CONF_MESSAGE[Api Key]" description="CONF_MESSAGE[Api Key as provided in your Pydio.com account]"/> | ||
<global_param name="API_SECRET" type="password" label="CONF_MESSAGE[Api Secret]" description="CONF_MESSAGE[Api Secret, as provided in your Pydio.com account]"/> | ||
<global_param name="GATEWAY_SERVER" type="select" choices="filesend|Filesend.cc (EU Region),yourshare|Yoursha.re (US Region)" label="CONF_MESSAGE[Gateway Server]" description="CONF_MESSAGE[Choose on which server you want the link to be proxied. You may choose depending on your region.]"/> | ||
</server_settings> | ||
<registry_contributions> | ||
<hooks> | ||
<serverCallback methodName="processShortenHook" hookName="url.shorten"/> | ||
</hooks> | ||
</registry_contributions> | ||
<class_definition filename="plugins/shorten.gateway/FileGateway.php" classname="Pydio\LinkShortener\FileGateway"/> | ||
<dependencies> | ||
<activePlugin pluginName="action.share"/> | ||
</dependencies> | ||
</ajxp_plugin> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<p> | ||
This plugin allows you to use the exclusive Pydio hosted service, FileGateway. By shortening AND proxying your public links | ||
to your servers, FileGateway allows to you securely share resources with external users via public links without the risk of | ||
revealing your Pydio server URL. | ||
</p> | ||
<p> | ||
To be able to use this service, please buy a subscription on Pydio.com website and grab the API Keys / API Secret that will be available | ||
in your account to configure the plugin. You can choose on which region you wish your links to be "hosted", either in the US (filesend.cc) | ||
or in Europe (yoursha.re). | ||
</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters