mirror of
https://github.com/moparisthebest/user_sql
synced 2024-11-21 16:55:02 -05:00
Add possibility to append server domain to username or to map domains
This commit is contained in:
parent
47b1eb8187
commit
7d18f65f67
@ -14,7 +14,7 @@ $l = new OC_L10N('use_sql');
|
||||
$params = array('sql_host', 'sql_user', 'sql_database', 'sql_password',
|
||||
'sql_table', 'sql_column_username', 'sql_column_password',
|
||||
'sql_type', 'sql_column_active', 'strip_domain', 'default_domain',
|
||||
'crypt_type', 'sql_column_displayname');
|
||||
'crypt_type', 'sql_column_displayname', 'domain_settings', 'map_array', 'domain_array');
|
||||
|
||||
if (isset($_POST['appname']) && $_POST['appname'] == "user_sql") {
|
||||
foreach ($params as $param) {
|
||||
|
@ -1 +1 @@
|
||||
0.9.1
|
||||
0.9.2
|
||||
|
@ -1,6 +1,36 @@
|
||||
// declare namespace
|
||||
var user_sql = user_sql || {};
|
||||
|
||||
user_sql.adminSettingsCheckRadio = function() {
|
||||
if($('#domain_none').attr("checked") == "checked")
|
||||
{
|
||||
$('#default_domain').attr("disabled", true);
|
||||
$('#inputServerDomain').attr("disabled", true);
|
||||
$('#inputMapDomain').attr("disabled", true);
|
||||
$('#domainAddMap').attr("disabled", true);
|
||||
}
|
||||
else if($('#domain_server').attr("checked") == "checked")
|
||||
{
|
||||
$('#default_domain').attr("disabled", true);
|
||||
$('#inputServerDomain').attr("disabled", true);
|
||||
$('#inputMapDomain').attr("disabled", true);
|
||||
$('#domainAddMap').attr("disabled", true);
|
||||
}
|
||||
else if($('#domain_mapping').attr("checked") == "checked")
|
||||
{
|
||||
$('#default_domain').attr("disabled", true);
|
||||
$('#inputServerDomain').removeAttr("disabled");
|
||||
$('#inputMapDomain').removeAttr("disabled");
|
||||
$('#domainAddMap').removeAttr("disabled");
|
||||
}
|
||||
else if($('#domain_default').attr("checked") == "checked")
|
||||
{
|
||||
$('#default_domain').removeAttr("disabled");
|
||||
$('#inputServerDomain').attr("disabled", true);
|
||||
$('#inputMapDomain').attr("disabled", true);
|
||||
$('#domainAddMap').attr("disabled", true);
|
||||
}
|
||||
};
|
||||
/**
|
||||
* init admin settings view
|
||||
*/
|
||||
@ -14,7 +44,20 @@ user_sql.adminSettingsUI = function() {
|
||||
event.preventDefault();
|
||||
|
||||
var self = $(this);
|
||||
var post = $('#sqlForm').serialize();
|
||||
var post = $('#sqlForm').serializeArray();
|
||||
var domainArr = new Array();
|
||||
var mapArr = new Array();
|
||||
$('#domain_map_entries tr').each(function() {
|
||||
var d = $(this).find("td:first").html();
|
||||
var m = $(this).find("td").eq(1).html();
|
||||
if(d != undefined && m != undefined)
|
||||
{
|
||||
mapArr.push(m);
|
||||
domainArr.push(d);
|
||||
}
|
||||
});
|
||||
post.push({name: 'map_array', value: mapArr});
|
||||
post.push({name: 'domain_array', value: domainArr});
|
||||
$('#sql_update_message').show();
|
||||
$('#sql_success_message').hide();
|
||||
$('#sql_error_message').hide();
|
||||
@ -34,12 +77,55 @@ user_sql.adminSettingsUI = function() {
|
||||
}, 'json');
|
||||
return false;
|
||||
});
|
||||
|
||||
$('#domain_none').click(function(event) {
|
||||
user_sql.adminSettingsCheckRadio();
|
||||
});
|
||||
|
||||
$('#domain_server').click(function(event) {
|
||||
user_sql.adminSettingsCheckRadio();
|
||||
});
|
||||
|
||||
$('#domain_mapping').click(function(event) {
|
||||
user_sql.adminSettingsCheckRadio();
|
||||
});
|
||||
|
||||
$('#domain_default').click(function(event) {
|
||||
user_sql.adminSettingsCheckRadio();
|
||||
});
|
||||
|
||||
$('#domainAddMap').click(function(event) {
|
||||
event.preventDefault();
|
||||
var newDomain = $('#inputServerDomain').val();
|
||||
var newMap = $('#inputMapDomain').val();
|
||||
$('#domain_map_entries > tbody:last').append('<tr><td>' + newDomain + '</td><td>' + newMap + '</td><td><a class="deleteLink" href="#" >delete</a></td></tr>');
|
||||
$('#inputServerDomain').val("");
|
||||
$('#inputMapDomain').val("");
|
||||
$("#domain_map_entries .deleteLink").on("click",function() {
|
||||
var tr = $(this).closest('tr');
|
||||
tr.css("background-color","#FF3700");
|
||||
tr.fadeOut(400, function(){
|
||||
tr.remove();
|
||||
});
|
||||
return false;
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
$(document).ready(function() {
|
||||
if ($('#sql')) {
|
||||
user_sql.adminSettingsUI();
|
||||
user_sql.adminSettingsCheckRadio();
|
||||
|
||||
$("#domain_map_entries .deleteLink").on("click",function() {
|
||||
var tr = $(this).closest('tr');
|
||||
tr.css("background-color","#FF3700");
|
||||
tr.fadeOut(400, function(){
|
||||
tr.remove();
|
||||
});
|
||||
return false;
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
22
settings.php
22
settings.php
@ -23,28 +23,12 @@
|
||||
$params = array('sql_host', 'sql_user', 'sql_database', 'sql_password',
|
||||
'sql_table', 'sql_column_username', 'sql_column_password',
|
||||
'sql_type', 'sql_column_active', 'strip_domain', 'default_domain',
|
||||
'crypt_type', 'sql_column_displayname');
|
||||
'crypt_type', 'sql_column_displayname', 'domain_map', 'domain_settings');
|
||||
|
||||
OCP\Util::addStyle('user_sql', 'settings');
|
||||
OCP\Util::addScript('user_sql', 'settings');
|
||||
OCP\User::checkAdminUser();
|
||||
|
||||
/*
|
||||
if ($_POST) {
|
||||
OCP\JSON::callCheck();
|
||||
foreach($params as $param){
|
||||
if(isset($_POST[$param]))
|
||||
{
|
||||
OCP\Config::setAppValue('user_sql', $param, $_POST[$param]);
|
||||
}
|
||||
elseif($param == 'strip_domain')
|
||||
{
|
||||
OCP\Config::setAppValue('user_sql', $param, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
// fill template
|
||||
$tmpl = new OCP\Template( 'user_sql', 'settings');
|
||||
foreach($params as $param){
|
||||
@ -66,7 +50,9 @@ $tmpl->assign( 'strip_domain', OCP\Config::getAppValue( 'user_sql', 'strip_domai
|
||||
$tmpl->assign( 'default_domain', OCP\Config::getAppValue( 'user_sql', 'default_domain', ''));
|
||||
$tmpl->assign( 'crypt_type', OCP\Config::getAppValue( 'user_sql', 'crypt_type', 'mysql_encrypt'));
|
||||
$tmpl->assign( 'sql_column_displayname', OCP\Config::getAppValue( 'user_sql', 'sql_column_displayname', ''));
|
||||
|
||||
$tmpl->assign( 'map_array', OCP\Config::getAppValue( 'user_sql', 'map_array', ''));
|
||||
$tmpl->assign( 'domain_array', OCP\Config::getAppValue( 'user_sql', 'domain_array', ''));
|
||||
$tmpl->assign( 'domain_settings', OCP\Config::getAppValue( 'user_sql', 'domain_settings', ''));
|
||||
// workaround to detect OC version
|
||||
$ocVersion = @reset(OCP\Util::getVersion());
|
||||
$tmpl->assign('ocVersion', $ocVersion);
|
||||
|
@ -11,7 +11,8 @@ $cfgClass = $ocVersion >= 7 ? 'section' : 'personalblock';
|
||||
<legend><strong><?php echo $l->t('SQL'); ?></strong></legend>
|
||||
<ul>
|
||||
<li><a id="sqlBasicSettings" href="#sql-1"><?php echo $l -> t('Database Settings'); ?></a></li>
|
||||
<li><a id="sqlAdvSettings" href="#sql-2"><?php echo $l->t('Advanced Settings'); ?></a></li>
|
||||
<li><a id="sqlAdvSettings" href="#sql-2"><?php echo $l->t('Column/Password Settings'); ?></a></li>
|
||||
<li><a id="sqlDomainSettings" href="#sql-3"><?php echo $l->t('Domain Settings'); ?></a></li>
|
||||
</ul>
|
||||
|
||||
<fieldset id="sql-1">
|
||||
@ -58,8 +59,32 @@ $cfgClass = $ocVersion >= 7 ? 'section' : 'personalblock';
|
||||
</select></td>
|
||||
</tr>
|
||||
<tr><td><label for="sql_column_active"><?php echo $l->t('User Active Column');?></label></td><td><input type="text" id="sql_column_active" name="sql_column_active" value="<?php echo $_['sql_column_active']; ?>" /></td></tr>
|
||||
</table>
|
||||
</fieldset>
|
||||
<fieldset id="sql-3">
|
||||
<table>
|
||||
<tr><td><label for="domain_settings"><?php echo $l->t('Domain Settings');?></label></td><td><table>
|
||||
<tr><td><input type="radio" name="domain_settings" id="domain_none" value="none" <?php if($_['domain_settings'] == "") echo 'checked="checked"'; ?>><?php echo $l->t('No Mapping') ?></td></tr>
|
||||
<tr><td><input type="radio" name="domain_settings" id="domain_server" value="server" <?php if($_['domain_settings'] == "server") echo 'checked="checked"'; ?>><?php echo $l->t('Append Server Hostname') ?></td><td></td></tr>
|
||||
<tr><td><input type="radio" name="domain_settings" id="domain_default" value="default" <?php if($_['domain_settings'] == "default") echo 'checked="checked"'; ?>><?php echo $l->t('Append Default') ?></td><td><input type="text" id="default_domain" name="default_domain" value="<?php echo $_['default_domain']; ?>" /></td></tr>
|
||||
<tr><td><input type="radio" name="domain_settings" id="domain_mapping" value="mapping" <?php if($_['domain_settings'] == "mapping") echo 'checked="checked"'; ?>><?php echo $l->t('Map Domains') ?></td><td>
|
||||
<table id="domain_map_entries" cellspacing="2" cellpadding="2">
|
||||
<tbody>
|
||||
<tr><th><input type="text" placeholder="Server Domain" id="inputServerDomain"></th><th><input type="text" placeholder="Map to Domain" id="inputMapDomain"></th><th><input id="domainAddMap" type="submit" value="<?php echo $l->t('Add Entry'); ?>" /></th></tr>
|
||||
<?php
|
||||
$domains = explode(",", $_['domain_array']);
|
||||
$maps = explode(",", $_['map_array']);
|
||||
for($i=0;$i<count($domains);$i++)
|
||||
{
|
||||
if(trim($domains[$i]) != "" && trim($domains[$i]) != "")
|
||||
echo "<tr><td>".htmlspecialchars($domains[$i])."</td><td>".htmlspecialchars($maps[$i])."</td><td><a class=\"deleteLink\" href=\"#\" >delete</a></td></tr>";
|
||||
}
|
||||
?>
|
||||
</tbody>
|
||||
</table></td></tr>
|
||||
</table></td></tr>
|
||||
<tr><td><label for="strip_domain"><?php echo $l->t('Strip Domain Part from Username');?></label></td><td><input type="checkbox" id="strip_domain" name="strip_domain" value="1"<?php if($_['strip_domain']) echo ' checked'; ?> title="Strip Domain Part from Username when logging in and retrieving username lists"></td></tr>
|
||||
<tr><td><label for="default_domain"><?php echo $l->t('Add default domain to Usernames');?></label></td><td><input type="text" id="default_domain" name="default_domain" value="<?php echo $_['default_domain']; ?>" /></td></tr>
|
||||
|
||||
</table>
|
||||
</fieldset>
|
||||
<input type="hidden" name="requesttoken" value="<?php echo $_['requesttoken'] ?>" id="requesttoken" />
|
||||
|
78
user_sql.php
78
user_sql.php
@ -43,6 +43,9 @@ class OC_USER_SQL extends OC_User_Backend implements OC_User_Interface {
|
||||
protected $default_domain;
|
||||
protected $strip_domain;
|
||||
protected $crypt_type;
|
||||
protected $domain_settings;
|
||||
protected $domain_array;
|
||||
protected $map_array;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
@ -61,6 +64,9 @@ class OC_USER_SQL extends OC_User_Backend implements OC_User_Interface {
|
||||
$this->default_domain = OCP\Config::getAppValue('user_sql', 'default_domain', '');
|
||||
$this->strip_domain = OCP\Config::getAppValue('user_sql', 'strip_domain', 0);
|
||||
$this->crypt_type = OCP\Config::getAppValue('user_sql', 'crypt_type', 'md5crypt');
|
||||
$this->domain_settings = OCP\Config::getAppValue('user_sql', 'domain_settings', 'none');
|
||||
$this->domain_array = explode(",", OCP\Config::getAppValue('user_sql', 'domain_array', array()));
|
||||
$this->map_array = explode(",", OCP\Config::getAppValue('user_sql', 'map_array', array()));
|
||||
$dsn = $this->sql_type.":host=".$this->sql_host.";dbname=".$this->sql_database;
|
||||
try
|
||||
{
|
||||
@ -74,6 +80,49 @@ class OC_USER_SQL extends OC_User_Backend implements OC_User_Interface {
|
||||
return false;
|
||||
}
|
||||
|
||||
private function doUserDomainMapping($uid)
|
||||
{
|
||||
$uid = trim($uid);
|
||||
|
||||
switch($this->domain_settings)
|
||||
{
|
||||
case "none":
|
||||
OC_Log::write('OC_USER_SQL', "No mapping", OC_Log::DEBUG);
|
||||
break;
|
||||
case "default":
|
||||
OC_Log::write('OC_USER_SQL', "Default mapping", OC_Log::DEBUG);
|
||||
if($this->default_domain && (strpos($uid, '@') === false))
|
||||
$uid .= "@".$this->default_domain;
|
||||
break;
|
||||
case "server":
|
||||
OC_Log::write('OC_USER_SQL', "Server based mapping", OC_Log::DEBUG);
|
||||
if(strpos($uid, '@') === false)
|
||||
$uid .= "@".$_SERVER['SERVER_NAME'];
|
||||
break;
|
||||
case "mapping":
|
||||
OC_Log::write('OC_USER_SQL', 'Domain mapping selected', OC_Log::DEBUG);
|
||||
if(strpos($uid, '@') === false)
|
||||
{
|
||||
for($i=0;$i<count($this->domain_array);$i++)
|
||||
{
|
||||
OC_Log::write('OC_USER_SQL', 'Checking domain in mapping: '.$this->domain_array[$i], OC_Log::DEBUG);
|
||||
if($_SERVER['SERVER_NAME'] == trim($this->domain_array[$i]))
|
||||
{
|
||||
OC_Log::write('OC_USER_SQL', 'Found domain in mapping: '.$this->domain_array[$i], OC_Log::DEBUG);
|
||||
$uid .= "@".trim($this->map_array[$i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
$uid = strtolower($uid);
|
||||
OC_Log::write('OC_USER_SQL', 'Returning mapped UID: '.$uid, OC_Log::DEBUG);
|
||||
return $uid;
|
||||
}
|
||||
|
||||
public function implementsAction($actions)
|
||||
{
|
||||
return (bool)((OC_USER_BACKEND_CHECK_PASSWORD | OC_USER_BACKEND_GET_DISPLAYNAME) & $actions);
|
||||
@ -103,11 +152,8 @@ class OC_USER_SQL extends OC_User_Backend implements OC_User_Interface {
|
||||
{
|
||||
return false;
|
||||
}
|
||||
$uid = trim($uid);
|
||||
if($this->default_domain && (strpos($uid, '@') === false))
|
||||
{
|
||||
$uid .= "@".$this->default_domain;
|
||||
}
|
||||
$uid = $this->doUserDomainMapping($uid);
|
||||
|
||||
$query = "SELECT $this->sql_column_password FROM $this->sql_table WHERE $this->sql_column_username = :uid";
|
||||
OC_Log::write('OC_USER_SQL', "Preparing query: $query", OC_Log::DEBUG);
|
||||
$result = $this->db->prepare($query);
|
||||
@ -157,12 +203,7 @@ class OC_USER_SQL extends OC_User_Backend implements OC_User_Interface {
|
||||
{
|
||||
return false;
|
||||
}
|
||||
$uid = trim($uid);
|
||||
if($this->default_domain && (strpos($uid, '@') === false))
|
||||
{
|
||||
$uid .= "@".$this->default_domain;
|
||||
}
|
||||
$uid = strtolower($uid);
|
||||
$uid = $this->doUserDomainMapping($uid);
|
||||
|
||||
$query = "SELECT $this->sql_column_username, $this->sql_column_password FROM $this->sql_table WHERE $this->sql_column_username = :uid";
|
||||
if($this->sql_column_active != '')
|
||||
@ -286,13 +327,7 @@ class OC_USER_SQL extends OC_User_Backend implements OC_User_Interface {
|
||||
{
|
||||
return false;
|
||||
}
|
||||
$uid = trim($uid);
|
||||
if($this->default_domain && (strpos($uid, '@') === false))
|
||||
{
|
||||
$uid .= "@".$this->default_domain;
|
||||
}
|
||||
$uid = strtolower($uid);
|
||||
|
||||
$uid = $this->doUserDomainMapping($uid);
|
||||
$query = "SELECT $this->sql_column_username FROM $this->sql_table WHERE $this->sql_column_username = :uid";
|
||||
if($this->sql_column_active != '')
|
||||
$query .= " AND $this->sql_column_active = 1";
|
||||
@ -331,12 +366,7 @@ class OC_USER_SQL extends OC_User_Backend implements OC_User_Interface {
|
||||
{
|
||||
return false;
|
||||
}
|
||||
$uid = trim($uid);
|
||||
if($this->default_domain && (strpos($uid, '@') === false))
|
||||
{
|
||||
$uid .= "@".$this->default_domain;
|
||||
}
|
||||
$uid = strtolower($uid);
|
||||
$uid = $this->doUserDomainMapping($uid);
|
||||
|
||||
if(!$this->userExists($uid))
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user