else:
self.finish_json({'ok': False})
-
+
@BaseHandler.auth(admin=True)
def test(self, camera_id):
what = self.get_argument('what')
data = self.get_all_arguments()
camera_config = config.get_camera(camera_id)
- if what == 'upload_service':
- service_name = data.get('service')
- if not service_name:
- raise HTTPError(400, 'service_name required')
-
- if utils.local_motion_camera(camera_config):
+
+ if utils.local_motion_camera(camera_config):
+ if what == 'upload_service':
+ service_name = data['service']
service = uploadservices.get(camera_id, service_name)
service.load(data)
if not service:
else:
logging.warn('accessing %s failed: %s' % (service, result))
self.finish_json({'error': result})
-
- elif utils.remote_camera(camera_config):
- def on_response(result=None, error=None):
- if result is True:
- self.finish_json()
-
- else:
- result = result or error
- self.finish_json({'error': result})
-
- remote.test(camera_config, data, on_response)
-
- elif what == 'email':
- import sendmail
- import tzctl
- import smtplib
-
- if utils.local_motion_camera(camera_config):
+
+ elif what == 'email':
+ import sendmail
+ import tzctl
+ import smtplib
+
logging.debug('testing notification email')
try:
settings.SMTP_TIMEOUT = old_timeout
self.finish_json()
-
+
+ logging.debug('notification email test succeeded')
+
except Exception as e:
if isinstance(e, smtplib.SMTPResponseException):
msg = e.smtp_error
logging.error('notification email test failed: %s' % msg, exc_info=True)
self.finish_json({'error': str(msg)})
-
- elif utils.remote_camera(camera_config):
- def on_response(result=None, error=None):
- if result is True:
- self.finish_json()
-
- else:
- result = result or error
- self.finish_json({'error': result})
- remote.test(camera_config, data, on_response)
+ elif what == 'network_share':
+ logging.debug('testing access to network share //%s/%s' % (data['server'], data['share']))
+
+ try:
+ smbctl.test_share(data['server'], data['share'], data['username'], data['password'], data['root_directory'])
+ logging.debug('access to network share //%s/%s succeeded' % (data['server'], data['share']))
+ self.finish_json()
+
+ except Exception as e:
+ logging.error('access to network share //%s/%s failed: %s' % (data['server'], data['share'], e))
+ self.finish_json({'error': str(e)})
+
+ else:
+ raise HTTPError(400, 'unknown test %s' % what)
+ elif utils.remote_camera(camera_config):
+ def on_response(result=None, error=None):
+ if result is True:
+ self.finish_json()
+
+ else:
+ result = result or error
+ self.finish_json({'error': result})
+
+ remote.test(camera_config, data, on_response)
+
else:
- raise HTTPError(400, 'unknown test %s' % what)
+ raise HTTPError(400, 'cannot test features on this type of camera')
@BaseHandler.auth(admin=True)
def authorize(self, camera_id):
return (should_stop, should_start)
+def test_share(server, share, username, password, root_directory):
+ mounts = list_mounts()
+ mounts = dict(((m['server'], m['share'], m['username'] or ''), m['mount_point']) for m in mounts)
+
+ key = (server, share, username or '')
+ mounted = False
+ mount_point = mounts.get(key)
+ if not mount_point:
+ mount_point = _mount(server, share, username, password)
+ if not mount_point:
+ raise Exception('cannot mount network share')
+
+ mounted = True
+
+ def maybe_umount():
+ if mounted:
+ time.sleep(1)
+ _umount(server, share, username)
+
+ path = os.path.join(mount_point, root_directory)
+ if os.path.exists(path):
+ return maybe_umount()
+
+ try:
+ os.makedirs(path)
+
+ except:
+ raise Exception('cannot create root directory')
+
+ finally:
+ maybe_umount()
+
+
def _mount(server, share, username, password):
mount_point = make_mount_point(server, share, username)
});
}
+function doTestNetworkShare() {
+ var q = $('#networkServerEntry, #networkShareNameEntry, #rootDirectoryEntry');
+ var valid = true;
+ q.each(function() {
+ this.validate();
+ if (this.invalid) {
+ valid = false;
+ }
+ });
+
+ if (!valid) {
+ return runAlertDialog('Make sure all the configuration options are valid!');
+ }
+
+ showModalDialog('<div class="modal-progress"></div>', null, null, true);
+
+ var data = {
+ what: 'network_share',
+ server: $('#networkServerEntry').val(),
+ share: $('#networkShareNameEntry').val(),
+ username: $('#networkUsernameEntry').val(),
+ password: $('#networkPasswordEntry').val(),
+ root_directory: $('#rootDirectoryEntry').val()
+ };
+
+ var cameraId = $('#cameraSelect').val();
+
+ ajax('POST', basePath + 'config/' + cameraId + '/test/', data, function (data) {
+ hideModalDialog(); /* progress */
+ if (data.error) {
+ showErrorMessage('Accessing network share failed: ' + data.error + '!');
+ }
+ else {
+ showPopupMessage('Accessing network share succeeded!', 'info');
+ }
+ });
+}
+
function doDownloadZipped(cameraId, groupKey) {
showModalDialog('<div class="modal-progress"></div>', null, null, true);
ajax('GET', basePath + 'picture/' + cameraId + '/zipped/' + groupKey + '/', null, function (data) {
/* test buttons */
$('div#uploadTestButton').click(doTestUpload);
$('div#emailTestButton').click(doTestEmail);
+ $('div#networkShareTestButton').click(doTestNetworkShare);
initUI();
beginProgress();