Universal file server and file storage service for YOURLS
Provides links to files while obfuscating filesystem paths, allowing easy, secure access to files between plugins or from 3rd party scripts.
Given the following parameters:
- key => Access key
- id => plugin ID
- fn => filename
This script will:
- Retrieve the file store location per plugin, can be from a database
- Retrieve a particular file from the store (in or preferably out of the server doc root)
- Return a time limited link to that file
- Copy the
usrv
folder of this repo into/path/to/YOURLS/user/plugins/
- Enable the plugin as any other.
The script should automatically
- Copy
srv.php
to/path/to/YOURLS/pages/
- Install a database table to store uploaded file data
- Create the default cache location
At once you should be able to
- Upload files via a web browser that will be accessible via U-SRV
- Call U-SRV with a
GET
request fromhttps://sho.rt/srv/
- Use any plugin that utilizes U-SRV (listed below)
To be sent as a GET
request. All parameters are required.
- eg.
https://sho.rt/srv/?id=ID_VALUE&key=KEY_VALUE&fn=FILE_NAME_VALUE
The url's created with this script live for a maximum of 1 minute. This helps prevent unwanted hotlinking, etc.
To set up your own access key just add something equivalent to the following to your plugin or script:
<?php
$now = date("YmdGi");
$id = 'My_Fancy_Plugin';
$key = md5($now . $id);
?>
U-SRV will also set a cookie for use with javascript, etc. as
$cname = "usrv_" . $id;
where $cname
is the name of the cookie.
Add a new case with an arbitrary ID and file store location to the ID section of srv.php
. Send this same ID with the GET
request.
- In this example the store location is retrieved from a database as a typical
YOURLS
option:
case 'ID_VALUE':
$path = yourls_get_option('YOUR_CACHE_PATH');
break;
- In this example the store filepath is set explicitly:
case 'ID_VALUE':
$path = '/path/to/your/files/');
break;
The filename is set explicitly as a regular GET
value.
Mime types must be set expllicitly in the script in order to set header information correctly, and are restricted as an extra security measure.
To add a new filetype, just add a new case to the Mime Types section of srv.php
, check MIMETYPES.md for an exhaustive (?) list of examples.
- In order to allow the passing of a
tar.gz
file, add the following: - 'case "gz": $ctype="application/x-gzip"; break;`
- v2.0.0 and on is a complete rewrite. It is still backwards compatible with plugins that have not yet been updated.
- U-SRV is pre-configured for the default filetypes used by the YOURLS IQRCodes and Snapshot Visual Preview plugins.
- As should be obviouse, this script can be easily modified for use outside of the YOURLS environment.
- Increasing apache's SSL Renegotiation Buffer Size may save you a headache. Simply add something like the following to the host file:
<location '/admin/plugins.php' >
SSLRenegBufferSize 10486000
</location>
- YOURLS-Snapshot - To serve images
- YOURLS-IQRCodes - To serve code images
- YOURLS-Compliance - To retrieve Snapshot images
- YOURLS-rscrub - To retrieve Snapshot images and deliver
rscrub.js
All of my published code is developed and maintained in spare time, if you would like to support development of this, or any of my published code, I have set up a Liberpay account for just this purpose. Thank you.
===========================
Copyright (C) 2016 - 2018 Josh Panter
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.