- code formatting (PSR-2)

- removed all ownCloud references
- removed update.php as its supported version was never published on the app store
- updated info.xml
This commit is contained in:
Marcin Łojewski
2018-02-28 19:52:32 +01:00
parent ebcdaa813b
commit 936a831e5a
17 changed files with 1650 additions and 1738 deletions

View File

@@ -1,7 +1,7 @@
<?php <?php
/** /**
* ownCloud - user_sql * Nextcloud - user_sql
* *
* @author Andreas Böhler and contributors * @author Andreas Böhler and contributors
* @copyright 2012-2015 Andreas Böhler <dev (at) aboehler (dot) at> * @copyright 2012-2015 Andreas Böhler <dev (at) aboehler (dot) at>
@@ -21,22 +21,22 @@
* *
*/ */
/** /**
* This is the AJAX portion of the settings page. * This is the AJAX portion of the settings page.
* *
* It can: * It can:
* - Verify the connection settings * - Verify the connection settings
* - Load autocomplete values for tables * - Load autocomplete values for tables
* - Load autocomplete values for columns * - Load autocomplete values for columns
* - Save settings for a given domain * - Save settings for a given domain
* - Load settings for a given domain * - Load settings for a given domain
* *
* It always returns JSON encoded responses * It always returns JSON encoded responses
*/ */
namespace OCA\user_sql; namespace OCA\user_sql;
// Init owncloud // Init Nextcloud
// Check if we are a user // Check if we are a user
\OCP\User::checkAdminUser(); \OCP\User::checkAdminUser();
@@ -50,18 +50,17 @@ $helper = new \OCA\user_sql\lib\Helper;
$l = \OC::$server->getL10N('user_sql'); $l = \OC::$server->getL10N('user_sql');
$params = $helper -> getParameterArray(); $params = $helper->getParameterArray();
$response = new \OCP\AppFramework\Http\JSONResponse(); $response = new \OCP\AppFramework\Http\JSONResponse();
// Check if the request is for us // Check if the request is for us
if(isset($_POST['appname']) && ($_POST['appname'] === 'user_sql') && isset($_POST['function']) && isset($_POST['domain'])) if (isset($_POST['appname']) && ($_POST['appname'] === 'user_sql') && isset($_POST['function']) && isset($_POST['domain'])) {
{
$domain = $_POST['domain']; $domain = $_POST['domain'];
switch($_POST['function']) switch ($_POST['function']) {
{
// Save the settings for the given domain to the database // Save the settings for the given domain to the database
case 'saveSettings': case 'saveSettings':
$parameters = array('host' => $_POST['sql_hostname'], $parameters = array(
'host' => $_POST['sql_hostname'],
'password' => $_POST['sql_password'], 'password' => $_POST['sql_password'],
'user' => $_POST['sql_username'], 'user' => $_POST['sql_username'],
'dbname' => $_POST['sql_database'], 'dbname' => $_POST['sql_database'],
@@ -69,34 +68,31 @@ if(isset($_POST['appname']) && ($_POST['appname'] === 'user_sql') && isset($_POS
); );
// Check if the table exists // Check if the table exists
if(!$helper->verifyTable($parameters, $_POST['sql_driver'], $_POST['sql_table'])) if (!$helper->verifyTable($parameters, $_POST['sql_driver'], $_POST['sql_table'])) {
{ $response->setData(array(
$response->setData(array('status' => 'error', 'status' => 'error',
'data' => array('message' => $l -> t('The selected SQL table '.$_POST['sql_table'].' does not exist!')))); 'data' => array('message' => $l->t('The selected SQL table ' . $_POST['sql_table'] . ' does not exist!'))
));
break; break;
} }
if(!empty($_POST['sql_group_table']) && !$helper->verifyTable($parameters, $_POST['sql_driver'], $_POST['sql_group_table'])) if (!empty($_POST['sql_group_table']) && !$helper->verifyTable($parameters, $_POST['sql_driver'],
{ $_POST['sql_group_table'])) {
$response->setData(array('status' => 'error', $response->setData(array(
'data' => array('message' => $l -> t('The selected SQL table '.$_POST['sql_group_table'].' does not exist!')))); 'status' => 'error',
'data' => array('message' => $l->t('The selected SQL table ' . $_POST['sql_group_table'] . ' does not exist!'))
));
break; break;
} }
// Retrieve all column settings // Retrieve all column settings
$columns = array(); $columns = array();
$group_columns = array(); $group_columns = array();
foreach($params as $param) foreach ($params as $param) {
{ if (strpos($param, 'col_') === 0) {
if(strpos($param, 'col_') === 0) if (isset($_POST[$param]) && $_POST[$param] !== '') {
{ if (strpos($param, 'col_group_') === 0) {
if(isset($_POST[$param]) && $_POST[$param] !== '')
{
if(strpos($param, 'col_group_') === 0)
{
$group_columns[] = $_POST[$param]; $group_columns[] = $_POST[$param];
} } else {
else
{
$columns[] = $_POST[$param]; $columns[] = $_POST[$param];
} }
} }
@@ -105,97 +101,85 @@ if(isset($_POST['appname']) && ($_POST['appname'] === 'user_sql') && isset($_POS
// Check if the columns exist // Check if the columns exist
$status = $helper->verifyColumns($parameters, $_POST['sql_driver'], $_POST['sql_table'], $columns); $status = $helper->verifyColumns($parameters, $_POST['sql_driver'], $_POST['sql_table'], $columns);
if(!empty($_POST['sql_group_table']) && $status === true) if (!empty($_POST['sql_group_table']) && $status === true) {
{ $status = $helper->verifyColumns($parameters, $_POST['sql_driver'], $_POST['sql_group_table'],
$status = $helper->verifyColumns($parameters, $_POST['sql_driver'], $_POST['sql_group_table'], $group_columns); $group_columns);
} }
if($status !== true) if ($status !== true) {
{ $response->setData(array(
$response->setData(array('status' => 'error', 'status' => 'error',
'data' => array('message' => $l -> t('The selected SQL column(s) do(es) not exist: '.$status)))); 'data' => array('message' => $l->t('The selected SQL column(s) do(es) not exist: ' . $status))
));
break; break;
} }
// If we reach this point, all settings have been verified // If we reach this point, all settings have been verified
foreach($params as $param) foreach ($params as $param) {
{
// Special handling for checkbox fields // Special handling for checkbox fields
if(isset($_POST[$param])) if (isset($_POST[$param])) {
{ if ($param === 'set_strip_domain') {
if($param === 'set_strip_domain') \OC::$server->getConfig()->setAppValue('user_sql', 'set_strip_domain_' . $domain, 'true');
{ } elseif ($param === 'set_allow_pwchange') {
\OC::$server->getConfig()->setAppValue('user_sql', 'set_strip_domain_'.$domain, 'true'); \OC::$server->getConfig()->setAppValue('user_sql', 'set_allow_pwchange_' . $domain, 'true');
} elseif ($param === 'set_active_invert') {
\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]);
} }
elseif($param === 'set_allow_pwchange') } else {
{ if ($param === 'set_strip_domain') {
\OC::$server->getConfig()->setAppValue('user_sql', 'set_allow_pwchange_'.$domain, 'true'); \OC::$server->getConfig()->setAppValue('user_sql', 'set_strip_domain_' . $domain, 'false');
} } elseif ($param === 'set_allow_pwchange') {
elseif($param === 'set_active_invert') \OC::$server->getConfig()->setAppValue('user_sql', 'set_allow_pwchange_' . $domain, 'false');
{ } elseif ($param === 'set_active_invert') {
\OC::$server->getConfig()->setAppValue('user_sql', 'set_active_invert_'.$domain, 'true'); \OC::$server->getConfig()->setAppValue('user_sql', 'set_active_invert_' . $domain, 'false');
} } elseif ($param === 'set_enable_gethome') {
elseif($param === 'set_enable_gethome') \OC::$server->getConfig()->setAppValue('user_sql', 'set_enable_gethome_' . $domain, 'false');
{
\OC::$server->getConfig()->setAppValue('user_sql', 'set_enable_gethome_'.$domain, 'true');
}
else
{
\OC::$server->getConfig()->setAppValue('user_sql', $param.'_'.$domain, $_POST[$param]);
}
} else
{
if($param === 'set_strip_domain')
{
\OC::$server->getConfig()->setAppValue('user_sql', 'set_strip_domain_'.$domain, 'false');
}
elseif($param === 'set_allow_pwchange')
{
\OC::$server->getConfig()->setAppValue('user_sql', 'set_allow_pwchange_'.$domain, 'false');
}
elseif($param === 'set_active_invert')
{
\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', $response->setData(array(
'data' => array('message' => $l -> t('Application settings successfully stored.')))); 'status' => 'success',
break; 'data' => array('message' => $l->t('Application settings successfully stored.'))
));
break;
// Load the settings for a given domain // Load the settings for a given domain
case 'loadSettingsForDomain': case 'loadSettingsForDomain':
$retArr = array(); $retArr = array();
foreach($params as $param) foreach ($params as $param) {
{ $retArr[$param] = \OC::$server->getConfig()->getAppValue('user_sql', $param . '_' . $domain, '');
$retArr[$param] = \OC::$server->getConfig()->getAppValue('user_sql', $param.'_'.$domain, '');
} }
$response->setData(array('status' => 'success', $response->setData(array(
'settings' => $retArr)); 'status' => 'success',
break; 'settings' => $retArr
));
break;
// Try to verify the database connection settings // Try to verify the database connection settings
case 'verifySettings': case 'verifySettings':
$cm = new \OC\DB\ConnectionFactory(\OC::$server->getSystemConfig()); $cm = new \OC\DB\ConnectionFactory(\OC::$server->getSystemConfig());
if(!isset($_POST['sql_driver'])) if (!isset($_POST['sql_driver'])) {
{ $response->setData(array(
$response->setData(array('status' => 'error', 'status' => 'error',
'data' => array('message' => $l -> t('Error connecting to database: No driver specified.')))); 'data' => array('message' => $l->t('Error connecting to database: No driver specified.'))
));
break; break;
} }
if(($_POST['sql_hostname'] === '') || ($_POST['sql_database'] === '')) if (($_POST['sql_hostname'] === '') || ($_POST['sql_database'] === '')) {
{ $response->setData(array(
$response->setData(array('status' => 'error', 'status' => 'error',
'data' => array('message' => $l -> t('Error connecting to database: You must specify at least host and database')))); 'data' => array('message' => $l->t('Error connecting to database: You must specify at least host and database'))
));
break; break;
} }
$parameters = array('host' => $_POST['sql_hostname'], $parameters = array(
'host' => $_POST['sql_hostname'],
'password' => $_POST['sql_password'], 'password' => $_POST['sql_password'],
'user' => $_POST['sql_username'], 'user' => $_POST['sql_username'],
'dbname' => $_POST['sql_database'], 'dbname' => $_POST['sql_database'],
@@ -203,22 +187,25 @@ if(isset($_POST['appname']) && ($_POST['appname'] === 'user_sql') && isset($_POS
); );
try { try {
$conn = $cm -> getConnection($_POST['sql_driver'], $parameters); $conn = $cm->getConnection($_POST['sql_driver'], $parameters);
$response->setData(array('status' => 'success', $response->setData(array(
'data' => array('message' => $l -> t('Successfully connected to database')))); 'status' => 'success',
'data' => array('message' => $l->t('Successfully connected to database'))
));
} catch (\Exception $e) {
$response->setData(array(
'status' => 'error',
'data' => array('message' => $l->t('Error connecting to database: ') . $e->getMessage())
));
} }
catch(\Exception $e) break;
{
$response->setData(array('status' => 'error',
'data' => array('message' => $l -> t('Error connecting to database: ').$e->getMessage())));
}
break;
// Get the autocompletion values for a column // Get the autocompletion values for a column
case 'getColumnAutocomplete': case 'getColumnAutocomplete':
$parameters = array('host' => $_POST['sql_hostname'], $parameters = array(
'host' => $_POST['sql_hostname'],
'password' => $_POST['sql_password'], 'password' => $_POST['sql_password'],
'user' => $_POST['sql_username'], 'user' => $_POST['sql_username'],
'dbname' => $_POST['sql_database'], 'dbname' => $_POST['sql_database'],
@@ -231,28 +218,30 @@ if(isset($_POST['appname']) && ($_POST['appname'] === 'user_sql') && isset($_POS
$sql_table = $_POST['sql_table']; $sql_table = $_POST['sql_table'];
} }
if($helper->verifyTable($parameters, $_POST['sql_driver'], $_POST['sql_table'])) if ($helper->verifyTable($parameters, $_POST['sql_driver'], $_POST['sql_table'])) {
$columns = $helper->getColumns($parameters, $_POST['sql_driver'], $sql_table); $columns = $helper->getColumns($parameters, $_POST['sql_driver'], $sql_table);
else } else {
$columns = array(); $columns = array();
}
$search = $_POST['request']; $search = $_POST['request'];
$ret = array(); $ret = array();
foreach($columns as $name) foreach ($columns as $name) {
{ if (($search === '') || ($search === 'search') || (strpos($name, $search) === 0)) {
if(($search === '') || ($search === 'search') || (strpos($name, $search) === 0)) $ret[] = array(
{ 'label' => $name,
$ret[] = array('label' => $name, 'value' => $name
'value' => $name); );
} }
} }
$response -> setData($ret); $response->setData($ret);
break; break;
// Get the autocompletion values for a table // Get the autocompletion values for a table
case 'getTableAutocomplete': case 'getTableAutocomplete':
$parameters = array('host' => $_POST['sql_hostname'], $parameters = array(
'host' => $_POST['sql_hostname'],
'password' => $_POST['sql_password'], 'password' => $_POST['sql_password'],
'user' => $_POST['sql_username'], 'user' => $_POST['sql_username'],
'dbname' => $_POST['sql_database'], 'dbname' => $_POST['sql_database'],
@@ -263,23 +252,24 @@ if(isset($_POST['appname']) && ($_POST['appname'] === 'user_sql') && isset($_POS
$search = $_POST['request']; $search = $_POST['request'];
$ret = array(); $ret = array();
foreach($tables as $name) foreach ($tables as $name) {
{ if (($search === '') || ($search === 'search') || (strpos($name, $search) === 0)) {
if(($search === '') || ($search === 'search') || (strpos($name, $search) === 0)) $ret[] = array(
{ 'label' => $name,
$ret[] = array('label' => $name, 'value' => $name
'value' => $name); );
} }
} }
$response -> setData($ret); $response->setData($ret);
break; break;
} }
} else } else {
{
// If the request was not for us, set an error message // If the request was not for us, set an error message
$response->setData(array('status' => 'error', $response->setData(array(
'data' => array('message' => $l -> t('Not submitted for us.')))); 'status' => 'error',
'data' => array('message' => $l->t('Not submitted for us.'))
));
} }
// Return the JSON array // Return the JSON array

View File

@@ -1,31 +1,31 @@
<?php <?php
/** /**
* ownCloud - user_sql * Nextcloud - user_sql
* *
* @author Andreas Böhler * @author Andreas Böhler
* @copyright 2012-2015 Andreas Böhler <dev (at) aboehler (dot) at> * @copyright 2012-2015 Andreas Böhler <dev (at) aboehler (dot) at>
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either * License as published by the Free Software Foundation; either
* version 3 of the License, or any later version. * version 3 of the License, or any later version.
* *
* This library is distributed in the hope that it will be useful, * This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
* *
* You should have received a copy of the GNU Affero General Public * You should have received a copy of the GNU Affero General Public
* 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/>.
* *
*/ */
require_once(__DIR__ . '/../lib/user_sql.php'); require_once(__DIR__ . '/../lib/user_sql.php');
require_once __DIR__ . '/../lib/group_sql.php'; require_once __DIR__ . '/../lib/group_sql.php';
$backend = new \OCA\user_sql\OC_USER_SQL; $backend = new \OCA\user_sql\OC_USER_SQL;
$group_backend = new \OCA\user_sql\OC_GROUP_SQL; $group_backend = new \OCA\user_sql\OC_GROUP_SQL;
\OC::$server->getUserManager()->registerBackend($backend); \OC::$server->getUserManager()->registerBackend($backend);
\OC::$server->getGroupManager()->addBackend($group_backend); \OC::$server->getGroupManager()->addBackend($group_backend);
?>

View File

@@ -1,27 +1,28 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<info> <info>
<id>user_sql</id> <id>user_sql</id>
<name>SQL user backend</name> <name>SQL User Backend</name>
<summary>Authenticate Users by SQL</summary> <summary>Authenticate Users by SQL</summary>
<description>Authenticate Users by SQL</description> <description>Authenticate users and retrieve their groups from external database by native SQL queries.</description>
<version>3.1.0</version> <version>4.0.0-dev</version>
<licence>agpl</licence> <licence>agpl</licence>
<author>Andreas Boehler &lt;dev (at) aboehler (dot) at &gt;</author> <author>Andreas Boehler &lt;dev (at) aboehler (dot) at &gt;</author>
<namespace>user_sql</namespace> <namespace>user_sql</namespace>
<bugs>https://github.com/nextcloud/user_sql/issues</bugs> <bugs>https://github.com/nextcloud/user_sql/issues</bugs>
<repository>https://github.com/nextcloud/user_sql</repository> <repository>https://github.com/nextcloud/user_sql</repository>
<screenshot>https://raw.githubusercontent.com/nextcloud/user_sql/v2.4.0/screenshot.png</screenshot> <screenshot>https://raw.githubusercontent.com/nextcloud/user_sql/v4.0.0/img/screenshot.png</screenshot>
<types> <types>
<authentication/> <authentication/>
</types> </types>
<category>auth</category> <category>auth</category>
<dependencies> <dependencies>
<nextcloud min-version="12" max-version="13"/> <php min-version="5.4"/>
<database>mysql</database> <nextcloud min-version="12" max-version="13"/>
<database>pgsql</database> <database>mysql</database>
</dependencies> <database>pgsql</database>
<settings> </dependencies>
<admin>\OCA\user_sql\Settings\Admin</admin> <settings>
<admin-section>OCA\user_sql\Settings\Section</admin-section> <admin>\OCA\user_sql\Settings\Admin</admin>
</settings> <admin-section>OCA\user_sql\Settings\Section</admin-section>
</settings>
</info> </info>

View File

@@ -1,8 +1,9 @@
<?php <?php
/** /**
* Copyright (c) 2015, Andreas Böhler <dev@aboehler.at> * Copyright (c) 2015, Andreas Böhler <dev@aboehler.at>
* This file is licensed under the Affero General Public License version 3 or later. * This file is licensed under the Affero General Public License version 3 or later.
* See the COPYING-README file. * See the COPYING-README file.
*/ */
/** @var $this \OCP\Route\IRouter */ /** @var $this \OCP\Route\IRouter */
$this->create('user_sql_ajax_settings', 'ajax/settings.php')->actionInclude('user_sql/ajax/settings.php'); $this->create('user_sql_ajax_settings', 'ajax/settings.php')->actionInclude('user_sql/ajax/settings.php');

View File

@@ -1,71 +0,0 @@
<?php
/**
* ownCloud - user_sql
*
* @author Andreas Böhler and contributors
* @copyright 2012-2015 Andreas Böhler <dev (at) aboehler (dot) at>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
$installedVersion = \OC::$server->getConfig()->getAppValue('user_sql', 'installed_version');
$params = array('sql_host' => 'sql_hostname',
'sql_user' => 'sql_username',
'sql_database' => 'sql_database',
'sql_password' => 'sql_password',
'sql_table' => 'sql_table',
'sql_column_username' => 'col_username',
'sql_column_password' => 'col_password',
'sql_type' => 'sql_driver',
'sql_column_active' => 'col_active',
'strip_domain' => 'set_strip_domain',
'default_domain' => 'set_default_domain',
'crypt_type' => 'set_crypt_type',
'sql_column_displayname' => 'col_displayname',
'allow_password_change' => 'set_allow_pwchange',
'sql_column_active_invert' => 'set_active_invert',
'sql_column_email' => 'col_email',
'mail_sync_mode' => 'set_mail_sync_mode'
);
$delParams = array('domain_settings',
'map_array',
'domain_array'
);
if(version_compare($installedVersion, '1.99', '<'))
{
foreach($params as $oldPar => $newPar)
{
$val = \OC::$server->getConfig()->getAppValue('user_sql', $oldPar);
if(($oldPar === 'strip_domain') || ($oldPar === 'allow_password_change') || ($oldPar === 'sql_column_active_invert'))
{
if($val)
$val = 'true';
else
$val = 'false';
}
if($val)
\OC::$server->getConfig()->setAppValue('user_sql', $newPar.'_default', $val);
\OC::$server->getConfig()->deleteAppValue('user_sql', $oldPar);
}
foreach($delParams as $param)
{
\OC::$server->getConfig()->deleteAppValue('user_sql', $param);
}
}

View File

@@ -1,15 +1,18 @@
.statusmessage { .statusmessage {
background-color: #DDDDFF; background-color: #DDDDFF;
} }
.errormessage { .errormessage {
background-color: #FFDDDD; background-color: #FFDDDD;
} }
.successmessage { .successmessage {
background-color: #DDFFDD; background-color: #DDFFDD;
} }
.statusmessage,.errormessage,.successmessage{
display:none; .statusmessage, .errormessage, .successmessage {
padding: 1px; display: none;
padding: 1px;
} }
#sql-1 p label:first-child, #sql-1 p label:first-child,

View File

@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns="http://www.w3.org/2000/svg" height="16" width="16" version="1.0" viewBox="0 0 16 16"> <svg xmlns="http://www.w3.org/2000/svg" height="16" width="16" version="1.0" viewBox="0 0 16 16">
<path style="block-progression:tb;color:#000000;text-transform:none;text-indent:0" fill="#000" d="m8.4036 1c-1.7312 0-3.1998 1.2661-3.1998 2.9 0.012287 0.51643 0.058473 1.1532 0.36664 2.5v0.033333l0.033328 0.033333c0.098928 0.28338 0.24289 0.44549 0.4333 0.66666s0.41742 0.48149 0.63328 0.69999c0.025397 0.025708 0.041676 0.041633 0.066656 0.066677 0.04281 0.18631 0.094672 0.38681 0.13332 0.56666 0.10284 0.47851 0.092296 0.81737 0.066668 0.93332-0.74389 0.26121-1.6694 0.57228-2.4998 0.93332-0.46622 0.2027-0.8881 0.3837-1.2332 0.59999-0.34513 0.2163-0.68837 0.37971-0.79994 0.86666-0.16004 0.63293-0.19866 0.7539-0.39997 1.5333-0.027212 0.20914 0.083011 0.42961 0.26665 0.53333 1.5078 0.81451 3.824 1.1423 6.1329 1.1333s4.6066-0.35609 6.0662-1.1333c0.11739-0.07353 0.14304-0.10869 0.13332-0.2333-0.04365-0.68908-0.08154-1.3669-0.13332-1.7666-0.01807-0.09908-0.06492-0.19275-0.13332-0.26666-0.46366-0.5537-1.1564-0.89218-1.9665-1.2333-0.7396-0.31144-1.6067-0.63486-2.4665-0.99999-0.048123-0.10721-0.095926-0.41912 0-0.89999 0.025759-0.12912 0.066096-0.26742 0.099994-0.4 0.0808-0.090507 0.14378-0.16447 0.23332-0.26666 0.19096-0.21796 0.39614-0.44661 0.56662-0.66666s0.30996-0.40882 0.39997-0.66666l0.03333-0.033333c0.34839-1.4062 0.34857-1.9929 0.36664-2.5v-0.033333c0-1.6339-1.4686-2.9-3.1998-2.9z"/> <path style="block-progression:tb;color:#000000;text-transform:none;text-indent:0" fill="#000"
d="m8.4036 1c-1.7312 0-3.1998 1.2661-3.1998 2.9 0.012287 0.51643 0.058473 1.1532 0.36664 2.5v0.033333l0.033328 0.033333c0.098928 0.28338 0.24289 0.44549 0.4333 0.66666s0.41742 0.48149 0.63328 0.69999c0.025397 0.025708 0.041676 0.041633 0.066656 0.066677 0.04281 0.18631 0.094672 0.38681 0.13332 0.56666 0.10284 0.47851 0.092296 0.81737 0.066668 0.93332-0.74389 0.26121-1.6694 0.57228-2.4998 0.93332-0.46622 0.2027-0.8881 0.3837-1.2332 0.59999-0.34513 0.2163-0.68837 0.37971-0.79994 0.86666-0.16004 0.63293-0.19866 0.7539-0.39997 1.5333-0.027212 0.20914 0.083011 0.42961 0.26665 0.53333 1.5078 0.81451 3.824 1.1423 6.1329 1.1333s4.6066-0.35609 6.0662-1.1333c0.11739-0.07353 0.14304-0.10869 0.13332-0.2333-0.04365-0.68908-0.08154-1.3669-0.13332-1.7666-0.01807-0.09908-0.06492-0.19275-0.13332-0.26666-0.46366-0.5537-1.1564-0.89218-1.9665-1.2333-0.7396-0.31144-1.6067-0.63486-2.4665-0.99999-0.048123-0.10721-0.095926-0.41912 0-0.89999 0.025759-0.12912 0.066096-0.26742 0.099994-0.4 0.0808-0.090507 0.14378-0.16447 0.23332-0.26666 0.19096-0.21796 0.39614-0.44661 0.56662-0.66666s0.30996-0.40882 0.39997-0.66666l0.03333-0.033333c0.34839-1.4062 0.34857-1.9929 0.36664-2.5v-0.033333c0-1.6339-1.4686-2.9-3.1998-2.9z"/>
</svg> </svg>

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 24 KiB

View File

@@ -2,24 +2,20 @@
// declare namespace // declare namespace
var user_sql = user_sql || var user_sql = user_sql ||
{ {};
};
/** /**
* init admin settings view * init admin settings view
*/ */
user_sql.adminSettingsUI = function() user_sql.adminSettingsUI = function () {
{
if($('#sqlDiv').length > 0) if ($('#sqlDiv').length > 0) {
{
// enable tabs on settings page // enable tabs on settings page
$('#sqlDiv').tabs(); $('#sqlDiv').tabs();
// Attach auto-completion to all column fields // Attach auto-completion to all column fields
$('#col_username, #col_password, #col_displayname, #col_active, #col_email, #col_gethome').autocomplete({ $('#col_username, #col_password, #col_displayname, #col_active, #col_email, #col_gethome').autocomplete({
source: function(request, response) source: function (request, response) {
{
var post = $('#sqlForm').serializeArray(); var post = $('#sqlForm').serializeArray();
var domain = $('#sql_domain_chooser option:selected').val(); var domain = $('#sql_domain_chooser option:selected').val();
@@ -42,23 +38,21 @@ user_sql.adminSettingsUI = function()
$.post(OC.filePath('user_sql', 'ajax', 'settings.php'), post, response, 'json'); $.post(OC.filePath('user_sql', 'ajax', 'settings.php'), post, response, 'json');
}, },
minLength: 0, minLength: 0,
open: function() { open: function () {
$(this).attr('state', 'open'); $(this).attr('state', 'open');
}, },
close: function() { close: function () {
$(this).attr('state', 'closed'); $(this).attr('state', 'closed');
} }
}).focus(function() { }).focus(function () {
if($(this).attr('state') != 'open') if ($(this).attr('state') != 'open') {
{ $(this).autocomplete("search");
$(this).autocomplete("search"); }
}
}); });
// Attach auto-completion to all group column fields // Attach auto-completion to all group column fields
$('#col_group_name, #col_group_username').autocomplete({ $('#col_group_name, #col_group_username').autocomplete({
source: function(request, response) source: function (request, response) {
{
var post = $('#sqlForm').serializeArray(); var post = $('#sqlForm').serializeArray();
var domain = $('#sql_domain_chooser option:selected').val(); var domain = $('#sql_domain_chooser option:selected').val();
@@ -86,23 +80,21 @@ user_sql.adminSettingsUI = function()
$.post(OC.filePath('user_sql', 'ajax', 'settings.php'), post, response, 'json'); $.post(OC.filePath('user_sql', 'ajax', 'settings.php'), post, response, 'json');
}, },
minLength: 0, minLength: 0,
open: function() { open: function () {
$(this).attr('state', 'open'); $(this).attr('state', 'open');
}, },
close: function() { close: function () {
$(this).attr('state', 'closed'); $(this).attr('state', 'closed');
} }
}).focus(function() { }).focus(function () {
if($(this).attr('state') != 'open') if ($(this).attr('state') != 'open') {
{ $(this).autocomplete("search");
$(this).autocomplete("search"); }
}
}); });
// Attach auto-completion to all table fields // Attach auto-completion to all table fields
$('#sql_table, #sql_group_table').autocomplete({ $('#sql_table, #sql_group_table').autocomplete({
source: function(request, response) source: function (request, response) {
{
var post = $('#sqlForm').serializeArray(); var post = $('#sqlForm').serializeArray();
var domain = $('#sql_domain_chooser option:selected').val(); var domain = $('#sql_domain_chooser option:selected').val();
@@ -125,22 +117,20 @@ user_sql.adminSettingsUI = function()
$.post(OC.filePath('user_sql', 'ajax', 'settings.php'), post, response, 'json'); $.post(OC.filePath('user_sql', 'ajax', 'settings.php'), post, response, 'json');
}, },
minLength: 0, minLength: 0,
open: function() { open: function () {
$(this).attr('state', 'open'); $(this).attr('state', 'open');
}, },
close: function() { close: function () {
$(this).attr('state', 'closed'); $(this).attr('state', 'closed');
} }
}).focus(function() { }).focus(function () {
if($(this).attr('state') != 'open') if ($(this).attr('state') != 'open') {
{ $(this).autocomplete("search");
$(this).autocomplete("search"); }
}
}); });
// Verify the SQL database settings // Verify the SQL database settings
$('#sqlVerify').click(function(event) $('#sqlVerify').click(function (event) {
{
event.preventDefault(); event.preventDefault();
var post = $('#sqlForm').serializeArray(); var post = $('#sqlForm').serializeArray();
@@ -161,19 +151,15 @@ user_sql.adminSettingsUI = function()
$('#sql_error_message').hide(); $('#sql_error_message').hide();
$('#sql_update_message').hide(); $('#sql_update_message').hide();
// Ajax foobar // Ajax foobar
$.post(OC.filePath('user_sql', 'ajax', 'settings.php'), post, function(data) $.post(OC.filePath('user_sql', 'ajax', 'settings.php'), post, function (data) {
{
$('#sql_verify_message').hide(); $('#sql_verify_message').hide();
if(data.status == 'success') if (data.status == 'success') {
{
$('#sql_success_message').html(data.data.message); $('#sql_success_message').html(data.data.message);
$('#sql_success_message').show(); $('#sql_success_message').show();
window.setTimeout(function() window.setTimeout(function () {
{
$('#sql_success_message').hide(); $('#sql_success_message').hide();
}, 10000); }, 10000);
} else } else {
{
$('#sql_error_message').html(data.data.message); $('#sql_error_message').html(data.data.message);
$('#sql_error_message').show(); $('#sql_error_message').show();
} }
@@ -182,8 +168,7 @@ user_sql.adminSettingsUI = function()
}); });
// Save the settings for a domain // Save the settings for a domain
$('#sqlSubmit').click(function(event) $('#sqlSubmit').click(function (event) {
{
event.preventDefault(); event.preventDefault();
var post = $('#sqlForm').serializeArray(); var post = $('#sqlForm').serializeArray();
@@ -204,19 +189,15 @@ user_sql.adminSettingsUI = function()
$('#sql_verify_message').hide(); $('#sql_verify_message').hide();
$('#sql_error_message').hide(); $('#sql_error_message').hide();
// Ajax foobar // Ajax foobar
$.post(OC.filePath('user_sql', 'ajax', 'settings.php'), post, function(data) $.post(OC.filePath('user_sql', 'ajax', 'settings.php'), post, function (data) {
{
$('#sql_update_message').hide(); $('#sql_update_message').hide();
if(data.status == 'success') if (data.status == 'success') {
{
$('#sql_success_message').html(data.data.message); $('#sql_success_message').html(data.data.message);
$('#sql_success_message').show(); $('#sql_success_message').show();
window.setTimeout(function() window.setTimeout(function () {
{
$('#sql_success_message').hide(); $('#sql_success_message').hide();
}, 10000); }, 10000);
} else } else {
{
$('#sql_error_message').html(data.data.message); $('#sql_error_message').html(data.data.message);
$('#sql_error_message').show(); $('#sql_error_message').show();
} }
@@ -225,45 +206,39 @@ user_sql.adminSettingsUI = function()
}); });
// Attach event handler to the domain chooser // Attach event handler to the domain chooser
$('#sql_domain_chooser').change(function() { $('#sql_domain_chooser').change(function () {
user_sql.loadDomainSettings($('#sql_domain_chooser option:selected').val()); user_sql.loadDomainSettings($('#sql_domain_chooser option:selected').val());
}); });
$('#set_gethome_mode').change(function() { $('#set_gethome_mode').change(function () {
user_sql.setGethomeMode(); user_sql.setGethomeMode();
}); });
$('#set_enable_gethome').change(function() { $('#set_enable_gethome').change(function () {
user_sql.setGethomeMode(); user_sql.setGethomeMode();
}); });
} }
}; };
user_sql.setGethomeMode = function() user_sql.setGethomeMode = function () {
{
var enabled = $('#set_enable_gethome').prop('checked'); var enabled = $('#set_enable_gethome').prop('checked');
if(enabled) if (enabled) {
{
$('#set_gethome_mode').prop('disabled', false); $('#set_gethome_mode').prop('disabled', false);
var val = $('#set_gethome_mode option:selected').val(); var val = $('#set_gethome_mode option:selected').val();
if(val === 'query') if (val === 'query') {
{
$('#set_gethome').prop('disabled', true); $('#set_gethome').prop('disabled', true);
$('#col_gethome').prop('disabled', false); $('#col_gethome').prop('disabled', false);
} }
else if(val === 'static') else if (val === 'static') {
{
$('#set_gethome').prop('disabled', false); $('#set_gethome').prop('disabled', false);
$('#col_gethome').prop('disabled', true); $('#col_gethome').prop('disabled', true);
} }
else else {
{
$('#set_gethome').prop('disabled', true); $('#set_gethome').prop('disabled', true);
$('#col_gethome').prop('disabled', true); $('#col_gethome').prop('disabled', true);
} }
} }
else else {
{
$('#set_gethome_mode').prop('disabled', true); $('#set_gethome_mode').prop('disabled', true);
$('#set_gethome').prop('disabled', true); $('#set_gethome').prop('disabled', true);
$('#col_gethome').prop('disabled', true); $('#col_gethome').prop('disabled', true);
@@ -274,8 +249,7 @@ user_sql.setGethomeMode = function()
* Load the settings for the selected domain * Load the settings for the selected domain
* @param string domain The domain to load * @param string domain The domain to load
*/ */
user_sql.loadDomainSettings = function(domain) user_sql.loadDomainSettings = function (domain) {
{
$('#sql_success_message').hide(); $('#sql_success_message').hide();
$('#sql_error_message').hide(); $('#sql_error_message').hide();
$('#sql_verify_message').hide(); $('#sql_verify_message').hide();
@@ -294,49 +268,40 @@ user_sql.loadDomainSettings = function(domain)
value: domain value: domain
} }
]; ];
$.post(OC.filePath('user_sql', 'ajax', 'settings.php'), post, function(data) $.post(OC.filePath('user_sql', 'ajax', 'settings.php'), post, function (data) {
{
$('#sql_loading_message').hide(); $('#sql_loading_message').hide();
if(data.status == 'success') if (data.status == 'success') {
{ for (key in data.settings) {
for(key in data.settings) if (key == 'set_strip_domain') {
{ if (data.settings[key] == 'true')
if(key == 'set_strip_domain')
{
if(data.settings[key] == 'true')
$('#' + key).prop('checked', true); $('#' + key).prop('checked', true);
else else
$('#' + key).prop('checked', false); $('#' + key).prop('checked', false);
} }
else if(key == 'set_allow_pwchange') else if (key == 'set_allow_pwchange') {
{ if (data.settings[key] == 'true')
if(data.settings[key] == 'true')
$('#' + key).prop('checked', true); $('#' + key).prop('checked', true);
else else
$('#' + key).prop('checked', false); $('#' + key).prop('checked', false);
} }
else if(key == 'set_active_invert') else if (key == 'set_active_invert') {
{ if (data.settings[key] == 'true')
if(data.settings[key] == 'true')
$('#' + key).prop('checked', true); $('#' + key).prop('checked', true);
else else
$('#' + key).prop('checked', false); $('#' + key).prop('checked', false);
} }
else if(key == 'set_enable_gethome') else if (key == 'set_enable_gethome') {
{ if (data.settings[key] == 'true')
if(data.settings[key] == 'true')
$('#' + key).prop('checked', true); $('#' + key).prop('checked', true);
else else
$('#' + key).prop('checked', false); $('#' + key).prop('checked', false);
} }
else else {
{
$('#' + key).val(data.settings[key]); $('#' + key).val(data.settings[key]);
} }
} }
} }
else else {
{
$('#sql_error_message').html(data.data.message); $('#sql_error_message').html(data.data.message);
$('#sql_error_message').show(); $('#sql_error_message').show();
} }
@@ -346,10 +311,8 @@ user_sql.loadDomainSettings = function(domain)
}; };
// Run our JS if the SQL settings are present // Run our JS if the SQL settings are present
$(document).ready(function() $(document).ready(function () {
{ if ($('#sqlDiv')) {
if($('#sqlDiv'))
{
user_sql.adminSettingsUI(); user_sql.adminSettingsUI();
user_sql.loadDomainSettings($('#sql_domain_chooser option:selected').val()); user_sql.loadDomainSettings($('#sql_domain_chooser option:selected').val());
user_sql.setGethomeMode(); user_sql.setGethomeMode();

View File

@@ -24,230 +24,245 @@
# Obviously, since this code is in the public domain, the above are not # Obviously, since this code is in the public domain, the above are not
# requirements (there can be none), but merely suggestions. # requirements (there can be none), but merely suggestions.
# #
class PasswordHash { class PasswordHash
var $itoa64; {
var $iteration_count_log2; var $itoa64;
var $portable_hashes; var $iteration_count_log2;
var $random_state; var $portable_hashes;
var $random_state;
function __construct($iteration_count_log2, $portable_hashes) function __construct($iteration_count_log2, $portable_hashes)
{ {
$this->itoa64 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; $this->itoa64 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
if ($iteration_count_log2 < 4 || $iteration_count_log2 > 31) if ($iteration_count_log2 < 4 || $iteration_count_log2 > 31) {
$iteration_count_log2 = 8; $iteration_count_log2 = 8;
$this->iteration_count_log2 = $iteration_count_log2; }
$this->iteration_count_log2 = $iteration_count_log2;
$this->portable_hashes = $portable_hashes; $this->portable_hashes = $portable_hashes;
$this->random_state = microtime(); $this->random_state = microtime();
if (function_exists('getmypid')) if (function_exists('getmypid')) {
$this->random_state .= getmypid(); $this->random_state .= getmypid();
} }
}
function get_random_bytes($count) function get_random_bytes($count)
{ {
$output = ''; $output = '';
if (is_readable('/dev/urandom') && if (is_readable('/dev/urandom') &&
($fh = @fopen('/dev/urandom', 'rb'))) { ($fh = @fopen('/dev/urandom', 'rb'))) {
$output = fread($fh, $count); $output = fread($fh, $count);
fclose($fh); fclose($fh);
} }
if (strlen($output) < $count) { if (strlen($output) < $count) {
$output = ''; $output = '';
for ($i = 0; $i < $count; $i += 16) { for ($i = 0; $i < $count; $i += 16) {
$this->random_state = $this->random_state =
md5(microtime() . $this->random_state); md5(microtime() . $this->random_state);
$output .= $output .=
pack('H*', md5($this->random_state)); pack('H*', md5($this->random_state));
} }
$output = substr($output, 0, $count); $output = substr($output, 0, $count);
} }
return $output; return $output;
} }
function encode64($input, $count) function encode64($input, $count)
{ {
$output = ''; $output = '';
$i = 0; $i = 0;
do { do {
$value = ord($input[$i++]); $value = ord($input[$i++]);
$output .= $this->itoa64[$value & 0x3f]; $output .= $this->itoa64[$value & 0x3f];
if ($i < $count) if ($i < $count) {
$value |= ord($input[$i]) << 8; $value |= ord($input[$i]) << 8;
$output .= $this->itoa64[($value >> 6) & 0x3f]; }
if ($i++ >= $count) $output .= $this->itoa64[($value >> 6) & 0x3f];
break; if ($i++ >= $count) {
if ($i < $count) break;
$value |= ord($input[$i]) << 16; }
$output .= $this->itoa64[($value >> 12) & 0x3f]; if ($i < $count) {
if ($i++ >= $count) $value |= ord($input[$i]) << 16;
break; }
$output .= $this->itoa64[($value >> 18) & 0x3f]; $output .= $this->itoa64[($value >> 12) & 0x3f];
} while ($i < $count); if ($i++ >= $count) {
break;
}
$output .= $this->itoa64[($value >> 18) & 0x3f];
} while ($i < $count);
return $output; return $output;
} }
function gensalt_private($input) function gensalt_private($input)
{ {
$output = '$P$'; $output = '$P$';
$output .= $this->itoa64[min($this->iteration_count_log2 + $output .= $this->itoa64[min($this->iteration_count_log2 +
((PHP_VERSION >= '5') ? 5 : 3), 30)]; ((PHP_VERSION >= '5') ? 5 : 3), 30)];
$output .= $this->encode64($input, 6); $output .= $this->encode64($input, 6);
return $output; return $output;
} }
function crypt_private($password, $setting) function crypt_private($password, $setting)
{ {
$output = '*0'; $output = '*0';
if (substr($setting, 0, 2) === $output) if (substr($setting, 0, 2) === $output) {
$output = '*1'; $output = '*1';
}
$id = substr($setting, 0, 3); $id = substr($setting, 0, 3);
# We use "$P$", phpBB3 uses "$H$" for the same thing # We use "$P$", phpBB3 uses "$H$" for the same thing
if ($id !== '$P$' && $id !== '$H$') if ($id !== '$P$' && $id !== '$H$') {
return $output; return $output;
}
$count_log2 = strpos($this->itoa64, $setting[3]); $count_log2 = strpos($this->itoa64, $setting[3]);
if ($count_log2 < 7 || $count_log2 > 30) if ($count_log2 < 7 || $count_log2 > 30) {
return $output; return $output;
}
$count = 1 << $count_log2; $count = 1 << $count_log2;
$salt = substr($setting, 4, 8); $salt = substr($setting, 4, 8);
if (strlen($salt) !== 8) if (strlen($salt) !== 8) {
return $output; return $output;
}
# We're kind of forced to use MD5 here since it's the only # We're kind of forced to use MD5 here since it's the only
# cryptographic primitive available in all versions of PHP # cryptographic primitive available in all versions of PHP
# currently in use. To implement our own low-level crypto # currently in use. To implement our own low-level crypto
# in PHP would result in much worse performance and # in PHP would result in much worse performance and
# consequently in lower iteration counts and hashes that are # consequently in lower iteration counts and hashes that are
# quicker to crack (by non-PHP code). # quicker to crack (by non-PHP code).
if (PHP_VERSION >= '5') { if (PHP_VERSION >= '5') {
$hash = md5($salt . $password, TRUE); $hash = md5($salt . $password, true);
do { do {
$hash = md5($hash . $password, TRUE); $hash = md5($hash . $password, true);
} while (--$count); } while (--$count);
} else { } else {
$hash = pack('H*', md5($salt . $password)); $hash = pack('H*', md5($salt . $password));
do { do {
$hash = pack('H*', md5($hash . $password)); $hash = pack('H*', md5($hash . $password));
} while (--$count); } while (--$count);
} }
$output = substr($setting, 0, 12); $output = substr($setting, 0, 12);
$output .= $this->encode64($hash, 16); $output .= $this->encode64($hash, 16);
return $output; return $output;
} }
function gensalt_extended($input) function gensalt_extended($input)
{ {
$count_log2 = min($this->iteration_count_log2 + 8, 24); $count_log2 = min($this->iteration_count_log2 + 8, 24);
# This should be odd to not reveal weak DES keys, and the # This should be odd to not reveal weak DES keys, and the
# maximum valid value is (2**24 - 1) which is odd anyway. # maximum valid value is (2**24 - 1) which is odd anyway.
$count = (1 << $count_log2) - 1; $count = (1 << $count_log2) - 1;
$output = '_'; $output = '_';
$output .= $this->itoa64[$count & 0x3f]; $output .= $this->itoa64[$count & 0x3f];
$output .= $this->itoa64[($count >> 6) & 0x3f]; $output .= $this->itoa64[($count >> 6) & 0x3f];
$output .= $this->itoa64[($count >> 12) & 0x3f]; $output .= $this->itoa64[($count >> 12) & 0x3f];
$output .= $this->itoa64[($count >> 18) & 0x3f]; $output .= $this->itoa64[($count >> 18) & 0x3f];
$output .= $this->encode64($input, 3); $output .= $this->encode64($input, 3);
return $output; return $output;
} }
function gensalt_blowfish($input) function gensalt_blowfish($input)
{ {
# This one needs to use a different order of characters and a # This one needs to use a different order of characters and a
# different encoding scheme from the one in encode64() above. # different encoding scheme from the one in encode64() above.
# We care because the last character in our encoded string will # We care because the last character in our encoded string will
# only represent 2 bits. While two known implementations of # only represent 2 bits. While two known implementations of
# bcrypt will happily accept and correct a salt string which # bcrypt will happily accept and correct a salt string which
# has the 4 unused bits set to non-zero, we do not want to take # has the 4 unused bits set to non-zero, we do not want to take
# chances and we also do not want to waste an additional byte # chances and we also do not want to waste an additional byte
# of entropy. # of entropy.
$itoa64 = './ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; $itoa64 = './ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
$output = '$2a$'; $output = '$2a$';
$output .= chr(ord('0') + $this->iteration_count_log2 / 10); $output .= chr(ord('0') + $this->iteration_count_log2 / 10);
$output .= chr(ord('0') + $this->iteration_count_log2 % 10); $output .= chr(ord('0') + $this->iteration_count_log2 % 10);
$output .= '$'; $output .= '$';
$i = 0; $i = 0;
do { do {
$c1 = ord($input[$i++]); $c1 = ord($input[$i++]);
$output .= $itoa64[$c1 >> 2]; $output .= $itoa64[$c1 >> 2];
$c1 = ($c1 & 0x03) << 4; $c1 = ($c1 & 0x03) << 4;
if ($i >= 16) { if ($i >= 16) {
$output .= $itoa64[$c1]; $output .= $itoa64[$c1];
break; break;
} }
$c2 = ord($input[$i++]); $c2 = ord($input[$i++]);
$c1 |= $c2 >> 4; $c1 |= $c2 >> 4;
$output .= $itoa64[$c1]; $output .= $itoa64[$c1];
$c1 = ($c2 & 0x0f) << 2; $c1 = ($c2 & 0x0f) << 2;
$c2 = ord($input[$i++]); $c2 = ord($input[$i++]);
$c1 |= $c2 >> 6; $c1 |= $c2 >> 6;
$output .= $itoa64[$c1]; $output .= $itoa64[$c1];
$output .= $itoa64[$c2 & 0x3f]; $output .= $itoa64[$c2 & 0x3f];
} while (1); } while (1);
return $output; return $output;
} }
function HashPassword($password) function HashPassword($password)
{ {
$random = ''; $random = '';
if (CRYPT_BLOWFISH === 1 && !$this->portable_hashes) { if (CRYPT_BLOWFISH === 1 && !$this->portable_hashes) {
$random = $this->get_random_bytes(16); $random = $this->get_random_bytes(16);
$hash = $hash =
crypt($password, $this->gensalt_blowfish($random)); crypt($password, $this->gensalt_blowfish($random));
if (strlen($hash) === 60) if (strlen($hash) === 60) {
return $hash; return $hash;
} }
}
if (CRYPT_EXT_DES === 1 && !$this->portable_hashes) { if (CRYPT_EXT_DES === 1 && !$this->portable_hashes) {
if (strlen($random) < 3) if (strlen($random) < 3) {
$random = $this->get_random_bytes(3); $random = $this->get_random_bytes(3);
$hash = }
crypt($password, $this->gensalt_extended($random)); $hash =
if (strlen($hash) === 20) crypt($password, $this->gensalt_extended($random));
return $hash; if (strlen($hash) === 20) {
} return $hash;
}
}
if (strlen($random) < 6) if (strlen($random) < 6) {
$random = $this->get_random_bytes(6); $random = $this->get_random_bytes(6);
$hash = }
$this->crypt_private($password, $hash =
$this->gensalt_private($random)); $this->crypt_private($password,
if (strlen($hash) === 34) $this->gensalt_private($random));
return $hash; if (strlen($hash) === 34) {
return $hash;
}
# Returning '*' on error is safe here, but would _not_ be safe # Returning '*' on error is safe here, but would _not_ be safe
# in a crypt(3)-like function used _both_ for generating new # in a crypt(3)-like function used _both_ for generating new
# hashes and for validating passwords against existing hashes. # hashes and for validating passwords against existing hashes.
return '*'; return '*';
} }
function CheckPassword($password, $stored_hash) function CheckPassword($password, $stored_hash)
{ {
$hash = $this->crypt_private($password, $stored_hash); $hash = $this->crypt_private($password, $stored_hash);
if ($hash[0] === '*') if ($hash[0] === '*') {
$hash = crypt($password, $stored_hash); $hash = crypt($password, $stored_hash);
}
return $hash === $stored_hash; return $hash === $stored_hash;
} }
} }
?>

View File

@@ -28,73 +28,76 @@ use OCP\Defaults;
use OCP\IConfig; use OCP\IConfig;
use OCP\IL10N; use OCP\IL10N;
use OCP\Settings\ISettings; use OCP\Settings\ISettings;
use OCA\user_sql\lib\Helper;
class Admin implements ISettings { class Admin implements ISettings
/** @var IL10N */ {
private $l10n; /** @var IL10N */
/** @var Defaults */ private $l10n;
private $defaults; /** @var Defaults */
/** @var IConfig */ private $defaults;
private $config; /** @var IConfig */
private $config;
/** /**
* @param IL10N $l10n * @param IL10N $l10n
* @param Defaults $defaults * @param Defaults $defaults
* @param IConfig $config * @param IConfig $config
*/ */
public function __construct(IL10N $l10n, public function __construct(
Defaults $defaults, IL10N $l10n,
IConfig $config) { Defaults $defaults,
$this->l10n = $l10n; IConfig $config
$this->defaults = $defaults; ) {
$this->config = $config; $this->l10n = $l10n;
$this->helper = new \OCA\user_sql\lib\Helper(); $this->defaults = $defaults;
$this->params = $this->helper->getParameterArray(); $this->config = $config;
$this->settings = $this->helper -> loadSettingsForDomain('default'); $this->helper = new \OCA\user_sql\lib\Helper();
} $this->params = $this->helper->getParameterArray();
$this->settings = $this->helper->loadSettingsForDomain('default');
}
/** /**
* @return TemplateResponse * @return TemplateResponse
*/ */
public function getForm() { public function getForm()
{
$type = $this->config->getAppValue('user_sql', 'type'); $type = $this->config->getAppValue('user_sql', 'type');
$trusted_domains = \OC::$server->getConfig()->getSystemValue('trusted_domains'); $trusted_domains = \OC::$server->getConfig()->getSystemValue('trusted_domains');
$inserted = array('default'); $inserted = array('default');
array_splice($trusted_domains, 0, 0, $inserted); array_splice($trusted_domains, 0, 0, $inserted);
$params = [ $params = [
'type' => $type, 'type' => $type,
]; ];
$params['allowed_domains']= array_unique($trusted_domains); $params['allowed_domains'] = array_unique($trusted_domains);
foreach($this->params as $key) foreach ($this->params as $key) {
{ $value = $this->settings[$key];
$value = $this->settings[$key]; $params[$key] = $value;
$params[$key]=$value; }
}
$params["config"]=$this->config; $params["config"] = $this->config;
return new TemplateResponse('user_sql', 'admin', $params); return new TemplateResponse('user_sql', 'admin', $params);
} }
/** /**
* @return string the section ID, e.g. 'sharing' * @return string the section ID, e.g. 'sharing'
*/ */
public function getSection() { public function getSection()
return 'usersql'; {
} return 'user_sql';
}
/**
* @return int whether the form should be rather on the top or bottom of
* the admin section. The forms are arranged in ascending order of the
* priority values. It is required to return a value between 0 and 100.
*
* keep the server setting at the top, right after "server settings"
*/
public function getPriority() {
return 0;
}
/**
* @return int whether the form should be rather on the top or bottom of
* the admin section. The forms are arranged in ascending order of the
* priority values. It is required to return a value between 0 and 100.
*
* keep the server setting at the top, right after "server settings"
*/
public function getPriority()
{
return 0;
}
} }

View File

@@ -27,42 +27,49 @@ use OCP\IL10N;
use OCP\Settings\IIconSection; use OCP\Settings\IIconSection;
use OCP\IURLGenerator; use OCP\IURLGenerator;
class Section implements IIconSection { class Section implements IIconSection
/** @var IL10N */ {
private $l; /** @var IL10N */
private $l;
/** /**
* @param IL10N $l * @param IL10N $l
*/ */
public function __construct(IURLGenerator $url,IL10N $l) { public function __construct(IURLGenerator $url, IL10N $l)
$this->l = $l; {
$this->url = $url; $this->l = $l;
} $this->url = $url;
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getID() { public function getID()
return 'usersql'; {
} return 'user_sql';
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getName() { public function getName()
return $this->l->t('User SQL'); {
} return $this->l->t('User SQL');
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getPriority() { public function getPriority()
return 75; {
} return 75;
/** }
* {@inheritdoc}
*/ /**
public function getIcon() { * {@inheritdoc}
return $this->url->imagePath('user_sql', 'app-dark.svg'); */
} public function getIcon()
{
return $this->url->imagePath('user_sql', 'app-dark.svg');
}
} }

View File

@@ -39,8 +39,9 @@ define('HASH_LENGTH', 55);
/** /**
* Returns a string for mapping an int to the corresponding base 64 character. * Returns a string for mapping an int to the corresponding base 64 character.
*/ */
function _password_itoa64() { function _password_itoa64()
return './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; {
return './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
} }
/** /**
@@ -54,32 +55,34 @@ function _password_itoa64() {
* @return * @return
* Encoded string * Encoded string
*/ */
function _password_base64_encode($input, $count) { function _password_base64_encode($input, $count)
$output = ''; {
$i = 0; $output = '';
$itoa64 = _password_itoa64(); $i = 0;
do { $itoa64 = _password_itoa64();
$value = ord($input[$i++]); do {
$output .= $itoa64[$value & 0x3f]; $value = ord($input[$i++]);
if ($i < $count) { $output .= $itoa64[$value & 0x3f];
$value |= ord($input[$i]) << 8; if ($i < $count) {
} $value |= ord($input[$i]) << 8;
$output .= $itoa64[($value >> 6) & 0x3f]; }
if ($i++ >= $count) { $output .= $itoa64[($value >> 6) & 0x3f];
break; if ($i++ >= $count) {
} break;
if ($i < $count) { }
$value |= ord($input[$i]) << 16; if ($i < $count) {
} $value |= ord($input[$i]) << 16;
$output .= $itoa64[($value >> 12) & 0x3f]; }
if ($i++ >= $count) { $output .= $itoa64[($value >> 12) & 0x3f];
break; if ($i++ >= $count) {
} break;
$output .= $itoa64[($value >> 18) & 0x3f]; }
} while ($i < $count); $output .= $itoa64[($value >> 18) & 0x3f];
} while ($i < $count);
return $output; return $output;
} }
/** /**
* Returns a string of highly randomized bytes (over the full 8-bit range). * Returns a string of highly randomized bytes (over the full 8-bit range).
* *
@@ -92,65 +95,66 @@ function _password_base64_encode($input, $count) {
* The number of characters (bytes) to return in the string. * The number of characters (bytes) to return in the string.
*/ */
function _random_bytes($count) { function _random_bytes($count)
// $random_state does not use static as it stores random bytes. {
static $random_state, $bytes, $has_openssl; // $random_state does not use static as it stores random bytes.
static $random_state, $bytes, $has_openssl;
$missing_bytes = $count - strlen($bytes); $missing_bytes = $count - strlen($bytes);
if ($missing_bytes > 0) { if ($missing_bytes > 0) {
// PHP versions prior 5.3.4 experienced openssl_random_pseudo_bytes() // PHP versions prior 5.3.4 experienced openssl_random_pseudo_bytes()
// locking on Windows and rendered it unusable. // locking on Windows and rendered it unusable.
if (!isset($has_openssl)) { if (!isset($has_openssl)) {
$has_openssl = version_compare(PHP_VERSION, '5.3.4', '>=') && function_exists('openssl_random_pseudo_bytes'); $has_openssl = version_compare(PHP_VERSION, '5.3.4',
} '>=') && function_exists('openssl_random_pseudo_bytes');
// openssl_random_pseudo_bytes() will find entropy in a system-dependent
// way.
if ($has_openssl) {
$bytes .= openssl_random_pseudo_bytes($missing_bytes);
}
// Else, read directly from /dev/urandom, which is available on many *nix
// systems and is considered cryptographically secure.
elseif ($fh = @fopen('/dev/urandom', 'rb')) {
// PHP only performs buffered reads, so in reality it will always read
// at least 4096 bytes. Thus, it costs nothing extra to read and store
// that much so as to speed any additional invocations.
$bytes .= fread($fh, max(4096, $missing_bytes));
fclose($fh);
}
// If we couldn't get enough entropy, this simple hash-based PRNG will
// generate a good set of pseudo-random bytes on any system.
// Note that it may be important that our $random_state is passed
// through hash() prior to being rolled into $output, that the two hash()
// invocations are different, and that the extra input into the first one -
// the microtime() - is prepended rather than appended. This is to avoid
// directly leaking $random_state via the $output stream, which could
// allow for trivial prediction of further "random" numbers.
if (strlen($bytes) < $count) {
// Initialize on the first call. The contents of $_SERVER includes a mix of
// user-specific and system information that varies a little with each page.
if (!isset($random_state)) {
$random_state = print_r($_SERVER, TRUE);
if (function_exists('getmypid')) {
// Further initialize with the somewhat random PHP process ID.
$random_state .= getmypid();
} }
$bytes = '';
}
do { // openssl_random_pseudo_bytes() will find entropy in a system-dependent
$random_state = hash('sha256', microtime() . mt_rand() . $random_state); // way.
$bytes .= hash('sha256', mt_rand() . $random_state, TRUE); if ($has_openssl) {
} $bytes .= openssl_random_pseudo_bytes($missing_bytes);
while (strlen($bytes) < $count); }
// Else, read directly from /dev/urandom, which is available on many *nix
// systems and is considered cryptographically secure.
elseif ($fh = @fopen('/dev/urandom', 'rb')) {
// PHP only performs buffered reads, so in reality it will always read
// at least 4096 bytes. Thus, it costs nothing extra to read and store
// that much so as to speed any additional invocations.
$bytes .= fread($fh, max(4096, $missing_bytes));
fclose($fh);
}
// If we couldn't get enough entropy, this simple hash-based PRNG will
// generate a good set of pseudo-random bytes on any system.
// Note that it may be important that our $random_state is passed
// through hash() prior to being rolled into $output, that the two hash()
// invocations are different, and that the extra input into the first one -
// the microtime() - is prepended rather than appended. This is to avoid
// directly leaking $random_state via the $output stream, which could
// allow for trivial prediction of further "random" numbers.
if (strlen($bytes) < $count) {
// Initialize on the first call. The contents of $_SERVER includes a mix of
// user-specific and system information that varies a little with each page.
if (!isset($random_state)) {
$random_state = print_r($_SERVER, true);
if (function_exists('getmypid')) {
// Further initialize with the somewhat random PHP process ID.
$random_state .= getmypid();
}
$bytes = '';
}
do {
$random_state = hash('sha256', microtime() . mt_rand() . $random_state);
$bytes .= hash('sha256', mt_rand() . $random_state, true);
} while (strlen($bytes) < $count);
}
} }
} $output = substr($bytes, 0, $count);
$output = substr($bytes, 0, $count); $bytes = substr($bytes, $count);
$bytes = substr($bytes, $count); return $output;
return $output;
} }
/** /**
@@ -169,16 +173,17 @@ function _password_base64_encode($input, $count) {
* @return * @return
* A 12 character string containing the iteration count and a random salt. * A 12 character string containing the iteration count and a random salt.
*/ */
function _password_generate_salt($count_log2) { function _password_generate_salt($count_log2)
$output = '$S$'; {
// Ensure that $count_log2 is within set bounds. $output = '$S$';
$count_log2 = _password_enforce_log2_boundaries($count_log2); // Ensure that $count_log2 is within set bounds.
// We encode the final log2 iteration count in base 64. $count_log2 = _password_enforce_log2_boundaries($count_log2);
$itoa64 = _password_itoa64(); // We encode the final log2 iteration count in base 64.
$output .= $itoa64[$count_log2]; $itoa64 = _password_itoa64();
// 6 bytes is the standard salt for a portable phpass hash. $output .= $itoa64[$count_log2];
$output .= _password_base64_encode(_random_bytes(6), 6); // 6 bytes is the standard salt for a portable phpass hash.
return $output; $output .= _password_base64_encode(_random_bytes(6), 6);
return $output;
} }
/** /**
@@ -191,15 +196,15 @@ function _password_generate_salt($count_log2) {
* @return * @return
* Integer within set bounds that is closest to $count_log2. * Integer within set bounds that is closest to $count_log2.
*/ */
function _password_enforce_log2_boundaries($count_log2) { function _password_enforce_log2_boundaries($count_log2)
if ($count_log2 < MIN_HASH_COUNT) { {
return MIN_HASH_COUNT; if ($count_log2 < MIN_HASH_COUNT) {
} return MIN_HASH_COUNT;
elseif ($count_log2 > MAX_HASH_COUNT) { } elseif ($count_log2 > MAX_HASH_COUNT) {
return MAX_HASH_COUNT; return MAX_HASH_COUNT;
} }
return (int) $count_log2; return (int)$count_log2;
} }
/** /**
@@ -222,51 +227,53 @@ function _password_enforce_log2_boundaries($count_log2) {
* A string containing the hashed password (and salt) or FALSE on failure. * A string containing the hashed password (and salt) or FALSE on failure.
* The return string will be truncated at DRUPAL_HASH_LENGTH characters max. * The return string will be truncated at DRUPAL_HASH_LENGTH characters max.
*/ */
function _password_crypt($algo, $password, $setting) { function _password_crypt($algo, $password, $setting)
// Prevent DoS attacks by refusing to hash large passwords. {
if (strlen($password) > 512) { // Prevent DoS attacks by refusing to hash large passwords.
return FALSE; if (strlen($password) > 512) {
} return false;
// The first 12 characters of an existing hash are its setting string. }
$setting = substr($setting, 0, 12); // The first 12 characters of an existing hash are its setting string.
$setting = substr($setting, 0, 12);
if ($setting[0] != '$' || $setting[2] != '$') { if ($setting[0] != '$' || $setting[2] != '$') {
return FALSE; return false;
} }
$count_log2 = _password_get_count_log2($setting); $count_log2 = _password_get_count_log2($setting);
// Hashes may be imported from elsewhere, so we allow != DRUPAL_HASH_COUNT // Hashes may be imported from elsewhere, so we allow != DRUPAL_HASH_COUNT
if ($count_log2 < MIN_HASH_COUNT || $count_log2 > MAX_HASH_COUNT) { if ($count_log2 < MIN_HASH_COUNT || $count_log2 > MAX_HASH_COUNT) {
return FALSE; return false;
} }
$salt = substr($setting, 4, 8); $salt = substr($setting, 4, 8);
// Hashes must have an 8 character salt. // Hashes must have an 8 character salt.
if (strlen($salt) != 8) { if (strlen($salt) != 8) {
return FALSE; return false;
} }
// Convert the base 2 logarithm into an integer. // Convert the base 2 logarithm into an integer.
$count = 1 << $count_log2; $count = 1 << $count_log2;
// We rely on the hash() function being available in PHP 5.2+. // We rely on the hash() function being available in PHP 5.2+.
$hash = hash($algo, $salt . $password, TRUE); $hash = hash($algo, $salt . $password, true);
do { do {
$hash = hash($algo, $hash . $password, TRUE); $hash = hash($algo, $hash . $password, true);
} while (--$count); } while (--$count);
$len = strlen($hash); $len = strlen($hash);
$output = $setting . _password_base64_encode($hash, $len); $output = $setting . _password_base64_encode($hash, $len);
// _password_base64_encode() of a 16 byte MD5 will always be 22 characters. // _password_base64_encode() of a 16 byte MD5 will always be 22 characters.
// _password_base64_encode() of a 64 byte sha512 will always be 86 characters. // _password_base64_encode() of a 64 byte sha512 will always be 86 characters.
$expected = 12 + ceil((8 * $len) / 6); $expected = 12 + ceil((8 * $len) / 6);
return (strlen($output) == $expected) ? substr($output, 0, HASH_LENGTH) : FALSE; return (strlen($output) == $expected) ? substr($output, 0, HASH_LENGTH) : false;
} }
/** /**
* Parse the log2 iteration count from a stored hash or setting string. * Parse the log2 iteration count from a stored hash or setting string.
*/ */
function _password_get_count_log2($setting) { function _password_get_count_log2($setting)
$itoa64 = _password_itoa64(); {
return strpos($itoa64, $setting[3]); $itoa64 = _password_itoa64();
return strpos($itoa64, $setting[3]);
} }
/** /**
@@ -281,12 +288,13 @@ function _password_get_count_log2($setting) {
* @return * @return
* A string containing the hashed password (and a salt), or FALSE on failure. * A string containing the hashed password (and a salt), or FALSE on failure.
*/ */
function user_hash_password($password, $count_log2 = 0) { function user_hash_password($password, $count_log2 = 0)
if (empty($count_log2)) { {
// Use the standard iteration count. if (empty($count_log2)) {
$count_log2 = variable_get('password_count_log2', DRUPAL_HASH_COUNT); // Use the standard iteration count.
} $count_log2 = variable_get('password_count_log2', DRUPAL_HASH_COUNT);
return _password_crypt('sha512', $password, _password_generate_salt($count_log2)); }
return _password_crypt('sha512', $password, _password_generate_salt($count_log2));
} }
/** /**
@@ -299,23 +307,24 @@ function user_hash_password($password, $count_log2 = 0) {
* @return * @return
* TRUE or FALSE. * TRUE or FALSE.
*/ */
function user_check_password($password, $hashpass) { function user_check_password($password, $hashpass)
$stored_hash = $hashpass; {
$type = substr($stored_hash, 0, 3); $stored_hash = $hashpass;
switch ($type) { $type = substr($stored_hash, 0, 3);
case '$S$': switch ($type) {
// A normal Drupal 7 password using sha512. case '$S$':
$hash = _password_crypt('sha512', $password, $stored_hash); // A normal Drupal 7 password using sha512.
break; $hash = _password_crypt('sha512', $password, $stored_hash);
case '$H$': break;
// phpBB3 uses "$H$" for the same thing as "$P$". case '$H$':
case '$P$': // phpBB3 uses "$H$" for the same thing as "$P$".
// A phpass password generated using md5. This is an case '$P$':
// imported password or from an earlier Drupal version. // A phpass password generated using md5. This is an
$hash = _password_crypt('md5', $password, $stored_hash); // imported password or from an earlier Drupal version.
break; $hash = _password_crypt('md5', $password, $stored_hash);
default: break;
return FALSE; default:
} return false;
return ($hash && $stored_hash == $hash); }
return ($hash && $stored_hash == $hash);
} }

View File

@@ -2,7 +2,6 @@
namespace OCA\user_sql; namespace OCA\user_sql;
use \OCA\user_sql\lib\Helper;
use OCP\Util; use OCP\Util;
class OC_GROUP_SQL extends \OC_Group_Backend implements \OCP\GroupInterface class OC_GROUP_SQL extends \OC_Group_Backend implements \OCP\GroupInterface
@@ -12,85 +11,78 @@ class OC_GROUP_SQL extends \OC_Group_Backend implements \OCP\GroupInterface
public function __construct() public function __construct()
{ {
$this -> helper = new \OCA\user_sql\lib\Helper(); $this->helper = new \OCA\user_sql\lib\Helper();
$domain = \OC::$server->getRequest()->getServerHost(); $domain = \OC::$server->getRequest()->getServerHost();
$this -> settings = $this -> helper -> loadSettingsForDomain($domain); $this->settings = $this->helper->loadSettingsForDomain($domain);
$this -> helper -> connectToDb($this -> settings); $this->helper->connectToDb($this->settings);
return false; return false;
} }
public function getUserGroups($uid) { public function getUserGroups($uid)
if(empty($this -> settings['sql_group_table'])) {
{ if (empty($this->settings['sql_group_table'])) {
Util::writeLog('OC_USER_SQL', "Group table not configured", Util::DEBUG); Util::writeLog('OC_USER_SQL', "Group table not configured", Util::DEBUG);
return []; return [];
} }
$rows = $this -> helper -> runQuery('getUserGroups', array('uid' => $uid), false, true); $rows = $this->helper->runQuery('getUserGroups', array('uid' => $uid), false, true);
if($rows === false) if ($rows === false) {
{
Util::writeLog('OC_USER_SQL', "Found no group", Util::DEBUG); Util::writeLog('OC_USER_SQL', "Found no group", Util::DEBUG);
return []; return [];
} }
$groups = array(); $groups = array();
foreach($rows as $row) foreach ($rows as $row) {
{ $groups[] = $row[$this->settings['col_group_name']];
$groups[] = $row[$this -> settings['col_group_name']];
} }
return $groups; return $groups;
} }
public function getGroups($search = '', $limit = null, $offset = null) { public function getGroups($search = '', $limit = null, $offset = null)
if(empty($this -> settings['sql_group_table'])) {
{ if (empty($this->settings['sql_group_table'])) {
return []; return [];
} }
$search = "%".$search."%"; $search = "%" . $search . "%";
$rows = $this -> helper -> runQuery('getGroups', array('search' => $search), false, true, array('limit' => $limit, 'offset' => $offset)); $rows = $this->helper->runQuery('getGroups', array('search' => $search), false, true,
if($rows === false) array('limit' => $limit, 'offset' => $offset));
{ if ($rows === false) {
return []; return [];
} }
$groups = array(); $groups = array();
foreach($rows as $row) foreach ($rows as $row) {
{ $groups[] = $row[$this->settings['col_group_name']];
$groups[] = $row[$this -> settings['col_group_name']];
} }
return $groups; return $groups;
} }
public function usersInGroup($gid, $search = '', $limit = null, $offset = null) { public function usersInGroup($gid, $search = '', $limit = null, $offset = null)
if(empty($this -> settings['sql_group_table'])) {
{ if (empty($this->settings['sql_group_table'])) {
Util::writeLog('OC_USER_SQL', "Group table not configured", Util::DEBUG); Util::writeLog('OC_USER_SQL', "Group table not configured", Util::DEBUG);
return []; return [];
} }
$rows = $this -> helper -> runQuery('getGroupUsers', array('gid' => $gid), false, true); $rows = $this->helper->runQuery('getGroupUsers', array('gid' => $gid), false, true);
if($rows === false) if ($rows === false) {
{
Util::writeLog('OC_USER_SQL', "Found no users for group", Util::DEBUG); Util::writeLog('OC_USER_SQL', "Found no users for group", Util::DEBUG);
return []; return [];
} }
$users = array(); $users = array();
foreach($rows as $row) foreach ($rows as $row) {
{ $users[] = $row[$this->settings['col_group_username']];
$users[] = $row[$this -> settings['col_group_username']];
} }
return $users; return $users;
} }
public function countUsersInGroup($gid, $search = '') { public function countUsersInGroup($gid, $search = '')
if(empty($this -> settings['sql_group_table'])) {
{ if (empty($this->settings['sql_group_table'])) {
return 0; return 0;
} }
$search = "%".$search."%"; $search = "%" . $search . "%";
$count = $this -> helper -> runQuery('countUsersInGroup', array('gid' => $gid, 'search' => $search)); $count = $this->helper->runQuery('countUsersInGroup', array('gid' => $gid, 'search' => $search));
if($count === false) if ($count === false) {
{
return 0; return 0;
} else { } else {
return intval(reset($count)); return intval(reset($count));
} }
} }
} }
?>

View File

@@ -1,7 +1,7 @@
<?php <?php
/** /**
* nextCloud - user_sql * Nextcloud - user_sql
* *
* @author Andreas Böhler and contributors * @author Andreas Böhler and contributors
* @copyright 2012-2015 Andreas Böhler <dev (at) aboehler (dot) at> * @copyright 2012-2015 Andreas Böhler <dev (at) aboehler (dot) at>
@@ -22,10 +22,12 @@
*/ */
namespace OCA\user_sql\lib; namespace OCA\user_sql\lib;
use OCP\IConfig; use OCP\IConfig;
use OCP\Util; use OCP\Util;
class Helper { class Helper
{
protected $db; protected $db;
protected $db_conn; protected $db_conn;
@@ -85,15 +87,13 @@ class Helper {
{ {
Util::writeLog('OC_USER_SQL', "Trying to load settings for domain: " . $domain, Util::DEBUG); Util::writeLog('OC_USER_SQL', "Trying to load settings for domain: " . $domain, Util::DEBUG);
$settings = array(); $settings = array();
$sql_host = \OC::$server->getConfig()->getAppValue('user_sql', 'sql_hostname_'.$domain, ''); $sql_host = \OC::$server->getConfig()->getAppValue('user_sql', 'sql_hostname_' . $domain, '');
if($sql_host === '') if ($sql_host === '') {
{
$domain = 'default'; $domain = 'default';
} }
$params = $this -> getParameterArray(); $params = $this->getParameterArray();
foreach($params as $param) foreach ($params as $param) {
{ $settings[$param] = \OC::$server->getConfig()->getAppValue('user_sql', $param . '_' . $domain, '');
$settings[$param] = \OC::$server->getConfig()->getAppValue('user_sql', $param.'_'.$domain, '');
} }
Util::writeLog('OC_USER_SQL', "Loaded settings for domain: " . $domain, Util::DEBUG); Util::writeLog('OC_USER_SQL', "Loaded settings for domain: " . $domain, Util::DEBUG);
return $settings; return $settings;
@@ -111,159 +111,157 @@ class Helper {
public function runQuery($type, $params, $execOnly = false, $fetchArray = false, $limits = array()) public function runQuery($type, $params, $execOnly = false, $fetchArray = false, $limits = array())
{ {
Util::writeLog('OC_USER_SQL', "Entering runQuery for type: " . $type, Util::DEBUG); Util::writeLog('OC_USER_SQL', "Entering runQuery for type: " . $type, Util::DEBUG);
if(!$this -> db_conn) if (!$this->db_conn) {
return false; return false;
}
switch($type) switch ($type) {
{
case 'getHome': case 'getHome':
$query = "SELECT ".$this->settings['col_gethome']." FROM ".$this->settings['sql_table']." WHERE ".$this->settings['col_username']." = :uid"; $query = "SELECT " . $this->settings['col_gethome'] . " FROM " . $this->settings['sql_table'] . " WHERE " . $this->settings['col_username'] . " = :uid";
break; break;
case 'getMail': case 'getMail':
$query = "SELECT ".$this->settings['col_email']." FROM ".$this->settings['sql_table']." WHERE ".$this->settings['col_username']." = :uid"; $query = "SELECT " . $this->settings['col_email'] . " FROM " . $this->settings['sql_table'] . " WHERE " . $this->settings['col_username'] . " = :uid";
break; break;
case 'setMail': case 'setMail':
$query = "UPDATE ".$this->settings['sql_table']." SET ".$this->settings['col_email']." = :currMail WHERE ".$this->settings['col_username']." = :uid"; $query = "UPDATE " . $this->settings['sql_table'] . " SET " . $this->settings['col_email'] . " = :currMail WHERE " . $this->settings['col_username'] . " = :uid";
break; break;
case 'getPass': case 'getPass':
$query = "SELECT ".$this->settings['col_password']." FROM ".$this->settings['sql_table']." WHERE ".$this->settings['col_username']." = :uid"; $query = "SELECT " . $this->settings['col_password'] . " FROM " . $this->settings['sql_table'] . " WHERE " . $this->settings['col_username'] . " = :uid";
if($this -> settings['col_active'] !== '') if ($this->settings['col_active'] !== '') {
$query .= " AND " .($this -> settings['set_active_invert'] === 'true' ? "NOT " : "" ) . $this -> settings['col_active']; $query .= " AND " . ($this->settings['set_active_invert'] === 'true' ? "NOT " : "") . $this->settings['col_active'];
break; }
break;
case 'setPass': case 'setPass':
$query = "UPDATE ".$this->settings['sql_table']." SET ".$this->settings['col_password']." = :enc_password WHERE ".$this->settings['col_username'] ." = :uid"; $query = "UPDATE " . $this->settings['sql_table'] . " SET " . $this->settings['col_password'] . " = :enc_password WHERE " . $this->settings['col_username'] . " = :uid";
break; break;
case 'getRedmineSalt': case 'getRedmineSalt':
$query = "SELECT salt FROM ".$this->settings['sql_table']." WHERE ".$this->settings['col_username'] ." = :uid;"; $query = "SELECT salt FROM " . $this->settings['sql_table'] . " WHERE " . $this->settings['col_username'] . " = :uid;";
break; break;
case 'countUsers': case 'countUsers':
$query = "SELECT COUNT(*) FROM ".$this->settings['sql_table']." WHERE ".$this->settings['col_username'] ." LIKE :search"; $query = "SELECT COUNT(*) FROM " . $this->settings['sql_table'] . " WHERE " . $this->settings['col_username'] . " LIKE :search";
if($this -> settings['col_active'] !== '') if ($this->settings['col_active'] !== '') {
$query .= " AND " .($this -> settings['set_active_invert'] === 'true' ? "NOT " : "" ) . $this -> settings['col_active']; $query .= " AND " . ($this->settings['set_active_invert'] === 'true' ? "NOT " : "") . $this->settings['col_active'];
break; }
break;
case 'getUsers': case 'getUsers':
$query = "SELECT ".$this->settings['col_username']." FROM ".$this->settings['sql_table']; $query = "SELECT " . $this->settings['col_username'] . " FROM " . $this->settings['sql_table'];
$query .= " WHERE ".$this->settings['col_username']." LIKE :search"; $query .= " WHERE " . $this->settings['col_username'] . " LIKE :search";
if($this -> settings['col_active'] !== '') if ($this->settings['col_active'] !== '') {
$query .= " AND " .($this -> settings['set_active_invert'] === 'true' ? "NOT " : "" ) . $this -> settings['col_active']; $query .= " AND " . ($this->settings['set_active_invert'] === 'true' ? "NOT " : "") . $this->settings['col_active'];
$query .= " ORDER BY ".$this->settings['col_username']; }
break; $query .= " ORDER BY " . $this->settings['col_username'];
break;
case 'userExists': case 'userExists':
$query = "SELECT ".$this->settings['col_username']." FROM ".$this->settings['sql_table']." WHERE ".$this->settings['col_username']." = :uid"; $query = "SELECT " . $this->settings['col_username'] . " FROM " . $this->settings['sql_table'] . " WHERE " . $this->settings['col_username'] . " = :uid";
if($this -> settings['col_active'] !== '') if ($this->settings['col_active'] !== '') {
$query .= " AND " .($this -> settings['set_active_invert'] === 'true' ? "NOT " : "" ) . $this -> settings['col_active']; $query .= " AND " . ($this->settings['set_active_invert'] === 'true' ? "NOT " : "") . $this->settings['col_active'];
break; }
break;
case 'getDisplayName': case 'getDisplayName':
$query = "SELECT ".$this->settings['col_displayname']." FROM ".$this->settings['sql_table']." WHERE ".$this->settings['col_username']." = :uid"; $query = "SELECT " . $this->settings['col_displayname'] . " FROM " . $this->settings['sql_table'] . " WHERE " . $this->settings['col_username'] . " = :uid";
if($this -> settings['col_active'] !== '') if ($this->settings['col_active'] !== '') {
$query .= " AND " .($this -> settings['set_active_invert'] === 'true' ? "NOT " : "" ) . $this -> settings['col_active']; $query .= " AND " . ($this->settings['set_active_invert'] === 'true' ? "NOT " : "") . $this->settings['col_active'];
break; }
break;
case 'mysqlEncryptSalt': case 'mysqlEncryptSalt':
$query = "SELECT ENCRYPT(:pw, :salt);"; $query = "SELECT ENCRYPT(:pw, :salt);";
break; break;
case 'mysqlEncrypt': case 'mysqlEncrypt':
$query = "SELECT ENCRYPT(:pw);"; $query = "SELECT ENCRYPT(:pw);";
break; break;
case 'mysqlPassword': case 'mysqlPassword':
$query = "SELECT PASSWORD(:pw);"; $query = "SELECT PASSWORD(:pw);";
break; break;
case 'getUserGroups': case 'getUserGroups':
$query = "SELECT ".$this->settings['col_group_name']." FROM ".$this->settings['sql_group_table']." WHERE ".$this->settings['col_group_username']." = :uid"; $query = "SELECT " . $this->settings['col_group_name'] . " FROM " . $this->settings['sql_group_table'] . " WHERE " . $this->settings['col_group_username'] . " = :uid";
break; break;
case 'getGroups': case 'getGroups':
$query = "SELECT distinct ".$this->settings['col_group_name']." FROM ".$this->settings['sql_group_table']." WHERE ".$this->settings['col_group_name']." LIKE :search"; $query = "SELECT distinct " . $this->settings['col_group_name'] . " FROM " . $this->settings['sql_group_table'] . " WHERE " . $this->settings['col_group_name'] . " LIKE :search";
break; break;
case 'getGroupUsers': case 'getGroupUsers':
$query = "SELECT distinct ".$this->settings['col_group_username']." FROM ".$this->settings['sql_group_table']." WHERE ".$this->settings['col_group_name']." = :gid"; $query = "SELECT distinct " . $this->settings['col_group_username'] . " FROM " . $this->settings['sql_group_table'] . " WHERE " . $this->settings['col_group_name'] . " = :gid";
break; break;
case 'countUsersInGroup': case 'countUsersInGroup':
$query = "SELECT count(".$this->settings['col_group_username'].") FROM ".$this->settings['sql_group_table']." WHERE ".$this->settings['col_group_name']." = :gid AND ".$this->settings['col_group_username']." LIKE :search"; $query = "SELECT count(" . $this->settings['col_group_username'] . ") FROM " . $this->settings['sql_group_table'] . " WHERE " . $this->settings['col_group_name'] . " = :gid AND " . $this->settings['col_group_username'] . " LIKE :search";
break; break;
} }
if(isset($limits['limit']) && $limits['limit'] !== null) if (isset($limits['limit']) && $limits['limit'] !== null) {
{
$limit = intval($limits['limit']); $limit = intval($limits['limit']);
$query .= " LIMIT ".$limit; $query .= " LIMIT " . $limit;
} }
if(isset($limits['offset']) && $limits['offset'] !== null) if (isset($limits['offset']) && $limits['offset'] !== null) {
{
$offset = intval($limits['offset']); $offset = intval($limits['offset']);
$query .= " OFFSET ".$offset; $query .= " OFFSET " . $offset;
} }
Util::writeLog('OC_USER_SQL', "Preparing query: $query", Util::DEBUG); Util::writeLog('OC_USER_SQL', "Preparing query: $query", Util::DEBUG);
$result = $this -> db -> prepare($query); $result = $this->db->prepare($query);
foreach($params as $param => $value) foreach ($params as $param => $value) {
{ $result->bindValue(":" . $param, $value);
$result -> bindValue(":".$param, $value);
} }
Util::writeLog('OC_USER_SQL', "Executing query...", Util::DEBUG); Util::writeLog('OC_USER_SQL', "Executing query...", Util::DEBUG);
if(!$result -> execute()) if (!$result->execute()) {
{ $err = $result->errorInfo();
$err = $result -> errorInfo();
Util::writeLog('OC_USER_SQL', "Query failed: " . $err[2], Util::DEBUG); Util::writeLog('OC_USER_SQL', "Query failed: " . $err[2], Util::DEBUG);
return false; return false;
} }
if($execOnly === true) if ($execOnly === true) {
{
return true; return true;
} }
Util::writeLog('OC_USER_SQL', "Fetching result...", Util::DEBUG); Util::writeLog('OC_USER_SQL', "Fetching result...", Util::DEBUG);
if($fetchArray === true) if ($fetchArray === true) {
$row = $result -> fetchAll(); $row = $result->fetchAll();
else } else {
$row = $result -> fetch(); $row = $result->fetch();
}
if(!$row) if (!$row) {
{
return false; return false;
} }
return $row; return $row;
} }
/** /**
* Connect to the database using ownCloud's DBAL * Connect to the database using Nextcloud's DBAL
* @param array $settings The settings for the connection * @param array $settings The settings for the connection
* @return bool * @return bool
*/ */
public function connectToDb($settings) public function connectToDb($settings)
{ {
$this -> settings = $settings; $this->settings = $settings;
$cm = new \OC\DB\ConnectionFactory(\OC::$server->getSystemConfig()); $cm = new \OC\DB\ConnectionFactory(\OC::$server->getSystemConfig());
$parameters = array('host' => $this -> settings['sql_hostname'], $parameters = array(
'password' => $this -> settings['sql_password'], 'host' => $this->settings['sql_hostname'],
'user' => $this -> settings['sql_username'], 'password' => $this->settings['sql_password'],
'dbname' => $this -> settings['sql_database'], 'user' => $this->settings['sql_username'],
'tablePrefix' => '' 'dbname' => $this->settings['sql_database'],
); 'tablePrefix' => ''
try );
{ try {
$this -> db = $cm -> getConnection($this -> settings['sql_driver'], $parameters); $this->db = $cm->getConnection($this->settings['sql_driver'], $parameters);
$this -> db -> query("SET NAMES 'UTF8'"); $this->db->query("SET NAMES 'UTF8'");
$this -> db_conn = true; $this->db_conn = true;
return true; return true;
} } catch (\Exception $e) {
catch (\Exception $e) Util::writeLog('OC_USER_SQL', 'Failed to connect to the database: ' . $e->getMessage(), Util::ERROR);
{ $this->db_conn = false;
Util::writeLog('OC_USER_SQL', 'Failed to connect to the database: ' . $e -> getMessage(), Util::ERROR);
$this -> db_conn = false;
return false; return false;
} }
} }
@@ -275,24 +273,24 @@ class Helper {
* @param string $table The table name to check * @param string $table The table name to check
* @param array $cols The columns to check * @param array $cols The columns to check
* @param array True if found, otherwise false * @param array True if found, otherwise false
* @return bool|string
*/ */
public function verifyColumns($parameters, $sql_driver, $table, $cols) public function verifyColumns($parameters, $sql_driver, $table, $cols)
{ {
$columns = $this->getColumns($parameters, $sql_driver, $table); $columns = $this->getColumns($parameters, $sql_driver, $table);
$res = true; $res = true;
$err = ''; $err = '';
foreach($cols as $col) foreach ($cols as $col) {
{ if (!in_array($col, $columns, true)) {
if(!in_array($col, $columns, true))
{
$res = false; $res = false;
$err .= $col.' '; $err .= $col . ' ';
} }
} }
if($res) if ($res) {
return true; return true;
else } else {
return $err; return $err;
}
} }
/** /**
@@ -301,6 +299,7 @@ class Helper {
* @param string $sql_driver The SQL driver to use * @param string $sql_driver The SQL driver to use
* @param string $table The table name to check * @param string $table The table name to check
* @param array True if found, otherwise false * @param array True if found, otherwise false
* @return bool
*/ */
public function verifyTable($parameters, $sql_driver, $table) public function verifyTable($parameters, $sql_driver, $table)
{ {
@@ -320,8 +319,8 @@ class Helper {
{ {
$cm = new \OC\DB\ConnectionFactory(\OC::$server->getSystemConfig()); $cm = new \OC\DB\ConnectionFactory(\OC::$server->getSystemConfig());
try { try {
$conn = $cm -> getConnection($sql_driver, $parameters); $conn = $cm->getConnection($sql_driver, $parameters);
$platform = $conn -> getDatabasePlatform(); $platform = $conn->getDatabasePlatform();
$queryTables = $platform->getListTablesSQL(); $queryTables = $platform->getListTablesSQL();
$queryViews = $platform->getListViewsSQL($parameters['dbname']); $queryViews = $platform->getListViewsSQL($parameters['dbname']);
@@ -339,9 +338,7 @@ class Helper {
$ret[] = $name; $ret[] = $name;
} }
return $ret; return $ret;
} } catch (\Exception $e) {
catch(\Exception $e)
{
return array(); return array();
} }
} }
@@ -404,13 +401,12 @@ class Helper {
{ {
$cm = new \OC\DB\ConnectionFactory(\OC::$server->getSystemConfig()); $cm = new \OC\DB\ConnectionFactory(\OC::$server->getSystemConfig());
try { try {
$conn = $cm -> getConnection($sql_driver, $parameters); $conn = $cm->getConnection($sql_driver, $parameters);
$platform = $conn -> getDatabasePlatform(); $platform = $conn->getDatabasePlatform();
$query = $platform -> getListTableColumnsSQL($table); $query = $platform->getListTableColumnsSQL($table);
$result = $conn -> executeQuery($query); $result = $conn->executeQuery($query);
$ret = array(); $ret = array();
while($row = $result -> fetch()) while ($row = $result->fetch()) {
{
switch ($sql_driver) { switch ($sql_driver) {
case 'mysql': case 'mysql':
$name = $row['Field']; $name = $row['Field'];
@@ -424,12 +420,8 @@ class Helper {
$ret[] = $name; $ret[] = $name;
} }
return $ret; return $ret;
} } catch (\Exception $e) {
catch(\Exception $e)
{
return array(); return array();
} }
} }
} }

File diff suppressed because it is too large Load Diff

View File

@@ -1,181 +1,273 @@
<?php <?php
script('user_sql', 'settings'); script('user_sql', 'settings');
style('user_sql', 'settings'); style('user_sql', 'settings');
$cfgClass = 'section'; $cfgClass = 'section';
?> ?>
<div class="<?php p($cfgClass); ?>"> <div class="<?php p($cfgClass); ?>">
<h2><?php p($l->t('SQL User Backend')); ?></h2> <h2><?php p($l->t('SQL User Backend')); ?></h2>
<form id="sqlForm" action="#" method="post" class="<?php p($cfgClass); ?>"> <form id="sqlForm" action="#" method="post" class="<?php p($cfgClass); ?>">
<div id="sqlDiv" class="<?php p($cfgClass); ?>"> <div id="sqlDiv" class="<?php p($cfgClass); ?>">
<label for="sql_domain_chooser"><?php p($l -> t('Settings for Domain')) ?></label> <label for="sql_domain_chooser"><?php p($l->t('Settings for Domain')) ?></label>
<select id="sql_domain_chooser" name="sql_domain_chooser"> <select id="sql_domain_chooser" name="sql_domain_chooser">
<?php foreach ($_['allowed_domains'] as $domain): ?> <?php foreach ($_['allowed_domains'] as $domain): ?>
<option value="<?php p($domain); ?>"><?php p($domain); ?></option> <option value="<?php p($domain); ?>"><?php p($domain); ?></option>
<?php endforeach ?> <?php endforeach ?>
</select> </select>
<ul> <ul>
<li><a id="sqlBasicSettings" href="#sql-1"><?php p($l -> t('Connection Settings')); ?></a></li> <li><a id="sqlBasicSettings" href="#sql-1"><?php p($l->t('Connection Settings')); ?></a></li>
<li><a id="sqlColSettings" href="#sql-2"><?php p($l -> t('Column Settings')); ?></a></li> <li><a id="sqlColSettings" href="#sql-2"><?php p($l->t('Column Settings')); ?></a></li>
<li><a id="sqlEmailSettings" href="#sql-3"><?php p($l -> t('E-Mail Settings')); ?></a></li> <li><a id="sqlEmailSettings" href="#sql-3"><?php p($l->t('E-Mail Settings')); ?></a></li>
<li><a id="sqlDomainSettings" href="#sql-4"><?php p($l -> t('Domain Settings')); ?></a></li> <li><a id="sqlDomainSettings" href="#sql-4"><?php p($l->t('Domain Settings')); ?></a></li>
<li><a id="sqlGethomeSettings" href="#sql-5"><?php p($l -> t('getHome Settings')); ?></a></li> <li><a id="sqlGethomeSettings" href="#sql-5"><?php p($l->t('getHome Settings')); ?></a></li>
<li><a id="sqlGroupsSettings" href="#sql-6"><?php p($l -> t('Groups Settings')); ?></a></li> <li><a id="sqlGroupsSettings" href="#sql-6"><?php p($l->t('Groups Settings')); ?></a></li>
</ul> </ul>
<fieldset id="sql-1"> <fieldset id="sql-1">
<p><label for="sql_driver"><?php p($l -> t('SQL Driver')); ?></label> <p><label for="sql_driver"><?php p($l->t('SQL Driver')); ?></label>
<?php $db_driver = array('mysql' => 'MySQL', 'pgsql' => 'PostgreSQL'); ?> <?php $db_driver = array('mysql' => 'MySQL', 'pgsql' => 'PostgreSQL'); ?>
<select id="sql_driver" name="sql_driver"> <select id="sql_driver" name="sql_driver">
<?php <?php
foreach ($db_driver as $driver => $name): foreach ($db_driver as $driver => $name):
//echo $_['sql_driver']; //echo $_['sql_driver'];
if($_['sql_driver'] === $driver): ?> if ($_['sql_driver'] === $driver): ?>
<option selected="selected" value="<?php p($driver); ?>"><?php p($name); ?></option> <option selected="selected" value="<?php p($driver); ?>"><?php p($name); ?></option>
<?php else: ?> <?php else: ?>
<option value="<?php p($driver); ?>"><?php p($name); ?></option> <option value="<?php p($driver); ?>"><?php p($name); ?></option>
<?php endif; <?php endif;
endforeach; endforeach;
?> ?>
</select> </select>
</p> </p>
<p><label for="sql_hostname"><?php p($l -> t('Host')); ?></label><input type="text" id="sql_hostname" name="sql_hostname" value="<?php p($_['sql_hostname']); ?>"></p> <p><label for="sql_hostname"><?php p($l->t('Host')); ?></label><input type="text" id="sql_hostname"
name="sql_hostname"
value="<?php p($_['sql_hostname']); ?>">
</p>
<p><label for="sql_database"><?php p($l -> t('Database')); ?></label><input type="text" id="sql_database" name="sql_database" value="<?php p($_['sql_database']); ?>" /></p> <p><label for="sql_database"><?php p($l->t('Database')); ?></label><input type="text" id="sql_database"
name="sql_database"
value="<?php p($_['sql_database']); ?>"/>
</p>
<p><label for="sql_username"><?php p($l -> t('Username')); ?></label><input type="text" id="sql_username" name="sql_username" value="<?php p($_['sql_username']); ?>" /></p> <p><label for="sql_username"><?php p($l->t('Username')); ?></label><input type="text" id="sql_username"
name="sql_username"
value="<?php p($_['sql_username']); ?>"/>
</p>
<p><label for="sql_password"><?php p($l -> t('Password')); ?></label><input type="password" id="sql_password" name="sql_password" value="<?php p($_['sql_password']); ?>" /></p> <p><label for="sql_password"><?php p($l->t('Password')); ?></label><input type="password"
id="sql_password"
name="sql_password"
value="<?php p($_['sql_password']); ?>"/>
</p>
<p><input type="submit" id="sqlVerify" value="<?php p($l -> t('Verify Settings')); ?>"></p> <p><input type="submit" id="sqlVerify" value="<?php p($l->t('Verify Settings')); ?>"></p>
</fieldset> </fieldset>
<fieldset id="sql-2"> <fieldset id="sql-2">
<p><label for="sql_table"><?php p($l -> t('Table')); ?></label><input type="text" id="sql_table" name="sql_table" value="<?php p($_['sql_table']); ?>" /></p> <p><label for="sql_table"><?php p($l->t('Table')); ?></label><input type="text" id="sql_table"
name="sql_table"
value="<?php p($_['sql_table']); ?>"/>
</p>
<p><label for="col_username"><?php p($l -> t('Username Column')); ?></label><input type="text" id="col_username" name="col_username" value="<?php p($_['col_username']); ?>" /></p> <p><label for="col_username"><?php p($l->t('Username Column')); ?></label><input type="text"
id="col_username"
name="col_username"
value="<?php p($_['col_username']); ?>"/>
</p>
<p><label for="col_password"><?php p($l -> t('Password Column')); ?></label><input type="text" id="col_password" name="col_password" value="<?php p($_['col_password']); ?>" /></p> <p><label for="col_password"><?php p($l->t('Password Column')); ?></label><input type="text"
id="col_password"
name="col_password"
value="<?php p($_['col_password']); ?>"/>
</p>
<p><label for="set_allow_pwchange"><?php p($l -> t('Allow password changing (read README!)')); ?></label><input type="checkbox" id="set_allow_pwchange" name="set_allow_pwchange" value="1"<?php <p>
if($_['set_allow_pwchange']) <label for="set_allow_pwchange"><?php p($l->t('Allow password changing (read README!)')); ?></label><input
p(' checked'); type="checkbox" id="set_allow_pwchange" name="set_allow_pwchange" value="1"<?php
?>><br> if ($_['set_allow_pwchange']) {
<em><?php p($l -> t('Allow changing passwords. Imposes a security risk if password salts are not recreated.')); ?></em></p> p(' checked');
<em><?php p($l -> t('Only the encryption types "System","password_hash" and "Joomla2" are safe.')); ?></em></p> }
?>><br>
<em><?php p($l->t('Allow changing passwords. Imposes a security risk if password salts are not recreated.')); ?></em>
</p>
<em><?php p($l->t('Only the encryption types "System","password_hash" and "Joomla2" are safe.')); ?></em></p>
<p><label for="col_displayname"><?php p($l -> t('Real Name Column')); ?></label><input type="text" id="col_displayname" name="col_displayname" value="<?php p($_['col_displayname']); ?>" /></p> <p><label for="col_displayname"><?php p($l->t('Real Name Column')); ?></label><input type="text"
id="col_displayname"
name="col_displayname"
value="<?php p($_['col_displayname']); ?>"/>
</p>
<p><label for="set_crypt_type"><?php p($l -> t('Encryption Type')); ?></label> <p><label for="set_crypt_type"><?php p($l->t('Encryption Type')); ?></label>
<?php $crypt_types = array('drupal' => 'Drupal 7', 'md5' => 'MD5', 'md5crypt' => 'MD5 Crypt', 'cleartext' => 'Cleartext', 'mysql_encrypt' => 'mySQL ENCRYPT()', 'system' => 'System (crypt)', 'password_hash' => 'password_hash','mysql_password' => 'mySQL PASSWORD()', 'joomla' => 'Joomla MD5 Encryption', 'joomla2' => 'Joomla > 2.5.18 phpass', 'ssha256' => 'Salted SSHA256', 'redmine' => 'Redmine', 'sha1' => 'SHA1', 'courier_md5' => 'Courier base64-encoded MD5', 'courier_md5raw' => 'Courier hexadecimal MD5', 'courier_sha1' => 'Courier base64-encoded SHA1', 'courier_sha256' => 'Courier base64-encoded SHA256'); ?> <?php $crypt_types = array(
<select id="set_crypt_type" name="set_crypt_type"> 'drupal' => 'Drupal 7',
<?php 'md5' => 'MD5',
'md5crypt' => 'MD5 Crypt',
'cleartext' => 'Cleartext',
'mysql_encrypt' => 'mySQL ENCRYPT()',
'system' => 'System (crypt)',
'password_hash' => 'password_hash',
'mysql_password' => 'mySQL PASSWORD()',
'joomla' => 'Joomla MD5 Encryption',
'joomla2' => 'Joomla > 2.5.18 phpass',
'ssha256' => 'Salted SSHA256',
'redmine' => 'Redmine',
'sha1' => 'SHA1',
'courier_md5' => 'Courier base64-encoded MD5',
'courier_md5raw' => 'Courier hexadecimal MD5',
'courier_sha1' => 'Courier base64-encoded SHA1',
'courier_sha256' => 'Courier base64-encoded SHA256'
); ?>
<select id="set_crypt_type" name="set_crypt_type">
<?php
foreach ($crypt_types as $driver => $name): foreach ($crypt_types as $driver => $name):
//echo $_['set_crypt_type']; //echo $_['set_crypt_type'];
if($_['set_crypt_type'] === $driver): ?> if ($_['set_crypt_type'] === $driver): ?>
<option selected="selected" value="<?php p($driver); ?>"><?php p($name); ?></option> <option selected="selected" value="<?php p($driver); ?>"><?php p($name); ?></option>
<?php else: ?> <?php else: ?>
<option value="<?php p($driver); ?>"><?php p($name); ?></option> <option value="<?php p($driver); ?>"><?php p($name); ?></option>
<?php endif; <?php endif;
endforeach; endforeach;
?> ?>
</select> </select>
</p> </p>
<p><label for="col_active"><?php p($l -> t('User Active Column')); ?></label><input type="text" id="col_active" name="col_active" value="<?php p($_['col_active']); ?>" /></p> <p><label for="col_active"><?php p($l->t('User Active Column')); ?></label><input type="text"
id="col_active"
name="col_active"
value="<?php p($_['col_active']); ?>"/>
</p>
<p><label for="set_active_invert"><?php p($l -> t('Invert Active Value')); ?></label><input type="checkbox" id="set_active_invert" name="set_active_invert" value="1"<?php <p><label for="set_active_invert"><?php p($l->t('Invert Active Value')); ?></label><input
if($_['set_active_invert']) type="checkbox" id="set_active_invert" name="set_active_invert" value="1"<?php
p(' checked'); if ($_['set_active_invert']) {
?> /><br> p(' checked');
<em><?php p($l -> t("Invert the logic of the active column (for blocked users in the SQL DB)")); ?></em></p> }
?> /><br>
<em><?php p($l->t("Invert the logic of the active column (for blocked users in the SQL DB)")); ?></em>
</p>
</fieldset> </fieldset>
<fieldset id="sql-3"> <fieldset id="sql-3">
<p><label for="col_email"><?php p($l -> t('E-Mail Column')); ?></label><input type="text" id="col_email" name="col_email" value="<?php p($_['col_email']); ?>" /></p> <p><label for="col_email"><?php p($l->t('E-Mail Column')); ?></label><input type="text" id="col_email"
name="col_email"
value="<?php p($_['col_email']); ?>"/>
</p>
<p><label for="set_mail_sync_mode"><?php p($l -> t('E-Mail address sync mode')); ?></label> <p><label for="set_mail_sync_mode"><?php p($l->t('E-Mail address sync mode')); ?></label>
<?php $mail_modes = array('none' => 'No Synchronisation', 'initial' => 'Synchronise only once', 'forceoc' => 'Nextcloud always wins', 'forcesql' => 'SQL always wins'); ?> <?php $mail_modes = array(
<select id="set_mail_sync_mode" name="set_mail_sync_mode"> 'none' => 'No Synchronisation',
<?php 'initial' => 'Synchronise only once',
foreach ($mail_modes as $mode => $name): 'forceoc' => 'Nextcloud always wins',
//echo $_['set_mail_sync_mode']; 'forcesql' => 'SQL always wins'
if($_['set_mail_sync_mode'] === $mode): ?> ); ?>
<option selected="selected" value="<?php p($mode); ?>"><?php p($name); ?></option> <select id="set_mail_sync_mode" name="set_mail_sync_mode">
<?php else: ?> <?php
<option value="<?php p($mode); ?>"><?php p($name); ?></option> foreach ($mail_modes as $mode => $name):
<?php endif; //echo $_['set_mail_sync_mode'];
endforeach; if ($_['set_mail_sync_mode'] === $mode): ?>
?> <option selected="selected" value="<?php p($mode); ?>"><?php p($name); ?></option>
</select> <?php else: ?>
</p> <option value="<?php p($mode); ?>"><?php p($name); ?></option>
<?php endif;
endforeach;
?>
</select>
</p>
</fieldset> </fieldset>
<fieldset id="sql-4"> <fieldset id="sql-4">
<p><label for="set_default_domain"><?php p($l -> t('Append Default Domain')); ?></label><input type="text" id="set_default_domain", name="set_default_domain" value="<?php p($_['set_default_domain']); ?>" /><br> <p><label for="set_default_domain"><?php p($l->t('Append Default Domain')); ?></label><input type="text"
<em><?php p($l -> t('Append this string, e.g. a domain name, to each user name. The @-sign is automatically inserted.')); ?></em> id="set_default_domain"
</p> ,
name="set_default_domain"
value="<?php p($_['set_default_domain']); ?>"/><br>
<em><?php p($l->t('Append this string, e.g. a domain name, to each user name. The @-sign is automatically inserted.')); ?></em>
</p>
<p><label for="set_strip_domain"><?php p($l -> t('Strip Domain Part from Username')); ?></label><input type="checkbox" id="set_strip_domain" name="set_strip_domain" value="1"<?php <p><label for="set_strip_domain"><?php p($l->t('Strip Domain Part from Username')); ?></label><input
if($_['set_strip_domain']) type="checkbox" id="set_strip_domain" name="set_strip_domain" value="1"<?php
p(' checked'); if ($_['set_strip_domain']) {
?> /><br> p(' checked');
<em><?php p($l -> t("Strip Domain Part including @-sign from Username when logging in and retrieving username lists")); ?></em></p> }
?> /><br>
<em><?php p($l->t("Strip Domain Part including @-sign from Username when logging in and retrieving username lists")); ?></em>
</p>
</fieldset> </fieldset>
<fieldset id="sql-5"> <fieldset id="sql-5">
<p><label for="set_enable_gethome"><?php p($l -> t('Enable support for getHome()')); ?></label><input type="checkbox" id="set_enable_gethome", name="set_enable_gethome" value="1" <?php <p><label for="set_enable_gethome"><?php p($l->t('Enable support for getHome()')); ?></label><input
if($_['set_enable_gethome']) type="checkbox" id="set_enable_gethome" , name="set_enable_gethome" value="1" <?php
p(' checked'); if ($_['set_enable_gethome']) {
?>/></p> p(' checked');
}
?>/></p>
<p><label for="set_gethome_mode"><?php p($l -> t('Method for getHome')); ?></label> <p><label for="set_gethome_mode"><?php p($l->t('Method for getHome')); ?></label>
<?php $gethome_modes = array('query' => 'SQL Column', 'static' => 'Static (with Variables)'); ?> <?php $gethome_modes = array('query' => 'SQL Column', 'static' => 'Static (with Variables)'); ?>
<select id="set_gethome_mode" name="set_gethome_mode"> <select id="set_gethome_mode" name="set_gethome_mode">
<?php <?php
foreach ($gethome_modes as $mode => $name): foreach ($gethome_modes as $mode => $name):
//echo $_['set_mail_sync_mode']; //echo $_['set_mail_sync_mode'];
if($_['set_gethome_mode'] === $mode): ?> if ($_['set_gethome_mode'] === $mode): ?>
<option selected="selected" value="<?php p($mode); ?>"><?php p($name); ?></option> <option selected="selected" value="<?php p($mode); ?>"><?php p($name); ?></option>
<?php else: ?> <?php else: ?>
<option value="<?php p($mode); ?>"><?php p($name); ?></option> <option value="<?php p($mode); ?>"><?php p($name); ?></option>
<?php endif; <?php endif;
endforeach; endforeach;
?> ?>
</select> </select>
</p> </p>
<p><label for="col_gethome"><?php p($l -> t('Home Column')); ?></label><input type="text" id="col_gethome" name="col_gethome" value="<?php p($_['col_gethome']); ?>"></p> <p><label for="col_gethome"><?php p($l->t('Home Column')); ?></label><input type="text" id="col_gethome"
name="col_gethome"
value="<?php p($_['col_gethome']); ?>">
</p>
<p><label for="set_gethome"><?php p($l -> t('Home Dir')); ?></label><input type="text" id="set_gethome" name="set_gethome" value="<?php p($_['set_gethome']); ?>"><br> <p><label for="set_gethome"><?php p($l->t('Home Dir')); ?></label><input type="text" id="set_gethome"
<em><?php p($l -> 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')); ?></em></p> name="set_gethome"
value="<?php p($_['set_gethome']); ?>"><br>
<em><?php p($l->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')); ?></em>
</p>
</fieldset> </fieldset>
<fieldset id="sql-6"> <fieldset id="sql-6">
<p><label for="sql_group_table"><?php p($l -> t('Table')); ?></label><input type="text" id="sql_group_table" name="sql_group_table" value="<?php p($_['sql_group_table']); ?>" /></p> <p><label for="sql_group_table"><?php p($l->t('Table')); ?></label><input type="text"
id="sql_group_table"
name="sql_group_table"
value="<?php p($_['sql_group_table']); ?>"/>
</p>
<p><label for="col_group_username"><?php p($l -> t('Username Column')); ?></label><input type="text" id="col_group_username" name="col_group_username" value="<?php p($_['col_group_username']); ?>" /></p> <p><label for="col_group_username"><?php p($l->t('Username Column')); ?></label><input type="text"
id="col_group_username"
name="col_group_username"
value="<?php p($_['col_group_username']); ?>"/>
</p>
<p><label for="col_group_name"><?php p($l -> t('Group Name Column')); ?></label><input type="text" id="col_group_name" name="col_group_name" value="<?php p($_['col_group_name']); ?>" /></p> <p><label for="col_group_name"><?php p($l->t('Group Name Column')); ?></label><input type="text"
id="col_group_name"
name="col_group_name"
value="<?php p($_['col_group_name']); ?>"/>
</p>
</fieldset> </fieldset>
<input type="hidden" name="requesttoken" value="<?php p($_['requesttoken']); ?>" id="requesttoken" /> <input type="hidden" name="requesttoken" value="<?php p($_['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 p($l -> t('Save')); ?>" /> <input id="sqlSubmit" type="submit" value="<?php p($l->t('Save')); ?>"/>
<div id="sql_update_message" class="statusmessage"><?php p($l -> t('Saving...')); ?></div> <div id="sql_update_message" class="statusmessage"><?php p($l->t('Saving...')); ?></div>
<div id="sql_loading_message" class="statusmessage"><?php p($l -> t('Loading...')); ?></div> <div id="sql_loading_message" class="statusmessage"><?php p($l->t('Loading...')); ?></div>
<div id="sql_verify_message" class="statusmessage"><?php p($l -> t('Verifying...')); ?></div> <div id="sql_verify_message" class="statusmessage"><?php p($l->t('Verifying...')); ?></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>
</form> </form>
</div> </div>