[Pkg-owncloud-commits] [owncloud] 138/258: Moved WebDAV and internet checks to client side JS

David Prévot taffit at moszumanska.debian.org
Sat Oct 11 17:22:29 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository owncloud.

commit 2013404e0a5ccb4d0fce73ee3ff6af2ece0a1c70
Author: Vincent Petry <pvince81 at owncloud.com>
Date:   Mon Feb 3 12:48:17 2014 +0100

    Moved WebDAV and internet checks to client side JS
    
    - Added setup checks in JavaScript
    - Moved isWebDAVWorking to JS using SetupChecks
    - Moved internet connection checks to an ajax call that goes through the
      server
    
    Backport of e65ceb08fc4a56d0fb9e4be5d51ba04168cbb59a from master
---
 core/js/js.js                |  1 +
 core/js/setupchecks.js       | 71 ++++++++++++++++++++++++++++++++++++++++++++
 lib/private/util.php         | 46 ----------------------------
 settings/admin.php           |  9 +++---
 settings/ajax/checksetup.php | 23 ++++++++++++++
 settings/css/settings.css    | 14 ++++++++-
 settings/js/admin.js         | 21 +++++++++++++
 settings/routes.php          |  2 ++
 settings/templates/admin.php | 41 +++++++------------------
 9 files changed, 146 insertions(+), 82 deletions(-)

