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
Use (with YOURLS)
- Copy the
usrvfolder of this repo into
- Enable the plugin as any other.
The script should automatically
- 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
- Use any plugin that utilizes U-SRV (listed below)
To be sent as a
GET request. All parameters are required.
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); ?>
$cname = "usrv_" . $id;
$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
- In this example the store location is retrieved from a database as a typical
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
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.gzfile, add the following: - 'case "gz": $ctype="application/x-gzip"; break;`
- Compatability with YOURLS 1.7.9 + (tested against this commit)
- v2.0.0 and on is a complete rewrite and is not backwards compatible. Update your plugins accordingly.
- 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>
define( 'USRV_DB_UPDATE', true );in
config.phpin order to update DB from versions earlier than 1.5.0. After one page load delte this option.
Plugins using this script
- 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
Copyright (C) 2016 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/>.