mirror of
https://github.com/moparisthebest/user_sql
synced 2024-10-31 15:35:05 -04:00
Fix "default" case in switch statement
Format code Add hgignore file
This commit is contained in:
parent
7d18f65f67
commit
2e83d3a059
@ -12,28 +12,36 @@ OCP\JSON::callCheck();
|
|||||||
$l = new OC_L10N('use_sql');
|
$l = new OC_L10N('use_sql');
|
||||||
|
|
||||||
$params = array('sql_host', 'sql_user', 'sql_database', 'sql_password',
|
$params = array('sql_host', 'sql_user', 'sql_database', 'sql_password',
|
||||||
'sql_table', 'sql_column_username', 'sql_column_password',
|
'sql_table', 'sql_column_username', 'sql_column_password', 'sql_type',
|
||||||
'sql_type', 'sql_column_active', 'strip_domain', 'default_domain',
|
'sql_column_active', 'strip_domain', 'default_domain', 'crypt_type',
|
||||||
'crypt_type', 'sql_column_displayname', 'domain_settings', 'map_array', 'domain_array');
|
'sql_column_displayname', 'domain_settings', 'map_array', 'domain_array');
|
||||||
|
|
||||||
if (isset($_POST['appname']) && $_POST['appname'] == "user_sql") {
|
if(isset($_POST['appname']) && $_POST['appname'] == "user_sql")
|
||||||
foreach ($params as $param) {
|
{
|
||||||
if (isset($_POST[$param])) {
|
foreach($params as $param)
|
||||||
if ($param === 'strip_domain') {
|
{
|
||||||
OCP\Config::setAppValue('user_sql', 'strip_domain', true);
|
if(isset($_POST[$param]))
|
||||||
} else {
|
{
|
||||||
OCP\Config::setAppValue('user_sql', $param, $_POST[$param]);
|
if($param === 'strip_domain')
|
||||||
}
|
{
|
||||||
} else {
|
OCP\Config::setAppValue('user_sql', 'strip_domain', true);
|
||||||
if ($param === 'strip_domain') {
|
} else
|
||||||
OCP\Config::setAppValue('user_sql', 'strip_domain', false);
|
{
|
||||||
}
|
OCP\Config::setAppValue('user_sql', $param, $_POST[$param]);
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
if($param === 'strip_domain')
|
||||||
|
{
|
||||||
|
OCP\Config::setAppValue('user_sql', 'strip_domain', false);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
} else
|
||||||
} else {
|
{
|
||||||
OC_JSON::error(array("data" => array( "message" => $l->t("Not submitted for us.") )));
|
OC_JSON::error(array("data" => array("message" => $l -> t("Not submitted for us."))));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
OCP\JSON::success(array('data' => array( 'message' => $l->t('Application settings successfully stored.') )));
|
OCP\JSON::success(array('data' => array('message' => $l -> t('Application settings successfully stored.'))));
|
||||||
return true;
|
return true;
|
||||||
|
227
js/settings.js
227
js/settings.js
@ -1,131 +1,158 @@
|
|||||||
// declare namespace
|
// declare namespace
|
||||||
var user_sql = user_sql || {};
|
var user_sql = user_sql ||
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
user_sql.adminSettingsCheckRadio = function() {
|
user_sql.adminSettingsCheckRadio = function()
|
||||||
if($('#domain_none').attr("checked") == "checked")
|
{
|
||||||
{
|
if($('#domain_none').attr("checked") == "checked")
|
||||||
$('#default_domain').attr("disabled", true);
|
{
|
||||||
|
$('#default_domain').attr("disabled", true);
|
||||||
$('#inputServerDomain').attr("disabled", true);
|
$('#inputServerDomain').attr("disabled", true);
|
||||||
$('#inputMapDomain').attr("disabled", true);
|
$('#inputMapDomain').attr("disabled", true);
|
||||||
$('#domainAddMap').attr("disabled", true);
|
$('#domainAddMap').attr("disabled", true);
|
||||||
}
|
} else if($('#domain_server').attr("checked") == "checked")
|
||||||
else if($('#domain_server').attr("checked") == "checked")
|
{
|
||||||
{
|
$('#default_domain').attr("disabled", true);
|
||||||
$('#default_domain').attr("disabled", true);
|
|
||||||
$('#inputServerDomain').attr("disabled", true);
|
$('#inputServerDomain').attr("disabled", true);
|
||||||
$('#inputMapDomain').attr("disabled", true);
|
$('#inputMapDomain').attr("disabled", true);
|
||||||
$('#domainAddMap').attr("disabled", true);
|
$('#domainAddMap').attr("disabled", true);
|
||||||
}
|
} else if($('#domain_mapping').attr("checked") == "checked")
|
||||||
else if($('#domain_mapping').attr("checked") == "checked")
|
{
|
||||||
{
|
$('#default_domain').attr("disabled", true);
|
||||||
$('#default_domain').attr("disabled", true);
|
|
||||||
$('#inputServerDomain').removeAttr("disabled");
|
$('#inputServerDomain').removeAttr("disabled");
|
||||||
$('#inputMapDomain').removeAttr("disabled");
|
$('#inputMapDomain').removeAttr("disabled");
|
||||||
$('#domainAddMap').removeAttr("disabled");
|
$('#domainAddMap').removeAttr("disabled");
|
||||||
}
|
} else if($('#domain_default').attr("checked") == "checked")
|
||||||
else if($('#domain_default').attr("checked") == "checked")
|
{
|
||||||
{
|
$('#default_domain').removeAttr("disabled");
|
||||||
$('#default_domain').removeAttr("disabled");
|
|
||||||
$('#inputServerDomain').attr("disabled", true);
|
$('#inputServerDomain').attr("disabled", true);
|
||||||
$('#inputMapDomain').attr("disabled", true);
|
$('#inputMapDomain').attr("disabled", true);
|
||||||
$('#domainAddMap').attr("disabled", true);
|
$('#domainAddMap').attr("disabled", true);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* init admin settings view
|
* init admin settings view
|
||||||
*/
|
*/
|
||||||
user_sql.adminSettingsUI = function() {
|
user_sql.adminSettingsUI = function()
|
||||||
|
{
|
||||||
|
|
||||||
if ($('#sql').length > 0) {
|
if($('#sql').length > 0)
|
||||||
// enable tabs on settings page
|
{
|
||||||
$('#sql').tabs();
|
// enable tabs on settings page
|
||||||
|
$('#sql').tabs();
|
||||||
|
|
||||||
$('#sqlSubmit').click(function(event) {
|
$('#sqlSubmit').click(function(event)
|
||||||
event.preventDefault();
|
{
|
||||||
|
event.preventDefault();
|
||||||
|
|
||||||
var self = $(this);
|
var self = $(this);
|
||||||
var post = $('#sqlForm').serializeArray();
|
var post = $('#sqlForm').serializeArray();
|
||||||
var domainArr = new Array();
|
var domainArr = new Array();
|
||||||
var mapArr = new Array();
|
var mapArr = new Array();
|
||||||
$('#domain_map_entries tr').each(function() {
|
$('#domain_map_entries tr').each(function()
|
||||||
var d = $(this).find("td:first").html();
|
{
|
||||||
var m = $(this).find("td").eq(1).html();
|
var d = $(this).find("td:first").html();
|
||||||
if(d != undefined && m != undefined)
|
var m = $(this).find("td").eq(1).html();
|
||||||
{
|
if(d != undefined && m != undefined)
|
||||||
mapArr.push(m);
|
{
|
||||||
domainArr.push(d);
|
mapArr.push(m);
|
||||||
}
|
domainArr.push(d);
|
||||||
});
|
}
|
||||||
post.push({name: 'map_array', value: mapArr});
|
});
|
||||||
post.push({name: 'domain_array', value: domainArr});
|
post.push(
|
||||||
$('#sql_update_message').show();
|
{
|
||||||
$('#sql_success_message').hide();
|
name : 'map_array',
|
||||||
$('#sql_error_message').hide();
|
value : mapArr
|
||||||
// Ajax foobar
|
});
|
||||||
$.post(OC.filePath('user_sql', 'ajax', 'settings.php'), post, function(data) {
|
post.push(
|
||||||
$('#sql_update_message').hide();
|
{
|
||||||
if (data.status == 'success') {
|
name : 'domain_array',
|
||||||
$('#sql_success_message').html(data.data.message);
|
value : domainArr
|
||||||
$('#sql_success_message').show();
|
});
|
||||||
window.setTimeout(function() {
|
$('#sql_update_message').show();
|
||||||
$('#sql_success_message').hide();
|
$('#sql_success_message').hide();
|
||||||
}, 10000);
|
$('#sql_error_message').hide();
|
||||||
} else {
|
// Ajax foobar
|
||||||
$('#sql_error_message').html(data.data.message);
|
$.post(OC.filePath('user_sql', 'ajax', 'settings.php'), post, function(data)
|
||||||
$('#sql_error_message').show();
|
{
|
||||||
}
|
$('#sql_update_message').hide();
|
||||||
}, 'json');
|
if(data.status == 'success')
|
||||||
return false;
|
{
|
||||||
});
|
$('#sql_success_message').html(data.data.message);
|
||||||
|
$('#sql_success_message').show();
|
||||||
|
window.setTimeout(function()
|
||||||
|
{
|
||||||
|
$('#sql_success_message').hide();
|
||||||
|
}, 10000);
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
$('#sql_error_message').html(data.data.message);
|
||||||
|
$('#sql_error_message').show();
|
||||||
|
}
|
||||||
|
}, 'json');
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
$('#domain_none').click(function(event) {
|
$('#domain_none').click(function(event)
|
||||||
user_sql.adminSettingsCheckRadio();
|
{
|
||||||
});
|
user_sql.adminSettingsCheckRadio();
|
||||||
|
});
|
||||||
|
|
||||||
$('#domain_server').click(function(event) {
|
$('#domain_server').click(function(event)
|
||||||
user_sql.adminSettingsCheckRadio();
|
{
|
||||||
});
|
user_sql.adminSettingsCheckRadio();
|
||||||
|
});
|
||||||
|
|
||||||
$('#domain_mapping').click(function(event) {
|
$('#domain_mapping').click(function(event)
|
||||||
user_sql.adminSettingsCheckRadio();
|
{
|
||||||
});
|
user_sql.adminSettingsCheckRadio();
|
||||||
|
});
|
||||||
|
|
||||||
$('#domain_default').click(function(event) {
|
$('#domain_default').click(function(event)
|
||||||
user_sql.adminSettingsCheckRadio();
|
{
|
||||||
});
|
user_sql.adminSettingsCheckRadio();
|
||||||
|
});
|
||||||
|
|
||||||
$('#domainAddMap').click(function(event) {
|
$('#domainAddMap').click(function(event)
|
||||||
event.preventDefault();
|
{
|
||||||
var newDomain = $('#inputServerDomain').val();
|
event.preventDefault();
|
||||||
var newMap = $('#inputMapDomain').val();
|
var newDomain = $('#inputServerDomain').val();
|
||||||
$('#domain_map_entries > tbody:last').append('<tr><td>' + newDomain + '</td><td>' + newMap + '</td><td><a class="deleteLink" href="#" >delete</a></td></tr>');
|
var newMap = $('#inputMapDomain').val();
|
||||||
$('#inputServerDomain').val("");
|
$('#domain_map_entries > tbody:last').append('<tr><td>' + newDomain + '</td><td>' + newMap + '</td><td><a class="deleteLink" href="#" >delete</a></td></tr>');
|
||||||
$('#inputMapDomain').val("");
|
$('#inputServerDomain').val("");
|
||||||
$("#domain_map_entries .deleteLink").on("click",function() {
|
$('#inputMapDomain').val("");
|
||||||
var tr = $(this).closest('tr');
|
$("#domain_map_entries .deleteLink").on("click", function()
|
||||||
tr.css("background-color","#FF3700");
|
{
|
||||||
tr.fadeOut(400, function(){
|
var tr = $(this).closest('tr');
|
||||||
tr.remove();
|
tr.css("background-color", "#FF3700");
|
||||||
});
|
tr.fadeOut(400, function()
|
||||||
return false;
|
{
|
||||||
});
|
tr.remove();
|
||||||
});
|
});
|
||||||
}
|
return false;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
$(document).ready(function() {
|
$(document).ready(function()
|
||||||
if ($('#sql')) {
|
{
|
||||||
user_sql.adminSettingsUI();
|
if($('#sql'))
|
||||||
user_sql.adminSettingsCheckRadio();
|
{
|
||||||
|
user_sql.adminSettingsUI();
|
||||||
|
user_sql.adminSettingsCheckRadio();
|
||||||
|
|
||||||
$("#domain_map_entries .deleteLink").on("click",function() {
|
$("#domain_map_entries .deleteLink").on("click", function()
|
||||||
var tr = $(this).closest('tr');
|
{
|
||||||
tr.css("background-color","#FF3700");
|
var tr = $(this).closest('tr');
|
||||||
tr.fadeOut(400, function(){
|
tr.css("background-color", "#FF3700");
|
||||||
tr.remove();
|
tr.fadeOut(400, function()
|
||||||
});
|
{
|
||||||
return false;
|
tr.remove();
|
||||||
});
|
});
|
||||||
}
|
return false;
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
53
settings.php
53
settings.php
@ -20,42 +20,41 @@
|
|||||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
$params = array('sql_host', 'sql_user', 'sql_database', 'sql_password',
|
$params = array('sql_host', 'sql_user', 'sql_database', 'sql_password', 'sql_table',
|
||||||
'sql_table', 'sql_column_username', 'sql_column_password',
|
'sql_column_username', 'sql_column_password', 'sql_type', 'sql_column_active',
|
||||||
'sql_type', 'sql_column_active', 'strip_domain', 'default_domain',
|
'strip_domain', 'default_domain', 'crypt_type', 'sql_column_displayname', 'domain_map', 'domain_settings');
|
||||||
'crypt_type', 'sql_column_displayname', 'domain_map', 'domain_settings');
|
|
||||||
|
|
||||||
OCP\Util::addStyle('user_sql', 'settings');
|
OCP\Util::addStyle('user_sql', 'settings');
|
||||||
OCP\Util::addScript('user_sql', 'settings');
|
OCP\Util::addScript('user_sql', 'settings');
|
||||||
OCP\User::checkAdminUser();
|
OCP\User::checkAdminUser();
|
||||||
|
|
||||||
// fill template
|
// fill template
|
||||||
$tmpl = new OCP\Template( 'user_sql', 'settings');
|
$tmpl = new OCP\Template('user_sql', 'settings');
|
||||||
foreach($params as $param){
|
foreach($params as $param)
|
||||||
$value = htmlentities(OCP\Config::getAppValue('user_sql', $param,''));
|
{
|
||||||
$tmpl->assign($param, $value);
|
$value = htmlentities(OCP\Config::getAppValue('user_sql', $param, ''));
|
||||||
|
$tmpl -> assign($param, $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
// settings with default values
|
// settings with default values
|
||||||
$tmpl->assign( 'sql_host', OCP\Config::getAppValue('user_sql', 'sql_host', OC_USER_BACKEND_SQL_DEFAULT_HOST));
|
$tmpl -> assign('sql_host', OCP\Config::getAppValue('user_sql', 'sql_host', OC_USER_BACKEND_SQL_DEFAULT_HOST));
|
||||||
$tmpl->assign( 'sql_user', OCP\Config::getAppValue('user_sql', 'sql_user', OC_USER_BACKEND_SQL_DEFAULT_USER));
|
$tmpl -> assign('sql_user', OCP\Config::getAppValue('user_sql', 'sql_user', OC_USER_BACKEND_SQL_DEFAULT_USER));
|
||||||
$tmpl->assign( 'sql_database', OCP\Config::getAppValue( 'user_sql', 'sql_database', OC_USER_BACKEND_SQL_DEFAULT_DB));
|
$tmpl -> assign('sql_database', OCP\Config::getAppValue('user_sql', 'sql_database', OC_USER_BACKEND_SQL_DEFAULT_DB));
|
||||||
$tmpl->assign( 'sql_password', OCP\Config::getAppValue( 'user_sql', 'sql_password', OC_USER_BACKEND_SQL_DEFAULT_PASSWORD));
|
$tmpl -> assign('sql_password', OCP\Config::getAppValue('user_sql', 'sql_password', OC_USER_BACKEND_SQL_DEFAULT_PASSWORD));
|
||||||
$tmpl->assign( 'sql_table', OCP\Config::getAppValue( 'user_sql', 'sql_table', OC_USER_BACKEND_SQL_DEFAULT_TABLE));
|
$tmpl -> assign('sql_table', OCP\Config::getAppValue('user_sql', 'sql_table', OC_USER_BACKEND_SQL_DEFAULT_TABLE));
|
||||||
$tmpl->assign( 'sql_column_password', OCP\Config::getAppValue( 'user_sql', 'sql_column_password', OC_USER_BACKEND_SQL_DEFAULT_PW_COLUMN));
|
$tmpl -> assign('sql_column_password', OCP\Config::getAppValue('user_sql', 'sql_column_password', OC_USER_BACKEND_SQL_DEFAULT_PW_COLUMN));
|
||||||
$tmpl->assign( 'sql_column_username', OCP\Config::getAppValue( 'user_sql', 'sql_column_username', OC_USER_BACKEND_SQL_DEFAULT_USER_COLUMN));
|
$tmpl -> assign('sql_column_username', OCP\Config::getAppValue('user_sql', 'sql_column_username', OC_USER_BACKEND_SQL_DEFAULT_USER_COLUMN));
|
||||||
$tmpl->assign( 'sql_type', OCP\Config::getAppValue( 'user_sql', 'sql_type', OC_USER_BACKEND_SQL_DEFAULT_DRIVER));
|
$tmpl -> assign('sql_type', OCP\Config::getAppValue('user_sql', 'sql_type', OC_USER_BACKEND_SQL_DEFAULT_DRIVER));
|
||||||
$tmpl->assign( 'sql_column_active', OCP\Config::getAppValue( 'user_sql', 'sql_column_active', ''));
|
$tmpl -> assign('sql_column_active', OCP\Config::getAppValue('user_sql', 'sql_column_active', ''));
|
||||||
$tmpl->assign( 'strip_domain', OCP\Config::getAppValue( 'user_sql', 'strip_domain', 0));
|
$tmpl -> assign('strip_domain', OCP\Config::getAppValue('user_sql', 'strip_domain', 0));
|
||||||
$tmpl->assign( 'default_domain', OCP\Config::getAppValue( 'user_sql', 'default_domain', ''));
|
$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('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('sql_column_displayname', OCP\Config::getAppValue('user_sql', 'sql_column_displayname', ''));
|
||||||
$tmpl->assign( 'map_array', OCP\Config::getAppValue( 'user_sql', 'map_array', ''));
|
$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_array', OCP\Config::getAppValue('user_sql', 'domain_array', ''));
|
||||||
$tmpl->assign( 'domain_settings', OCP\Config::getAppValue( 'user_sql', 'domain_settings', ''));
|
$tmpl -> assign('domain_settings', OCP\Config::getAppValue('user_sql', 'domain_settings', ''));
|
||||||
// workaround to detect OC version
|
// workaround to detect OC version
|
||||||
$ocVersion = @reset(OCP\Util::getVersion());
|
$ocVersion = @reset(OCP\Util::getVersion());
|
||||||
$tmpl->assign('ocVersion', $ocVersion);
|
$tmpl -> assign('ocVersion', $ocVersion);
|
||||||
|
|
||||||
|
return $tmpl -> fetchPage();
|
||||||
return $tmpl->fetchPage();
|
|
||||||
|
@ -1,24 +1,22 @@
|
|||||||
<?php
|
<?php $ocVersion = $_['ocVersion'];
|
||||||
$ocVersion = $_['ocVersion'];
|
|
||||||
$cfgClass = $ocVersion >= 7 ? 'section' : 'personalblock';
|
$cfgClass = $ocVersion >= 7 ? 'section' : 'personalblock';
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
|
||||||
<form id="sqlForm" action="#" method="post" class="<?php echo $cfgClass; ?>">
|
<form id="sqlForm" action="#" method="post" class="<?php echo $cfgClass; ?>">
|
||||||
|
|
||||||
<div id="sql" class="<?php echo $cfgClass; ?>">
|
<div id="sql" class="<?php echo $cfgClass; ?>">
|
||||||
<legend><strong><?php echo $l->t('SQL'); ?></strong></legend>
|
<legend><strong><?php echo $l -> t('SQL'); ?></strong></legend>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a id="sqlBasicSettings" href="#sql-1"><?php echo $l -> t('Database Settings'); ?></a></li>
|
<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('Column/Password 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>
|
<li><a id="sqlDomainSettings" href="#sql-3"><?php echo $l -> t('Domain Settings'); ?></a></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<fieldset id="sql-1">
|
<fieldset id="sql-1">
|
||||||
<table>
|
<table>
|
||||||
<tr><td><label for="sql_type"><?php echo $l->t('SQL Driver');?></label></td>
|
<tr><td><label for="sql_type"><?php echo $l -> t('SQL Driver'); ?></label></td>
|
||||||
<?php $db_driver = array('mysql' => 'MySQL', 'pgsql' => 'PostgreSQL');?>
|
<?php $db_driver = array('mysql' => 'MySQL', 'pgsql' => 'PostgreSQL'); ?>
|
||||||
<td><select id="sql_type" name="sql_type">
|
<td><select id="sql_type" name="sql_type">
|
||||||
<?php
|
<?php
|
||||||
foreach ($db_driver as $driver => $name):
|
foreach ($db_driver as $driver => $name):
|
||||||
@ -28,24 +26,25 @@ $cfgClass = $ocVersion >= 7 ? 'section' : 'personalblock';
|
|||||||
<?php else: ?>
|
<?php else: ?>
|
||||||
<option value="<?php echo $driver; ?>"><?php echo $name; ?></option>
|
<option value="<?php echo $driver; ?>"><?php echo $name; ?></option>
|
||||||
<?php endif;
|
<?php endif;
|
||||||
endforeach; ?>
|
endforeach;
|
||||||
|
?>
|
||||||
</select></td>
|
</select></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
<tr><td><label for="sql_host"><?php echo $l->t('Host');?></label></td><td><input type="text" id="sql_host" name="sql_host" value="<?php echo $_['sql_host']; ?>"></td></tr>
|
<tr><td><label for="sql_host"><?php echo $l -> t('Host'); ?></label></td><td><input type="text" id="sql_host" name="sql_host" value="<?php echo $_['sql_host']; ?>"></td></tr>
|
||||||
<tr><td><label for="sql_user"><?php echo $l->t('Username');?></label></td><td><input type="text" id="sql_user" name="sql_user" value="<?php echo $_['sql_user']; ?>" /></td></tr>
|
<tr><td><label for="sql_user"><?php echo $l -> t('Username'); ?></label></td><td><input type="text" id="sql_user" name="sql_user" value="<?php echo $_['sql_user']; ?>" /></td></tr>
|
||||||
<tr><td><label for="sql_database"><?php echo $l->t('Database');?></label></td><td><input type="text" id="sql_database" name="sql_database" value="<?php echo $_['sql_database']; ?>" /></td></tr>
|
<tr><td><label for="sql_database"><?php echo $l -> t('Database'); ?></label></td><td><input type="text" id="sql_database" name="sql_database" value="<?php echo $_['sql_database']; ?>" /></td></tr>
|
||||||
<tr><td><label for="sql_password"><?php echo $l->t('Password');?></label></td><td><input type="password" id="sql_password" name="sql_password" value="<?php echo $_['sql_password']; ?>" /></td></tr>
|
<tr><td><label for="sql_password"><?php echo $l -> t('Password'); ?></label></td><td><input type="password" id="sql_password" name="sql_password" value="<?php echo $_['sql_password']; ?>" /></td></tr>
|
||||||
<tr><td><label for="sql_table"><?php echo $l->t('Table');?></label></td><td><input type="text" id="sql_table" name="sql_table" value="<?php echo $_['sql_table']; ?>" /></td></tr>
|
<tr><td><label for="sql_table"><?php echo $l -> t('Table'); ?></label></td><td><input type="text" id="sql_table" name="sql_table" value="<?php echo $_['sql_table']; ?>" /></td></tr>
|
||||||
</table>
|
</table>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<fieldset id="sql-2">
|
<fieldset id="sql-2">
|
||||||
<table>
|
<table>
|
||||||
<tr><td><label for="sql_column_username"><?php echo $l->t('Username Column');?></label></td><td><input type="text" id="sql_column_username" name="sql_column_username" value="<?php echo $_['sql_column_username']; ?>" /></td></tr>
|
<tr><td><label for="sql_column_username"><?php echo $l -> t('Username Column'); ?></label></td><td><input type="text" id="sql_column_username" name="sql_column_username" value="<?php echo $_['sql_column_username']; ?>" /></td></tr>
|
||||||
<tr><td><label for="sql_column_password"><?php echo $l->t('Password Column');?></label></td><td><input type="text" id="sql_column_password" name="sql_column_password" value="<?php echo $_['sql_column_password']; ?>" /></td></tr>
|
<tr><td><label for="sql_column_password"><?php echo $l -> t('Password Column'); ?></label></td><td><input type="text" id="sql_column_password" name="sql_column_password" value="<?php echo $_['sql_column_password']; ?>" /></td></tr>
|
||||||
<tr><td><label for="sql_column_displayname"><?php echo $l->t('Real Name Column');?></label></td><td><input type="text" id="sql_column_displayname" name="sql_column_displayname" value="<?php echo $_['sql_column_displayname']; ?>" /></td></tr>
|
<tr><td><label for="sql_column_displayname"><?php echo $l -> t('Real Name Column'); ?></label></td><td><input type="text" id="sql_column_displayname" name="sql_column_displayname" value="<?php echo $_['sql_column_displayname']; ?>" /></td></tr>
|
||||||
<tr><td><label for="crypt_type"><?php echo $l->t('Encryption Type');?></label></td>
|
<tr><td><label for="crypt_type"><?php echo $l -> t('Encryption Type'); ?></label></td>
|
||||||
<?php $crypt_types = array('md5' => 'MD5', 'md5crypt' => 'MD5 Crypt', 'cleartext' => 'Cleartext', 'mysql_encrypt' => 'mySQL ENCRYPT()', 'system' => 'System (crypt)', 'mysql_password' => 'mySQL PASSWORD()', 'joomla' => 'Joomla MD5 Encryption');?>
|
<?php $crypt_types = array('md5' => 'MD5', 'md5crypt' => 'MD5 Crypt', 'cleartext' => 'Cleartext', 'mysql_encrypt' => 'mySQL ENCRYPT()', 'system' => 'System (crypt)', 'mysql_password' => 'mySQL PASSWORD()', 'joomla' => 'Joomla MD5 Encryption'); ?>
|
||||||
<td><select id="crypt_type" name="crypt_type">
|
<td><select id="crypt_type" name="crypt_type">
|
||||||
<?php
|
<?php
|
||||||
foreach ($crypt_types as $driver => $name):
|
foreach ($crypt_types as $driver => $name):
|
||||||
@ -55,42 +54,57 @@ $cfgClass = $ocVersion >= 7 ? 'section' : 'personalblock';
|
|||||||
<?php else: ?>
|
<?php else: ?>
|
||||||
<option value="<?php echo $driver; ?>"><?php echo $name; ?></option>
|
<option value="<?php echo $driver; ?>"><?php echo $name; ?></option>
|
||||||
<?php endif;
|
<?php endif;
|
||||||
endforeach; ?>
|
endforeach;
|
||||||
|
?>
|
||||||
</select></td>
|
</select></td>
|
||||||
</tr>
|
</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>
|
<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>
|
</table>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<fieldset id="sql-3">
|
<fieldset id="sql-3">
|
||||||
<table>
|
<table>
|
||||||
<tr><td><label for="domain_settings"><?php echo $l->t('Domain Settings');?></label></td><td><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_none" value="none" <?php
|
||||||
<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>
|
if($_['domain_settings'] == "")
|
||||||
<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>
|
echo 'checked="checked"';
|
||||||
<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>
|
?>><?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">
|
<table id="domain_map_entries" cellspacing="2" cellpadding="2">
|
||||||
<tbody>
|
<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>
|
<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
|
<?php $domains = explode(",", $_['domain_array']);
|
||||||
$domains = explode(",", $_['domain_array']);
|
$maps = explode(",", $_['map_array']);
|
||||||
$maps = explode(",", $_['map_array']);
|
for($i = 0; $i < count($domains); $i++)
|
||||||
for($i=0;$i<count($domains);$i++)
|
{
|
||||||
{
|
if(trim($domains[$i]) != "" && trim($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>";
|
||||||
echo "<tr><td>".htmlspecialchars($domains[$i])."</td><td>".htmlspecialchars($maps[$i])."</td><td><a class=\"deleteLink\" href=\"#\" >delete</a></td></tr>";
|
}
|
||||||
}
|
|
||||||
?>
|
?>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table></td></tr>
|
</table></td></tr>
|
||||||
</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="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>
|
||||||
|
|
||||||
</table>
|
</table>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<input type="hidden" name="requesttoken" value="<?php echo $_['requesttoken'] ?>" id="requesttoken" />
|
<input type="hidden" name="requesttoken" value="<?php echo $_['requesttoken'] ?>" id="requesttoken" />
|
||||||
<input type="hidden" name="appname" value="user_sql" />
|
<input type="hidden" name="appname" value="user_sql" />
|
||||||
<input id="sqlSubmit" type="submit" value="<?php echo $l->t('Save'); ?>" />
|
<input id="sqlSubmit" type="submit" value="<?php echo $l -> t('Save'); ?>" />
|
||||||
<div id="sql_update_message" class="statusmessage"><?php echo $l->t('Saving...'); ?></div>
|
<div id="sql_update_message" class="statusmessage"><?php echo $l -> t('Saving...'); ?></div>
|
||||||
<div id="sql_error_message" class="errormessage"></div>
|
<div id="sql_error_message" class="errormessage"></div>
|
||||||
<div id="sql_success_message" class="successmessage"></div>
|
<div id="sql_success_message" class="successmessage"></div>
|
||||||
</div>
|
</div>
|
||||||
|
602
user_sql.php
602
user_sql.php
@ -25,7 +25,8 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class OC_USER_SQL extends OC_User_Backend implements OC_User_Interface {
|
class OC_USER_SQL extends OC_User_Backend implements OC_User_Interface
|
||||||
|
{
|
||||||
protected $cache;
|
protected $cache;
|
||||||
// cached settings
|
// cached settings
|
||||||
protected $sql_host;
|
protected $sql_host;
|
||||||
@ -43,144 +44,147 @@ class OC_USER_SQL extends OC_User_Backend implements OC_User_Interface {
|
|||||||
protected $default_domain;
|
protected $default_domain;
|
||||||
protected $strip_domain;
|
protected $strip_domain;
|
||||||
protected $crypt_type;
|
protected $crypt_type;
|
||||||
protected $domain_settings;
|
protected $domain_settings;
|
||||||
protected $domain_array;
|
protected $domain_array;
|
||||||
protected $map_array;
|
protected $map_array;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->db_conn = false;
|
$this -> db_conn = false;
|
||||||
$this->cache = \OC\Cache::getGlobalCache();
|
$this -> cache = \OC\Cache::getGlobalCache();
|
||||||
$this->sql_host = OCP\Config::getAppValue('user_sql', 'sql_host', '');
|
$this -> sql_host = OCP\Config::getAppValue('user_sql', 'sql_host', '');
|
||||||
$this->sql_username = OCP\Config::getAppValue('user_sql', 'sql_user', '');
|
$this -> sql_username = OCP\Config::getAppValue('user_sql', 'sql_user', '');
|
||||||
$this->sql_database = OCP\Config::getAppValue('user_sql', 'sql_database', '');
|
$this -> sql_database = OCP\Config::getAppValue('user_sql', 'sql_database', '');
|
||||||
$this->sql_password = OCP\Config::getAppValue('user_sql', 'sql_password', '');
|
$this -> sql_password = OCP\Config::getAppValue('user_sql', 'sql_password', '');
|
||||||
$this->sql_table = OCP\Config::getAppValue('user_sql', 'sql_table', '');
|
$this -> sql_table = OCP\Config::getAppValue('user_sql', 'sql_table', '');
|
||||||
$this->sql_column_username = OCP\Config::getAppValue('user_sql', 'sql_column_username', '');
|
$this -> sql_column_username = OCP\Config::getAppValue('user_sql', 'sql_column_username', '');
|
||||||
$this->sql_column_password = OCP\Config::getAppValue('user_sql', 'sql_column_password', '');
|
$this -> sql_column_password = OCP\Config::getAppValue('user_sql', 'sql_column_password', '');
|
||||||
$this->sql_column_displayname = OCP\Config::getAppValue('user_sql', 'sql_column_displayname', '');
|
$this -> sql_column_displayname = OCP\Config::getAppValue('user_sql', 'sql_column_displayname', '');
|
||||||
$this->sql_column_active = OCP\Config::getAppValue('user_sql', 'sql_column_active', '');
|
$this -> sql_column_active = OCP\Config::getAppValue('user_sql', 'sql_column_active', '');
|
||||||
$this->sql_type = OCP\Config::getAppValue('user_sql', 'sql_type', '');
|
$this -> sql_type = OCP\Config::getAppValue('user_sql', 'sql_type', '');
|
||||||
$this->default_domain = OCP\Config::getAppValue('user_sql', 'default_domain', '');
|
$this -> default_domain = OCP\Config::getAppValue('user_sql', 'default_domain', '');
|
||||||
$this->strip_domain = OCP\Config::getAppValue('user_sql', 'strip_domain', 0);
|
$this -> strip_domain = OCP\Config::getAppValue('user_sql', 'strip_domain', 0);
|
||||||
$this->crypt_type = OCP\Config::getAppValue('user_sql', 'crypt_type', 'md5crypt');
|
$this -> crypt_type = OCP\Config::getAppValue('user_sql', 'crypt_type', 'md5crypt');
|
||||||
$this->domain_settings = OCP\Config::getAppValue('user_sql', 'domain_settings', 'none');
|
$this -> domain_settings = OCP\Config::getAppValue('user_sql', 'domain_settings', 'none');
|
||||||
$this->domain_array = explode(",", OCP\Config::getAppValue('user_sql', 'domain_array', array()));
|
$this -> domain_array = explode(",", OCP\Config::getAppValue('user_sql', 'domain_array', array()));
|
||||||
$this->map_array = explode(",", OCP\Config::getAppValue('user_sql', 'map_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;
|
$dsn = $this -> sql_type . ":host=" . $this -> sql_host . ";dbname=" . $this -> sql_database;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$this->db = new PDO($dsn, $this->sql_username, $this->sql_password);
|
$this -> db = new PDO($dsn, $this -> sql_username, $this -> sql_password);
|
||||||
$this->db_conn = true;
|
$this -> db_conn = true;
|
||||||
}
|
} catch (PDOException $e)
|
||||||
catch (PDOException $e)
|
|
||||||
{
|
{
|
||||||
OC_Log::write('OC_USER_SQL', 'Failed to connect to the database: ' . $e->getMessage(), OC_Log::ERROR);
|
OC_Log::write('OC_USER_SQL', 'Failed to connect to the database: ' . $e -> getMessage(), OC_Log::ERROR);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function doUserDomainMapping($uid)
|
private function doUserDomainMapping($uid)
|
||||||
{
|
{
|
||||||
$uid = trim($uid);
|
$uid = trim($uid);
|
||||||
|
|
||||||
switch($this->domain_settings)
|
switch($this->domain_settings)
|
||||||
{
|
{
|
||||||
case "none":
|
case "default" :
|
||||||
OC_Log::write('OC_USER_SQL', "No mapping", OC_Log::DEBUG);
|
OC_Log::write('OC_USER_SQL', "Default mapping", OC_Log::DEBUG);
|
||||||
break;
|
if($this -> default_domain && (strpos($uid, '@') === false))
|
||||||
case "default":
|
$uid .= "@" . $this -> default_domain;
|
||||||
OC_Log::write('OC_USER_SQL', "Default mapping", OC_Log::DEBUG);
|
break;
|
||||||
if($this->default_domain && (strpos($uid, '@') === false))
|
case "server" :
|
||||||
$uid .= "@".$this->default_domain;
|
OC_Log::write('OC_USER_SQL', "Server based mapping", OC_Log::DEBUG);
|
||||||
break;
|
if(strpos($uid, '@') === false)
|
||||||
case "server":
|
$uid .= "@" . $_SERVER['SERVER_NAME'];
|
||||||
OC_Log::write('OC_USER_SQL', "Server based mapping", OC_Log::DEBUG);
|
break;
|
||||||
if(strpos($uid, '@') === false)
|
case "mapping" :
|
||||||
$uid .= "@".$_SERVER['SERVER_NAME'];
|
OC_Log::write('OC_USER_SQL', 'Domain mapping selected', OC_Log::DEBUG);
|
||||||
break;
|
if(strpos($uid, '@') === false)
|
||||||
case "mapping":
|
{
|
||||||
OC_Log::write('OC_USER_SQL', 'Domain mapping selected', OC_Log::DEBUG);
|
for($i = 0; $i < count($this -> domain_array); $i++)
|
||||||
if(strpos($uid, '@') === false)
|
{
|
||||||
{
|
OC_Log::write('OC_USER_SQL', 'Checking domain in mapping: ' . $this -> domain_array[$i], OC_Log::DEBUG);
|
||||||
for($i=0;$i<count($this->domain_array);$i++)
|
if($_SERVER['SERVER_NAME'] == trim($this -> domain_array[$i]))
|
||||||
{
|
{
|
||||||
OC_Log::write('OC_USER_SQL', 'Checking domain in mapping: '.$this->domain_array[$i], OC_Log::DEBUG);
|
OC_Log::write('OC_USER_SQL', 'Found domain in mapping: ' . $this -> domain_array[$i], OC_Log::DEBUG);
|
||||||
if($_SERVER['SERVER_NAME'] == trim($this->domain_array[$i]))
|
$uid .= "@" . trim($this -> map_array[$i]);
|
||||||
{
|
break;
|
||||||
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;
|
||||||
}
|
case "none" :
|
||||||
}
|
default :
|
||||||
break;
|
OC_Log::write('OC_USER_SQL', "No mapping", OC_Log::DEBUG);
|
||||||
}
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$uid = strtolower($uid);
|
||||||
$uid = strtolower($uid);
|
OC_Log::write('OC_USER_SQL', 'Returning mapped UID: ' . $uid, OC_Log::DEBUG);
|
||||||
OC_Log::write('OC_USER_SQL', 'Returning mapped UID: '.$uid, OC_Log::DEBUG);
|
return $uid;
|
||||||
return $uid;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public function implementsAction($actions)
|
public function implementsAction($actions)
|
||||||
{
|
{
|
||||||
return (bool)((OC_USER_BACKEND_CHECK_PASSWORD | OC_USER_BACKEND_GET_DISPLAYNAME) & $actions);
|
return (bool)((OC_USER_BACKEND_CHECK_PASSWORD | OC_USER_BACKEND_GET_DISPLAYNAME) & $actions);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function hasUserListings() {
|
public function hasUserListings()
|
||||||
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function createUser() {
|
public function createUser()
|
||||||
|
{
|
||||||
// Can't create user
|
// Can't create user
|
||||||
OC_Log::write('OC_USER_SQL', 'Not possible to create local users from web frontend using SQL user backend', OC_Log::ERROR);
|
OC_Log::write('OC_USER_SQL', 'Not possible to create local users from web frontend using SQL user backend', OC_Log::ERROR);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function deleteUser( $uid )
|
public function deleteUser($uid)
|
||||||
{
|
{
|
||||||
// Can't delete user
|
// Can't delete user
|
||||||
OC_Log::write('OC_USER_SQL', 'Not possible to delete local users from web frontend using SQL user backend', OC_Log::ERROR);
|
OC_Log::write('OC_USER_SQL', 'Not possible to delete local users from web frontend using SQL user backend', OC_Log::ERROR);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setPassword ( $uid, $password ) {
|
public function setPassword($uid, $password)
|
||||||
// Update the user's password - this might affect other services, that user the same database, as well
|
{
|
||||||
|
// Update the user's password - this might affect other services, that
|
||||||
|
// user the same database, as well
|
||||||
OC_Log::write('OC_USER_SQL', "Entering setPassword for UID: $uid", OC_Log::DEBUG);
|
OC_Log::write('OC_USER_SQL', "Entering setPassword for UID: $uid", OC_Log::DEBUG);
|
||||||
if(!$this->db_conn)
|
if(!$this -> db_conn)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$uid = $this->doUserDomainMapping($uid);
|
$uid = $this -> doUserDomainMapping($uid);
|
||||||
|
|
||||||
$query = "SELECT $this->sql_column_password FROM $this->sql_table WHERE $this->sql_column_username = :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);
|
OC_Log::write('OC_USER_SQL', "Preparing query: $query", OC_Log::DEBUG);
|
||||||
$result = $this->db->prepare($query);
|
$result = $this -> db -> prepare($query);
|
||||||
$result->bindParam(":uid", $uid);
|
$result -> bindParam(":uid", $uid);
|
||||||
OC_Log::write('OC_USER_SQL', "Executing query...", OC_Log::DEBUG);
|
OC_Log::write('OC_USER_SQL', "Executing query...", OC_Log::DEBUG);
|
||||||
if(!$result->execute())
|
if(!$result -> execute())
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
OC_Log::write('OC_USER_SQL', "Fetching result...", OC_Log::DEBUG);
|
OC_Log::write('OC_USER_SQL', "Fetching result...", OC_Log::DEBUG);
|
||||||
$row = $result->fetch();
|
$row = $result -> fetch();
|
||||||
if(!$row)
|
if(!$row)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$old_password = $row[$this->sql_column_password];
|
$old_password = $row[$this -> sql_column_password];
|
||||||
$enc_password = $this->pacrypt($password, $old_password);
|
$enc_password = $this -> pacrypt($password, $old_password);
|
||||||
$query = "UPDATE $this->sql_table SET $this->sql_column_password = :enc_password WHERE $this->sql_column_username = :uid";
|
$query = "UPDATE $this->sql_table SET $this->sql_column_password = :enc_password WHERE $this->sql_column_username = :uid";
|
||||||
OC_Log::write('OC_USER_SQL', "Preapring query: $query", OC_Log::DEBUG);
|
OC_Log::write('OC_USER_SQL', "Preapring query: $query", OC_Log::DEBUG);
|
||||||
$result = $this->db->prepare($query);
|
$result = $this -> db -> prepare($query);
|
||||||
$result->bindParam(":enc_password", $enc_password);
|
$result -> bindParam(":enc_password", $enc_password);
|
||||||
$result->bindParam(":uid", $uid);
|
$result -> bindParam(":uid", $uid);
|
||||||
OC_Log::write('OC_USER_SQL', "Executing query...", OC_Log::DEBUG);
|
OC_Log::write('OC_USER_SQL', "Executing query...", OC_Log::DEBUG);
|
||||||
if(!$result->execute())
|
if(!$result -> execute())
|
||||||
{
|
{
|
||||||
$err = $result->errorInfo();
|
$err = $result -> errorInfo();
|
||||||
OC_Log::write('OC_USER_SQL', "Query failed: ".$err[2], OC_Log::DEBUG);
|
OC_Log::write('OC_USER_SQL', "Query failed: " . $err[2], OC_Log::DEBUG);
|
||||||
OC_Log::write('OC_USER_SQL', "Could not update password!", OC_Log::ERROR);
|
OC_Log::write('OC_USER_SQL', "Could not update password!", OC_Log::ERROR);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -189,54 +193,53 @@ class OC_USER_SQL extends OC_User_Backend implements OC_User_Interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Check if the password is correct
|
* @brief Check if the password is correct
|
||||||
* @param $uid The username
|
* @param $uid The username
|
||||||
* @param $password The password
|
* @param $password The password
|
||||||
* @returns true/false
|
* @returns true/false
|
||||||
*
|
*
|
||||||
* Check if the password is correct without logging in the user
|
* Check if the password is correct without logging in the user
|
||||||
*/
|
*/
|
||||||
public function checkPassword($uid, $password)
|
public function checkPassword($uid, $password)
|
||||||
{
|
{
|
||||||
OC_Log::write('OC_USER_SQL', "Entering checkPassword() for UID: $uid", OC_Log::DEBUG);
|
OC_Log::write('OC_USER_SQL', "Entering checkPassword() for UID: $uid", OC_Log::DEBUG);
|
||||||
if(!$this->db_conn)
|
if(!$this -> db_conn)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$uid = $this->doUserDomainMapping($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";
|
$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 != '')
|
if($this -> sql_column_active != '')
|
||||||
$query .= " AND $this->sql_column_active = 1";
|
$query .= " AND $this->sql_column_active = 1";
|
||||||
OC_Log::write('OC_USER_SQL', "Preparing query: $query", OC_Log::DEBUG);
|
OC_Log::write('OC_USER_SQL', "Preparing query: $query", OC_Log::DEBUG);
|
||||||
$result = $this->db->prepare($query);
|
$result = $this -> db -> prepare($query);
|
||||||
$result->bindParam(":uid", $uid);
|
$result -> bindParam(":uid", $uid);
|
||||||
OC_Log::write('OC_USER_SQL', "Executing query...", OC_Log::DEBUG);
|
OC_Log::write('OC_USER_SQL', "Executing query...", OC_Log::DEBUG);
|
||||||
if(!$result->execute())
|
if(!$result -> execute())
|
||||||
{
|
{
|
||||||
$err = $result->errorInfo();
|
$err = $result -> errorInfo();
|
||||||
OC_Log::write('OC_USER_SQL', "Query failed: ".$err[2], OC_Log::DEBUG);
|
OC_Log::write('OC_USER_SQL', "Query failed: " . $err[2], OC_Log::DEBUG);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
OC_Log::write('OC_USER_SQL', "Fetching row...", OC_Log::DEBUG);
|
OC_Log::write('OC_USER_SQL', "Fetching row...", OC_Log::DEBUG);
|
||||||
$row = $result->fetch();
|
$row = $result -> fetch();
|
||||||
if(!$row)
|
if(!$row)
|
||||||
{
|
{
|
||||||
OC_Log::write('OC_USER_SQL', "Got no row, return false", OC_Log::DEBUG);
|
OC_Log::write('OC_USER_SQL', "Got no row, return false", OC_Log::DEBUG);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
OC_Log::write('OC_USER_SQL', "Encrypting and checking password", OC_Log::DEBUG);
|
OC_Log::write('OC_USER_SQL', "Encrypting and checking password", OC_Log::DEBUG);
|
||||||
if($this->pacrypt($password, $row[$this->sql_column_password]) == $row[$this->sql_column_password])
|
if($this -> pacrypt($password, $row[$this -> sql_column_password]) == $row[$this -> sql_column_password])
|
||||||
{
|
{
|
||||||
OC_Log::write('OC_USER_SQL', "Passwords matching, return true", OC_Log::DEBUG);
|
OC_Log::write('OC_USER_SQL', "Passwords matching, return true", OC_Log::DEBUG);
|
||||||
if($this->strip_domain)
|
if($this -> strip_domain)
|
||||||
{
|
{
|
||||||
$uid = explode("@", $uid);
|
$uid = explode("@", $uid);
|
||||||
$uid = $uid[0];
|
$uid = $uid[0];
|
||||||
}
|
}
|
||||||
return $uid;
|
return $uid;
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
{
|
{
|
||||||
OC_Log::write('OC_USER_SQL', "Passwords do not match, return false", OC_Log::DEBUG);
|
OC_Log::write('OC_USER_SQL', "Passwords do not match, return false", OC_Log::DEBUG);
|
||||||
return false;
|
return false;
|
||||||
@ -244,24 +247,24 @@ class OC_USER_SQL extends OC_User_Backend implements OC_User_Interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get a list of all users
|
* @brief Get a list of all users
|
||||||
* @returns array with all uids
|
* @returns array with all uids
|
||||||
*
|
*
|
||||||
* Get a list of all users.
|
* Get a list of all users.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public function getUsers($search = '', $limit = null, $offset = null)
|
public function getUsers($search = '', $limit = null, $offset = null)
|
||||||
{
|
{
|
||||||
OC_Log::write('OC_USER_SQL', "Entering getUsers() with Search: $search, Limit: $limit, Offset: $offset", OC_Log::DEBUG);
|
OC_Log::write('OC_USER_SQL', "Entering getUsers() with Search: $search, Limit: $limit, Offset: $offset", OC_Log::DEBUG);
|
||||||
$users = array();
|
$users = array();
|
||||||
if(!$this->db_conn)
|
if(!$this -> db_conn)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$query = "SELECT $this->sql_column_username FROM $this->sql_table";
|
$query = "SELECT $this->sql_column_username FROM $this->sql_table";
|
||||||
if($search != '')
|
if($search != '')
|
||||||
$query .= " WHERE $this->sql_column_username LIKE :search";
|
$query .= " WHERE $this->sql_column_username LIKE :search";
|
||||||
if($this->sql_column_active != '')
|
if($this -> sql_column_active != '')
|
||||||
{
|
{
|
||||||
if($search != '')
|
if($search != '')
|
||||||
$query .= " AND";
|
$query .= " AND";
|
||||||
@ -269,89 +272,89 @@ class OC_USER_SQL extends OC_User_Backend implements OC_User_Interface {
|
|||||||
$query .= " WHERE";
|
$query .= " WHERE";
|
||||||
$query .= " $this->sql_column_active = 1";
|
$query .= " $this->sql_column_active = 1";
|
||||||
}
|
}
|
||||||
$query .= " ORDER BY $this->sql_column_username";
|
$query .= " ORDER BY $this->sql_column_username";
|
||||||
if($limit != null)
|
if($limit != null)
|
||||||
{
|
{
|
||||||
$limit = intval($limit);
|
$limit = intval($limit);
|
||||||
$query .= " LIMIT $limit";
|
$query .= " LIMIT $limit";
|
||||||
}
|
}
|
||||||
if($offset != null)
|
if($offset != null)
|
||||||
{
|
{
|
||||||
$offset = intval($offset);
|
$offset = intval($offset);
|
||||||
$query .= " OFFSET $offset";
|
$query .= " OFFSET $offset";
|
||||||
}
|
}
|
||||||
OC_Log::write('OC_USER_SQL', "Preparing query: $query", OC_Log::DEBUG);
|
OC_Log::write('OC_USER_SQL', "Preparing query: $query", OC_Log::DEBUG);
|
||||||
$result = $this->db->prepare($query);
|
$result = $this -> db -> prepare($query);
|
||||||
if($search != '')
|
if($search != '')
|
||||||
{
|
{
|
||||||
$search = "%$search%";
|
$search = "%$search%";
|
||||||
$result->bindParam(":search", $search);
|
$result -> bindParam(":search", $search);
|
||||||
}
|
}
|
||||||
OC_Log::write('OC_USER_SQL', "Executing query...", OC_Log::DEBUG);
|
OC_Log::write('OC_USER_SQL', "Executing query...", OC_Log::DEBUG);
|
||||||
if(!$result->execute())
|
if(!$result -> execute())
|
||||||
{
|
{
|
||||||
$err = $result->errorInfo();
|
$err = $result -> errorInfo();
|
||||||
OC_Log::write('OC_USER_SQL', "Query failed: ".$err[2], OC_Log::DEBUG);
|
OC_Log::write('OC_USER_SQL', "Query failed: " . $err[2], OC_Log::DEBUG);
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
OC_Log::write('OC_USER_SQL', "Fetching results...", OC_Log::DEBUG);
|
OC_Log::write('OC_USER_SQL', "Fetching results...", OC_Log::DEBUG);
|
||||||
while($row = $result->fetch())
|
while($row = $result -> fetch())
|
||||||
{
|
{
|
||||||
$uid = $row[$this->sql_column_username];
|
$uid = $row[$this -> sql_column_username];
|
||||||
if($this->strip_domain)
|
if($this -> strip_domain)
|
||||||
{
|
{
|
||||||
$uid = explode("@", $uid);
|
$uid = explode("@", $uid);
|
||||||
$uid = $uid[0];
|
$uid = $uid[0];
|
||||||
}
|
}
|
||||||
$users[] = strtolower($uid);
|
$users[] = strtolower($uid);
|
||||||
}
|
}
|
||||||
OC_Log::write('OC_USER_SQL', "Return list of results", OC_Log::DEBUG);
|
OC_Log::write('OC_USER_SQL', "Return list of results", OC_Log::DEBUG);
|
||||||
return $users;
|
return $users;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief check if a user exists
|
* @brief check if a user exists
|
||||||
* @param string $uid the username
|
* @param string $uid the username
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public function userExists($uid)
|
public function userExists($uid)
|
||||||
{
|
{
|
||||||
|
|
||||||
$cacheKey = 'sql_user_exists_' . $uid;
|
$cacheKey = 'sql_user_exists_' . $uid;
|
||||||
$cacheVal = $this->cache->get($cacheKey);
|
$cacheVal = $this -> cache -> get($cacheKey);
|
||||||
if(!is_null($cacheVal)) return (bool)$cacheVal;
|
if(!is_null($cacheVal))
|
||||||
|
return (bool)$cacheVal;
|
||||||
|
|
||||||
OC_Log::write('OC_USER_SQL', "Entering userExists() for UID: $uid", OC_Log::DEBUG);
|
OC_Log::write('OC_USER_SQL', "Entering userExists() for UID: $uid", OC_Log::DEBUG);
|
||||||
if(!$this->db_conn)
|
if(!$this -> db_conn)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$uid = $this->doUserDomainMapping($uid);
|
$uid = $this -> doUserDomainMapping($uid);
|
||||||
$query = "SELECT $this->sql_column_username FROM $this->sql_table WHERE $this->sql_column_username = :uid";
|
$query = "SELECT $this->sql_column_username FROM $this->sql_table WHERE $this->sql_column_username = :uid";
|
||||||
if($this->sql_column_active != '')
|
if($this -> sql_column_active != '')
|
||||||
$query .= " AND $this->sql_column_active = 1";
|
$query .= " AND $this->sql_column_active = 1";
|
||||||
OC_Log::write('OC_USER_SQL', "Preparing query: $query", OC_Log::DEBUG);
|
OC_Log::write('OC_USER_SQL', "Preparing query: $query", OC_Log::DEBUG);
|
||||||
$result = $this->db->prepare($query);
|
$result = $this -> db -> prepare($query);
|
||||||
$result->bindParam(":uid", $uid);
|
$result -> bindParam(":uid", $uid);
|
||||||
OC_Log::write('OC_USER_SQL', "Executing query...", OC_Log::DEBUG);
|
OC_Log::write('OC_USER_SQL', "Executing query...", OC_Log::DEBUG);
|
||||||
if(!$result->execute())
|
if(!$result -> execute())
|
||||||
{
|
{
|
||||||
$err = $result->errorInfo();
|
$err = $result -> errorInfo();
|
||||||
OC_Log::write('OC_USER_SQL', "Query failed: ".$err[2], OC_Log::DEBUG);
|
OC_Log::write('OC_USER_SQL', "Query failed: " . $err[2], OC_Log::DEBUG);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
OC_Log::write('OC_USER_SQL', "Fetching results...", OC_Log::DEBUG);
|
OC_Log::write('OC_USER_SQL', "Fetching results...", OC_Log::DEBUG);
|
||||||
|
|
||||||
$exists = (bool)$result->fetch();
|
$exists = (bool)$result -> fetch();
|
||||||
$this->cache->set($cacheKey, $exists, 60);
|
$this -> cache -> set($cacheKey, $exists, 60);
|
||||||
|
|
||||||
if(!$exists)
|
if(!$exists)
|
||||||
{
|
{
|
||||||
OC_Log::write('OC_USER_SQL', "Empty row, user does not exists, return false", OC_Log::DEBUG);
|
OC_Log::write('OC_USER_SQL', "Empty row, user does not exists, return false", OC_Log::DEBUG);
|
||||||
return false;
|
return false;
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
{
|
{
|
||||||
OC_Log::write('OC_USER_SQL', "User exists, return true", OC_Log::DEBUG);
|
OC_Log::write('OC_USER_SQL', "User exists, return true", OC_Log::DEBUG);
|
||||||
return true;
|
return true;
|
||||||
@ -362,142 +365,144 @@ class OC_USER_SQL extends OC_User_Backend implements OC_User_Interface {
|
|||||||
public function getDisplayName($uid)
|
public function getDisplayName($uid)
|
||||||
{
|
{
|
||||||
OC_Log::write('OC_USER_SQL', "Entering getDisplayName() for UID: $uid", OC_Log::DEBUG);
|
OC_Log::write('OC_USER_SQL', "Entering getDisplayName() for UID: $uid", OC_Log::DEBUG);
|
||||||
if(!$this->db_conn)
|
if(!$this -> db_conn)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$uid = $this->doUserDomainMapping($uid);
|
$uid = $this -> doUserDomainMapping($uid);
|
||||||
|
|
||||||
if(!$this->userExists($uid))
|
if(!$this -> userExists($uid))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$query = "SELECT $this->sql_column_displayname FROM $this->sql_table WHERE $this->sql_column_username = :uid";
|
$query = "SELECT $this->sql_column_displayname FROM $this->sql_table WHERE $this->sql_column_username = :uid";
|
||||||
if($this->sql_column_active != '')
|
if($this -> sql_column_active != '')
|
||||||
$query .= " AND $this->sql_column_active = 1";
|
$query .= " AND $this->sql_column_active = 1";
|
||||||
OC_Log::write('OC_USER_SQL', "Preparing query: $query", OC_Log::DEBUG);
|
OC_Log::write('OC_USER_SQL', "Preparing query: $query", OC_Log::DEBUG);
|
||||||
$result = $this->db->prepare($query);
|
$result = $this -> db -> prepare($query);
|
||||||
$result->bindParam(":uid", $uid);
|
$result -> bindParam(":uid", $uid);
|
||||||
OC_Log::write('OC_USER_SQL', "Executing query...", OC_Log::DEBUG);
|
OC_Log::write('OC_USER_SQL', "Executing query...", OC_Log::DEBUG);
|
||||||
if(!$result->execute())
|
if(!$result -> execute())
|
||||||
{
|
{
|
||||||
$err = $result->errorInfo();
|
$err = $result -> errorInfo();
|
||||||
OC_Log::write('OC_USER_SQL', "Query failed: ".$err[2], OC_Log::DEBUG);
|
OC_Log::write('OC_USER_SQL', "Query failed: " . $err[2], OC_Log::DEBUG);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
OC_Log::write('OC_USER_SQL', "Fetching results...", OC_Log::DEBUG);
|
OC_Log::write('OC_USER_SQL', "Fetching results...", OC_Log::DEBUG);
|
||||||
$row = $result->fetch();
|
$row = $result -> fetch();
|
||||||
if(!$row)
|
if(!$row)
|
||||||
{
|
{
|
||||||
OC_Log::write('OC_USER_SQL', "Empty row, user has no display name or does not exist, return false", OC_Log::DEBUG);
|
OC_Log::write('OC_USER_SQL', "Empty row, user has no display name or does not exist, return false", OC_Log::DEBUG);
|
||||||
return false;
|
return false;
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
{
|
{
|
||||||
OC_Log::write('OC_USER_SQL', "User exists, return true", OC_Log::DEBUG);
|
OC_Log::write('OC_USER_SQL', "User exists, return true", OC_Log::DEBUG);
|
||||||
$displayName = utf8_encode($row[$this->sql_column_displayname]);
|
$displayName = utf8_encode($row[$this -> sql_column_displayname]);
|
||||||
return $displayName;;
|
return $displayName; ;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDisplayNames($search = '', $limit = null, $offset = null)
|
public function getDisplayNames($search = '', $limit = null, $offset = null)
|
||||||
{
|
{
|
||||||
$uids = $this->getUsers($search, $limit, $offset);
|
$uids = $this -> getUsers($search, $limit, $offset);
|
||||||
$displayNames = array();
|
$displayNames = array();
|
||||||
foreach($uids as $uid)
|
foreach($uids as $uid)
|
||||||
{
|
{
|
||||||
$displayNames[$uid] = $this->getDisplayName($uid);
|
$displayNames[$uid] = $this -> getDisplayName($uid);
|
||||||
}
|
}
|
||||||
return $displayNames;
|
return $displayNames;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The following functions were directly taken from PostfixAdmin and just slightly modified
|
* The following functions were directly taken from PostfixAdmin and just
|
||||||
|
* slightly modified
|
||||||
* to suit our needs.
|
* to suit our needs.
|
||||||
* Encrypt a password, using the apparopriate hashing mechanism as defined in
|
* Encrypt a password, using the apparopriate hashing mechanism as defined in
|
||||||
* config.inc.php ($this->crypt_type).
|
* config.inc.php ($this->crypt_type).
|
||||||
* When wanting to compare one pw to another, it's necessary to provide the salt used - hence
|
* When wanting to compare one pw to another, it's necessary to provide the
|
||||||
|
* salt used - hence
|
||||||
* the second parameter ($pw_db), which is the existing hash from the DB.
|
* the second parameter ($pw_db), which is the existing hash from the DB.
|
||||||
*
|
*
|
||||||
* @param string $pw
|
* @param string $pw
|
||||||
* @param string $encrypted password
|
* @param string $encrypted password
|
||||||
* @return string encrypted password.
|
* @return string encrypted password.
|
||||||
*/
|
*/
|
||||||
private function pacrypt ($pw, $pw_db="")
|
private function pacrypt($pw, $pw_db = "")
|
||||||
{
|
{
|
||||||
OC_Log::write('OC_USER_SQL', "Entering private pacrypt()", OC_Log::DEBUG);
|
OC_Log::write('OC_USER_SQL', "Entering private pacrypt()", OC_Log::DEBUG);
|
||||||
$pw = stripslashes($pw);
|
$pw = stripslashes($pw);
|
||||||
$password = "";
|
$password = "";
|
||||||
$salt = "";
|
$salt = "";
|
||||||
|
|
||||||
if ($this->crypt_type == 'md5crypt') {
|
if($this -> crypt_type == 'md5crypt')
|
||||||
$split_salt = preg_split ('/\$/', $pw_db);
|
{
|
||||||
if (isset ($split_salt[2])) {
|
$split_salt = preg_split('/\$/', $pw_db);
|
||||||
|
if(isset($split_salt[2]))
|
||||||
|
{
|
||||||
$salt = $split_salt[2];
|
$salt = $split_salt[2];
|
||||||
}
|
}
|
||||||
$password = $this->md5crypt ($pw, $salt);
|
$password = $this -> md5crypt($pw, $salt);
|
||||||
}
|
} elseif($this -> crypt_type == 'md5')
|
||||||
|
{
|
||||||
elseif ($this->crypt_type == 'md5') {
|
|
||||||
$password = md5($pw);
|
$password = md5($pw);
|
||||||
}
|
} elseif($this -> crypt_type == 'system')
|
||||||
|
{
|
||||||
elseif ($this->crypt_type == 'system') { // We never generate salts, as user creation is not allowed here
|
// We never generate salts, as user creation is not allowed here
|
||||||
$password = crypt ($pw, $pw_db);
|
$password = crypt($pw, $pw_db);
|
||||||
}
|
} elseif($this -> crypt_type == 'cleartext')
|
||||||
|
{
|
||||||
elseif ($this->crypt_type == 'cleartext') {
|
|
||||||
$password = $pw;
|
$password = $pw;
|
||||||
}
|
}
|
||||||
|
|
||||||
// See https://sourceforge.net/tracker/?func=detail&atid=937966&aid=1793352&group_id=191583
|
// See
|
||||||
|
// https://sourceforge.net/tracker/?func=detail&atid=937966&aid=1793352&group_id=191583
|
||||||
// this is apparently useful for pam_mysql etc.
|
// this is apparently useful for pam_mysql etc.
|
||||||
elseif ($this->crypt_type == 'mysql_encrypt')
|
elseif($this -> crypt_type == 'mysql_encrypt')
|
||||||
{
|
{
|
||||||
if(!$this->db_conn)
|
if(!$this -> db_conn)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if ($pw_db!="") {
|
if($pw_db != "")
|
||||||
$salt=substr($pw_db,0,2);
|
{
|
||||||
|
$salt = substr($pw_db, 0, 2);
|
||||||
$query = "SELECT ENCRYPT(:pw, :salt);";
|
$query = "SELECT ENCRYPT(:pw, :salt);";
|
||||||
} else {
|
} else
|
||||||
|
{
|
||||||
$query = "SELECT ENCRYPT(:pw);";
|
$query = "SELECT ENCRYPT(:pw);";
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = $this->db->prepare($query);
|
$result = $this -> db -> prepare($query);
|
||||||
$result->bindParam(":pw", $pw);
|
$result -> bindParam(":pw", $pw);
|
||||||
if($pw_db != "")
|
if($pw_db != "")
|
||||||
$result->bindParam(":salt", $salt);
|
$result -> bindParam(":salt", $salt);
|
||||||
if(!$result->execute())
|
if(!$result -> execute())
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$row = $result->fetch();
|
$row = $result -> fetch();
|
||||||
if(!$row)
|
if(!$row)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$password = $row[0];
|
$password = $row[0];
|
||||||
}
|
} elseif($this -> crypt_type == 'mysql_password')
|
||||||
|
|
||||||
elseif($this->crypt_type == 'mysql_password')
|
|
||||||
{
|
{
|
||||||
if(!$this->db_conn)
|
if(!$this -> db_conn)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$query = "SELECT PASSWORD(:pw);";
|
$query = "SELECT PASSWORD(:pw);";
|
||||||
|
|
||||||
$result = $this->db->prepare($query);
|
$result = $this -> db -> prepare($query);
|
||||||
$result->bindParam(":pw", $pw);
|
$result -> bindParam(":pw", $pw);
|
||||||
if(!$result->execute())
|
if(!$result -> execute())
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$row = $result->fetch();
|
$row = $result -> fetch();
|
||||||
if(!$row)
|
if(!$row)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
@ -506,20 +511,19 @@ class OC_USER_SQL extends OC_User_Backend implements OC_User_Interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// The following is by Frédéric France
|
// The following is by Frédéric France
|
||||||
elseif($this->crypt_type == 'joomla')
|
elseif($this -> crypt_type == 'joomla')
|
||||||
{
|
{
|
||||||
$split_salt = preg_split ('/:/', $pw_db);
|
$split_salt = preg_split('/:/', $pw_db);
|
||||||
if(isset($split_salt[1]))
|
if(isset($split_salt[1]))
|
||||||
{
|
{
|
||||||
$salt = $split_salt[1];
|
$salt = $split_salt[1];
|
||||||
}
|
}
|
||||||
$password = ($salt) ? md5($pw.$salt) : md5($pw);
|
$password = ($salt) ? md5($pw . $salt) : md5($pw);
|
||||||
$password.= ':'.$salt;
|
$password .= ':' . $salt;
|
||||||
}
|
} else
|
||||||
|
{
|
||||||
else {
|
|
||||||
OC_Log::write('OC_USER_SQL', "unknown/invalid crypt_type settings: $this->crypt_type", OC_Log::ERROR);
|
OC_Log::write('OC_USER_SQL', "unknown/invalid crypt_type settings: $this->crypt_type", OC_Log::ERROR);
|
||||||
die ('unknown/invalid Encryption type setting: ' . $this->crypt_type);
|
die('unknown/invalid Encryption type setting: ' . $this -> crypt_type);
|
||||||
}
|
}
|
||||||
OC_Log::write('OC_USER_SQL', "pacrypt() done, return", OC_Log::DEBUG);
|
OC_Log::write('OC_USER_SQL', "pacrypt() done, return", OC_Log::DEBUG);
|
||||||
return $password;
|
return $password;
|
||||||
@ -531,112 +535,114 @@ class OC_USER_SQL extends OC_User_Backend implements OC_User_Interface {
|
|||||||
// Call: md5crypt (string cleartextpassword)
|
// Call: md5crypt (string cleartextpassword)
|
||||||
//
|
//
|
||||||
|
|
||||||
private function md5crypt ($pw, $salt="", $magic="")
|
private function md5crypt($pw, $salt = "", $magic = "")
|
||||||
{
|
{
|
||||||
$MAGIC = "$1$";
|
$MAGIC = "$1$";
|
||||||
|
|
||||||
if ($magic == "") $magic = $MAGIC;
|
if($magic == "")
|
||||||
if ($salt == "") $salt = $this->create_salt ();
|
$magic = $MAGIC;
|
||||||
$slist = explode ("$", $salt);
|
if($salt == "")
|
||||||
if ($slist[0] == "1") $salt = $slist[1];
|
$salt = $this -> create_salt();
|
||||||
|
$slist = explode("$", $salt);
|
||||||
|
if($slist[0] == "1")
|
||||||
|
$salt = $slist[1];
|
||||||
|
|
||||||
$salt = substr ($salt, 0, 8);
|
$salt = substr($salt, 0, 8);
|
||||||
$ctx = $pw . $magic . $salt;
|
$ctx = $pw . $magic . $salt;
|
||||||
$final = $this->pahex2bin (md5 ($pw . $salt . $pw));
|
$final = $this -> pahex2bin(md5($pw . $salt . $pw));
|
||||||
|
|
||||||
for ($i=strlen ($pw); $i>0; $i-=16)
|
for($i = strlen($pw); $i > 0; $i -= 16)
|
||||||
{
|
{
|
||||||
if ($i > 16)
|
if($i > 16)
|
||||||
{
|
{
|
||||||
$ctx .= substr ($final,0,16);
|
$ctx .= substr($final, 0, 16);
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
$ctx .= substr($final, 0, $i);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
$i = strlen($pw);
|
||||||
|
|
||||||
|
while($i > 0)
|
||||||
|
{
|
||||||
|
if($i & 1)
|
||||||
|
$ctx .= chr(0);
|
||||||
else
|
else
|
||||||
{
|
$ctx .= $pw[0];
|
||||||
$ctx .= substr ($final,0,$i);
|
$i = $i>>1;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
$i = strlen ($pw);
|
$final = $this -> pahex2bin(md5($ctx));
|
||||||
|
|
||||||
while ($i > 0)
|
for($i = 0; $i < 1000; $i++)
|
||||||
{
|
|
||||||
if ($i & 1) $ctx .= chr (0);
|
|
||||||
else $ctx .= $pw[0];
|
|
||||||
$i = $i >> 1;
|
|
||||||
}
|
|
||||||
$final = $this->pahex2bin (md5 ($ctx));
|
|
||||||
|
|
||||||
for ($i=0;$i<1000;$i++)
|
|
||||||
{
|
{
|
||||||
$ctx1 = "";
|
$ctx1 = "";
|
||||||
if ($i & 1)
|
if($i & 1)
|
||||||
|
{
|
||||||
|
$ctx1 .= $pw;
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
$ctx1 .= substr($final, 0, 16);
|
||||||
|
}
|
||||||
|
if($i % 3)
|
||||||
|
$ctx1 .= $salt;
|
||||||
|
if($i % 7)
|
||||||
|
$ctx1 .= $pw;
|
||||||
|
if($i & 1)
|
||||||
|
{
|
||||||
|
$ctx1 .= substr($final, 0, 16);
|
||||||
|
} else
|
||||||
{
|
{
|
||||||
$ctx1 .= $pw;
|
$ctx1 .= $pw;
|
||||||
}
|
}
|
||||||
else
|
$final = $this -> pahex2bin(md5($ctx1));
|
||||||
{
|
|
||||||
$ctx1 .= substr ($final,0,16);
|
|
||||||
}
|
|
||||||
if ($i % 3) $ctx1 .= $salt;
|
|
||||||
if ($i % 7) $ctx1 .= $pw;
|
|
||||||
if ($i & 1)
|
|
||||||
{
|
|
||||||
$ctx1 .= substr ($final,0,16);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$ctx1 .= $pw;
|
|
||||||
}
|
|
||||||
$final = $this->pahex2bin (md5 ($ctx1));
|
|
||||||
}
|
}
|
||||||
$passwd = "";
|
$passwd = "";
|
||||||
$passwd .= $this->to64 (((ord ($final[0]) << 16) | (ord ($final[6]) << 8) | (ord ($final[12]))), 4);
|
$passwd .= $this -> to64(((ord($final[0])<<16) | (ord($final[6])<<8) | (ord($final[12]))), 4);
|
||||||
$passwd .= $this->to64 (((ord ($final[1]) << 16) | (ord ($final[7]) << 8) | (ord ($final[13]))), 4);
|
$passwd .= $this -> to64(((ord($final[1])<<16) | (ord($final[7])<<8) | (ord($final[13]))), 4);
|
||||||
$passwd .= $this->to64 (((ord ($final[2]) << 16) | (ord ($final[8]) << 8) | (ord ($final[14]))), 4);
|
$passwd .= $this -> to64(((ord($final[2])<<16) | (ord($final[8])<<8) | (ord($final[14]))), 4);
|
||||||
$passwd .= $this->to64 (((ord ($final[3]) << 16) | (ord ($final[9]) << 8) | (ord ($final[15]))), 4);
|
$passwd .= $this -> to64(((ord($final[3])<<16) | (ord($final[9])<<8) | (ord($final[15]))), 4);
|
||||||
$passwd .= $this->to64 (((ord ($final[4]) << 16) | (ord ($final[10]) << 8) | (ord ($final[5]))), 4);
|
$passwd .= $this -> to64(((ord($final[4])<<16) | (ord($final[10])<<8) | (ord($final[5]))), 4);
|
||||||
$passwd .= $this->to64 (ord ($final[11]), 2);
|
$passwd .= $this -> to64(ord($final[11]), 2);
|
||||||
return "$magic$salt\$$passwd";
|
return "$magic$salt\$$passwd";
|
||||||
}
|
}
|
||||||
|
|
||||||
private function create_salt ()
|
private function create_salt()
|
||||||
{
|
{
|
||||||
srand ((double) microtime ()*1000000);
|
srand((double) microtime() * 1000000);
|
||||||
$salt = substr (md5 (rand (0,9999999)), 0, 8);
|
$salt = substr(md5(rand(0, 9999999)), 0, 8);
|
||||||
return $salt;
|
return $salt;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function pahex2bin ($str)
|
private function pahex2bin($str)
|
||||||
{
|
{
|
||||||
if(function_exists('hex2bin'))
|
if(function_exists('hex2bin'))
|
||||||
{
|
{
|
||||||
return hex2bin($str);
|
return hex2bin($str);
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
{
|
{
|
||||||
$len = strlen ($str);
|
$len = strlen($str);
|
||||||
$nstr = "";
|
$nstr = "";
|
||||||
for ($i=0;$i<$len;$i+=2)
|
for($i = 0; $i < $len; $i += 2)
|
||||||
{
|
{
|
||||||
$num = sscanf (substr ($str,$i,2), "%x");
|
$num = sscanf(substr($str, $i, 2), "%x");
|
||||||
$nstr.=chr ($num[0]);
|
$nstr .= chr($num[0]);
|
||||||
}
|
}
|
||||||
return $nstr;
|
return $nstr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function to64 ($v, $n)
|
private function to64($v, $n)
|
||||||
{
|
{
|
||||||
$ITOA64 = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
$ITOA64 = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
||||||
$ret = "";
|
$ret = "";
|
||||||
while (($n - 1) >= 0)
|
while(($n - 1) >= 0)
|
||||||
{
|
{
|
||||||
$n--;
|
$n--;
|
||||||
$ret .= $ITOA64[$v & 0x3f];
|
$ret .= $ITOA64[$v & 0x3f];
|
||||||
$v = $v >> 6;
|
$v = $v>>6;
|
||||||
}
|
}
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
Loading…
Reference in New Issue
Block a user