diff --git a/core/js/js.js b/core/js/js.js
index 60f9cc1..83ba91a 100644
--- a/core/js/js.js
+++ b/core/js/js.js
@@ -254,6 +254,7 @@ var OC={
 	 * @param {string} type the type of the file to link to (e.g. css,img,ajax.template)
 	 * @param {string} file the filename
 	 * @return {string} Absolute URL for a file in an app
+	 * @deprecated use OC.generateUrl() instead
 	 */
 	filePath:function(app,type,file){
 		var isCore=OC.coreApps.indexOf(app)!==-1,
diff --git a/core/js/setupchecks.js b/core/js/setupchecks.js
new file mode 100644
index 0000000..f351c1b
--- /dev/null
+++ b/core/js/setupchecks.js
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2014
+ *
+ * This file is licensed under the Affero General Public License version 3
+ * or later.
+ *
+ * See the COPYING-README file.
+ *
+ */
+
+(function() {
+	OC.SetupChecks = {
+		/**
+		 * Check whether the WebDAV connection works.
+		 *
+		 * @return $.Deferred object resolved with an array of error messages
+		 */
+		checkWebDAV: function() {
+			var deferred = $.Deferred();
+			var afterCall = function(xhr) {
+				var messages = [];
+				if (xhr.status !== 207 && xhr.status !== 401) {
+					messages.push(
+						t('core', 'Your web server is not yet properly setup to allow files synchronization because the WebDAV interface seems to be broken.')
+					);
+				}
+				deferred.resolve(messages);
+			};
+
+			$.ajax({
+				type: 'PROPFIND',
+				url: OC.linkToRemoteBase('webdav'),
+				data: '<?xml version="1.0"?>' +
+						'<d:propfind xmlns:d="DAV:">' +
+						'<d:prop><d:resourcetype/></d:prop>' +
+						'</d:propfind>',
+				complete: afterCall
+			});
+			return deferred.promise();
+		},
+
+		/**
+		 * Runs setup checks on the server side
+		 *
+		 * @return $.Deferred object resolved with an array of error messages
+		 */
+		checkSetup: function() {
+			var deferred = $.Deferred();
+			var afterCall = function(data, statusText, xhr) {
+				var messages = [];
+				if (xhr.status === 200 && data) {
+					if (!data.serverhasinternetconnection) {
+						messages.push(
+							t('core', 'This server has no working internet connection. This means that some of the features like mounting of external storage, notifications about updates or installation of 3rd party apps don´t work. Accessing files from remote and sending of notification emails might also not work. We suggest to enable internet connection for this server if you want to have all features.')
+						);
+					}
+				} else {
+					messages.push(t('core', 'Error occurred while checking server setup'));
+				}
+				deferred.resolve(messages);
+			};
+
+			$.ajax({
+				type: 'GET',
+				url: OC.generateUrl('settings/ajax/checksetup')
+			}).then(afterCall, afterCall);
+			return deferred.promise();
+		}
+	};
+})();
+
diff --git a/lib/private/util.php b/lib/private/util.php
index 3e1f334..ceb55bb 100755
--- a/lib/private/util.php
+++ b/lib/private/util.php
@@ -1029,52 +1029,6 @@ class OC_Util {
 	}
 
 	/**
-	 * test if webDAV is working properly
-	 * @return bool
-	 * @description
-	 * The basic assumption is that if the server returns 401/Not Authenticated for an unauthenticated PROPFIND
-	 * the web server it self is setup properly.
-	 *
-	 * Why not an authenticated PROPFIND and other verbs?
-	 *  - We don't have the password available
-	 *  - We have no idea about other auth methods implemented (e.g. OAuth with Bearer header)
-	 *
-	 */
-	public static function isWebDAVWorking() {
-		if (!function_exists('curl_init')) {
-			return true;
-		}
-		if (!\OC_Config::getValue("check_for_working_webdav", true)) {
-			return true;
-		}
-		$settings = array(
-			'baseUri' => OC_Helper::linkToRemote('webdav'),
-		);
-
-		$client = new \OC_DAVClient($settings);
-
-		$client->setRequestTimeout(10);
-
-		// for this self test we don't care if the ssl certificate is self signed and the peer cannot be verified.
-		$client->setVerifyPeer(false);
-		// also don't care if the host can't be verified
-		$client->setVerifyHost(0);
-
-		$return = true;
-		try {
-			// test PROPFIND
-			$client->propfind('', array('{DAV:}resourcetype'));
-		} catch (\Sabre\DAV\Exception\NotAuthenticated $e) {
-			$return = true;
-		} catch (\Exception $e) {
-			OC_Log::write('core', 'isWebDAVWorking: NO - Reason: '.$e->getMessage(). ' ('.get_class($e).')', OC_Log::WARN);
-			$return = false;
-		}
-
-		return $return;
-	}
-
-	/**
 	 * Check if the setlocal call does not work. This can happen if the right
 	 * local packages are not available on the server.
 	 * @return bool
diff --git a/settings/admin.php b/settings/admin.php
index 7d4fc31..9b1a822 100755
--- a/settings/admin.php
+++ b/settings/admin.php
@@ -9,11 +9,12 @@ OC_Util::checkAdminUser();
 
 OCP\Util::addStyle('settings', 'settings');
 OCP\Util::addScript('settings', 'settings');
-OC_Util::addScript( "settings", "admin" );
-OC_Util::addScript( "settings", "log" );
-OC_Util::addScript( 'core', 'multiselect' );
+OCP\Util::addScript( "settings", "admin" );
+OCP\Util::addScript( "settings", "log" );
+OCP\Util::addScript( 'core', 'multiselect' );
 OCP\Util::addScript('core', 'select2/select2');
 OCP\Util::addStyle('core', 'select2/select2');
+OCP\Util::addScript('core', 'setupchecks');
 OC_App::setActiveNavigationEntry( "admin" );
 
 $tmpl = new OC_Template( 'settings', 'admin', 'user');
@@ -41,10 +42,8 @@ $tmpl->assign('mail_smtppassword', OC_Config::getValue( "mail_smtppassword", ''
 $tmpl->assign('entries', $entries);
 $tmpl->assign('entriesremain', $entriesremain);
 $tmpl->assign('htaccessworking', $htaccessworking);
-$tmpl->assign('internetconnectionworking', OC_Util::isInternetConnectionEnabled() ? OC_Util::isInternetConnectionWorking() : 'disabled');
 $tmpl->assign('isLocaleWorking', OC_Util::isSetLocaleWorking());
 $tmpl->assign('isAnnotationsWorking', OC_Util::isAnnotationsWorking());
-$tmpl->assign('isWebDavWorking', OC_Util::isWebDAVWorking());
 $tmpl->assign('has_fileinfo', OC_Util::fileInfoLoaded());
 $tmpl->assign('old_php', OC_Util::isPHPoutdated());
 $tmpl->assign('backgroundjobs_mode', OC_Appconfig::getValue('core', 'backgroundjobs_mode', 'ajax'));
diff --git a/settings/ajax/checksetup.php b/settings/ajax/checksetup.php
new file mode 100644
index 0000000..6bf5bc5
--- /dev/null
+++ b/settings/ajax/checksetup.php
@@ -0,0 +1,23 @@
+<?php
+/**
+ * Copyright (c) 2014, Vincent Petry <pvince81 at owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or later.
+ * See the COPYING-README file.
+ */
+
+OCP\JSON::checkAdminUser();
+OCP\JSON::callCheck();
+
+\OC::$server->getSession()->close();
+
+// no warning when has_internet_connection is false in the config
+$hasInternet = true;
+if (OC_Util::isInternetConnectionEnabled()) {
+	$hasInternet = OC_Util::isInternetConnectionWorking();
+}
+
+OCP\JSON::success(
+	array(
+		'serverhasinternetconnection' => $hasInternet
+	)
+);
diff --git a/settings/css/settings.css b/settings/css/settings.css
index a62a971..8989bad 100644
--- a/settings/css/settings.css
+++ b/settings/css/settings.css
@@ -163,7 +163,7 @@ table.grid td.date{
 }
 
 /* ADMIN */
-span.securitywarning, span.connectionwarning {
+span.securitywarning, span.connectionwarning, .setupwarning {
 	color:#C33;
 	font-weight:bold;
 }
@@ -254,3 +254,15 @@ doesnotexist:-o-prefocus, .strengthify-wrapper {
 	border: 0;
 	overflow: auto;
 }
+
+#postsetupchecks .loading {
+	height: 50px;
+}
+
+#postsetupchecks.section .loading {
+	background-position: left center;
+}
+
+#postsetupchecks .hint, #postsetupchecks .setupwarning {
+	margin-top: 15px;
+}
diff --git a/settings/js/admin.js b/settings/js/admin.js
index 95be13d..d8cdae9 100644
--- a/settings/js/admin.js
+++ b/settings/js/admin.js
@@ -122,4 +122,25 @@ $(document).ready(function(){
 	$('#shareapiExcludeGroups').change(function() {
 		$("#selectExcludedGroups").toggleClass('hidden', !this.checked);
 	});
+
+	// run setup checks then gather error messages
+	$.when(
+		OC.SetupChecks.checkWebDAV(),
+		OC.SetupChecks.checkSetup()
+	).then(function(check1, check2) {
+		var errors = [].concat(check1, check2);
+		var $el = $('#postsetupchecks');
+		var $errorsEl;
+		$el.find('.loading').addClass('hidden');
+		if (errors.length === 0) {
+			$el.find('.success').removeClass('hidden');
+		} else {
+			$errorsEl = $el.find('.errors');
+			for (var i = 0; i < errors.length; i++ ) {
+				$errorsEl.append('<div class="setupwarning">' + errors[i] + '</div>');
+			}
+			$errorsEl.removeClass('hidden');
+			$el.find('.hint').removeClass('hidden');
+		}
+	});
 });
