Pārlūkot izejas kodu

add satisfy configuration to the ui

Kyle Klaus 5 gadi atpakaļ
vecāks
revīzija
0f238a5021

+ 5 - 1
backend/internal/access-list.js

@@ -30,6 +30,7 @@ const internalAccessList = {
 					.omit(omissions())
 					.insertAndFetch({
 						name:          data.name,
+						satify_any:    data.satify_any,
 						owner_user_id: access.token.getUserId(1)
 					});
 			})
@@ -125,7 +126,8 @@ const internalAccessList = {
 						.query()
 						.where({id: data.id})
 						.patch({
-							name: data.name
+							name:       data.name,
+							satify_any: data.satify_any,
 						});
 				}
 			})
@@ -478,10 +480,12 @@ const internalAccessList = {
 
 		return new Promise((resolve, reject) => {
 			let htpasswd_file = internalAccessList.getFilename(list);
+			let nginx_file = internalAccessList.getFilename(list) + '.conf';
 
 			// 1. remove any existing access file
 			try {
 				fs.unlinkSync(htpasswd_file);
+				fs.unlinkSync(nginx_file);
 			} catch (err) {
 				// do nothing
 			}

+ 7 - 0
backend/migrations/20200410143839_access_list_client.js

@@ -26,6 +26,13 @@ exports.up = function (knex/*, Promise*/) {
 	})
 		.then(function () {
 			logger.info('[' + migrate_name + '] access_list_client Table created');
+
+			return knex.schema.table('access_list', function (access_list) {
+				access_list.integer('satify_any').notNull().defaultTo(0);
+			});
+		})
+		.then(() => {
+			logger.info('[' + migrate_name + '] access_list Table altered');
 		});
 };
 

+ 11 - 2
backend/schema/endpoints/access-lists.json

@@ -27,6 +27,9 @@
       "type": "string",
       "format": "ipv4"
     },
+    "satify_any": {
+      "type": "boolean"
+    },
     "meta": {
       "type": "object"
     }
@@ -86,9 +89,12 @@
           "name": {
             "$ref": "#/definitions/name"
           },
+          "satify_any": {
+            "$ref": "#/definitions/satify_any"
+          },
           "items": {
             "type": "array",
-            "minItems": 1,
+            "minItems": 0,
             "items": {
               "type": "object",
               "additionalProperties": false,
@@ -148,9 +154,12 @@
           "name": {
             "$ref": "#/definitions/name"
           },
+          "satify_any": {
+            "$ref": "#/definitions/satify_any"
+          },
           "items": {
             "type": "array",
-            "minItems": 1,
+            "minItems": 0,
             "items": {
               "type": "object",
               "additionalProperties": false,

+ 10 - 0
frontend/js/app/nginx/access/form.ejs

@@ -21,6 +21,16 @@
                                 <input type="text" name="name" class="form-control" value="<%- name %>" required>
                             </div>
                         </div>
+
+                        <div class="col-sm-6 col-md-6">
+                            <div class="form-group">
+                                <label class="custom-switch">
+                                    <input type="checkbox" class="custom-switch-input" name="satify_any" value="1"<%- typeof satify_any !== 'undefined' && satify_any ? ' checked' : '' %>>
+                                    <span class="custom-switch-indicator"></span>
+                                    <span class="custom-switch-description"><%- i18n('access-lists', 'satisfy-any') %></span>
+                                </label>
+                            </div>
+                        </div>
                     </div>
                 </div>
 

+ 8 - 5
frontend/js/app/nginx/access/form.js

@@ -65,17 +65,20 @@ module.exports = Mn.View.extend({
                 }
             });
 
-            if (!items_data.length) {
-                alert('You must specify at least 1 Username and Password combination');
+            if (!items_data.length && !clients_data.length) {
+                alert('You must specify at least 1 Authorization or Access rule');
                 return;
             }
 
             let data = {
-                name:    form_data.name,
-                items:   items_data,
-                clients: clients_data
+                name:       form_data.name,
+                satify_any: !!form_data.satify_any,
+                items:      items_data,
+                clients:    clients_data
             };
 
+            console.log(data);
+
             let method = App.Api.Nginx.AccessLists.create;
             let is_new = true;
 

+ 7 - 0
frontend/js/app/nginx/access/list/item.ejs

@@ -17,6 +17,13 @@
 <td>
     <%- i18n('access-lists', 'client-count', {count: clients.length || 0}) %>
 </td>
+<td>
+    <% if (satify_any) { %>
+    <%- i18n('str', 'any') %>
+    <%} else { %>
+    <%- i18n('str', 'all') %>
+    <% } %>
+</td>
 <td>
     <%- i18n('access-lists', 'proxy-host-count', {count: proxy_host_count}) %>
 </td>

+ 1 - 0
frontend/js/app/nginx/access/list/main.ejs

@@ -3,6 +3,7 @@
     <th><%- i18n('str', 'name') %></th>
     <th><%- i18n('access-lists', 'authorization') %></th>
     <th><%- i18n('access-lists', 'access') %></th>
+    <th><%- i18n('access-lists', 'satisfy') %></th>
     <th><%- i18n('proxy-hosts', 'title') %></th>
     <% if (canManage) { %>
     <th>&nbsp;</th>

+ 6 - 2
frontend/js/i18n/messages.json

@@ -33,7 +33,9 @@
       "unknown": "Unknown",
       "expires": "Expires",
       "value": "Value",
-      "please-wait": "Please wait..."
+      "please-wait": "Please wait...",
+      "all": "All",
+      "any": "Any"
     },
     "login": {
       "title": "Login to your account"
@@ -191,7 +193,9 @@
       "delete-has-hosts": "This Access List is associated with {count} Proxy Hosts. They will become publicly available upon deletion.",
       "details": "Details",
       "authorization": "Authorization",
-      "access": "Access"
+      "access": "Access",
+      "satisfy": "Satisfy",
+      "satisfy-any": "Satify Any"
     },
     "users": {
       "title": "Users",