]> www.vanbest.org Git - motioneye-debian/commitdiff
fixed issues with special characters in camera device paths
authorCalin Crisan <ccrisan@gmail.com>
Sun, 31 May 2015 08:30:27 +0000 (11:30 +0300)
committerCalin Crisan <ccrisan@gmail.com>
Sun, 31 May 2015 08:30:27 +0000 (11:30 +0300)
src/config.py
src/utils.py
src/v4l2ctl.py
static/js/main.js

index d4e48b812450e2eda1da37412b1485ad2d8ffcb3..af8d1f20cc69c3088619fbf4c616fbe001e053f1 100644 (file)
@@ -150,7 +150,7 @@ def set_main(main_config):
     lines = _dict_to_conf(lines, main_config, list_names=['thread'])
     
     try:
-        file.writelines([l + '\n' for l in lines])
+        file.writelines([utils.make_str(l) + '\n' for l in lines])
     
     except Exception as e:
         logging.error('could not write main config file %(path)s: %(msg)s' % {
@@ -420,7 +420,7 @@ def set_camera(camera_id, camera_config):
     lines = _dict_to_conf(lines, camera_config)
     
     try:
-        file.writelines([l + '\n' for l in lines])
+        file.writelines([utils.make_str(l) + '\n' for l in lines])
     
     except Exception as e:
         logging.error('could not write camera config file %(path)s: %(msg)s' % {
index b7aaf87dfeac6ebf349a2c76b14ffbe77e9d7535..32eb0c0501f6c281f2b683c1b57199c05e71ee5f 100644 (file)
@@ -37,6 +37,9 @@ except:
     from ordereddict import OrderedDict  # @UnusedImport @Reimport
 
 
+_SIGNATURE_REGEX = re.compile('[^a-zA-Z0-9/?_.=&{}\[\]":, _-]')
+
+
 def pretty_date_time(date_time, tzinfo=None, short=False):
     if date_time is None:
         return '('+  _('never') + ')'
@@ -230,6 +233,36 @@ def pretty_http_error(response):
     return msg
 
 
+def make_str(s):
+    if isinstance(s, str):
+        return s
+
+    try:
+        return str(s)
+
+    except:
+        try:
+            return unicode(s, encoding='utf8').encode('utf8')
+    
+        except:
+            return unicode(s).encode('utf8')
+
+
+def make_unicode(s):
+    if isinstance(s, unicode):
+        return s
+
+    try:
+        return unicode(s, encoding='utf8')
+    
+    except:
+        try:
+            return unicode(s)
+        
+        except:
+            return str(s).decode('utf8')
+
+
 def get_disk_usage(path):
     logging.debug('getting disk usage for path %(path)s...' % {
             'path': path})
@@ -359,10 +392,14 @@ def compute_signature(method, uri, body, key):
     parts[0] = parts[1] = ''
     parts[3] = query
     uri = urlparse.urlunsplit(parts)
-    
+    uri = _SIGNATURE_REGEX.sub('-', uri)
+    key = _SIGNATURE_REGEX.sub('-', key)
+
     if body and body.startswith('---'):
         body = None # file attachment
 
+    body = body and _SIGNATURE_REGEX.sub('-', body.decode('utf8'))
+
     return hashlib.sha1('%s:%s:%s:%s' % (method, uri, body or '', key)).hexdigest().lower()
 
 
index 8c17bd9e4ed584071285dc4ccae64185abefcbc4..3be3467522a5cda2cd3ed09717df2e0326b6573d 100644 (file)
@@ -22,6 +22,7 @@ import re
 import stat
 import subprocess
 import time
+import utils
 
 
 _resolutions_cache = {}
@@ -109,6 +110,8 @@ def list_devices():
 def list_resolutions(device):
     global _resolutions_cache
     
+    device = utils.make_str(device)
+    
     if device in _resolutions_cache:
         return _resolutions_cache[device]
     
@@ -117,7 +120,7 @@ def list_resolutions(device):
     resolutions = set()
     output = ''
     started = time.time()
-    p = subprocess.Popen('v4l2-ctl -d %(device)s --list-formats-ext | grep -vi stepwise | grep -oE "[0-9]+x[0-9]+" || true' % {
+    p = subprocess.Popen('v4l2-ctl -d "%(device)s" --list-formats-ext | grep -vi stepwise | grep -oE "[0-9]+x[0-9]+" || true' % {
             'device': device}, shell=True, stdout=subprocess.PIPE, bufsize=1)
 
     fd = p.stdout.fileno()
@@ -198,6 +201,8 @@ def list_resolutions(device):
 
 
 def device_present(device):
+    device = utils.make_str(device)
+    
     try:
         st = os.stat(device)
         return stat.S_ISCHR(st.st_mode)
@@ -207,6 +212,8 @@ def device_present(device):
     
 
 def find_persistent_device(device):
+    device = utils.make_str(device)
+    
     try:
         devs_by_id = os.listdir(_DEV_V4L_BY_ID)
 
@@ -256,6 +263,8 @@ def set_hue(device, value):
 def _get_ctrl(device, control):
     global _ctrl_values_cache
     
+    device = utils.make_str(device)
+    
     if not device_present(device):
         return None
     
@@ -292,6 +301,8 @@ def _get_ctrl(device, control):
 def _set_ctrl(device, control, value):
     global _ctrl_values_cache
     
+    device = utils.make_str(device)
+    
     if not device_present(device):
         return
 
@@ -321,7 +332,7 @@ def _set_ctrl(device, control, value):
 
     output = ''
     started = time.time()
-    p = subprocess.Popen('v4l2-ctl -d %(device)s --set-ctrl %(control)s=%(value)s' % {
+    p = subprocess.Popen('v4l2-ctl -d "%(device)s" --set-ctrl %(control)s=%(value)s' % {
             'device': device, 'control': control, 'value': value}, shell=True, stdout=subprocess.PIPE, bufsize=1)
 
     fd = p.stdout.fileno()
@@ -358,13 +369,15 @@ def _set_ctrl(device, control, value):
 
 def _list_ctrls(device):
     global _ctrls_cache
+    
+    device = utils.make_str(device)
 
     if device in _ctrls_cache:
         return _ctrls_cache[device]
     
     output = ''
     started = time.time()
-    p = subprocess.Popen('v4l2-ctl -d %(device)s --list-ctrls' % {
+    p = subprocess.Popen('v4l2-ctl -d "%(device)s" --list-ctrls' % {
             'device': device}, shell=True, stdout=subprocess.PIPE, bufsize=1)
 
     fd = p.stdout.fileno()
index c0a575b9363369b14bf4b887cce1225abf689927..8c0ddfb31879e448e3a8b5b4fa2c0528b4c802ae 100644 (file)
@@ -8,6 +8,7 @@ var refreshInterval = 50; /* milliseconds */
 var username = '';
 var password = '';
 var baseUri = null;
+var signatureRegExp = new RegExp('[^a-zA-Z0-9/?_.=&{}\\[\\]":, _-]', 'g');
 
 
     /* utils */
@@ -150,9 +151,12 @@ function computeSignature(method, uri, body) {
     query = query.filter(function (q) {return q.key !== '_signature';});
     query.sortKey(function (q) {return q.key;});
     query = query.map(function (q) {return q.key + '=' + encodeURIComponent(q.value);}).join('&');
-    uri = baseUrl + '?' + query; 
+    uri = baseUrl + '?' + query;
+    uri = uri.replace(signatureRegExp, '-');
+    body = body && body.replace(signatureRegExp, '-');
+    var password = window.password.replace(signatureRegExp, '-');
     
-    return sha1(method + ':' + uri + ':' + (body || '') + ':' + window.password).toLowerCase();
+    return sha1(method + ':' + uri + ':' + (body || '') + ':' + password).toLowerCase();
 }
 
 function addAuthParams(method, url, body) {