예제 #1
0
 /**
  * Retreive all users that belong to the given group.
  * 
  * @param int $id
  * @return array Users
  */
 protected function actionGetUsers($params)
 {
     //don't check ACL here because this method may be called by anyone.
     $group = \GO\Base\Model\Group::model()->findByPk($params['id'], false, true);
     if (empty($group)) {
         $group = new \GO\Base\Model\Group();
     }
     if (isset($params['add_users']) && !empty($group->id)) {
         $users = json_decode($params['add_users']);
         foreach ($users as $usr_id) {
             if ($group->addUser($usr_id)) {
                 \GO\Base\Model\User::model()->findByPk($usr_id)->checkDefaultModels();
             }
         }
     }
     $store = \GO\Base\Data\Store::newInstance(\GO\Base\Model\User::model());
     $store->getColumnModel()->formatColumn('name', '$model->name', array(), array('first_name', 'last_name'));
     $storeParams = $store->getDefaultParams($params)->joinCustomFields(false);
     $delresponse = array();
     //manually check permission here because this method may be accessed by any logged in user. allowWithoutModuleAccess is used above.
     if ($group->checkPermissionLevel(\GO\Base\Model\Acl::DELETE_PERMISSION)) {
         // The users in the group "everyone" cannot be deleted
         if ($group->id != \GO::config()->group_everyone) {
             $store->processDeleteActions($params, 'GO\\Base\\Model\\UserGroup', array('group_id' => $group->id));
         } else {
             $delresponse['deleteSuccess'] = false;
             $delresponse['deleteFeedback'] = 'Members of the group everyone cannot be deleted.';
         }
     }
     $stmt = $group->users($storeParams);
     $store->setStatement($stmt);
     $response = $store->getData();
     $response = array_merge($response, $delresponse);
     return $response;
 }
예제 #2
0
 public function actionManyGroups($params)
 {
     if (!\GO::user()->isAdmin()) {
         throw new \Exception("You must be logged in as admin");
     }
     for ($i = 1; $i <= 600; $i++) {
         $group = new \GO\Base\Model\Group();
         $group->name = 'group' . $i;
         $group->save();
     }
 }
예제 #3
0
 } else {
     echo "Database connection established. Database is empty\n";
 }
 \GO\Base\Util\SQL::executeSqlFile('install.sql');
 $dbVersion = \GO\Base\Util\Common::countUpgradeQueries("updates.php");
 \GO::config()->save_setting('version', $dbVersion);
 \GO::config()->save_setting('upgrade_mtime', \GO::config()->mtime);
 $adminGroup = new \GO\Base\Model\Group();
 $adminGroup->id = 1;
 $adminGroup->name = \GO::t('group_admins');
 $adminGroup->save();
 $everyoneGroup = new \GO\Base\Model\Group();
 $everyoneGroup->id = 2;
 $everyoneGroup->name = \GO::t('group_everyone');
 $everyoneGroup->save();
 $internalGroup = new \GO\Base\Model\Group();
 $internalGroup->id = 3;
 $internalGroup->name = \GO::t('group_internal');
 $internalGroup->save();
 //\GO::config()->register_user_groups = \GO::t('group_internal');
 //\GO::config()->register_visible_user_groups = \GO::t('group_internal');
 $modules = \GO::modules()->getAvailableModules();
 if (isset($args['modules'])) {
     $installModules = explode(',', $args['modules']);
 } elseif (!empty(\GO::config()->allowed_modules)) {
     $installModules = explode(',', \GO::config()->allowed_modules);
 }
 if (isset($installModules)) {
     $installModules[] = "modules";
     $installModules[] = "users";
     $installModules[] = "groups";
예제 #4
0
 /**
  * 
  * php groupofficecli.php -r=ldapauth/sync/groups --delete=1 --max_delete_percentage=34 --dry=1
  * 
  * @param type $params
  * @throws Exception
  */
 protected function actionGroups($params)
 {
     $this->requireCli();
     \GO::session()->runAsRoot();
     $dryRun = !empty($params['dry']);
     if ($dryRun) {
         echo "Dry run enabled.\n\n";
     }
     $ldapConn = \GO\Base\Ldap\Connection::getDefault();
     if (empty(\GO::config()->ldap_groupsdn)) {
         throw new \Exception('$config[\'ldap_groupsdn\'] is not set!');
     }
     $result = $ldapConn->search(\GO::config()->ldap_groupsdn, 'cn=*');
     //		$record = $result->fetch();
     //		$attr = $record->getAttributes();
     //		var_dump($attr);
     //		exit();
     //
     //keep an array of groups that exist in ldap. This array will be used later for deletes.
     //admin group is not in ldap but should not be removed.
     $groupsInLDAP = array(\GO::config()->group_root, \GO::config()->group_everyone, \GO::config()->group_internal);
     $i = 0;
     while ($record = $result->fetch()) {
         $i++;
         try {
             $groupname = $record->cn[0];
             if (empty($groupname)) {
                 throw new \Exception("Empty group name in LDAP record!");
             }
             $group = \GO\Base\Model\Group::model()->findByName($groupname);
             if (!$group) {
                 echo "Creating group '" . $groupname . "'\n";
                 $group = new \GO\Base\Model\Group();
                 $group->name = $groupname;
                 if (!$dryRun && !$group->save()) {
                     echo "Error saving group: " . implode("\n", $group->getValidationErrors());
                 }
             } else {
                 echo "Group '" . $groupname . "' exists\n";
             }
             $usersInGroup = array();
             foreach ($record->memberuid as $username) {
                 $user = \GO\Base\Model\User::model()->findSingleByAttribute('username', $username);
                 if (!$user) {
                     echo "Error: user '" . $username . "' does not exist in Group-Office\n";
                 } else {
                     echo "Adding user '{$username}'\n";
                     if (!$dryRun) {
                         $group->addUser($user->id);
                     }
                     $usersInGroup[] = $user->id;
                 }
             }
             echo "Removing users from group\n";
             $findParams = \GO\Base\Db\FindParams::newInstance();
             $findParams->getCriteria()->addInCondition('user_id', $usersInGroup, 'link_t', true, true);
             $usersToRemove = $group->users($findParams);
             foreach ($usersToRemove as $user) {
                 echo "Removing user '" . $user->username . "'\n";
                 if (!$dryRun) {
                     $group->removeUser($user->id);
                 }
             }
             if (!$dryRun) {
                 $this->fireEvent("ldapsyncgroup", array($group, $record));
             }
             echo "Synced " . $groupname . "\n";
         } catch (\Exception $e) {
             echo "ERROR:\n";
             echo (string) $e;
             echo "LDAP record:";
             var_dump($record->getAttributes());
         }
         if ($group) {
             $groupsInLDAP[] = $group->id;
         }
         //			if($i==100)
         //				exit("Reached 100. Exitting");
     }
     $stmt = \GO\Base\Model\Group::model()->find();
     $totalInGO = $stmt->rowCount();
     $totalInLDAP = count($groupsInLDAP);
     echo "Groups in Group-Office: " . $totalInGO . "\n";
     echo "Groups in LDAP: " . $totalInLDAP . "\n";
     if (!empty($params['delete'])) {
         $percentageToDelete = round((1 - $totalInLDAP / $totalInGO) * 100);
         $maxDeletePercentage = isset($params['max_delete_percentage']) ? intval($params['max_delete_percentage']) : 5;
         if ($percentageToDelete > $maxDeletePercentage) {
             die("Delete Aborted because script was about to delete more then {$maxDeletePercentage}% of the groups (" . $percentageToDelete . "%, " . ($totalInGO - $totalInLDAP) . " groups)\n");
         }
         while ($group = $stmt->fetch()) {
             if (!in_array($group->id, $groupsInLDAP)) {
                 echo "Deleting " . $group->name . "\n";
                 if (!$dryRun) {
                     $group->delete();
                 }
             }
         }
     }
     echo "Done\n\n";
     //var_dump($attr);
 }
예제 #5
0
파일: install.php 프로젝트: ajaboa/crmpuan
 $dbVersion = \GO\Base\Util\Common::countUpgradeQueries("updates.php");
 \GO::config()->save_setting('version', $dbVersion);
 \GO::config()->save_setting('upgrade_mtime', \GO::config()->mtime);
 $adminGroup = new \GO\Base\Model\Group();
 $adminGroup->id = 1;
 $adminGroup->name = \GO::t('group_admins');
 if (!$adminGroup->save()) {
     throw new \Exception("Could not save admin group");
 }
 $everyoneGroup = new \GO\Base\Model\Group();
 $everyoneGroup->id = 2;
 $everyoneGroup->name = \GO::t('group_everyone');
 if (!$everyoneGroup->save()) {
     throw new \Exception("Could not save everyone group");
 }
 $internalGroup = new \GO\Base\Model\Group();
 $internalGroup->id = 3;
 $internalGroup->name = \GO::t('group_internal');
 if (!$internalGroup->save()) {
     throw new \Exception("Could not save internal group");
 }
 \GO::config()->register_user_groups = \GO::t('group_internal');
 \GO::config()->register_visible_user_groups = \GO::t('group_internal');
 $modules = \GO::modules()->getAvailableModules();
 foreach ($modules as $moduleClass) {
     $moduleController = new $moduleClass();
     if ($moduleController->autoInstall() && $moduleController->isInstallable()) {
         $module = new \GO\Base\Model\Module();
         $module->id = $moduleController->id();
         if (!$module->save()) {
             throw new \Exception("Could not save module " . $module->id);