diff --git a/.gitignore b/.gitignore index aa99075..28eb5fc 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ /src/Gist/Model/Map/ /web/components/ /app/propel/ +/app/config/config.yml /app/config/propel/ /data/ /trans/ diff --git a/.mage/config/environment/prod.yml-dist b/.mage/config/environment/prod.yml.dist similarity index 93% rename from .mage/config/environment/prod.yml-dist rename to .mage/config/environment/prod.yml.dist index 83aaeee..a5bcb3b 100644 --- a/.mage/config/environment/prod.yml-dist +++ b/.mage/config/environment/prod.yml.dist @@ -8,6 +8,7 @@ deployment: - "*.svn" - "*.git" - "*.swp" + - "app/config/config.yml" - "app/config/propel/" - "app/propel/" - "data/git" diff --git a/README.md b/README.md index e43e1d6..5da7741 100644 --- a/README.md +++ b/README.md @@ -8,21 +8,14 @@ Table of Contents * [Bower](#bower) * [Installation](#installation) * [Upgrade](#upgrade) + * [Configuration](#configuration) * [Makefile](#makefile) * [API](#api) - * [Create a new gist](#create-a-new-gist) - * [Update an existing Gist](#update-an-existing-gist) * [Console](#console) - * [Create and update gists](#create-and-update-gists) - * [Create user](#create-user) - * [Show stats](#show-stats) - * [Configuration](#configuration) - * [API](#api-1) - * [Authentication](#authentication) - * [Debug](#debug) * [Deployment](#deployment) * [Contributors](#contributors) + GIST ==== @@ -33,6 +26,7 @@ https://www.deblan.io/post/517/gist-est-dans-la-place ![Gist](https://upload.deblan.org/u/2016-06/57655dec.png "Gist") + Requirements ------------ @@ -80,7 +74,7 @@ Installation $ git clone https://gitnet.fr/deblan/gist $ cd gist $ make - $ mv propel-dist.yaml propel.yaml + $ cp propel-dist.yaml propel.yaml Edit `propel.yaml`. **Use spaces instead of tabulations**. @@ -118,7 +112,11 @@ Edit `propel.yaml`. **Use spaces instead of tabulations**. Then `$ make propel`. -Edit `app/bootstrap.php.d/70-security.php` and modify the value of `$app['token']` with a strong secret phrase. +**Versions >= 1.4.4 only**: `$ cp app/config/config.yml.dist app/config/config.yml` + +See the [configuration section](#configuration) for more information about configuration. + +--- The web server must have permission to write into `data`. @@ -129,6 +127,8 @@ Your webserver must be configured to serve `web/` as document root. If you use n $ sudo a2enmod rewrite $ sudo service apache2 restart +`app_dev.php` is the development router. Access is granted for an IP range defined in the same file. + Upgrade ------- @@ -139,6 +139,40 @@ If your version is less than v1.4.2, run: `test -d app && git add app && git com If you upgrade to v1.4.1, run: `app/console migrate:to:v1.4.1`. +If you upgrade to v1.4.4 or more, the configuration is moved to a `app/config/config.yml`: `$ cp app/config/config.yml.dist app/config/config.yml` and see the [configuration section](#configuration) for more information. + +Configuration +------------- + +### Version < 1.4.4 + +Edit `app/bootstrap.php.d/70-security.php`. + +* `$app['token']`: the securty token (a strong passphrase). +* `$app['enable_registration']`: defines if the registration is allowed (`true` or `false`) +* `$app['enable_login']`: defines if the login is allowed (`true` or `false`) +* `$app['login_required_to_edit_gist']`: defines if the user must be logged to create or clone a Gist (`true` or `false`) +* `$app['login_required_to_view_gist']`: defines if the user must be logged to view a Gist (`true` or `false`) +* `$app['login_required_to_view_gist']`: defines if the user must be logged to view an embeded Gist (`true` or `false`) + +If you install Gist on your server, you have to modify the `base_uri` of the API. +Edit `app/bootstrap.php.d/60-api.php` and replace `https://gist.deblan.org/`. + +### Version >= 1.4.4 + +Edit `app/config/config.yml`. + +* `security.token`: the securty token (a strong passphrase) +* `security.enable_registration`: defines if the registration is allowed (`true` or `false`) +* `security.enable_login`: defines if the login is allowed (`true` or `false`) +* `security.login_required_to_edit_gist`: defines if the user must be logged to create or clone a Gist (`true` or `false`) +* `security.login_required_to_view_gist`: defines if the user must be logged to view a Gist (`true` or `false`) +* `security.login_required_to_view_gist`: defines if the user must be logged to view an embeded Gist (`true` or `false`) +* `api.base_uri`: The url of your instance. +* `data.path`: the path where the files are saved. +* `git.path`: The path of `git`. +* `theme.name`: the name of the theme (`dark` or `light`) + Makefile -------- @@ -165,8 +199,11 @@ Params: **Responses:** +* Code `405`: Method Not Allowed +* Code `400`: Bad Request * Code `200`: A json which contains gist's information. Example: - ```javascript + +```javascript { "url": "https:\/\/gist.deblan.org\/en\/view\/55abcfa7771e0\/f4afbf72967dd95e3461490dcaa310d728d6a97d", "gist": { @@ -179,11 +216,9 @@ Params: "UpdatedAt": "2015-07-19T16:26:15Z" } } - ``` -* Code `405`: Method Not Allowed -* Code `400`: Bad Request +``` -### Update an existing Gist +### Update an existing gist **POST** /{locale}/api/update/{id} Params: @@ -193,8 +228,11 @@ Params: **Responses:** +* Code `405`: Method Not Allowed +* Code `400`: Bad Request * Code `200`: A json which contains gist's information. Example: - ```javascript + +```javascript { "url": "https:\/\/gist.deblan.org\/en\/view\/55abcfa7771e0\/abcgi72967dd95e3461490dcaa310d728d6adef", "gist": { @@ -207,67 +245,15 @@ Params: "UpdatedAt": "2015-07-19T16:30:15Z" } } - ``` -* Code `405`: Method Not Allowed -* Code `400`: Bad Request +``` Console ------- -### Create and update gists - -``` -$ app/console --help create -$ app/console --help update -``` - -### Create user - -``` -$ app/console --help user:create -``` - -### Show stats - -``` -$ app/console --help stats -``` - -Configuration -------------- - -### API - -**Personal instance** - -If you install Gist on your server, you have to modify the `base_uri` of the API. -Edit `app/bootstrap.php.d/60-api.php` and replace `https://gist.deblan.org/`. - -### Authentication - -**Disabling login** - -Edit `app/bootstrap.php.d/70-security.php` and modify the value of `$app['enable_login']` with `false`. - -**Disabling registration** - -Edit `app/bootstrap.php.d/70-security.php` and modify the value of `$app['enable_registration']` with `false`. - -**Login required to edit a gist** - -Edit `app/bootstrap.php.d/70-security.php` and modify the value of `$app['login_required_to_edit_gist']` with `true`. - -**Login required to view a gist** - -Edit `app/bootstrap.php.d/70-security.php` and modify the value of `$app['login_required_to_view_gist']` with `true`. - -**Login required to view an embeded gist** - -Edit `app/bootstrap.php.d/70-security.php` and modify the value of `$app['login_required_to_view_embeded_gist']` with `true`. - -### Debug - -`app_dev.php` is the development router. Access is granted for an IP range defined in the same file. +* **Create a gist**: `$ app/console --help create` +* **Update a gist**: `$ app/console --help update` +* **Create user**: `app/console --help user:create` +* **Show stats**: `$ app/console --help stats` Deployment ---------- @@ -284,7 +270,7 @@ Gist uses [Magallanes](http://magephp.com/) to manage deployment. $ composer require andres-montanez/magallanes -There is an example of the configuration of an environment in `.mage/config/environment/prod.yml-dist`. +There is an example of the configuration of an environment in `.mage/config/environment/prod.yml.dist`. # global installation $ mage deploy to:prod diff --git a/app/bootstrap.php.d/10-config.php b/app/bootstrap.php.d/10-config.php index 16c2133..193d647 100644 --- a/app/bootstrap.php.d/10-config.php +++ b/app/bootstrap.php.d/10-config.php @@ -1,9 +1,14 @@ share(function ($app) { + return Yaml::parse($app['config.locator']->locate('config.yml')); +}); diff --git a/app/bootstrap.php.d/50-git.php b/app/bootstrap.php.d/50-git.php index 5508ca5..9511253 100644 --- a/app/bootstrap.php.d/50-git.php +++ b/app/bootstrap.php.d/50-git.php @@ -3,10 +3,16 @@ use GitWrapper\GitWrapper; use Gist\Service\Gist; -$app['gist_path'] = $app['root_path'].'/data/git'; +$dataPath = $app['settings']['data']['path']; + +if ($dataPath[0] !== '/') { + $app['gist_path'] = $app['root_path'].$dataPath; +} else { + $app['gist_path'] = $dataPath; +} $app['git_wrapper'] = $app->share(function ($app) { - return new GitWrapper('/usr/bin/git'); + return new GitWrapper($app['settings']['git']['path']); }); $app['git_working_copy'] = $app->share(function ($app) { diff --git a/app/bootstrap.php.d/60-api.php b/app/bootstrap.php.d/60-api.php index c7085ab..c66683b 100644 --- a/app/bootstrap.php.d/60-api.php +++ b/app/bootstrap.php.d/60-api.php @@ -3,5 +3,5 @@ use Gist\Api\Client; $app['api_client'] = $app->share(function ($app) { - return new Client(['base_uri' => 'https://gist.deblan.org/']); + return new Client(['base_uri' => $app['settings']['api']['base_uri']]); }); diff --git a/app/bootstrap.php.d/70-security.php b/app/bootstrap.php.d/70-security.php index 845aca2..dbc3ca4 100644 --- a/app/bootstrap.php.d/70-security.php +++ b/app/bootstrap.php.d/70-security.php @@ -9,13 +9,9 @@ use Gist\Security\AuthenticationListener; use Gist\Security\LogoutSuccessHandler; use Silex\Provider\SessionServiceProvider; -$app['enable_registration'] = true; -$app['enable_login'] = true; -$app['login_required_to_edit_gist'] = false; -$app['login_required_to_view_gist'] = false; -$app['login_required_to_view_embeded_gist'] = false; +$securitySettings = $app['settings']['security']; -$app['token'] = 'ThisTokenIsNotSoSecretChangeIt'; +$app['token'] = $securitySettings['token']; $app['salt_generator'] = $app->share(function ($app) { return new SaltGenerator(); @@ -77,10 +73,10 @@ $firewall = [ ], ]; -if ($app['login_required_to_edit_gist'] || $app['login_required_to_view_gist'] || $app['login_required_to_view_embeded_gist']) { +if ($securitySettings['login_required_to_edit_gist'] || $securitySettings['login_required_to_view_gist'] || $securitySettings['login_required_to_view_embeded_gist']) { $exceptedUriPattern = ['login', 'register']; - if ($app['login_required_to_view_gist'] === true) { + if ($securitySettings['login_required_to_view_gist'] === true) { $firewall['security.access_rules'][] = ['^/[a-z]{2}/view.*$', 'ROLE_USER']; $firewall['security.access_rules'][] = ['^/[a-z]{2}/revs.*$', 'ROLE_USER']; } else { @@ -88,13 +84,13 @@ if ($app['login_required_to_edit_gist'] || $app['login_required_to_view_gist'] | $exceptedUriPattern[] = 'revs'; } - if ($app['login_required_to_view_embeded_gist'] === true) { + if ($securitySettings['login_required_to_view_embeded_gist'] === true) { $firewall['security.access_rules'][] = ['^/[a-z]{2}/embed.*$', 'ROLE_USER']; } else { $exceptedUriPattern[] = 'embed'; } - if ($app['login_required_to_edit_gist'] === true) { + if ($securitySettings['login_required_to_edit_gist'] === true) { $firewall['security.access_rules'][] = ['^/[a-z]{2}/(?!('.implode('|', $exceptedUriPattern).')).*$', 'ROLE_USER']; } } diff --git a/app/config/config.yml.dist b/app/config/config.yml.dist new file mode 100644 index 0000000..0719a87 --- /dev/null +++ b/app/config/config.yml.dist @@ -0,0 +1,15 @@ +security: + token: ThisTokenIsNotSoSecretChangeIt + enable_registration: true + enable_login: true + login_required_to_edit_gist: true + login_required_to_view_gist: true + login_required_to_view_embeded_gist: true +api: + base_url: 'https://gist.deblan.org/' +data: + path: data/git +git: + path: /usr/bin/git +theme: + name: dark diff --git a/src/Gist/Controller/LoginController.php b/src/Gist/Controller/LoginController.php index 57723ed..a45d1a3 100644 --- a/src/Gist/Controller/LoginController.php +++ b/src/Gist/Controller/LoginController.php @@ -26,7 +26,7 @@ class LoginController extends Controller { $app = $this->getApp(); - if (false === $app['enable_registration']) { + if (false === $app['settings']['enable_registration']) { return new Response('', 403); } @@ -78,7 +78,7 @@ class LoginController extends Controller { $app = $this->getApp(); - if (false === $app['enable_login']) { + if (false === $app['settings']['enable_login']) { return new Response('', 403); } diff --git a/src/Gist/Resources/views/base.html.twig b/src/Gist/Resources/views/base.html.twig index 8ffe273..2410dd7 100644 --- a/src/Gist/Resources/views/base.html.twig +++ b/src/Gist/Resources/views/base.html.twig @@ -1,11 +1,19 @@ +{% set theme_settings = app.settings.theme %} +{% set security_dettings = app.settings.security %} {% block css %} - - + + {% if theme_settings.name == 'dark' %} + + {% else %} + + {% endif %} + + {% endblock %} {% block metas %} @@ -17,7 +25,7 @@ {% block nav %} -