Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasbestle committed Aug 25, 2018
0 parents commit 5b03858
Show file tree
Hide file tree
Showing 69 changed files with 7,166 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .coveralls.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
service_name: travis-ci
coverage_clover: build/logs/clover.xml
json_path: build/logs/coveralls-upload.json
27 changes: 27 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# This file is for unifying the coding style for different editors and IDEs
# editorconfig.org

# PHP PSR-2 Coding Standards
# http://www.php-fig.org/psr/psr-2/

root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = space
indent_size = 2

[*.php]
indent_size = 4

[etc/**.php]
indent_size = 2

[*.{json,txt,md}]
insert_final_newline = false

[*.md]
trim_trailing_whitespace = false
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.DS_Store

/tests/coverage
/vendor

/.php_cs.cache
/dist.zip
39 changes: 39 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
language: php

os:
- linux

sudo: false

php:
- 7.1
- 7.2

install:
# Install composer packages, will also trigger dump-autoload
- composer self-update
- composer install --no-interaction

# Install coveralls.phar
- wget -c -nc --retry-connrefused --tries=0 https://github.com/satooshi/php-coveralls/releases/download/v1.0.1/coveralls.phar
- chmod +x coveralls.phar
- php coveralls.phar --version

before_script:
- mkdir -p build/logs
- ls -al

script:
- phpunit --coverage-clover build/logs/clover.xml
- phpenv config-rm xdebug.ini
- vendor/bin/php-cs-fixer fix src/ --verbose --diff --dry-run

after_success:
- travis_retry php coveralls.phar -v

cache:
directories:
- $HOME/.php-cs-fixer

matrix:
fast_finish: true
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# The MIT License (MIT)

Copyright (c) 2018 Lukas Bestle <https://lukasbestle.com>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
98 changes: 98 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# Shareable

[![Build Status](https://travis-ci.com/lukasbestle/shareable.svg?branch=master)](https://travis-ci.com/lukasbestle/shareable) [![Coverage Status](https://coveralls.io/repos/github/lukasbestle/shareable/badge.svg?branch=master)](https://coveralls.io/github/lukasbestle/shareable?branch=master)

> Simple NoDB file upload app
## Screenshots

![Screenshots of the admin interface](screenshots.png)

## Features

- Completely file-based and very fast
- Simple admin interface to upload, publish and manage files with support for user permissions
- Support for uploads using SFTP/SCP or other protocols into an inbox directory on the server
- Support for automatic randomized URLs as well as completely custom URLs
- Support for time-based publishing and expiry
- Support for auto-expiry based on download inactivity
- Automatic cleanup of expired files using a Cronjob script
- Compatible with pull zone CDNs

## Installation

1. Download the [latest release ZIP](https://github.com/lukasbestle/shareable/releases) (includes all dependencies).
Alternatively you can clone the Git repository and install the dependencies with `composer install --no-dev`.
2. Upload the project to your webserver.
3. Shareable uses two webroots:
- Point the webserver for your main domain at the `public` directory.
- Point the webserver for your file domain/CDN at the `data/files` directory.
4. Copy the file `config/config.example.php` to `config/config.php` and adapt it to your needs.

Shareable requires PHP 7.1+.

## Usage

The admin interface of Shareable can be reached at the URL `https://example.com/_admin`. It will prompt for user credentials using HTTP Basic authentication.

### File upload

You can upload files directly in the admin interface on the **Inbox** screen. All uploaded files are stored in the `data/inbox` directory. Therefore it is also possible to place files into this directory manually (e.g. with SFTP or SCP).

### Publishing files

The next step is to publish the previously uploaded files. You can do this by clicking on the file in the **Inbox list**.
You will be prompted for the following options:

- **Created**
The time when the file should be published. The file won't be accessible before that time. This is useful if you want to upload files in advance and schedule their release.
If you leave this field empty, the file will immediately be public.
- **Expires**
The time when the file should expire. After that time the file won't be accessible.
If you remove the default value and leave the field empty, the file will never expire.
- **ID**
The slug in the shareable file URL.
By default it will be randomly generated as a six-char alphanumerical string. The random ID includes the current date in an encoded form, so the random ID will never be the same as one generated in the past.
If you want a custom ID for sharing, you can configure it here.
- **Timeout**
An inactivity timeout. If the file hasn't been downloaded for this amount of time, the file is considered expired.
If you remove the default value and leave the field empty, no timeout is set.

### Sharing files

You can now access your uploaded files at `https://example/<id>`.
If you want to share the URL, you can copy it from the link in the **Items** table in the ID column.

### Deleting expired files

Shareable doesn't delete expired files by default, but expired files are no longer accessible via their URL.

However it makes sense to clean up expired files by deleting the file and its metadata. For that, Shareable ships with the script in `bin/cleanup`. The script deletes all files that are expired based on their expiry date or timeout. It also outputs warnings if files and metadata are out of sync.

It is recommended to call this script daily from a Cronjob:

```
@daily /path/to/your/bin/cleanup
```

If you prefer, you can also call the script manually instead.

### Using Shareable with a CDN

The published files are stored in the `data/files` directory. You can directly point a subdomain at this directory and let your webserver serve the static files.

It is also possible to use a pull zone CDN:

1. Point your local webserver at the `data/files` directory. You can use any subdomain for this.
2. Set up a pull zone at your CDN provider by pointing the CDN to the file subdomain you set up in step 1.
3. Set the `fileUrl` option in Shareable's config to the URL of the CDN.

Shareable will now redirect file requests to the CDN instead of to your local file subdomain.

## License

<http://www.opensource.org/licenses/mit-license.php>

## Author

Lukas Bestle <[email protected]>
17 changes: 17 additions & 0 deletions bin/cleanup
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env php
<?php

/**
* cleanup
*
* Verifies the integrity of the items and
* files and cleans up expired items
*/

require_once(__DIR__ . '/../bootstrap.php');

$warnings = $app->items()->cleanUp();
if ($warnings) {
fwrite(STDERR, $warnings);
exit(1);
}
8 changes: 8 additions & 0 deletions bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace LukasBestle\Shareable;

require_once(__DIR__ . '/vendor/autoload.php');

$config = require_once(__DIR__ . '/config/config.php');
$app = new App($config);
51 changes: 51 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"name": "lukasbestle/shareable",
"description": "Simple NoDB file upload app",
"require": {
"php": ">=7.1.0",
"getkirby/cms": "dev-master"
},
"require-dev": {
"phpunit/phpunit": "^7.0",
"friendsofphp/php-cs-fixer": "^2.11.1"
},
"autoload": {
"psr-4": {
"LukasBestle\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"LukasBestle\\": "tests/"
}
},
"minimum-stability": "dev",
"repositories": [
{
"type": "vcs",
"url": "https://github.com/k-next/kirby"
}
],
"scripts": {
"test": "composer install; vendor/bin/phpunit --stderr --coverage-html=tests/coverage",
"fix": "composer install; vendor/bin/php-cs-fixer fix ./src/",
"zip": "composer install --no-dev -a; composer archive --file dist --format zip"
},
"archive": {
"exclude": [
".DS_Store",
"/.coveralls.yml",
"/.php_cs.cache",
"/.travis.yml",
"/composer.lock",
"/config/*",
"!/config/config.example.php",
"/data/*/*",
"/dist.zip",
"/phpunit.xml.dist",
"/tests",
"!/vendor",
"/vendor/**/.git"
]
}
}
Loading

0 comments on commit 5b03858

Please sign in to comment.