diff --git a/ajax/settings.php b/ajax/settings.php
index 1567dc5..87b936c 100644
--- a/ajax/settings.php
+++ b/ajax/settings.php
@@ -78,6 +78,10 @@ if(isset($_POST['appname']) && ($_POST['appname'] === 'user_sql') && isset($_POS
{
\OC::$server->getConfig()->setAppValue('user_sql', 'set_active_invert_'.$domain, 'true');
}
+ elseif($param === 'set_enable_gethome')
+ {
+ \OC::$server->getConfig()->setAppValue('user_sql', 'set_enable_gethome_'.$domain, 'true');
+ }
else
{
\OC::$server->getConfig()->setAppValue('user_sql', $param.'_'.$domain, $_POST[$param]);
@@ -96,6 +100,10 @@ if(isset($_POST['appname']) && ($_POST['appname'] === 'user_sql') && isset($_POS
{
\OC::$server->getConfig()->setAppValue('user_sql', 'set_active_invert_'.$domain, 'false');
}
+ elseif($param === 'set_enable_gethome')
+ {
+ \OC::$server->getConfig()->setAppValue('user_sql', 'set_enable_gethome_'.$domain, 'false');
+ }
}
}
$response->setData(array('status' => 'success',
diff --git a/appinfo/app.php b/appinfo/app.php
index 52e47c4..27d82f5 100644
--- a/appinfo/app.php
+++ b/appinfo/app.php
@@ -30,13 +30,3 @@ $backend = new \OCA\user_sql\OC_USER_SQL;
// register user backend
OC_User::registerBackend($backend);
OC_User::useBackend($backend);
-
-// add settings page to navigation
-$entry = array(
- 'id' => "user_sql_settings",
- 'order'=>1,
- 'href' => OC_Helper::linkTo( "user_sql", "settings.php" ),
- 'name' => 'SQL'
-);
-
-
diff --git a/appinfo/info.xml b/appinfo/info.xml
index eb45adc..ac5cdfd 100644
--- a/appinfo/info.xml
+++ b/appinfo/info.xml
@@ -6,7 +6,7 @@
AGPL
Andreas Boehler <dev (at) aboehler
(dot) at >
- 2.0
+ 2.1
8.1
false
user_sql
diff --git a/css/settings.css b/css/settings.css
index 92353e4..a899217 100644
--- a/css/settings.css
+++ b/css/settings.css
@@ -12,3 +12,13 @@
padding: 1px;
}
+#sql-1 p label:first-child,
+#sql-2 p label:first-child,
+#sql-3 p label:first-child,
+#sql-4 p label:first-child,
+#sql-5 p label:first-child {
+ display: inline-block;
+ text-align: right;
+ width: 300px;
+ padding-right: 10px;
+}
diff --git a/js/settings.js b/js/settings.js
index 9167fc9..a280e17 100644
--- a/js/settings.js
+++ b/js/settings.js
@@ -17,7 +17,7 @@ user_sql.adminSettingsUI = function()
$('#sql').tabs();
// Attach auto-completion to all column fields
- $('#col_username, #col_password, #col_displayname, #col_active, #col_email').autocomplete({
+ $('#col_username, #col_password, #col_displayname, #col_active, #col_email, #col_gethome').autocomplete({
source: function(request, response)
{
var post = $('#sqlForm').serializeArray();
@@ -184,6 +184,45 @@ user_sql.adminSettingsUI = function()
$('#sql_domain_chooser').change(function() {
user_sql.loadDomainSettings($('#sql_domain_chooser option:selected').val());
});
+
+ $('#set_gethome_mode').change(function() {
+ user_sql.setGethomeMode();
+ });
+
+ $('#set_enable_gethome').change(function() {
+ user_sql.setGethomeMode();
+ });
+ }
+};
+
+user_sql.setGethomeMode = function()
+{
+ var enabled = $('#set_enable_gethome').prop('checked');
+ if(enabled)
+ {
+ $('#set_gethome_mode').prop('disabled', false);
+ var val = $('#set_gethome_mode option:selected').val();
+ if(val === 'query')
+ {
+ $('#set_gethome').prop('disabled', true);
+ $('#col_gethome').prop('disabled', false);
+ }
+ else if(val === 'static')
+ {
+ $('#set_gethome').prop('disabled', false);
+ $('#col_gethome').prop('disabled', true);
+ }
+ else
+ {
+ $('#set_gethome').prop('disabled', true);
+ $('#col_gethome').prop('disabled', true);
+ }
+ }
+ else
+ {
+ $('#set_gethome_mode').prop('disabled', true);
+ $('#set_gethome').prop('disabled', true);
+ $('#col_gethome').prop('disabled', true);
}
};
@@ -239,6 +278,13 @@ user_sql.loadDomainSettings = function(domain)
else
$('#' + key).prop('checked', false);
}
+ else if(key == 'set_allow_gethome')
+ {
+ if(data.settings[key] == 'true')
+ $('#' + key).prop('checked', true);
+ else
+ $('#' + key).prop('checked', false);
+ }
else
{
$('#' + key).val(data.settings[key]);
@@ -261,6 +307,7 @@ $(document).ready(function()
{
user_sql.adminSettingsUI();
user_sql.loadDomainSettings($('#sql_domain_chooser option:selected').val());
+ user_sql.setGethomeMode();
}
});
diff --git a/lib/helper.php b/lib/helper.php
index 8f16311..b4a49e0 100644
--- a/lib/helper.php
+++ b/lib/helper.php
@@ -55,12 +55,16 @@ class Helper {
'col_active',
'col_displayname',
'col_email',
+ 'col_gethome',
'set_active_invert',
'set_allow_pwchange',
'set_default_domain',
'set_strip_domain',
'set_crypt_type',
- 'set_mail_sync_mode'
+ 'set_mail_sync_mode',
+ 'set_enable_gethome',
+ 'set_gethome_mode',
+ 'set_gethome'
);
return $params;
@@ -107,6 +111,9 @@ class Helper {
switch($type)
{
+ case 'getHome':
+ $query = "SELECT ".$this->settings['col_gethome']." FROM ".$this->settings['sql_table']." WHERE ".$this->settings['col_username']." = :uid";
+ break;
case 'getMail':
$query = "SELECT ".$this->settings['col_email']." FROM ".$this->settings['sql_table']." WHERE ".$this->settings['col_username']." = :uid";
break;
diff --git a/templates/settings.php b/templates/settings.php
index 163bf1b..fb9b097 100644
--- a/templates/settings.php
+++ b/templates/settings.php
@@ -16,14 +16,16 @@ $cfgClass = $ocVersion >= 7 ? 'section' : 'personalblock';
-
+ t('Host')); ?>
+
+ t('Username')); ?>
+
+ t('Database')); ?>
+
+ t('Password')); ?>
+
+
+
-
- t('Table')); ?>
- t('Username Column')); ?>
- t('Password Column')); ?>
- t('Allow password changing (read README!)')); ?> t('Table')); ?>
+
+ t('Username Column')); ?>
+
+ t('Password Column')); ?>
+
+ t('Allow password changing (read README!)')); ?> title="Allow changing passwords. Imposes a security risk as password salts are not recreated">
- t('Real Name Column')); ?>
- t('Encryption Type')); ?>
+ ?>>
+ t('Allow changing passwords. Imposes a security risk as password salts are not recreated')); ?>
+
+ t('Real Name Column')); ?>
+
+ t('Encryption Type')); ?>
'MD5', 'md5crypt' => 'MD5 Crypt', 'cleartext' => 'Cleartext', 'mysql_encrypt' => 'mySQL ENCRYPT()', 'system' => 'System (crypt)', 'mysql_password' => 'mySQL PASSWORD()', 'joomla' => 'Joomla MD5 Encryption', 'joomla2' => 'Joomla > 2.5.18 phpass', 'ssha256' => 'Salted SSHA256', 'redmine' => 'Redmine'); ?>
-
+
$name):
//echo $_['set_crypt_type'];
@@ -67,17 +78,26 @@ $cfgClass = $ocVersion >= 7 ? 'section' : 'personalblock';
-
-
- t('User Active Column')); ?>
- t('Invert Active Value')); ?>
+
+
+ t('User Active Column')); ?>
+
+ t('Invert Active Value')); ?> title="Invert the logic of the active column (for blocked users in the SQL DB)" />
- t('E-Mail Column')); ?>
- t('E-Mail address sync mode')); ?>
+ ?> />
+ t("Invert the logic of the active column (for blocked users in the SQL DB)")); ?>
+
+
+
+
+
+ t('E-Mail Column')); ?>
+
+ t('E-Mail address sync mode')); ?>
'No Synchronisation', 'initial' => 'Synchronise only once', 'forceoc' => 'ownCloud always wins', 'forcesql' => 'SQL always wins'); ?>
-
+
$name):
//echo $_['set_mail_sync_mode'];
@@ -89,13 +109,51 @@ $cfgClass = $ocVersion >= 7 ? 'section' : 'personalblock';
endforeach;
?>
-
- t('Append Default Domain')); ?>
- t('Strip Domain Part from Username')); ?>
+
+
+
+
+
+ t('Append Default Domain')); ?>
+ t('Append this string, e.g. a domain name, to each user name. The @-sign is automatically inserted.')); ?>
+
+
+ t('Strip Domain Part from Username')); ?> title="Strip Domain Part from Username when logging in and retrieving username lists">
-
+ ?> />
+ t("Strip Domain Part including @-sign from Username when logging in and retrieving username lists")); ?>
+
+
+
+
+ t('Enable support for getHome()')); ?> />
+
+ t('Method for getHome')); ?>
+ 'SQL Column', 'static' => 'Static (with Variables)'); ?>
+
+ $name):
+ //echo $_['set_mail_sync_mode'];
+ if($_['set_gethome_mode'] === $mode): ?>
+
+
+
+
+
+
+
+ t('Home Column')); ?>
+
+ t('Home Dir')); ?>
+ t('You can use the placeholders %%u to specify the user ID (before appending the default domain), %%ud to specify the user ID (after appending the default domain) and %%d to specify the default domain')); ?>
+
diff --git a/user_sql.php b/user_sql.php
index 807cf37..b857cff 100644
--- a/user_sql.php
+++ b/user_sql.php
@@ -149,6 +149,8 @@ class OC_USER_SQL extends \OC_User_Backend implements \OCP\IUserBackend, \OCP\Us
return (bool)((\OC_User_Backend::CHECK_PASSWORD
| \OC_User_Backend::GET_DISPLAYNAME
| \OC_User_Backend::COUNT_USERS
+ | $this -> settings['set_allow_pwchange'] === 'true' ? \OC_User_Backend::SET_PASSWORD : 0
+ | $this -> settings['set_enable_gethome'] === 'true' ? \OC_User_Backend::GET_HOME : 0
) & $actions);
}
@@ -160,6 +162,46 @@ class OC_USER_SQL extends \OC_User_Backend implements \OCP\IUserBackend, \OCP\Us
{
return true;
}
+
+ /**
+ * Return the user's home directory, if enabled
+ * @param string $uid The user's ID to retrieve
+ * @return mixed The user's home directory or false
+ */
+ public function getHome($uid)
+ {
+ \OCP\Util::writeLog('OC_USER_SQL', "Entering getHome for UID: $uid", \OCP\Util::DEBUG);
+
+ if($this -> settings['set_enable_gethome'] !== 'true')
+ return false;
+
+ $uidMapped = $this -> doUserDomainMapping($uid);
+ $home = false;
+
+ switch($this->settings['set_gethome_mode'])
+ {
+ case 'query':
+ \OCP\Util::writeLog('OC_USER_SQL', "getHome with Query selected, running Query...", \OCP\Util::DEBUG);
+ $row = $this -> helper -> runQuery('getHome', array('uid' => $uidMapped));
+ if($row === false)
+ {
+ \OCP\Util::writeLog('OC_USER_SQL', "Got no row, return false", \OCP\Util::DEBUG);
+ return false;
+ }
+ $home = $row[$this -> settings['col_gethome']];
+ break;
+
+ case 'static':
+ \OCP\Util::writeLog('OC_USER_SQL', "getHome with static selected", \OCP\Util::DEBUG);
+ $home = $this -> settings['set_gethome'];
+ $home = str_replace('%ud', $uidMapped, $home);
+ $home = str_replace('%u', $uid, $home);
+ $home = str_replace('%d', $this -> settings['set_default_domain'], $home);
+ break;
+ }
+ \OCP\Util::writeLog('OC_USER_SQL', "Returning getHome for UID: $uid with Home $home", \OCP\Util::DEBUG);
+ return $home;
+ }
/**
* Create a new user account using this backend