diff --git a/settings/routes.php b/settings/routes.php
index d98497e..19bbe0f 100644
--- a/settings/routes.php
+++ b/settings/routes.php
@@ -94,3 +94,5 @@ $this->create('settings_ajax_setsecurity', '/settings/ajax/setsecurity.php')
 	->actionInclude('settings/ajax/setsecurity.php');
 $this->create('settings_ajax_excludegroups', '/settings/ajax/excludegroups.php')
 	->actionInclude('settings/ajax/excludegroups.php');
+$this->create('settings_ajax_checksetup', '/settings/ajax/checksetup')
+	->actionInclude('settings/ajax/checksetup.php');
diff --git a/settings/templates/admin.php b/settings/templates/admin.php
index 057eb1b..a7d64d8 100644
--- a/settings/templates/admin.php
+++ b/settings/templates/admin.php
@@ -72,21 +72,6 @@ if (!$_['htaccessworking']) {
 <?php
 }
 
-// is WebDAV working ?
-if (!$_['isWebDavWorking']) {
-	?>
-<div class="section">
-	<h2><?php p($l->t('Setup Warning'));?></h2>
-
-	<span class="securitywarning">
-		<?php p($l->t('Your web server is not yet properly setup to allow files synchronization because the WebDAV interface seems to be broken.')); ?>
-		<?php print_unescaped($l->t('Please double check the <a href="%s">installation guides</a>.', link_to_docs('admin-install'))); ?>
-	</span>
-
-</div>
-<?php
-}
-
 // Are doc blocks accessible?
 if (!$_['isAnnotationsWorking']) {
 	?>
@@ -169,20 +154,6 @@ if (!$_['isLocaleWorking']) {
 <?php
 }
 
-// is internet connection working ?
-if ($_['internetconnectionworking'] === false) {
-	?>
-<div class="section">
-	<h2><?php p($l->t('Internet connection not working'));?></h2>
-
-		<span class="connectionwarning">
-		<?php p($l->t('This server has no working internet connection. This means that some of the features like mounting of external storage, notifications about updates or installation of 3rd party apps don´t work. Accessing files from remote and sending of notification emails might also not work. We suggest to enable internet connection for this server if you want to have all features.')); ?>
-	</span>
-
-</div>
-<?php
-}
-
 if ($_['suggestedOverwriteWebroot']) {
 	?>
 	<div class="section">
@@ -196,7 +167,17 @@ if ($_['suggestedOverwriteWebroot']) {
 <?php
 }
 ?>
-
+<div id="postsetupchecks" class="section">
+	<h2><?php p($l->t('Connectivity checks'));?></h2>
+	<div class="loading"></div>
+	<div class="success hidden"><?php p($l->t('No problems found'));?></div>
+	<div class="errors hidden"></div>
+	<div class="hint hidden">
+		<span class="setupwarning"><?php
+			print_unescaped($l->t('Please double check the <a href=\'%s\'>installation guides</a>.', \OC_Helper::linkToDocs('admin-install')));
+		?></span>
+	</div>
+</div>
 <?php foreach ($_['forms'] as $form) {
 	print_unescaped($form);
 }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git



More information about the Pkg-owncloud-commits mailing list