]> www.vanbest.org Git - motioneye-debian/commitdiff
initial work on smb shares
authorCalin Crisan <ccrisan@gmail.com>
Mon, 23 Jun 2014 18:52:15 +0000 (21:52 +0300)
committerCalin Crisan <ccrisan@gmail.com>
Mon, 23 Jun 2014 18:52:15 +0000 (21:52 +0300)
doc/requirements.txt
doc/todo.txt [new file with mode: 0644]
src/config.py
src/handlers.py
src/smbctl.py

index bea5c22041192d1773d491cc99bbbffd1cca9c59..9a71525d9b56f1e60d46738a8161a0bd409b0129 100644 (file)
@@ -6,3 +6,4 @@ pil
 ffmpeg
 motion
 v4l-utils
+cifs-utils
diff --git a/doc/todo.txt b/doc/todo.txt
new file mode 100644 (file)
index 0000000..0c770cf
--- /dev/null
@@ -0,0 +1,4 @@
+-> in continuare o camera remote moarta blocheaza intreg sistemul la load
+-> use minimum_frame_time
+-> implement custom camera frame sizes
+-> add a separate full-screen camera link
index b4ea82ee0d45c816663e75334c666d3db73c5b61..a5fa4cd49bf2c6546459c056505b7c871a8ca6a2 100644 (file)
@@ -24,6 +24,7 @@ from collections import OrderedDict
 
 import motionctl
 import settings
+import smbctl
 import update
 import utils
 import v4l2ctl
@@ -483,7 +484,6 @@ def camera_ui_to_dict(ui):
         '@network_share_name': ui['network_share_name'],
         '@network_username': ui['network_username'],
         '@network_password': ui['network_password'],
-        'target_dir': ui['root_directory'],
         
         # text overlay
         'text_left': '',
@@ -560,6 +560,15 @@ def camera_ui_to_dict(ui):
         else:
             data['hue'] = max(1, int(round(int(ui['hue']) * 2.55)))
 
+    if ui['storage_device'] == 'network-share':
+        mount_point = smbctl.make_mount_point(ui['network_server'], ui['network_share_name'], ui['network_username'])
+        if ui['root_directory'].startswith('/'):
+            ui['root_directory'] = ui['root_directory'][1:]
+        data['target_dir'] = os.path.join(mount_point, ui['root_directory'])
+
+    else:
+        data['target_dir'] = ui['root_directory']
+
     if ui['text_overlay']:
         left_text = ui['left_text']
         if left_text == 'camera-name':
@@ -617,7 +626,7 @@ def camera_ui_to_dict(ui):
                 ui['sunday_from'] + '-' + ui['sunday_to'])
 
     return data
-    
+
 
 def camera_dict_to_ui(data):
     usage = utils.get_disk_usage(data['target_dir'])
@@ -654,7 +663,6 @@ def camera_dict_to_ui(data):
         'network_share_name': data['@network_share_name'],
         'network_username': data['@network_username'],
         'network_password': data['@network_password'],
-        'root_directory': data['target_dir'],
         'disk_used': disk_used,
         'disk_total': disk_total,
         
@@ -745,6 +753,13 @@ def camera_dict_to_ui(data):
         
         else:
             ui['hue'] = 50
+    
+    if data['@storage_device'] == 'network-share':
+        mount_point = smbctl.make_mount_point(data['@network_server'], data['@network_share_name'], data['@network_username'])
+        ui['root_directory'] = data['target_dir'][len(mount_point):]
+    
+    else:
+        ui['root_directory'] = data['target_dir']
 
     text_left = data['text_left']
     text_right = data['text_right'] 
index ffa4f3b85ea386136f57fb9d40ca42b8aa97ad77..c82252db72fe42f8410809853476489e0347a501 100644 (file)
@@ -74,11 +74,9 @@ class BaseHandler(RequestHandler):
                 main_config = config.get_main()
                 
                 if user == main_config.get('@admin_username') and pwd == main_config.get('@admin_password'):
-                    
                     return 'admin'
                 
                 elif user == main_config.get('@normal_username') and pwd == main_config.get('@normal_password'):
-                    
                     return 'normal'
                 
                 else:
index 166c42756c32cd12717e2c73df4c1c675bd62795..009f69fea858ed072821304398525bcbe7fc0d20 100644 (file)
@@ -19,6 +19,7 @@ import logging
 import os
 import re
 import subprocess
+import time
 
 
 def find_mount_cifs():
@@ -29,7 +30,7 @@ def find_mount_cifs():
         return None
 
 
-def _make_mount_point(server, share, username):
+def make_mount_point(server, share, username):
     server = re.sub('[^a-zA-Z0-9]', '_', server).lower()
     share = re.sub('[^a-zA-Z0-9]', '_', share).lower()
     
@@ -39,12 +40,13 @@ def _make_mount_point(server, share, username):
     else:
         mount_point = '/media/motioneye_%s_%s' % (server, share)
 
-    logging.debug('making sure mount point "%s" exists' % mount_point)    
-    os.makedirs(mount_point)
-    
     return mount_point
 
 
+def _is_motioneye_mount(mount_point):
+    return bool(re.match('^/media/motioneye_\w+$', mount_point))
+
+
 def list_mounts():
     logging.debug('listing smb mounts...')
     
@@ -67,6 +69,9 @@ def list_mounts():
             if fstype != 'cifs':
                 continue
             
+            if not _is_motioneye_mount(mount_point):
+                continue
+            
             match = re.match('//([^/]+)/(.+)', target)
             if not match:
                 continue
@@ -82,7 +87,7 @@ def list_mounts():
             
             else:
                 username = None
-            
+                
             logging.debug('found smb mount "//%s/%s" at "%s"' % (server, share, mount_point))
             
             mounts.append({
@@ -91,18 +96,17 @@ def list_mounts():
                 'username': username,
                 'mount_point': mount_point
             })
-            
-    return mounts
-
 
-def is_motioneye_mount(mount_point):
-    return bool(re.match('^/media/motioneye_\w+$', mount_point))
+    return mounts
 
 
 def mount(server, share, username, password):
-    mount_point = _make_mount_point(server, share, username)
+    mount_point = make_mount_point(server, share, username)
     logging.debug('mounting "//%s/%s" at "%s"' % (server, share, mount_point))
     
+    logging.debug('making sure mount point "%s" exists' % mount_point)    
+    os.makedirs(mount_point)
+    
     if username:
         opts = 'username=%s,password=%s' % (username, password)
         
@@ -112,16 +116,28 @@ def mount(server, share, username, password):
     try:
         subprocess.check_call('mount.cifs //%s/%s %s -o %s' % (server, share, mount_point, opts), shell=True)
         
-        return mount_point
-
     except subprocess.CalledProcessError:
         logging.error('failed to mount smb share "//%s/%s" at "%s"' % (server, share, mount_point))
         
         return False
+    
+    # test to see if mount point is writable
+    try:
+        path = os.path.join(mount_point, '.motioneye_' + str(int(time.time())))
+        os.mkdir(path)
+        os.rmdir(path)
+        logging.debug('directory at "%s" is writable' % mount_point)
+    
+    except:
+        logging.error('directory at "%s" is not writable' % mount_point)
+        
+        return False
+    
+    return mount_point
 
 
 def umount(server, share, username):
-    mount_point = _make_mount_point(server, share, username)
+    mount_point = make_mount_point(server, share, username)
     logging.debug('unmounting "//%s/%s" from "%s"' % (server, share, mount_point))
     
     try: