Skip to content

Update phpopenldaper #213

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Apr 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/functional.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: true
- name: setup PHP
uses: shivammathur/setup-php@v2
with:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: true
- name: setup PHP
uses: shivammathur/setup-php@v2
with:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: true
- uses: actions/setup-python@v3
- name: setup PHP
uses: shivammathur/setup-php@v2
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "hakasapl/phpopenldaper"]
path = resources/lib/phpopenldaper
url = https://github.com/hakasapl/phpopenldaper.git
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ Unity Web Portal is a PHP application built in top of MariaDB and LDAP which act
6. `php-pdo`
2. Composer packages
1. `cd` to this repository
2. Install packages `composer update`
1. Setup git submodules `git submodule update --init --checkout`
1. Install packages `composer update`
3. Setup config file `config/config.ini` according to your site deployment
4. Setup branding file `config/branding/config.ini` according to your site deployment
5. Point your web server's document root to `webroot` in this repo
Expand Down
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
"require": {
"psr/log": "1.1.4",
"phpseclib/phpseclib": "3.0.43",
"phpmailer/phpmailer": "6.6.4",
"hakasapl/phpopenldaper": "1.0.6"
"phpmailer/phpmailer": "6.6.4"
},
"require-dev": {
"phpunit/phpunit": "<12.1"
Expand Down
4 changes: 4 additions & 0 deletions resources/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
// Load Composer Libs
require_once __DIR__ . "/../vendor/autoload.php";

// submodule
require_once __DIR__ . "/lib/phpopenldaper/src/PHPOpenLDAPer/LDAPEntry.php";
require_once __DIR__ . "/lib/phpopenldaper/src/PHPOpenLDAPer/LDAPConn.php";

// load libs
require_once __DIR__ . "/lib/UnityLDAP.php";
require_once __DIR__ . "/lib/UnityUser.php";
Expand Down
21 changes: 4 additions & 17 deletions resources/lib/UnityGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,7 @@ public function denyGroup($operator = null, $send_mail = true)
// // now we delete the ldap entry
// $ldapPiGroupEntry = $this->getLDAPPiGroup();
// if ($ldapPiGroupEntry->exists()) {
// if (!$ldapPiGroupEntry->delete()) {
// throw new Exception("Unable to delete PI ldap group");
// }
// ldapPiGroupEntry->delete();

// $this->REDIS->removeCacheArray("sorted_groups", "", $this->getPIUID());
// foreach ($users as $user) {
Expand Down Expand Up @@ -487,10 +485,7 @@ private function init()
$ldapPiGroupEntry->setAttribute("objectclass", UnityLDAP::POSIX_GROUP_CLASS);
$ldapPiGroupEntry->setAttribute("gidnumber", strval($nextGID));
$ldapPiGroupEntry->setAttribute("memberuid", array($owner->getUID()));

if (!$ldapPiGroupEntry->write()) {
throw new Exception("Failed to create POSIX group for " . $owner->getUID()); // this shouldn't execute
}
$ldapPiGroupEntry->write();
}

$this->REDIS->appendCacheArray("sorted_groups", "", $this->getPIUID());
Expand All @@ -503,11 +498,7 @@ private function addUserToGroup($new_user)
// Add to LDAP Group
$pi_group = $this->getLDAPPiGroup();
$pi_group->appendAttribute("memberuid", $new_user->getUID());

if (!$pi_group->write()) {
throw new Exception("Unable to write PI group");
}

$pi_group->write();
$this->REDIS->appendCacheArray($this->getPIUID(), "members", $new_user->getUID());
$this->REDIS->appendCacheArray($new_user->getUID(), "groups", $this->getPIUID());
}
Expand All @@ -517,11 +508,7 @@ private function removeUserFromGroup($old_user)
// Remove from LDAP Group
$pi_group = $this->getLDAPPiGroup();
$pi_group->removeAttributeEntryByValue("memberuid", $old_user->getUID());

if (!$pi_group->write()) {
throw new Exception("Unable to write PI group");
}

$pi_group->write();
$this->REDIS->removeCacheArray($this->getPIUID(), "members", $old_user->getUID());
$this->REDIS->removeCacheArray($old_user->getUID(), "groups", $this->getPIUID());
}
Expand Down
17 changes: 3 additions & 14 deletions resources/lib/UnityOrg.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ public function init()

$org_group->setAttribute("objectclass", UnityLDAP::POSIX_GROUP_CLASS);
$org_group->setAttribute("gidnumber", strval($nextGID));

if (!$org_group->write()) {
throw new Exception("Failed to create POSIX group for " . $this->orgid); // this shouldn't execute
}
$org_group->write();
}

$this->REDIS->appendCacheArray("sorted_orgs", "", $this->getOrgID());
Expand Down Expand Up @@ -101,23 +98,15 @@ public function addUser($user)
{
$org_group = $this->getLDAPOrgGroup();
$org_group->appendAttribute("memberuid", $user->getUID());

if (!$org_group->write()) {
throw new Exception("Unable to write to org group");
}

$org_group->write();
$this->REDIS->appendCacheArray($this->getOrgID(), "members", $user->getUID());
}

