forked from deblan/gist
1
0
Fork 0

Merge branch 'dev-master'

This commit is contained in:
Simon Vieille 2017-04-24 01:19:15 +02:00
commit 2f1d57d36b
12 changed files with 191 additions and 95 deletions

1
.gitignore vendored
View File

@ -7,6 +7,7 @@
/src/Gist/Model/Map/ /src/Gist/Model/Map/
/web/components/ /web/components/
/app/propel/ /app/propel/
/app/config/config.yml
/app/config/propel/ /app/config/propel/
/data/ /data/
/trans/ /trans/

View File

@ -8,6 +8,7 @@ deployment:
- "*.svn" - "*.svn"
- "*.git" - "*.git"
- "*.swp" - "*.swp"
- "app/config/config.yml"
- "app/config/propel/" - "app/config/propel/"
- "app/propel/" - "app/propel/"
- "data/git" - "data/git"

136
README.md
View File

@ -8,21 +8,14 @@ Table of Contents
* [Bower](#bower) * [Bower](#bower)
* [Installation](#installation) * [Installation](#installation)
* [Upgrade](#upgrade) * [Upgrade](#upgrade)
* [Configuration](#configuration)
* [Makefile](#makefile) * [Makefile](#makefile)
* [API](#api) * [API](#api)
* [Create a new gist](#create-a-new-gist)
* [Update an existing Gist](#update-an-existing-gist)
* [Console](#console) * [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) * [Deployment](#deployment)
* [Contributors](#contributors) * [Contributors](#contributors)
GIST 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") ![Gist](https://upload.deblan.org/u/2016-06/57655dec.png "Gist")
Requirements Requirements
------------ ------------
@ -80,7 +74,7 @@ Installation
$ git clone https://gitnet.fr/deblan/gist $ git clone https://gitnet.fr/deblan/gist
$ cd gist $ cd gist
$ make $ make
$ mv propel-dist.yaml propel.yaml $ cp propel-dist.yaml propel.yaml
Edit `propel.yaml`. **Use spaces instead of tabulations**. Edit `propel.yaml`. **Use spaces instead of tabulations**.
@ -118,7 +112,11 @@ Edit `propel.yaml`. **Use spaces instead of tabulations**.
Then `$ make propel`. 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`. 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 a2enmod rewrite
$ sudo service apache2 restart $ sudo service apache2 restart
`app_dev.php` is the development router. Access is granted for an IP range defined in the same file.
Upgrade 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.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 Makefile
-------- --------
@ -165,8 +199,11 @@ Params:
**Responses:** **Responses:**
* Code `405`: Method Not Allowed
* Code `400`: Bad Request
* Code `200`: A json which contains gist's information. Example: * Code `200`: A json which contains gist's information. Example:
```javascript
```javascript
{ {
"url": "https:\/\/gist.deblan.org\/en\/view\/55abcfa7771e0\/f4afbf72967dd95e3461490dcaa310d728d6a97d", "url": "https:\/\/gist.deblan.org\/en\/view\/55abcfa7771e0\/f4afbf72967dd95e3461490dcaa310d728d6a97d",
"gist": { "gist": {
@ -179,11 +216,9 @@ Params:
"UpdatedAt": "2015-07-19T16:26:15Z" "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} **POST** /{locale}/api/update/{id}
Params: Params:
@ -193,8 +228,11 @@ Params:
**Responses:** **Responses:**
* Code `405`: Method Not Allowed
* Code `400`: Bad Request
* Code `200`: A json which contains gist's information. Example: * Code `200`: A json which contains gist's information. Example:
```javascript
```javascript
{ {
"url": "https:\/\/gist.deblan.org\/en\/view\/55abcfa7771e0\/abcgi72967dd95e3461490dcaa310d728d6adef", "url": "https:\/\/gist.deblan.org\/en\/view\/55abcfa7771e0\/abcgi72967dd95e3461490dcaa310d728d6adef",
"gist": { "gist": {
@ -207,67 +245,15 @@ Params:
"UpdatedAt": "2015-07-19T16:30:15Z" "UpdatedAt": "2015-07-19T16:30:15Z"
} }
} }
``` ```
* Code `405`: Method Not Allowed
* Code `400`: Bad Request
Console Console
------- -------
### Create and update gists * **Create a gist**: `$ app/console --help create`
* **Update a gist**: `$ app/console --help update`
``` * **Create user**: `app/console --help user:create`
$ app/console --help create * **Show stats**: `$ app/console --help stats`
$ 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.
Deployment Deployment
---------- ----------
@ -284,7 +270,7 @@ Gist uses [Magallanes](http://magephp.com/) to manage deployment.
$ composer require andres-montanez/magallanes $ 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 # global installation
$ mage deploy to:prod $ mage deploy to:prod

View File

@ -1,9 +1,14 @@
<?php <?php
use Symfony\Component\Config\FileLocator; use Symfony\Component\Config\FileLocator;
use Symfony\Component\Yaml\Yaml;
$app['config.locator.path'] = $app['root_path'].'/app/config/'; $app['config.locator.path'] = $app['root_path'].'/app/config/';
$app['config.locator'] = function ($app) { $app['config.locator'] = function ($app) {
return new FileLocator($app['config.locator.path']); return new FileLocator($app['config.locator.path']);
}; };
$app['settings'] = $app->share(function ($app) {
return Yaml::parse($app['config.locator']->locate('config.yml'));
});

View File

@ -3,10 +3,16 @@
use GitWrapper\GitWrapper; use GitWrapper\GitWrapper;
use Gist\Service\Gist; 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) { $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) { $app['git_working_copy'] = $app->share(function ($app) {

View File

@ -3,5 +3,5 @@
use Gist\Api\Client; use Gist\Api\Client;
$app['api_client'] = $app->share(function ($app) { $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']]);
}); });

View File

@ -9,13 +9,9 @@ use Gist\Security\AuthenticationListener;
use Gist\Security\LogoutSuccessHandler; use Gist\Security\LogoutSuccessHandler;
use Silex\Provider\SessionServiceProvider; use Silex\Provider\SessionServiceProvider;
$app['enable_registration'] = true; $securitySettings = $app['settings']['security'];
$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;
$app['token'] = 'ThisTokenIsNotSoSecretChangeIt'; $app['token'] = $securitySettings['token'];
$app['salt_generator'] = $app->share(function ($app) { $app['salt_generator'] = $app->share(function ($app) {
return new SaltGenerator(); 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']; $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}/view.*$', 'ROLE_USER'];
$firewall['security.access_rules'][] = ['^/[a-z]{2}/revs.*$', 'ROLE_USER']; $firewall['security.access_rules'][] = ['^/[a-z]{2}/revs.*$', 'ROLE_USER'];
} else { } else {
@ -88,13 +84,13 @@ if ($app['login_required_to_edit_gist'] || $app['login_required_to_view_gist'] |
$exceptedUriPattern[] = 'revs'; $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']; $firewall['security.access_rules'][] = ['^/[a-z]{2}/embed.*$', 'ROLE_USER'];
} else { } else {
$exceptedUriPattern[] = 'embed'; $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']; $firewall['security.access_rules'][] = ['^/[a-z]{2}/(?!('.implode('|', $exceptedUriPattern).')).*$', 'ROLE_USER'];
} }
} }

View File

@ -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

View File

@ -26,7 +26,7 @@ class LoginController extends Controller
{ {
$app = $this->getApp(); $app = $this->getApp();
if (false === $app['enable_registration']) { if (false === $app['settings']['enable_registration']) {
return new Response('', 403); return new Response('', 403);
} }
@ -78,7 +78,7 @@ class LoginController extends Controller
{ {
$app = $this->getApp(); $app = $this->getApp();
if (false === $app['enable_login']) { if (false === $app['settings']['enable_login']) {
return new Response('', 403); return new Response('', 403);
} }

View File

@ -1,11 +1,19 @@
<!DOCTYPE html> <!DOCTYPE html>
{% set theme_settings = app.settings.theme %}
{% set security_dettings = app.settings.security %}
<html xmlns="http://www.w3.org/1999/xhtml"> <html xmlns="http://www.w3.org/1999/xhtml">
<head> <head>
{% block css %} {% block css %}
<link rel="stylesheet" href="{{ web_path }}components/bootstrap/dist/css/bootstrap.min.css" /> <link rel="stylesheet" href="{{ web_path }}components/bootstrap/dist/css/bootstrap.min.css" />
<link rel="stylesheet" href="{{ web_path }}components/flag-icon-css/css/flag-icon.min.css" /> <link rel="stylesheet" href="{{ web_path }}components/flag-icon-css/css/flag-icon.min.css" />
<link rel="stylesheet" href="{{ web_path }}app/css/bootstrap/bootstrap.min.css" />
<link rel="stylesheet" href="{{ web_path }}app/css/app.css" /> {% if theme_settings.name == 'dark' %}
<link rel="stylesheet" href="{{ web_path }}app/css/bootstrap/bootstrap.min.css" />
{% else %}
<link rel="stylesheet" href="{{ web_path }}components/bootstrap/dist/css/bootstrap-theme.min.css" />
{% endif %}
<link rel="stylesheet" href="{{ web_path }}app/css/themes/{{ theme_settings.name }}.css" />
{% endblock %} {% endblock %}
{% block metas %} {% block metas %}
@ -17,7 +25,7 @@
</head> </head>
<body> <body>
{% block nav %} {% block nav %}
<nav class="navbar navbar-inverse"> <nav class="navbar navbar-{{ theme_settings.name == 'dark' ? 'inverse' : 'default' }}">
<div class="container-fluid"> <div class="container-fluid">
<div class="navbar-header"> <div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#main-menu"> <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#main-menu">
@ -48,14 +56,14 @@
{{ 'app.menu.my.logout.title'|trans }} {{ 'app.menu.my.logout.title'|trans }}
</a> </a>
</li> </li>
{% elseif app.enable_login %} {% elseif security_dettings.enable_login %}
<li> <li>
<a href="{{ path('login') }}"> <a href="{{ path('login') }}">
{{ 'app.menu.my.login.title'|trans }} {{ 'app.menu.my.login.title'|trans }}
</a> </a>
</li> </li>
{% if app.enable_registration %} {% if security_dettings.enable_registration %}
<li> <li>
<a href="{{ path('register') }}"> <a href="{{ path('register') }}">
{{ 'app.menu.my.register.title'|trans }} {{ 'app.menu.my.register.title'|trans }}

View File

@ -0,0 +1,78 @@
.navbar {
border-radius: 0;
}
#form_content {
display: block;
width: 100%;
padding: 10px;
}
#languages {
padding-bottom: 5px;
}
#languages .btn-group:first-child {
margin-right: 4px;
}
pre {
background: #222;
border: #222;
color: #ddd;
white-space: pre-wrap;
white-space: -moz-pre-wrap;
white-space: -pre-wrap;
white-space: -o-pre-wrap;
word-wrap: break-word;
}
pre ol {
padding-left: 50px !important;
}
pre li:hover {
background: #444;
}
.panel-heading .actions {
margin-top: -5px;
}
div.diff {
display: none;
}
.de1 {
padding-left: 5px;
padding-right: 5px;
}
.li1 {
background: #333;
}
.re8 {
color: #52F700;
}
.kw3 {
color: #C6C765;
}
#viewer .syntaxhighlighter td {
vertical-align: top !important;
}
#options {
margin-bottom: 17px;
}
.btn-delete {
background: #DE3336;
color: #fff;
}
.btn-error:active, .btn-error:hover, .btn-error:focus {
color: #000;
}