Merge branch 'master' into master
This commit is contained in:
@@ -75,20 +75,40 @@ if(isset($_POST['appname']) && ($_POST['appname'] === 'user_sql') && isset($_POS
|
|||||||
'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']))
|
||||||
|
{
|
||||||
|
$response->setData(array('status' => 'error',
|
||||||
|
'data' => array('message' => $l -> t('The selected SQL table '.$_POST['sql_group_table'].' does not exist!'))));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
// Retrieve all column settings
|
// Retrieve all column settings
|
||||||
$columns = array();
|
$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(isset($_POST[$param]) && $_POST[$param] !== '')
|
||||||
|
{
|
||||||
|
if(strpos($param, 'col_group_') === 0)
|
||||||
|
{
|
||||||
|
$group_columns[] = $_POST[$param];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
$columns[] = $_POST[$param];
|
$columns[] = $_POST[$param];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 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)
|
||||||
|
{
|
||||||
|
$status = $helper->verifyColumns($parameters, $_POST['sql_driver'], $_POST['sql_group_table'], $group_columns);
|
||||||
|
}
|
||||||
if($status !== true)
|
if($status !== true)
|
||||||
{
|
{
|
||||||
$response->setData(array('status' => 'error',
|
$response->setData(array('status' => 'error',
|
||||||
|
|||||||
@@ -22,10 +22,13 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
require_once __DIR__ . '/../user_sql.php';
|
require_once __DIR__ . '/../user_sql.php';
|
||||||
|
require_once __DIR__ . '/../group_sql.php';
|
||||||
\OCP\App::registerAdmin('user_sql','settings');
|
\OCP\App::registerAdmin('user_sql','settings');
|
||||||
|
|
||||||
$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;
|
||||||
|
|
||||||
|
|
||||||
// register user backend
|
// register user backend
|
||||||
\OC_User::useBackend($backend);
|
\OC_User::useBackend($backend);
|
||||||
|
\OC::$server->getGroupManager()->addBackend($group_backend);
|
||||||
|
|||||||
@@ -15,5 +15,6 @@
|
|||||||
<category>auth</category>
|
<category>auth</category>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<nextcloud min-version="12" max-version="12"/>
|
<nextcloud min-version="12" max-version="12"/>
|
||||||
|
<owncloud min-version="10" max-version="10"/>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</info>
|
</info>
|
||||||
|
|||||||
95
group_sql.php
Normal file
95
group_sql.php
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace OCA\user_sql;
|
||||||
|
|
||||||
|
use \OCA\user_sql\lib\Helper;
|
||||||
|
|
||||||
|
class OC_GROUP_SQL extends \OC_Group_Backend implements \OCP\GroupInterface
|
||||||
|
{
|
||||||
|
protected $settings;
|
||||||
|
protected $helper;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this -> helper = new \OCA\user_sql\lib\Helper();
|
||||||
|
$domain = \OC::$server->getRequest()->getServerHost();
|
||||||
|
$this -> settings = $this -> helper -> loadSettingsForDomain($domain);
|
||||||
|
$this -> helper -> connectToDb($this -> settings);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getUserGroups($uid) {
|
||||||
|
if(empty($this -> settings['sql_group_table']))
|
||||||
|
{
|
||||||
|
\OCP\Util::writeLog('OC_USER_SQL', "Group table not configured", \OCP\Util::DEBUG);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
$rows = $this -> helper -> runQuery('getUserGroups', array('uid' => $uid), false, true);
|
||||||
|
if($rows === false)
|
||||||
|
{
|
||||||
|
\OCP\Util::writeLog('OC_USER_SQL', "Found no group", \OCP\Util::DEBUG);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
$groups = array();
|
||||||
|
foreach($rows as $row)
|
||||||
|
{
|
||||||
|
$groups[] = $row[$this -> settings['col_group_name']];
|
||||||
|
}
|
||||||
|
return $groups;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getGroups($search = '', $limit = null, $offset = null) {
|
||||||
|
if(empty($this -> settings['sql_group_table']))
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
$search = "%".$search."%";
|
||||||
|
$rows = $this -> helper -> runQuery('getGroups', array('search' => $search), false, true, array('limit' => $limit, 'offset' => $offset));
|
||||||
|
if($rows === false)
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
$groups = array();
|
||||||
|
foreach($rows as $row)
|
||||||
|
{
|
||||||
|
$groups[] = $row[$this -> settings['col_group_name']];
|
||||||
|
}
|
||||||
|
return $groups;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function usersInGroup($gid, $search = '', $limit = null, $offset = null) {
|
||||||
|
if(empty($this -> settings['sql_group_table']))
|
||||||
|
{
|
||||||
|
\OCP\Util::writeLog('OC_USER_SQL', "Group table not configured", \OCP\Util::DEBUG);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
$rows = $this -> helper -> runQuery('getGroupUsers', array('gid' => $gid), false, true);
|
||||||
|
if($rows === false)
|
||||||
|
{
|
||||||
|
\OCP\Util::writeLog('OC_USER_SQL', "Found no users for group", \OCP\Util::DEBUG);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
$users = array();
|
||||||
|
foreach($rows as $row)
|
||||||
|
{
|
||||||
|
$users[] = $row[$this -> settings['col_group_username']];
|
||||||
|
}
|
||||||
|
return $users;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function countUsersInGroup($gid, $search = '') {
|
||||||
|
if(empty($this -> settings['sql_group_table']))
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
$search = "%".$search."%";
|
||||||
|
$count = $this -> helper -> runQuery('countUsersInGroup', array('gid' => $gid, 'search' => $search));
|
||||||
|
if($count === false)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
return intval(reset($count));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
@@ -17,7 +17,7 @@ user_sql.adminSettingsUI = function()
|
|||||||
$('#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, #col_group_name, #col_group_username').autocomplete({
|
||||||
source: function(request, response)
|
source: function(request, response)
|
||||||
{
|
{
|
||||||
var post = $('#sqlForm').serializeArray();
|
var post = $('#sqlForm').serializeArray();
|
||||||
@@ -56,7 +56,7 @@ user_sql.adminSettingsUI = function()
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Attach auto-completion to all table fields
|
// Attach auto-completion to all table fields
|
||||||
$('#sql_table').autocomplete({
|
$('#sql_table, #sql_group_table').autocomplete({
|
||||||
source: function(request, response)
|
source: function(request, response)
|
||||||
{
|
{
|
||||||
var post = $('#sqlForm').serializeArray();
|
var post = $('#sqlForm').serializeArray();
|
||||||
|
|||||||
@@ -66,7 +66,10 @@ class Helper {
|
|||||||
'set_mail_sync_mode',
|
'set_mail_sync_mode',
|
||||||
'set_enable_gethome',
|
'set_enable_gethome',
|
||||||
'set_gethome_mode',
|
'set_gethome_mode',
|
||||||
'set_gethome'
|
'set_gethome',
|
||||||
|
'sql_group_table',
|
||||||
|
'col_group_username',
|
||||||
|
'col_group_name'
|
||||||
);
|
);
|
||||||
|
|
||||||
return $params;
|
return $params;
|
||||||
@@ -175,6 +178,22 @@ class Helper {
|
|||||||
case 'mysqlPassword':
|
case 'mysqlPassword':
|
||||||
$query = "SELECT PASSWORD(:pw);";
|
$query = "SELECT PASSWORD(:pw);";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'getUserGroups':
|
||||||
|
$query = "SELECT ".$this->settings['col_group_name']." FROM ".$this->settings['sql_group_table']." WHERE ".$this->settings['col_group_username']." = :uid";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'getGroups':
|
||||||
|
$query = "SELECT distinct ".$this->settings['col_group_name']." FROM ".$this->settings['sql_group_table']." WHERE ".$this->settings['col_group_name']." LIKE :search";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'getGroupUsers':
|
||||||
|
$query = "SELECT distinct ".$this->settings['col_group_username']." FROM ".$this->settings['sql_group_table']." WHERE ".$this->settings['col_group_name']." = :gid";
|
||||||
|
break;
|
||||||
|
|
||||||
|
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";
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isset($limits['limit']) && $limits['limit'] !== null)
|
if(isset($limits['limit']) && $limits['limit'] !== null)
|
||||||
@@ -267,7 +286,7 @@ class Helper {
|
|||||||
if(!in_array($col, $columns, true))
|
if(!in_array($col, $columns, true))
|
||||||
{
|
{
|
||||||
$res = false;
|
$res = false;
|
||||||
$err .= $col.' ';
|
$err .= $table.'.'.$col.' ';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if($res)
|
if($res)
|
||||||
@@ -301,14 +320,20 @@ class Helper {
|
|||||||
try {
|
try {
|
||||||
$conn = $cm -> getConnection($sql_driver, $parameters);
|
$conn = $cm -> getConnection($sql_driver, $parameters);
|
||||||
$platform = $conn -> getDatabasePlatform();
|
$platform = $conn -> getDatabasePlatform();
|
||||||
$query = $platform -> getListTablesSQL();
|
|
||||||
$result = $conn -> executeQuery($query);
|
$queries = array(
|
||||||
|
'Tables_in_'.$parameters['dbname'] => $platform -> getListTablesSQL(),
|
||||||
|
'TABLE_NAME' => $platform -> getListViewsSQL($parameters['dbname']));
|
||||||
$ret = array();
|
$ret = array();
|
||||||
|
foreach($queries as $field => $query)
|
||||||
|
{
|
||||||
|
$result = $conn -> executeQuery($query);
|
||||||
while($row = $result -> fetch())
|
while($row = $result -> fetch())
|
||||||
{
|
{
|
||||||
$name = $row['Tables_in_'.$parameters['dbname']];
|
$name = $row[$field];
|
||||||
$ret[] = $name;
|
$ret[] = $name;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
catch(\Exception $e)
|
catch(\Exception $e)
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ $cfgClass = $ocVersion >= 7 ? 'section' : 'personalblock';
|
|||||||
<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="sqlSupervisorSettings" href="#sql-6"><?php p($l -> t('Supervisor Settings')); ?></a></li>
|
<li><a id="sqlSupervisorSettings" href="#sql-6"><?php p($l -> t('Supervisor Settings')); ?></a></li>
|
||||||
|
<li><a id="sqlGroupsSettings" href="#sql-7"><?php p($l -> t('Groups Settings')); ?></a></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<fieldset id="sql-1">
|
<fieldset id="sql-1">
|
||||||
@@ -165,6 +166,16 @@ $cfgClass = $ocVersion >= 7 ? 'section' : 'personalblock';
|
|||||||
<p><label for="supervisor"><?php p($l -> t('Supervisor username')); ?></label><input type="text" id="supervisor" name="supervisor" value="<?php p($_['supervisor']); ?>" /></p>
|
<p><label for="supervisor"><?php p($l -> t('Supervisor username')); ?></label><input type="text" id="supervisor" name="supervisor" value="<?php p($_['supervisor']); ?>" /></p>
|
||||||
<em><?php p($l -> t("Use supervisor username and target username separated by ';' to login as target user using supervisor's password (ex. superuser;user).")); ?></em></p>
|
<em><?php p($l -> t("Use supervisor username and target username separated by ';' to login as target user using supervisor's password (ex. superuser;user).")); ?></em></p>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
||||||
|
<fieldset id="sql-7">
|
||||||
|
<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_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>
|
||||||
|
|
||||||
<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')); ?>" />
|
||||||
|
|||||||
17
user_sql.php
17
user_sql.php
@@ -31,7 +31,13 @@ namespace OCA\user_sql;
|
|||||||
|
|
||||||
use \OCA\user_sql\lib\Helper;
|
use \OCA\user_sql\lib\Helper;
|
||||||
|
|
||||||
class OC_USER_SQL extends \OC_User_Backend implements \OCP\IUserBackend, \OCP\UserInterface
|
if(!interface_exists('OCP\\User\\IProvidesEMailBackend'))
|
||||||
|
{
|
||||||
|
// hack for nextcloud
|
||||||
|
eval("namespace OCP\User; interface IProvidesEMailBackend {}");
|
||||||
|
}
|
||||||
|
|
||||||
|
class OC_USER_SQL extends \OC_User_Backend implements \OCP\IUserBackend, \OCP\UserInterface, \OCP\User\IProvidesEMailBackend
|
||||||
{
|
{
|
||||||
protected $cache;
|
protected $cache;
|
||||||
protected $settings;
|
protected $settings;
|
||||||
@@ -116,6 +122,15 @@ class OC_USER_SQL extends \OC_User_Backend implements \OCP\IUserBackend, \OCP\Us
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Only used by OwnCloud to get the email address
|
||||||
|
*/
|
||||||
|
public function getEMailAddress($uid) {
|
||||||
|
$this->doEmailSync($uid);
|
||||||
|
$email = $this->ocConfig->getUserValue($uid, 'settings', 'email', '');
|
||||||
|
return $email;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This maps the username to the specified domain name.
|
* This maps the username to the specified domain name.
|
||||||
* It can only append a default domain name.
|
* It can only append a default domain name.
|
||||||
|
|||||||
Reference in New Issue
Block a user