public function removeUser($user)
{
$org_group = $this->getLDAPOrgGroup();
$org_group->removeAttributeEntryByValue("memberuid", $user->getUID());

if (!$org_group->write()) {
throw new Exception("Unable to write to org group");
}

$org_group->write();
$this->REDIS->removeCacheArray($this->getOrgID(), "members", $user->getUID());
}
}
45 changes: 9 additions & 36 deletions resources/lib/UnityUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,7 @@ public function init($send_mail = true)
if (!$ldapGroupEntry->exists()) {
$ldapGroupEntry->setAttribute("objectclass", UnityLDAP::POSIX_GROUP_CLASS);
$ldapGroupEntry->setAttribute("gidnumber", strval($id));

if (!$ldapGroupEntry->write()) {
throw new Exception("Failed to create POSIX group for $this->uid");
}
$ldapGroupEntry->write();
}

//
Expand All @@ -80,11 +77,7 @@ public function init($send_mail = true)
$ldapUserEntry->setAttribute("loginshell", $this->LDAP->getDefUserShell());
$ldapUserEntry->setAttribute("uidnumber", strval($id));
$ldapUserEntry->setAttribute("gidnumber", strval($id));

if (!$ldapUserEntry->write()) {
$ldapGroupEntry->delete(); // Cleanup previous group
throw new Exception("Failed to create POSIX user for $this->uid");
}
$ldapUserEntry->write();
}

// update cache
Expand Down Expand Up @@ -177,11 +170,7 @@ public function setOrg($org)
{
$ldap_user = $this->getLDAPUser();
$ldap_user->setAttribute("o", $org);

if (!$ldap_user->write()) {
throw new Exception("Error updating LDAP entry $this->uid");
}

$ldap_user->write();
$this->REDIS->setCache($this->uid, "org", $org);
}

Expand Down Expand Up @@ -225,10 +214,7 @@ public function setFirstname($firstname, $operator = null)
$this->getUID()
);

if (!$ldap_user->write()) {
throw new Exception("Error updating LDAP entry $this->uid");
}

$ldap_user->write();
$this->REDIS->setCache($this->uid, "firstname", $firstname);
}

Expand Down Expand Up @@ -277,10 +263,7 @@ public function setLastname($lastname, $operator = null)
$this->getUID()
);

if (!$this->getLDAPUser()->write()) {
throw new Exception("Error updating LDAP entry $this->uid");
}

$this->getLDAPUser()->write();
$this->REDIS->setCache($this->uid, "lastname", $lastname);
}

Expand Down Expand Up @@ -334,10 +317,7 @@ public function setMail($email, $operator = null)
$this->getUID()
);

if (!$this->getLDAPUser()->write()) {
throw new Exception("Error updating LDAP entry $this->uid");
}

$this->getLDAPUser()->write();
$this->REDIS->setCache($this->uid, "mail", $email);
}

Expand Down Expand Up @@ -380,9 +360,7 @@ public function setSSHKeys($keys, $operator = null, $send_mail = true)
$keys_filt = array_values(array_unique($keys));
if ($ldapUser->exists()) {
$ldapUser->setAttribute("sshpublickey", $keys_filt);
if (!$ldapUser->write()) {
throw new Exception("Failed to modify SSH keys for $this->uid");
}
$ldapUser->write();
}

$this->REDIS->setCache($this->uid, "sshkeys", $keys_filt);
Expand Down Expand Up @@ -459,9 +437,7 @@ public function setLoginShell($shell, $operator = null, $send_mail = true)
$ldapUser = $this->getLDAPUser();
if ($ldapUser->exists()) {
$ldapUser->setAttribute("loginshell", $shell);
if (!$ldapUser->write()) {
throw new Exception("Failed to modify login shell for $this->uid");
}
$ldapUser->write();
}

$operator = is_null($operator) ? $this->getUID() : $operator->getUID();
Expand Down Expand Up @@ -518,10 +494,7 @@ public function setHomeDir($home, $operator = null)
$ldapUser = $this->getLDAPUser();
if ($ldapUser->exists()) {
$ldapUser->setAttribute("homedirectory", $home);
if (!$ldapUser->write()) {
throw new Exception("Failed to modify home directory for $this->uid");
}

$ldapUser->write();
$operator = is_null($operator) ? $this->getUID() : $operator->getUID();

$this->SQL->addLog(
Expand Down
1 change: 1 addition & 0 deletions resources/lib/phpopenldaper
Submodule phpopenldaper added at e3a778
4 changes: 4 additions & 0 deletions test/phpunit-bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

require_once __DIR__ . "/../vendor/autoload.php";

// submodule
require_once __DIR__ . "/../resources/lib/phpopenldaper/src/PHPOpenLDAPer/LDAPEntry.php";
require_once __DIR__ . "/../resources/lib/phpopenldaper/src/PHPOpenLDAPer/LDAPConn.php";

require_once __DIR__ . "/../resources/lib/UnityLDAP.php";
require_once __DIR__ . "/../resources/lib/UnityUser.php";
require_once __DIR__ . "/../resources/lib/UnityGroup.php";
Expand Down
1 change: 0 additions & 1 deletion tools/docker-dev/unity-web-portal
Submodule unity-web-portal deleted from 7087b7
Loading