Browse Source

Merge branch 'dev-master'

tags/v1.4.4
Simon Vieille 2 years ago
parent
commit
2f1d57d36b

+ 1
- 0
.gitignore View File

@@ -7,6 +7,7 @@
7 7
 /src/Gist/Model/Map/
8 8
 /web/components/
9 9
 /app/propel/
10
+/app/config/config.yml
10 11
 /app/config/propel/
11 12
 /data/
12 13
 /trans/

.mage/config/environment/prod.yml-dist → .mage/config/environment/prod.yml.dist View File

@@ -8,6 +8,7 @@ deployment:
8 8
         - "*.svn"
9 9
         - "*.git"
10 10
         - "*.swp"
11
+        - "app/config/config.yml"
11 12
         - "app/config/propel/"
12 13
         - "app/propel/"
13 14
         - "data/git"

+ 61
- 75
README.md View File

@@ -8,21 +8,14 @@ Table of Contents
8 8
       * [Bower](#bower)
9 9
     * [Installation](#installation)
10 10
     * [Upgrade](#upgrade)
11
+    * [Configuration](#configuration)
11 12
     * [Makefile](#makefile)
12 13
     * [API](#api)
13
-      * [Create a new gist](#create-a-new-gist)
14
-      * [Update an existing Gist](#update-an-existing-gist)
15 14
     * [Console](#console)
16
-      * [Create and update gists](#create-and-update-gists)
17
-      * [Create user](#create-user)
18
-      * [Show stats](#show-stats)
19
-    * [Configuration](#configuration)
20
-      * [API](#api-1)
21
-      * [Authentication](#authentication)
22
-      * [Debug](#debug)
23 15
     * [Deployment](#deployment)
24 16
     * [Contributors](#contributors)
25 17
 
18
+
26 19
 GIST
27 20
 ====
28 21
 
@@ -33,6 +26,7 @@ https://www.deblan.io/post/517/gist-est-dans-la-place
33 26
 
34 27
 ![Gist](https://upload.deblan.org/u/2016-06/57655dec.png "Gist")
35 28
 
29
+
36 30
 Requirements
37 31
 ------------
38 32
 
@@ -80,7 +74,7 @@ Installation
80 74
 	$ git clone https://gitnet.fr/deblan/gist
81 75
 	$ cd gist
82 76
 	$ make
83
-	$ mv propel-dist.yaml propel.yaml
77
+	$ cp propel-dist.yaml propel.yaml
84 78
 
85 79
 Edit `propel.yaml`. **Use spaces instead of tabulations**.
86 80
 
@@ -118,7 +112,11 @@ Edit `propel.yaml`. **Use spaces instead of tabulations**.
118 112
 
119 113
 Then `$ make propel`.
120 114
 
121
-Edit `app/bootstrap.php.d/70-security.php` and modify the value of `$app['token']` with a strong secret phrase.
115
+**Versions >= 1.4.4 only**: `$ cp app/config/config.yml.dist app/config/config.yml`
116
+
117
+See the [configuration section](#configuration) for more information about configuration.
118
+
119
+---
122 120
 
123 121
 The web server must have permission to write into `data`.
124 122
 
@@ -129,6 +127,8 @@ Your webserver must be configured to serve `web/` as document root. If you use n
129 127
 	$ sudo a2enmod rewrite
130 128
 	$ sudo service apache2 restart
131 129
 
130
+`app_dev.php` is the development router. Access is granted for an IP range defined in the same file.
131
+
132 132
 Upgrade
133 133
 -------
134 134
 
@@ -139,6 +139,40 @@ If your version is less than v1.4.2, run: `test -d app && git add app && git com
139 139
 
140 140
 If you upgrade to v1.4.1, run: `app/console migrate:to:v1.4.1`.
141 141
 
142
+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.
143
+
144
+Configuration
145
+-------------
146
+
147
+### Version < 1.4.4
148
+
149
+Edit `app/bootstrap.php.d/70-security.php`.
150
+
151
+* `$app['token']`: the securty token (a strong passphrase).
152
+* `$app['enable_registration']`: defines if the registration is allowed (`true` or `false`)
153
+* `$app['enable_login']`: defines if the login is allowed (`true` or `false`)
154
+* `$app['login_required_to_edit_gist']`: defines if the user must be logged to create or clone a Gist (`true` or `false`)
155
+* `$app['login_required_to_view_gist']`: defines if the user must be logged to view a Gist (`true` or `false`)
156
+* `$app['login_required_to_view_gist']`: defines if the user must be logged to view an embeded Gist (`true` or `false`)
157
+
158
+If you install Gist on your server, you have to modify the `base_uri` of the API.
159
+Edit `app/bootstrap.php.d/60-api.php` and replace `https://gist.deblan.org/`.
160
+
161
+### Version >= 1.4.4
162
+
163
+Edit `app/config/config.yml`.
164
+
165
+* `security.token`: the securty token (a strong passphrase)
166
+* `security.enable_registration`: defines if the registration is allowed (`true` or `false`)
167
+* `security.enable_login`: defines if the login is allowed (`true` or `false`)
168
+* `security.login_required_to_edit_gist`: defines if the user must be logged to create or clone a Gist (`true` or `false`)
169
+* `security.login_required_to_view_gist`: defines if the user must be logged to view a Gist (`true` or `false`)
170
+* `security.login_required_to_view_gist`: defines if the user must be logged to view an embeded Gist (`true` or `false`)
171
+* `api.base_uri`: The url of your instance.
172
+* `data.path`: the path where the files are saved.
173
+* `git.path`: The path of `git`.
174
+* `theme.name`: the name of the theme (`dark` or `light`)
175
+
142 176
 Makefile
143 177
 --------
144 178
 
@@ -165,8 +199,11 @@ Params:
165 199
 
166 200
 **Responses:**
167 201
 
202
+* Code `405`: Method Not Allowed
203
+* Code `400`: Bad Request
168 204
 * Code `200`: A json which contains gist's information. Example:
169
-  ```javascript
205
+
206
+```javascript
170 207
 {
171 208
     "url": "https:\/\/gist.deblan.org\/en\/view\/55abcfa7771e0\/f4afbf72967dd95e3461490dcaa310d728d6a97d",
172 209
     "gist": {
@@ -179,11 +216,9 @@ Params:
179 216
         "UpdatedAt": "2015-07-19T16:26:15Z"
180 217
     }
181 218
 }
182
-  ```
183
-* Code `405`: Method Not Allowed
184
-* Code `400`: Bad Request
219
+```
185 220
 
186
-### Update an existing Gist
221
+### Update an existing gist
187 222
 
188 223
 **POST** /{locale}/api/update/{id}
189 224
 Params:
@@ -193,8 +228,11 @@ Params:
193 228
 
194 229
 **Responses:**
195 230
 
231
+* Code `405`: Method Not Allowed
232
+* Code `400`: Bad Request
196 233
 * Code `200`: A json which contains gist's information. Example:
197
-  ```javascript
234
+
235
+```javascript
198 236
 {
199 237
     "url": "https:\/\/gist.deblan.org\/en\/view\/55abcfa7771e0\/abcgi72967dd95e3461490dcaa310d728d6adef",
200 238
     "gist": {
@@ -207,67 +245,15 @@ Params:
207 245
         "UpdatedAt": "2015-07-19T16:30:15Z"
208 246
     }
209 247
 }
210
-  ```
211
-* Code `405`: Method Not Allowed
212
-* Code `400`: Bad Request
248
+```
213 249
 
214 250
 Console
215 251
 -------
216 252
 
217
-### Create and update gists
218
-
219
-```
220
-$ app/console --help create
221
-$ app/console --help update
222
-```
223
-
224
-### Create user
225
-
226
-```
227
-$ app/console --help user:create
228
-```
229
-
230
-### Show stats
231
-
232
-```
233
-$ app/console --help stats
234
-```
235
-
236
-Configuration
237
--------------
238
-
239
-### API
240
-
241
-**Personal instance**
242
-
243
-If you install Gist on your server, you have to modify the `base_uri` of the API.
244
-Edit `app/bootstrap.php.d/60-api.php` and replace `https://gist.deblan.org/`.
245
-
246
-### Authentication
247
-
248
-**Disabling login**
249
-
250
-Edit `app/bootstrap.php.d/70-security.php` and modify the value of `$app['enable_login']` with `false`.
251
-
252
-**Disabling registration**
253
-
254
-Edit `app/bootstrap.php.d/70-security.php` and modify the value of `$app['enable_registration']` with `false`.
255
-
256
-**Login required to edit a gist**
257
-
258
-Edit `app/bootstrap.php.d/70-security.php` and modify the value of `$app['login_required_to_edit_gist']` with `true`.
259
-
260
-**Login required to view a gist**
261
-
262
-Edit `app/bootstrap.php.d/70-security.php` and modify the value of `$app['login_required_to_view_gist']` with `true`.
263
-
264
-**Login required to view an embeded gist**
265
-
266
-Edit `app/bootstrap.php.d/70-security.php` and modify the value of `$app['login_required_to_view_embeded_gist']` with `true`.
267
-
268
-### Debug
269
-
270
-`app_dev.php` is the development router. Access is granted for an IP range defined in the same file.
253
+* **Create a gist**: `$ app/console --help create`
254
+* **Update a gist**: `$ app/console --help update`
255
+* **Create user**: `app/console --help user:create`
256
+* **Show stats**: `$ app/console --help stats`
271 257
 
272 258
 Deployment
273 259
 ----------
@@ -284,7 +270,7 @@ Gist uses [Magallanes](http://magephp.com/) to manage deployment.
284 270
 
285 271
 	$ composer require andres-montanez/magallanes
286 272
 
287
-There is an example of the configuration of an environment in `.mage/config/environment/prod.yml-dist`.
273
+There is an example of the configuration of an environment in `.mage/config/environment/prod.yml.dist`.
288 274
 
289 275
 	# global installation
290 276
 	$ mage deploy to:prod

+ 5
- 0
app/bootstrap.php.d/10-config.php View File

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

+ 8
- 2
app/bootstrap.php.d/50-git.php View File

@@ -3,10 +3,16 @@
3 3
 use GitWrapper\GitWrapper;
4 4
 use Gist\Service\Gist;
5 5
 
6
-$app['gist_path'] = $app['root_path'].'/data/git';
6
+$dataPath = $app['settings']['data']['path'];
7
+
8
+if ($dataPath[0] !== '/') {
9
+    $app['gist_path'] = $app['root_path'].$dataPath;
10
+} else {
11
+    $app['gist_path'] = $dataPath;
12
+}
7 13
 
8 14
 $app['git_wrapper'] = $app->share(function ($app) {
9
-    return new GitWrapper('/usr/bin/git');
15
+    return new GitWrapper($app['settings']['git']['path']);
10 16
 });
11 17
 
12 18
 $app['git_working_copy'] = $app->share(function ($app) {

+ 1
- 1
app/bootstrap.php.d/60-api.php View File

@@ -3,5 +3,5 @@
3 3
 use Gist\Api\Client;
4 4
 
5 5
 $app['api_client'] = $app->share(function ($app) {
6
-    return new Client(['base_uri' => 'https://gist.deblan.org/']);
6
+    return new Client(['base_uri' => $app['settings']['api']['base_uri']]);
7 7
 });

+ 6
- 10
app/bootstrap.php.d/70-security.php View File

@@ -9,13 +9,9 @@ use Gist\Security\AuthenticationListener;
9 9
 use Gist\Security\LogoutSuccessHandler;
10 10
 use Silex\Provider\SessionServiceProvider;
11 11
 
12
-$app['enable_registration'] = true;
13
-$app['enable_login'] = true;
14
-$app['login_required_to_edit_gist'] = false;
15
-$app['login_required_to_view_gist'] = false;
16
-$app['login_required_to_view_embeded_gist'] = false;
12
+$securitySettings = $app['settings']['security'];
17 13
 
18
-$app['token'] = 'ThisTokenIsNotSoSecretChangeIt';
14
+$app['token'] = $securitySettings['token'];
19 15
 
20 16
 $app['salt_generator'] = $app->share(function ($app) {
21 17
     return new SaltGenerator();
@@ -77,10 +73,10 @@ $firewall = [
77 73
     ],
78 74
 ];
79 75
 
80
-if ($app['login_required_to_edit_gist'] || $app['login_required_to_view_gist'] || $app['login_required_to_view_embeded_gist']) {
76
+if ($securitySettings['login_required_to_edit_gist'] || $securitySettings['login_required_to_view_gist'] || $securitySettings['login_required_to_view_embeded_gist']) {
81 77
     $exceptedUriPattern = ['login', 'register'];
82 78
 
83
-    if ($app['login_required_to_view_gist'] === true) {
79
+    if ($securitySettings['login_required_to_view_gist'] === true) {
84 80
         $firewall['security.access_rules'][] = ['^/[a-z]{2}/view.*$', 'ROLE_USER'];
85 81
         $firewall['security.access_rules'][] = ['^/[a-z]{2}/revs.*$', 'ROLE_USER'];
86 82
     } else {
@@ -88,13 +84,13 @@ if ($app['login_required_to_edit_gist'] || $app['login_required_to_view_gist'] |
88 84
         $exceptedUriPattern[] = 'revs';
89 85
     }
90 86
 
91
-    if ($app['login_required_to_view_embeded_gist'] === true) {
87
+    if ($securitySettings['login_required_to_view_embeded_gist'] === true) {
92 88
         $firewall['security.access_rules'][] = ['^/[a-z]{2}/embed.*$', 'ROLE_USER'];
93 89
     } else {
94 90
         $exceptedUriPattern[] = 'embed';
95 91
     }
96 92
 
97
-    if ($app['login_required_to_edit_gist'] === true) {
93
+    if ($securitySettings['login_required_to_edit_gist'] === true) {
98 94
         $firewall['security.access_rules'][] = ['^/[a-z]{2}/(?!('.implode('|', $exceptedUriPattern).')).*$', 'ROLE_USER'];
99 95
     }
100 96
 }

+ 15
- 0
app/config/config.yml.dist View File

@@ -0,0 +1,15 @@
1
+security:
2
+    token: ThisTokenIsNotSoSecretChangeIt
3
+    enable_registration: true
4
+    enable_login: true
5
+    login_required_to_edit_gist: true
6
+    login_required_to_view_gist: true
7
+    login_required_to_view_embeded_gist: true
8
+api:
9
+    base_url: 'https://gist.deblan.org/'
10
+data:
11
+    path: data/git
12
+git:
13
+    path: /usr/bin/git
14
+theme:
15
+    name: dark

+ 2
- 2
src/Gist/Controller/LoginController.php View File

@@ -26,7 +26,7 @@ class LoginController extends Controller
26 26
     {
27 27
         $app = $this->getApp();
28 28
 
29
-        if (false === $app['enable_registration']) {
29
+        if (false === $app['settings']['enable_registration']) {
30 30
             return new Response('', 403);
31 31
         }
32 32
 
@@ -78,7 +78,7 @@ class LoginController extends Controller
78 78
     {
79 79
         $app = $this->getApp();
80 80
 
81
-        if (false === $app['enable_login']) {
81
+        if (false === $app['settings']['enable_login']) {
82 82
             return new Response('', 403);
83 83
         }
84 84
 

+ 13
- 5
src/Gist/Resources/views/base.html.twig View File

@@ -1,11 +1,19 @@
1 1
 <!DOCTYPE html>
2
+{% set theme_settings = app.settings.theme %}
3
+{% set security_dettings = app.settings.security %}
2 4
 <html xmlns="http://www.w3.org/1999/xhtml">
3 5
     <head>
4 6
         {% block css %}
5 7
             <link rel="stylesheet" href="{{ web_path }}components/bootstrap/dist/css/bootstrap.min.css" />
6 8
             <link rel="stylesheet" href="{{ web_path }}components/flag-icon-css/css/flag-icon.min.css" />
7
-            <link rel="stylesheet" href="{{ web_path }}app/css/bootstrap/bootstrap.min.css" />
8
-            <link rel="stylesheet" href="{{ web_path }}app/css/app.css" />
9
+
10
+            {% if theme_settings.name == 'dark' %}
11
+                <link rel="stylesheet" href="{{ web_path }}app/css/bootstrap/bootstrap.min.css" />
12
+            {% else %}
13
+                <link rel="stylesheet" href="{{ web_path }}components/bootstrap/dist/css/bootstrap-theme.min.css" />
14
+            {% endif %}
15
+
16
+            <link rel="stylesheet" href="{{ web_path }}app/css/themes/{{ theme_settings.name }}.css" />
9 17
         {% endblock %}
10 18
 
11 19
         {% block metas %}
@@ -17,7 +25,7 @@
17 25
     </head>
18 26
     <body>
19 27
         {% block nav %}
20
-            <nav class="navbar navbar-inverse">
28
+            <nav class="navbar navbar-{{ theme_settings.name == 'dark' ? 'inverse' : 'default' }}">
21 29
                 <div class="container-fluid">
22 30
                     <div class="navbar-header">
23 31
                         <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#main-menu">
@@ -48,14 +56,14 @@
48 56
                                         {{ 'app.menu.my.logout.title'|trans }}
49 57
                                     </a>
50 58
                                 </li>
51
-                            {% elseif app.enable_login %}
59
+                            {% elseif security_dettings.enable_login %}
52 60
                                 <li>
53 61
                                     <a href="{{ path('login') }}">
54 62
                                         {{ 'app.menu.my.login.title'|trans }}
55 63
                                     </a>
56 64
                                 </li>
57 65
 
58
-                                {% if app.enable_registration %}
66
+                                {% if security_dettings.enable_registration %}
59 67
                                     <li>
60 68
                                         <a href="{{ path('register') }}">
61 69
                                             {{ 'app.menu.my.register.title'|trans }}

web/app/css/app.css → web/app/css/themes/dark.css View File


+ 78
- 0
web/app/css/themes/light.css View File

@@ -0,0 +1,78 @@
1
+.navbar {
2
+	border-radius: 0;
3
+}
4
+
5
+#form_content {
6
+	display: block;
7
+	width: 100%;
8
+	padding: 10px;
9
+}
10
+
11
+#languages {
12
+	padding-bottom: 5px;
13
+}
14
+
15
+#languages .btn-group:first-child {
16
+	margin-right: 4px;
17
+}
18
+
19
+pre {
20
+	background: #222;
21
+	border: #222;
22
+	color: #ddd;
23
+	white-space: pre-wrap;
24
+	white-space: -moz-pre-wrap;
25
+	white-space: -pre-wrap;
26
+	white-space: -o-pre-wrap;
27
+	word-wrap: break-word;
28
+}
29
+
30
+pre ol {
31
+	padding-left: 50px !important;
32
+}
33
+
34
+pre li:hover {
35
+	background: #444;
36
+}
37
+
38
+.panel-heading .actions {
39
+	margin-top: -5px;
40
+}
41
+
42
+div.diff {
43
+	display: none;
44
+}
45
+
46
+.de1 {
47
+	padding-left: 5px;
48
+	padding-right: 5px;
49
+}
50
+
51
+.li1 {
52
+	background: #333;
53
+}
54
+
55
+.re8 {
56
+	color: #52F700;
57
+}
58
+
59
+.kw3 {
60
+	color: #C6C765;
61
+}
62
+
63
+#viewer .syntaxhighlighter td {
64
+	vertical-align: top !important;
65
+}
66
+
67
+#options {
68
+	margin-bottom: 17px;
69
+}
70
+
71
+.btn-delete {
72
+    background: #DE3336;
73
+    color: #fff;
74
+}
75
+
76
+.btn-error:active, .btn-error:hover, .btn-error:focus {
77
+    color: #000;
78
+}

Loading…
Cancel
Save