Skip to content

Commit 2e93b8f

Browse files
authored
Update phpopenldaper (#213)
* remove junk submodule * remove checks on write success * remove check on delete success * add submodule * remove composer dependency * update install instructions * update path to phpopenldaper * make sure github actions does recursive checkout
1 parent 513d875 commit 2e93b8f

File tree

13 files changed

+37
-71
lines changed

13 files changed

+37
-71
lines changed

.github/workflows/functional.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ jobs:
1010
runs-on: ubuntu-latest
1111
steps:
1212
- uses: actions/checkout@v3
13+
with:
14+
submodules: true
1315
- name: setup PHP
1416
uses: shivammathur/setup-php@v2
1517
with:

.github/workflows/phpunit.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ jobs:
77
runs-on: ubuntu-latest
88
steps:
99
- uses: actions/checkout@v3
10+
with:
11+
submodules: true
1012
- name: setup PHP
1113
uses: shivammathur/setup-php@v2
1214
with:

.github/workflows/pre-commit.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ jobs:
1010
runs-on: ubuntu-latest
1111
steps:
1212
- uses: actions/checkout@v3
13+
with:
14+
submodules: true
1315
- uses: actions/setup-python@v3
1416
- name: setup PHP
1517
uses: shivammathur/setup-php@v2

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "hakasapl/phpopenldaper"]
2+
path = resources/lib/phpopenldaper
3+
url = https://github.com/hakasapl/phpopenldaper.git

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ Unity Web Portal is a PHP application built in top of MariaDB and LDAP which act
2929
6. `php-pdo`
3030
2. Composer packages
3131
1. `cd` to this repository
32-
2. Install packages `composer update`
32+
1. Setup git submodules `git submodule update --init --checkout`
33+
1. Install packages `composer update`
3334
3. Setup config file `config/config.ini` according to your site deployment
3435
4. Setup branding file `config/branding/config.ini` according to your site deployment
3536
5. Point your web server's document root to `webroot` in this repo

composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
"require": {
33
"psr/log": "1.1.4",
44
"phpseclib/phpseclib": "3.0.43",
5-
"phpmailer/phpmailer": "6.6.4",
6-
"hakasapl/phpopenldaper": "1.0.6"
5+
"phpmailer/phpmailer": "6.6.4"
76
},
87
"require-dev": {
98
"phpunit/phpunit": "<12.1"

resources/autoload.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
// Load Composer Libs
88
require_once __DIR__ . "/../vendor/autoload.php";
99

10+
// submodule
11+
require_once __DIR__ . "/lib/phpopenldaper/src/PHPOpenLDAPer/LDAPEntry.php";
12+
require_once __DIR__ . "/lib/phpopenldaper/src/PHPOpenLDAPer/LDAPConn.php";
13+
1014
// load libs
1115
require_once __DIR__ . "/lib/UnityLDAP.php";
1216
require_once __DIR__ . "/lib/UnityUser.php";

resources/lib/UnityGroup.php

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,7 @@ public function denyGroup($operator = null, $send_mail = true)
218218
// // now we delete the ldap entry
219219
// $ldapPiGroupEntry = $this->getLDAPPiGroup();
220220
// if ($ldapPiGroupEntry->exists()) {
221-
// if (!$ldapPiGroupEntry->delete()) {
222-
// throw new Exception("Unable to delete PI ldap group");
223-
// }
221+
// ldapPiGroupEntry->delete();
224222

225223
// $this->REDIS->removeCacheArray("sorted_groups", "", $this->getPIUID());
226224
// foreach ($users as $user) {
@@ -487,10 +485,7 @@ private function init()
487485
$ldapPiGroupEntry->setAttribute("objectclass", UnityLDAP::POSIX_GROUP_CLASS);
488486
$ldapPiGroupEntry->setAttribute("gidnumber", strval($nextGID));
489487
$ldapPiGroupEntry->setAttribute("memberuid", array($owner->getUID()));
490-
491-
if (!$ldapPiGroupEntry->write()) {
492-
throw new Exception("Failed to create POSIX group for " . $owner->getUID()); // this shouldn't execute
493-
}
488+
$ldapPiGroupEntry->write();
494489
}
495490

