diff options
author | ZUNbado <git@acs.li> | 2013-01-16 03:41:37 +0400 |
---|---|---|
committer | ZUNbado <git@acs.li> | 2013-01-16 03:41:37 +0400 |
commit | 419cb2c1d91227da34dcf05cbff6ca21cf42a569 (patch) | |
tree | c781e3c2d8846148461fee6718af46345bbe682a /user_vd | |
parent | 2f6976e6535ed9a6258e4f68f8d235a290f5d8dc (diff) |
new pluguin user_vd
Diffstat (limited to 'user_vd')
-rw-r--r-- | user_vd/README | 5 | ||||
-rw-r--r-- | user_vd/adminSettings.php | 29 | ||||
-rw-r--r-- | user_vd/appinfo/app.php | 16 | ||||
-rw-r--r-- | user_vd/appinfo/database.xml | 46 | ||||
-rw-r--r-- | user_vd/appinfo/info.xml | 12 | ||||
-rw-r--r-- | user_vd/appinfo/version | 1 | ||||
-rw-r--r-- | user_vd/js/adminSettings.js | 3 | ||||
-rw-r--r-- | user_vd/lib/domains.php | 31 | ||||
-rw-r--r-- | user_vd/lib/vd.php | 92 | ||||
-rw-r--r-- | user_vd/templates/adminSettings.php | 33 |
10 files changed, 268 insertions, 0 deletions
diff --git a/user_vd/README b/user_vd/README new file mode 100644 index 000000000..af94caeea --- /dev/null +++ b/user_vd/README @@ -0,0 +1,5 @@ +This functionality adds pluguin enable autocomplete as the domain user that was used to access ownCloud. + +For example, the domain test.com can be accessed from cloud.test.com own.test.com and, in that case, the user "user@test.com" can put only "user" and password and system will validate the domain from which you are accessing. + +To use this pluguin, you must first check the option "Force user_vd backend to create new users", then create a user and assign to the group "admin", and then you can check the "Disable other backends" and disable all other authentication backends. This will disable users created previously, it is not recommended for production installations. diff --git a/user_vd/adminSettings.php b/user_vd/adminSettings.php new file mode 100644 index 000000000..dc1576eeb --- /dev/null +++ b/user_vd/adminSettings.php @@ -0,0 +1,29 @@ +<?php +OCP\Util::addscript('user_vd', 'adminSettings'); +$paramsCheck = array( 'forceCreateUsers', 'disableBackends'); +if ($_POST) { + if(array_key_exists('domain',$_POST) && array_key_exists('fqdn',$_POST)){ + foreach($_POST['domain'] as $index => $domain){ + $fqdn=$_POST['fqdn'][$index]; + if($domain!='' OR $fqdn!=''){ + $domains[$domain]=$fqdn; + } + } + OC_USER_VD_DOMAIN::saveDomains($domains); + } + foreach($paramsCheck as $param){ + if(isset($_POST[$param])){ + OCP\Config::setAppValue('user_vd',$param,true); + }else{ + OCP\Config::setAppValue('user_vd',$param,false); + } + } +} + + +$tmpl = new OCP\Template('user_vd', 'adminSettings'); +$tmpl->assign('domains',OC_USER_VD_DOMAIN::getDomains(true)); +foreach($paramsCheck as $param){ + $tmpl->assign($param,OCP\Config::getAppValue('user_vd',$param)); +} +return $tmpl->fetchPage(); diff --git a/user_vd/appinfo/app.php b/user_vd/appinfo/app.php new file mode 100644 index 000000000..fc4801a85 --- /dev/null +++ b/user_vd/appinfo/app.php @@ -0,0 +1,16 @@ +<?php +OC::$CLASSPATH['OC_USER_VD'] = 'apps/user_vd/lib/vd.php'; +OC::$CLASSPATH['OC_USER_VD_DOMAIN'] = 'apps/user_vd/lib/domains.php'; + +OCP\App::registerAdmin('user_vd','adminSettings'); + +if(OCP\Config::getAppValue('user_vd','forceCreateUsers')){ + OCP\Util::connectHook('OC_User','pre_createUser','OC_USER_VD','deleteBackends'); +} + +if(OCP\Config::getAppValue('user_vd','disableBackends')){ + OC_User::clearBackends(); +} + +OC_User::useBackend('VD'); +?> diff --git a/user_vd/appinfo/database.xml b/user_vd/appinfo/database.xml new file mode 100644 index 000000000..8e202decb --- /dev/null +++ b/user_vd/appinfo/database.xml @@ -0,0 +1,46 @@ +<?xml version="1.0" encoding="ISO-8859-1" ?> +<database> + <name>*dbname*</name> + <create>true</create> + <overwrite>false</overwrite> + <charset>latin1</charset> + <table> + <name>*dbprefix*users_vd</name> + <declaration> + <field> + <name>uid</name> + <type>text</type> + <default></default> + <notnull>true</notnull> + <length>4096</length> + </field> + <field> + <name>password</name> + <type>text</type> + <default></default> + <notnull>true</notnull> + <length>4096</length> + </field> + </declaration> + </table> + <table> + <name>*dbprefix*users_vd_domains</name> + <declaration> + <field> + <name>domain</name> + <type>text</type> + <default></default> + <notnull>true</notnull> + <length>4096</length> + </field> + <field> + <name>fqdn</name> + <type>text</type> + <default></default> + <notnull>true</notnull> + <length>4096</length> + </field> + </declaration> + </table> +</database> + diff --git a/user_vd/appinfo/info.xml b/user_vd/appinfo/info.xml new file mode 100644 index 000000000..37c13d695 --- /dev/null +++ b/user_vd/appinfo/info.xml @@ -0,0 +1,12 @@ +<?xml version="1.0"?> +<info> + <id>user_vd</id> + <name>user_vd</name> + <description>User Virtual Domain Backend</description> + <licence>GPL</licence> + <author>ZUNbado</author> + <require>4.5</require> + <types> + <authentication/> + </types> +</info> diff --git a/user_vd/appinfo/version b/user_vd/appinfo/version new file mode 100644 index 000000000..be5863417 --- /dev/null +++ b/user_vd/appinfo/version @@ -0,0 +1 @@ +0.3 diff --git a/user_vd/js/adminSettings.js b/user_vd/js/adminSettings.js new file mode 100644 index 000000000..fc765897a --- /dev/null +++ b/user_vd/js/adminSettings.js @@ -0,0 +1,3 @@ +$(document).ready(function() { + $('#uservdSettings').tabs(); +}); diff --git a/user_vd/lib/domains.php b/user_vd/lib/domains.php new file mode 100644 index 000000000..862d8e0d3 --- /dev/null +++ b/user_vd/lib/domains.php @@ -0,0 +1,31 @@ +<?php + +class OC_USER_VD_DOMAIN{ + public static function getDomains(){ + $query=OC_DB::prepare('SELECT domain,GROUP_CONCAT(fqdn) as fqdn FROM *PREFIX*users_vd_domains GROUP BY domain'); + $result=$query->execute(); + $row=$result->fetchAll(); + if($row){ + return $row; + }else{ + return false; + } + } + + public static function saveDomains($dom){ + if(is_array($dom)){ + $query=OC_DB::prepare('DELETE FROM *PREFIX*users_vd_domains'); + $query->execute(); + }else{ + return false; + } + $query=OC_DB::prepare('INSERT INTO *PREFIX*users_vd_domains (domain,fqdn) VALUES (?,?)'); + foreach($dom as $domain => $fqdn){ + $fqdn=explode(',',$fqdn); + foreach($fqdn as $f){ + $result=$query->execute(array($domain,$f)); + } + } + } +} +?> diff --git a/user_vd/lib/vd.php b/user_vd/lib/vd.php new file mode 100644 index 000000000..dafc7f2ff --- /dev/null +++ b/user_vd/lib/vd.php @@ -0,0 +1,92 @@ +<?php + +class OC_USER_VD extends OC_User_Backend{ + public $domain; + public function __construct(){ + } + + public function createUser($uid,$password){ + $uid=$this->checkUid($uid); + if($this->userExists($uid)){ + return false; + }else{ + list($partName,$partDomain)=explode('@',$uid); + $query=OC_DB::prepare('INSERT INTO *PREFIX*users_vd (uid,password,partName,partDomain) VALUES (?,?,?,?)'); + $result=$query->execute(array($uid,$password,$partName,$partDomain)); + return $result ? true : false; + } + } + + public function userExists($uid){ + $uid=$this->checkUid($uid); + $query=OC_DB::prepare('SELECT * FROM *PREFIX*users_vd WHERE LOWER(uid) = LOWER(?)'); + $result=$query->execute(array($uid)); + return $result->numRows()>0; + } + + public function checkPassword($uid,$password){ + $uid=$this->checkUid($uid); + $query = OC_DB::prepare( 'SELECT `uid`, `password` FROM `*PREFIX*users_vd` WHERE LOWER(`uid`) = LOWER(?)' ); + $result = $query->execute( array( $uid)); + $row=$result->fetchRow(); + if($row){ + if($row['password']==$password){ + return $row['uid']; + }else{ + return false; + } + }else{ + return false; + } + } + + public function getHome($uid){ + $uid=$this->checkUid($uid); + if($this->userExists($uid)){ + list($user,$domain)=explode('@',$uid); + return OC_Config::getValue( "datadirectory", OC::$SERVERROOT."/data" ) . '/' . $domain . '/' . $user; + }else{ + return false; + } + } + + public function getUsers($search = '', $limit = null, $offset = null) { + $query = OC_DB::prepare('SELECT `uid` FROM `*PREFIX*users_vd` WHERE LOWER(`uid`) LIKE LOWER(?)',$limit,$offset); + $result = $query->execute(array($search.'%')); + $users = array(); + while ($row = $result->fetchRow()) { + $users[] = $row['uid']; + } + return $users; + } + + public function implementsActions($actions){ + return true; + } + + public function checkUid($uid){ + if(strpos($uid,'@')){ + $uide=explode('@',$uid); + $nuid=$uide[0]; + $fqdn=$uide[1]; + }else{ + $nuid=$uid; + $fqdn=$_SERVER['SERVER_NAME']; + } + + $query=OC_DB::prepare('SELECT domain FROM *PREFIX*users_vd_domains WHERE LOWER(domain)=LOWER(?) OR LOWER(fqdn)=LOWER(?)'); + $result=$query->execute(array($fqdn,$fqdn)); + $row=$result->fetchRow(); + if($row){ + return $nuid.'@'.$row['domain']; + }else{ + return $uid; + } + } + + public static function deleteBackends(){ + OC_User::clearBackends(); + OC_User::useBackend('VD'); + } +} +?> diff --git a/user_vd/templates/adminSettings.php b/user_vd/templates/adminSettings.php new file mode 100644 index 000000000..d828cdac4 --- /dev/null +++ b/user_vd/templates/adminSettings.php @@ -0,0 +1,33 @@ +<?php $count=0; ?> +<form id='user_vd_form' method="POST" action="#"> + <div id="uservdSettings" class="personalblock"> + <ul> + <li><a href="#uservdSettings-1">Domain relations</a></li> + <li><a href="#uservdSettings-2">Configuration</a></li> + </ul> + + <fieldset id="uservdSettings-1"> + <?php foreach ($_['domains'] as $domain): ?> + <p> + <input type="text" name="domain[<?=$count?>]" value="<?=$domain['domain']?>"> + <input type="text" name="fqdn[<?=$count?>]" value="<?=$domain['fqdn']?>"> + </p> + <?php $count++; endforeach; ?> + <p> + <input type="text" name="domain[<?=$count?>]" value=""> + <input type="text" name="fqdn[<?=$count?>]" value=""> + </p> + </fieldset> + <fieldset id="uservdSettings-2"> + <p> + Force user_vd backend to create new users? + <input type="checkbox" name="forceCreateUsers" id="forceCreateUsers" <?php if ($_['forceCreateUsers']) echo ' checked'; ?>> + </p> + <p> + Disable other backends? + <input type="checkbox" name="disableBackends" id="disableBackends" <?php if ($_['disableBackends']) echo ' checked'; ?>> + </p> + </fieldset> + <input type='submit' value='Save'> + </div> +</form> |