This commit is contained in:
alcalbg
2022-10-12 10:49:45 +00:00
parent 78a77cc193
commit 21497025de
217 changed files with 49804 additions and 0 deletions

127
docs/configuration/auth.md Normal file
View File

@@ -0,0 +1,127 @@
---
currentMenu: auth
---
## Default Auth service
By default, users are stored in json file. For some use-cases, this is enough. It also makes this app lightweight since no database is required.
Default handler accepts only file name parameter. This file should be writable by the web server.
```
'Filegator\Services\Auth\AuthInterface' => [
'handler' => '\Filegator\Services\Auth\Adapters\JsonFile',
'config' => [
'file' => __DIR__.'/private/users.json',
],
],
```
## Configuring Auth service to use database
You can use mysql database to store your users.
First, create a table `users` with this sql query:
```
CREATE TABLE `users` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`username` varchar(255) NOT NULL,
`name` varchar(255) NOT NULL,
`role` varchar(20) NOT NULL,
`permissions` varchar(200) NOT NULL,
`homedir` varchar(2000) NOT NULL,
`password` varchar(255) NOT NULL,
PRIMARY KEY (`id`),
KEY `username` (`username`)
) CHARSET=utf8 COLLATE=utf8_bin;
```
Then, import default users with sql query:
```
INSERT INTO `users` (`username`, `name`, `role`, `permissions`, `homedir`, `password`)
VALUES
('guest', 'Guest', 'guest', '', '/', ''),
('admin', 'Admin', 'admin', 'read|write|upload|download|batchdownload|zip', '/', '$2y$10$Nu35w4pteLfc7BDCIkDPkecjw8wsH8Y2GMfIewUbXLT7zzW6WOxwq');
```
At the end, open `configuration.php` and update AuthInterface handler to reflect your database settings:
```
'Filegator\Services\Auth\AuthInterface' => [
'handler' => '\Filegator\Services\Auth\Adapters\Database',
'config' => [
'driver' => 'mysqli',
'host' => 'localhost',
'username' => 'root',
'password' => 'password',
'database' => 'filegator',
],
],
```
## Configuring Auth service to use WordPress
Replace your current Auth handler in `configuration.php` file like this:
```
'Filegator\Services\Auth\AuthInterface' => [
'handler' => '\Filegator\Services\Auth\Adapters\WPAuth',
'config' => [
'wp_dir' => '/var/www/my_wordpress_site/',
'permissions' => ['read', 'write', 'upload', 'download', 'batchdownload', 'zip'],
'private_repos' => false,
],
],
```
Adjust in the config above:
- `wp_dir` should be the directory path of your wordpress installation
- `permissions` is the array of permissions given to each user
- `private_repos` each user will have its own sub folder, admin will see everything (false/true)
Note: With more recent versions of FileGator you can set `guest_redirection` in your `configuration.php` to redirect logged-out users back to your WP site:
```
'frontend_config' => [
...
'guest_redirection' => 'http://example.com/wp-admin/',
...
]
```
## Configuring Auth service to use LDAP
Replace your current Auth handler in `configuration.php` file like this:
```
'Filegator\Services\Auth\AuthInterface' => [
'handler' => '\Filegator\Services\Auth\Adapters\LDAP',
'config' => [
'private_repos' => false,
'ldap_server'=>'ldap://192.168.1.1',
'ldap_bindDN'=>'uid=ldapbinduser,cn=users,dc=ldap,dc=example,dc=com',
'ldap_bindPass'=>'ldapbinduser-password',
'ldap_baseDN'=>'cn=users,dc=ldap,dc=example,dc=com',
'ldap_filter'=>'(uid=*)', //ex: 'ldap_filter'=>'(&(uid=*)(memberOf=cn=administrators,cn=groups,dc=ldap,dc=example,dc=com))',
'ldap_attributes' => ["uid","cn","dn"],
'ldap_userFieldMapping'=> [
'username' =>'uid',
'username_AddDomain' =>'@example.com',
'username_RemoveDomains' =>['@department1.example.com', '@department2.example.com'],
'name' =>'cn',
'userDN' =>'dn',
'default_permissions' => 'read|write|upload|download|batchdownload|zip',
'admin_usernames' =>['user1', 'user2'],
],
],
],
```
## Custom Authentication using 3rd party
If you want to use FileGator as a part of another application, you probably already have users stored somewhere else. What you need in this case is to build a new custom Auth adapter that matches the [AuthInterface](https://github.com/filegator/filegator/blob/master/backend/Services/Auth/AuthInterface.php) to connect those two. This new adapter will try to authenticate users in your application and translate each user into filegator [User](https://github.com/filegator/filegator/blob/master/backend/Services/Auth/User.php) object.
## API authentication
Front-end will use session based authentication to authenticate and consume the back-end.
Note: The application will not work if you disable cookies.

View File

@@ -0,0 +1,76 @@
---
currentMenu: basic
---
## Basic
All services are set with reasonable defaults. For regular users there is no need to change anything. The script should work out of the box.
You can edit `configuration.php` file to change the basic things like logo image, title, language and upload restrictions.
Note: if you've made a mistake in configuration file (forgot to close a quote?) the script will fail to load or throw an error. Please use provided default `configuration_sample.php` to put everything back to normal.
```
'frontend_config' => [
'app_name' => 'FileGator',
'app_version' => APP_VERSION,
'language' => 'english',
'logo' => 'https://filegator.io/filegator_logo.svg',
'upload_max_size' => 100 * 1024 * 1024, // 100MB
'upload_chunk_size' => 1 * 1024 * 1024, // 1MB
'upload_simultaneous' => 3,
'default_archive_name' => 'archive.zip',
'editable' => ['.txt', '.css', '.js', '.ts', '.html', '.php', '.json', '.md'],
'date_format' => 'YY/MM/DD hh:mm:ss', // see: https://momentjs.com/docs/#/displaying/format/
'guest_redirection' => '', // useful for external auth adapters
'search_simultaneous' => 5, // how many simultaneous getdirs to spawn when searching
// filter starts with separator => full path has to match, example: '/all/one/filegator/demo.txt'
// filter ends with separator => filter only folders (a file with the same name will be shown), example: '.git/'
// neither of above => it is a file and could be in every folder, example: '.htaccess'
// both of above => full folder path has to match, example: '/homes/web/filegator/.npm/'
'filter_entries' => ['Recycle.bin/', 'File System Information/', '.DS_Store', '@eaDir/', '#recycle/'],
],
```
## Additional HTML
You can add additional html to the head and body like this:
```
'Filegator\Services\View\ViewInterface' => [
'handler' => '\Filegator\Services\View\Adapters\Vuejs',
'config' => [
'add_to_head' => '<meta name="author" content="something">',
'add_to_body' => '<script src="http://example.com/analytics.js"></script>',
],
],
```
## Frontend tweaks
To change default color scheme and other options, edit `frontend/App.vue` When you're done, recompile with `npm run build` like described [here](/development.html)
```
// Primary color
$primary: #34B891;
$primary-invert: findColorInvert($primary);
$colors: (
"primary": ($primary, $primary-invert),
"info": ($info, $info-invert),
"success": ($success, $success-invert),
"warning": ($warning, $warning-invert),
"danger": ($danger, $danger-invert),
);
// Links
$link: $primary;
$link-invert: $primary-invert;
$link-focus-border: $primary;
// Disable the widescreen breakpoint
$widescreen-enabled: false;
// Disable the fullhd breakpoint
$fullhd-enabled: false;
```

View File

@@ -0,0 +1,27 @@
---
currentMenu: logging
---
## Configuring Logging service
Logging is provided trough the powerful [Monolog](https://github.com/Seldaek/monolog) library. Please check their docs for more info.
Default handler will use simple `private/logs/app.log` file to store application logs and errors.
```
'Filegator\Services\Logger\LoggerInterface' => [
'handler' => '\Filegator\Services\Logger\Adapters\MonoLogger',
'config' => [
'monolog_handlers' => [
function () {
return new \Monolog\Handler\StreamHandler(
__DIR__.'/private/logs/app.log',
\Monolog\Logger::DEBUG
);
},
],
],
],
```
There are many different handlers you can add on top of the stack (monolog_handlers array). Some of them are listed [here](https://github.com/Seldaek/monolog#documentation).

View File

@@ -0,0 +1,55 @@
---
currentMenu: router
---
## Router service
Router service is using well-known [FastRoute](https://github.com/nikic/FastRoute) library. There is no need to change this service unless you're extending the script.
The router uses unique query parameter `?r=` to pass the route info. Because of this feature, this (single-page) application does not require rewrite rules, .htaccess or similar tweaks.
Example routes:
- `http://example.com/?r=/some/route&param1=val1&param2=val2`
- `http://example.com/?r=/user/{user_id}&param1=val1`
## Routes file
Routes file is located here `backend/Controllers/routes.php` Each route in the routes array looks like this:
```
[
'route' => [
'GET', '/download/{path_encoded}', '\Filegator\Controllers\DownloadController@download',
],
'roles' => [
'guest', 'user', 'admin',
],
'permissions' => [
'download',
],
],
```
As you can see in the example, you can assign required user roles and permissions for each route.
## Controllers
Since FileGator is using an awesome dependency injection [container](https://github.com/PHP-DI/PHP-DI) you can type-hint dependencies directly in your controllers.
You can also mix route parameters and dependencies in any order like in this example:
```
public function __construct(Config $config, Session $session, AuthInterface $auth, Filesystem $storage)
{
// ...
}
public function download($path_encoded, Request $request, Response $response, StreamedResponse $streamedResponse)
{
// ...
}
```

View File

@@ -0,0 +1,28 @@
---
currentMenu: security
---
## Configuring Security service
Simple security service is included in the script by default. This service provides:
- Basic session-based [CSRF](https://en.wikipedia.org/wiki/Cross-site_request_forgery) protection
- IP allow list
- IP deny list
```
'Filegator\Services\Security\Security' => [
'handler' => '\Filegator\Services\Security\Security',
'config' => [
'csrf_protection' => true,
'csrf_key' => "123456", // randomize this
'ip_allowlist' => [],
'ip_denylist' => [
'172.16.1.2',
'172.16.3.4',
],
],
],
```
If you set `ip_allowlist` then only users coming from listed IP addresses will be able to use the script.

View File

@@ -0,0 +1,95 @@
---
currentMenu: sessions
---
## Default Session handler
Session handling is provided through the Symfony's [HttpFoundation](https://symfony.com/doc/4.4/components/http_foundation.html) component. Please check their docs for more info.
Default session handler will user PHP's built in file storage. You can also specify your own `$save_path` to store session files.
```
'Filegator\Services\Session\SessionStorageInterface' => [
'handler' => '\Filegator\Services\Session\Adapters\SessionStorage',
'config' => [
'handler' => function () {
$save_path = null; // use default system path
//$save_path = __DIR__.'/private/sessions';
$handler = new \Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeFileSessionHandler($save_path);
return new \Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage([], $handler);
},
],
],
```
## Configuring Session service to use database
First, create a table `sessions` with this sql:
```
CREATE TABLE `sessions` (
`sess_id` varbinary(128) NOT NULL,
`sess_data` blob NOT NULL,
`sess_lifetime` mediumint(9) NOT NULL,
`sess_time` int(10) unsigned NOT NULL,
PRIMARY KEY (`sess_id`)
) CHARSET=utf8 COLLATE=utf8_bin;
```
Then, open `configuration.php` and update Session handler to:
```
'Filegator\Services\Session\SessionStorageInterface' => [
'handler' => '\Filegator\Services\Session\Adapters\SessionStorage',
'config' => [
'handler' => function () {
$handler = new \Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler(
'mysql://root:password@localhost:3306/filegator'
);
return new \Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage([], $handler);
},
],
],
```
Don't forget to enter correct database details.
## Configuring Session service to use Redis
You must require additional [predis](https://github.com/nrk/predis/) library `composer require predis/predis`
```
'Filegator\Services\Session\SessionStorageInterface' => [
'handler' => '\Filegator\Services\Session\Adapters\SessionStorage',
'config' => [
'handler' => function () {
$predis = new \Predis\Client('tcp://127.0.0.1:6379');
$handler = new \Symfony\Component\HttpFoundation\Session\Storage\Handler\RedisSessionHandler($predis);
return new \Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage([], $handler);
},
],
],
```
## Tweaking session options
The underying [session component](https://github.com/symfony/symfony/blob/4.4/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php) accepts array of options.
For example you can pass `cookie_lifetime` parameter to extend default session lifetime:
```
'Filegator\Services\Session\SessionStorageInterface' => [
'handler' => '\Filegator\Services\Session\Adapters\SessionStorage',
'config' => [
'handler' => function () {
$handler = new \Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler(
'mysql://root:password@localhost:3306/filegator'
);
return new \Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage([
'cookie_lifetime' => 365 * 24 * 60 * 60, // one year
], $handler);
},
],
],
```

View File

@@ -0,0 +1,230 @@
---
currentMenu: storage
---
## Adapters
Different storage adapters are provided through the awesome [Flysystem](https://github.com/thephpleague/flysystem) library.
You can use local filesystem (default), FTP, SFTP, Amazon S3, DigitalOcean Spaces, Microsoft Azure Blob, Dropbox and many others.
Please check the Flysystem [docs](https://flysystem.thephpleague.com/v1/docs/) for the exact setup required for each adapter.
Notes: Some adapters do not support folder operations or their support is limited.
Requiring additional libraries with [composer](https://getcomposer.org/download/) requires root access.
## Default Local Disk Adapter
With default adapter you just need to configure where your `repository` folder is. This folder will serve as a root for everything else.
```
'Filegator\Services\Storage\Filesystem' => [
'handler' => '\Filegator\Services\Storage\Filesystem',
'config' => [
'separator' => '/',
'config' => [],
'adapter' => function () {
return new \League\Flysystem\Adapter\Local(
__DIR__.'/repository'
);
},
],
],
```
## FTP Adapter
See official [documentation](https://flysystem.thephpleague.com/v1/docs/adapter/ftp/).
Sample configuration:
```
'Filegator\Services\Storage\Filesystem' => [
'handler' => '\Filegator\Services\Storage\Filesystem',
'config' => [
'separator' => '/',
'config' => [],
'adapter' => function () {
return new \League\Flysystem\Adapter\Ftp([
'host' => 'example.com',
'username' => 'demo',
'password' => 'password',
'port' => 21,
'timeout' => 10,
]);
},
],
],
```
## SFTP Adapter
You must require additional library `composer require league/flysystem-sftp:^1.0 -W`
For more advanced options like using your private key or changing the document root see official [documentation](https://flysystem.thephpleague.com/v1/docs/adapter/sftp/).
Sample configuration:
```
'Filegator\Services\Storage\Filesystem' => [
'handler' => '\Filegator\Services\Storage\Filesystem',
'config' => [
'separator' => '/',
'config' => [],
'adapter' => function () {
return new \League\Flysystem\Sftp\SftpAdapter([
'host' => 'example.com',
'port' => 22,
'username' => 'demo',
'password' => 'password',
'timeout' => 10,
]);
},
],
],
```
## Dropbox Adapter
You must require additional library `composer require spatie/flysystem-dropbox`
See official [documentation](https://flysystem.thephpleague.com/v1/docs/adapter/dropbox/).
Sample configuration:
```
'Filegator\Services\Storage\Filesystem' => [
'handler' => '\Filegator\Services\Storage\Filesystem',
'config' => [
'separator' => '/',
'config' => [
'case_sensitive' => false,
],
'adapter' => function () {
$authorizationToken = '1234';
$client = new \Spatie\Dropbox\Client($authorizationToken);
return new \Spatie\FlysystemDropbox\DropboxAdapter($client);
},
],
],
```
## Amazon S3 Adapter (v3)
You must require additional library `composer require league/flysystem-aws-s3-v3:^1.0 -W`
See official [documentation](https://flysystem.thephpleague.com/v1/docs/adapter/aws-s3-v3/).
Sample configuration:
```
'Filegator\Services\Storage\Filesystem' => [
'handler' => '\Filegator\Services\Storage\Filesystem',
'config' => [
'separator' => '/',
'config' => [],
'adapter' => function () {
$client = new \Aws\S3\S3Client([
'credentials' => [
'key' => '123456',
'secret' => 'secret123456',
],
'region' => 'us-east-1',
'version' => 'latest',
]);
return new \League\Flysystem\AwsS3v3\AwsS3Adapter($client, 'my-bucket-name');
},
],
],
```
## DigitalOcean Spaces
You must require additional library `composer require league/flysystem-aws-s3-v3:^1.0 -W`
The DigitalOcean Spaces API are compatible with those of S3.
See official [documentation](https://flysystem.thephpleague.com/v1/docs/adapter/digitalocean-spaces/).
Sample configuration:
```
'Filegator\Services\Storage\Filesystem' => [
'handler' => '\Filegator\Services\Storage\Filesystem',
'config' => [
'separator' => '/',
'config' => [],
'adapter' => function () {
$client = new \Aws\S3\S3Client([
'credentials' => [
'key' => '123456',
'secret' => 'secret123456',
],
'region' => 'us-east-1',
'version' => 'latest',
'endpoint' => 'https://nyc3.digitaloceanspaces.com',
]);
return new \League\Flysystem\AwsS3v3\AwsS3Adapter($client, 'my-bucket-name');
},
],
],
```
## Microsoft Azure Blob Storage
You must require additional library `composer require league/flysystem-azure-blob-storage:^1.0 -W`
See official [documentation](https://flysystem.thephpleague.com/v1/docs/adapter/azure/).
Sample configuration:
```
'Filegator\Services\Storage\Filesystem' => [
'handler' => '\Filegator\Services\Storage\Filesystem',
'config' => [
'separator' => '/',
'config' => [],
'adapter' => function () {
$accountName = 'your_storage_account_name';
$accountKey = '123456';
$containerName = 'my_container';
$client = \MicrosoftAzure\Storage\Blob\BlobRestProxy::createBlobService(
"DefaultEndpointsProtocol=https;AccountName=${accountName};AccountKey=${accountKey};"
);
return new \League\Flysystem\AzureBlobStorage\AzureBlobStorageAdapter($client, $containerName);
},
],
],
```
## Replicate Adapter
You must require additional library `composer require league/flysystem-replicate-adapter`
The ReplicateAdapter facilitates smooth transitions between adapters, allowing an application to stay functional and migrate its files from one adapter to another. The adapter takes two other adapters, a source and a replica. Every change is delegated to both adapters, while all the read operations are passed onto the source only.
See official [documentation](https://flysystem.thephpleague.com/v1/docs/adapter/replicate/).
Sample configuration:
```
'Filegator\Services\Storage\Filesystem' => [
'handler' => '\Filegator\Services\Storage\Filesystem',
'config' => [
'separator' => '/',
'config' => [
'case_sensitive' => false,
],
'adapter' => function () {
$authorizationToken = '1234';
$client = new \Spatie\Dropbox\Client($authorizationToken);
$source = new \Spatie\FlysystemDropbox\DropboxAdapter($client);
$replica = new \League\Flysystem\Adapter\Local(__DIR__.'/repository');
return new League\Flysystem\Replicate\ReplicateAdapter($source, $replica);
},
],
],
```

View File

@@ -0,0 +1,26 @@
---
currentMenu: tmpfs
---
## Temporary file system service
This service is responsible for managing temporary files. TMP files are created:
- When uploading files, chunks are stored in the TMP folder before merging and moving to the final storage destination
- When creating and extracting archives (zip files)
- When downloading multiple files, they are copied into TMP folder before zipping
Tmp files are usually removed immediately after the use. For expired files, configurable garbage collection is used:
```
'Filegator\Services\Tmpfs\TmpfsInterface' => [
'handler' => '\Filegator\Services\Tmpfs\Adapters\Tmpfs',
'config' => [
'path' => __DIR__.'/private/tmp/',
'gc_probability_perc' => 10,
'gc_older_than' => 60 * 60 * 24 * 2, // 2 days
],
],
```
Note: if you want to use this script as a stateless app or in any kind of multi-node environment, you must mount a single shared TMP folder for all the instances. You can solve this problem with [Amazon Elastic File System](https://aws.amazon.com/efs/) or similar approach.