496491
$this->REDIS->appendCacheArray("sorted_groups", "", $this->getPIUID());
@@ -503,11 +498,7 @@ private function addUserToGroup($new_user)
503498
// Add to LDAP Group
504499
$pi_group = $this->getLDAPPiGroup();
505500
$pi_group->appendAttribute("memberuid", $new_user->getUID());
506-
507-
if (!$pi_group->write()) {
508-
throw new Exception("Unable to write PI group");
509-
}
510-
501+
$pi_group->write();
511502
$this->REDIS->appendCacheArray($this->getPIUID(), "members", $new_user->getUID());
512503
$this->REDIS->appendCacheArray($new_user->getUID(), "groups", $this->getPIUID());
513504
}
@@ -517,11 +508,7 @@ private function removeUserFromGroup($old_user)
517508
// Remove from LDAP Group
518509
$pi_group = $this->getLDAPPiGroup();
519510
$pi_group->removeAttributeEntryByValue("memberuid", $old_user->getUID());
520-
521-
if (!$pi_group->write()) {
522-
throw new Exception("Unable to write PI group");
523-
}
524-
511+
$pi_group->write();
525512
$this->REDIS->removeCacheArray($this->getPIUID(), "members", $old_user->getUID());
526513
$this->REDIS->removeCacheArray($old_user->getUID(), "groups", $this->getPIUID());
527514
}

resources/lib/UnityOrg.php

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,7 @@ public function init()
3434

3535
$org_group->setAttribute("objectclass", UnityLDAP::POSIX_GROUP_CLASS);
3636
$org_group->setAttribute("gidnumber", strval($nextGID));
37-
38-
if (!$org_group->write()) {
39-
throw new Exception("Failed to create POSIX group for " . $this->orgid); // this shouldn't execute
40-
}
37+
$org_group->write();
4138
}
4239

4340
$this->REDIS->appendCacheArray("sorted_orgs", "", $this->getOrgID());
@@ -101,23 +98,15 @@ public function addUser($user)
10198
{
10299
$org_group = $this->getLDAPOrgGroup();
103100
$org_group->appendAttribute("memberuid", $user->getUID());
104-
105-
if (!$org_group->write()) {
106-
throw new Exception("Unable to write to org group");
107-
}
108-
101+
$org_group->write();
109102
$this->REDIS->appendCacheArray($this->getOrgID(), "members", $user->getUID());
110103
}
111104

112105
public function removeUser($user)
113106
{
114107
$org_group = $this->getLDAPOrgGroup();
115108
$org_group->removeAttributeEntryByValue("memberuid", $user->getUID());
116-
117-
if (!$org_group->write()) {
118-
throw new Exception("Unable to write to org group");
119-
}
120-
109+
$org_group->write();
121110
$this->REDIS->removeCacheArray($this->getOrgID(), "members", $user->getUID());
122111
}
123112
}

resources/lib/UnityUser.php

Lines changed: 9 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,7 @@ public function init($send_mail = true)
5858
if (!$ldapGroupEntry->exists()) {
5959
$ldapGroupEntry->setAttribute("objectclass", UnityLDAP::POSIX_GROUP_CLASS);
6060
$ldapGroupEntry->setAttribute("gidnumber", strval($id));
61-
62-
if (!$ldapGroupEntry->write()) {
63-
throw new Exception("Failed to create POSIX group for $this->uid");
64-
}
61+
$ldapGroupEntry->write();
6562
}
6663

6764
//
@@ -80,11 +77,7 @@ public function init($send_mail = true)
8077
$ldapUserEntry->setAttribute("loginshell", $this->LDAP->getDefUserShell());
8178
$ldapUserEntry->setAttribute("uidnumber", strval($id));
8279
$ldapUserEntry->setAttribute("gidnumber", strval($id));
83-
84-
if (!$ldapUserEntry->write()) {
85-
$ldapGroupEntry->delete(); // Cleanup previous group
86-
throw new Exception("Failed to create POSIX user for $this->uid");
87-
}
80+
$ldapUserEntry->write();
8881
}
8982

