]> www.vanbest.org Git - motioneye-debian/commitdiff
added support for regex validators in additional config
authorCalin Crisan <ccrisan@gmail.com>
Tue, 24 Feb 2015 15:12:36 +0000 (17:12 +0200)
committerCalin Crisan <ccrisan@gmail.com>
Tue, 24 Feb 2015 15:12:36 +0000 (17:12 +0200)
motioneye.py
static/js/main.js
templates/main.html

index 9648fd39f5317146e327ba4215cbbd923d589498..915ba8b2b553dca97cad212364ba1d75bf9f8365 100755 (executable)
@@ -148,9 +148,9 @@ def _test_requirements():
             print('SMB_SHARES require root privileges')
             return False
 
-#         if settings.ENABLE_REBOOT: # TODO
-            print('reboot requires root privileges')
-            return False
+        if settings.ENABLE_REBOOT:
+            print('reboot requires root privileges')
+            return False
 
     try:
         import tornado  # @UnusedImport
index 4cce2c39aeaf96489316147050400a679b8c66ce..9b8691e0ee8e50d34b6831053a9544eaa72b5e02 100644 (file)
@@ -515,6 +515,27 @@ function initUI() {
         
         return true;
     }, '');
+    $('tr[validate] input[type=text]').each(function () {
+        var $this = $(this);
+        var $tr = $this.parent().parent();
+        var required = $tr.attr('required');
+        var validate = $tr.attr('validate');
+        if (!validate) {
+            return;
+        }
+
+        makeCustomValidator($this, function (value) {
+            if (!value && required) {
+                return 'this field is required';
+            }
+
+            if (!value.toLowerCase().match(new RegExp(validate))) {
+                return 'enter a valid value';
+            }
+
+            return true;
+        }, '');
+    });
     
     /* input value processors */
     makeStrippedInput($('tr[strip=true] input[type=text]'));
@@ -557,9 +578,8 @@ function initUI() {
         var $tr = $(this);
         var depends = $tr.attr('depends').split(' ');
         depends.forEach(function (depend) {
-            if (depend.charAt(0) == '!') {
-                depend = depend.substring(1);
-            }
+            depend = depend.split('=')[0];
+            depend = depend.replace(new RegExp('[^a-zA-Z0-9_]', 'g'), '');
             
             if (depend in seenDependNames) {
                 return;
@@ -850,11 +870,10 @@ function updateConfigUi() {
         var depends = $tr.attr('depends').split(' ');
         var conditionOk = true;
         depends.every(function (depend) {
-            var neg = false;
-            if (depend.charAt(0) == '!') {
-                neg = true;
-                depend = depend.substring(1);
-            }
+            var neg = depend.indexOf('!') >= 0;
+            var parts = depend.split('=');
+            var boolCheck = parts.length == 1;
+            depend = parts[0].replace(new RegExp('[^a-zA-Z0-9_$]', 'g'), '');
 
             var control = $('#' + depend + 'Entry, #' + depend + 'Select, #' + depend + 'Slider');
             var val = false;
@@ -867,17 +886,25 @@ function updateConfigUi() {
                     val = control.get(0).checked;
                 }
             }
-            
-            val = Boolean(val);
-            if (neg) {
-                val = !val;
+
+            if (boolCheck) {
+                if (neg) {
+                    val = !val;
+                }
+                
+                if (!val) {
+                    conditionOk = false;
+                    return false;
+                }
             }
-            
-            if (!val) {
-                conditionOk = false;
-                return false;
+            else { /* comparison */
+                var equal = parts[parts.length - 1] == val;
+                if (equal == neg) {
+                    conditionOk = false;
+                    return false;
+                }
             }
-            
+
             return true;
         });
         
index 9e1aa01d6c5a2c55b3bafe5de3ae0d66ac1d7a0d..b7119184f900fbc1031f65217f7a2bec5412fc46 100644 (file)
@@ -14,7 +14,8 @@
             {% if config.get('ticks') %}ticks="{{config['ticks']}}"{% endif %}
             {% if config.get('ticksnum') is not none %}ticksnum="{{config['ticksnum']}}"{% endif %}
             {% if config.get('decimals') is not none %}decimals="{{config['decimals']}}"{% endif %}
-            {% if config.get('unit') %}unit="{{config['unit']}}"{% endif %}>
+            {% if config.get('unit') %}unit="{{config['unit']}}"{% endif %}
+            {% if config.get('validate') %}validate="{{config['validate']}}"{% endif %}>
         {% if config['type'] == 'separator' %}
         <td colspan="100"><div class="settings-item-separator"></div></td>
         {% else %}