9083
// update cache
@@ -177,11 +170,7 @@ public function setOrg($org)
177170
{
178171
$ldap_user = $this->getLDAPUser();
179172
$ldap_user->setAttribute("o", $org);
180-
181-
if (!$ldap_user->write()) {
182-
throw new Exception("Error updating LDAP entry $this->uid");
183-
}
184-
173+
$ldap_user->write();
185174
$this->REDIS->setCache($this->uid, "org", $org);
186175
}
187176

@@ -225,10 +214,7 @@ public function setFirstname($firstname, $operator = null)
225214
$this->getUID()
226215
);
227216

228-
if (!$ldap_user->write()) {
229-
throw new Exception("Error updating LDAP entry $this->uid");
230-
}
231-
217+
$ldap_user->write();
232218
$this->REDIS->setCache($this->uid, "firstname", $firstname);
233219
}
234220

@@ -277,10 +263,7 @@ public function setLastname($lastname, $operator = null)
277263
$this->getUID()
278264
);
279265

280-
if (!$this->getLDAPUser()->write()) {
281-
throw new Exception("Error updating LDAP entry $this->uid");
282-
}
283-
266+
$this->getLDAPUser()->write();
284267
$this->REDIS->setCache($this->uid, "lastname", $lastname);
285268
}
286269

@@ -334,10 +317,7 @@ public function setMail($email, $operator = null)
334317
$this->getUID()
335318
);
336319

337-
if (!$this->getLDAPUser()->write()) {
338-
throw new Exception("Error updating LDAP entry $this->uid");
339-
}
340-
320+
$this->getLDAPUser()->write();
341321
$this->REDIS->setCache($this->uid, "mail", $email);
342322
}
343323

@@ -380,9 +360,7 @@ public function setSSHKeys($keys, $operator = null, $send_mail = true)
380360
$keys_filt = array_values(array_unique($keys));
381361
if ($ldapUser->exists()) {
382362
$ldapUser->setAttribute("sshpublickey", $keys_filt);
383-
if (!$ldapUser->write()) {
384-
throw new Exception("Failed to modify SSH keys for $this->uid");
385-
}
363+
$ldapUser->write();
386364
}
387365

388366
$this->REDIS->setCache($this->uid, "sshkeys", $keys_filt);
@@ -459,9 +437,7 @@ public function setLoginShell($shell, $operator = null, $send_mail = true)
459437
$ldapUser = $this->getLDAPUser();
460438
if ($ldapUser->exists()) {
461439
$ldapUser->setAttribute("loginshell", $shell);
462-
if (!$ldapUser->write()) {
463-
throw new Exception("Failed to modify login shell for $this->uid");
464-
}
440+
$ldapUser->write();
465441
}
466442

467443
$operator = is_null($operator) ? $this->getUID() : $operator->getUID();
@@ -518,10 +494,7 @@ public function setHomeDir($home, $operator = null)
518494
$ldapUser = $this->getLDAPUser();
519495
if ($ldapUser->exists()) {
520496
$ldapUser->setAttribute("homedirectory", $home);
521-
if (!$ldapUser->write()) {
522-
throw new Exception("Failed to modify home directory for $this->uid");
523-
}
524-
497+
$ldapUser->write();
525498
$operator = is_null($operator) ? $this->getUID() : $operator->getUID();
526499

527500
$this->SQL->addLog(

resources/lib/phpopenldaper

Submodule phpopenldaper added at e3a7783

test/phpunit-bootstrap.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

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

5+
// submodule
6+
require_once __DIR__ . "/../resources/lib/phpopenldaper/src/PHPOpenLDAPer/LDAPEntry.php";
7+
require_once __DIR__ . "/../resources/lib/phpopenldaper/src/PHPOpenLDAPer/LDAPConn.php";
8+
59
require_once __DIR__ . "/../resources/lib/UnityLDAP.php";
610
require_once __DIR__ . "/../resources/lib/UnityUser.php";
711
require_once __DIR__ . "/../resources/lib/UnityGroup.php";

tools/docker-dev/unity-web-portal

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)