diff --git a/.github/workflows/functional.yml b/.github/workflows/functional.yml index 431092c4..783539c7 100644 --- a/.github/workflows/functional.yml +++ b/.github/workflows/functional.yml @@ -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: diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index bfcb066c..013d7d89 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/phpunit.yml @@ -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: diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 5a5abbc2..929a14b2 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -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 diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..2a5345cd --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "hakasapl/phpopenldaper"] + path = resources/lib/phpopenldaper + url = https://github.com/hakasapl/phpopenldaper.git diff --git a/README.md b/README.md index 80f0c8b2..78bcae88 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/composer.json b/composer.json index 2b7bbc14..45e6d7ec 100644 --- a/composer.json +++ b/composer.json @@ -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" diff --git a/resources/autoload.php b/resources/autoload.php index 32a8ebf7..5c0c25c2 100644 --- a/resources/autoload.php +++ b/resources/autoload.php @@ -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"; diff --git a/resources/lib/UnityGroup.php b/resources/lib/UnityGroup.php index 02b9cbdc..b5966f9b 100644 --- a/resources/lib/UnityGroup.php +++ b/resources/lib/UnityGroup.php @@ -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) { @@ -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()); @@ -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()); } @@ -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()); } diff --git a/resources/lib/UnityOrg.php b/resources/lib/UnityOrg.php index 03f85818..d5215bf2 100644 --- a/resources/lib/UnityOrg.php +++ b/resources/lib/UnityOrg.php @@ -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()); @@ -101,11 +98,7 @@ 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()); } @@ -113,11 +106,7 @@ 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()); } } diff --git a/resources/lib/UnityUser.php b/resources/lib/UnityUser.php index e6274fc1..aaf64675 100644 --- a/resources/lib/UnityUser.php +++ b/resources/lib/UnityUser.php @@ -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(); } // @@ -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 @@ -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); } @@ -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); } @@ -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); } @@ -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); } @@ -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); @@ -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(); @@ -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( diff --git a/resources/lib/phpopenldaper b/resources/lib/phpopenldaper new file mode 160000 index 00000000..e3a77833 --- /dev/null +++ b/resources/lib/phpopenldaper @@ -0,0 +1 @@ +Subproject commit e3a778330704f50004c22586ea1a281d1db87d7e diff --git a/test/phpunit-bootstrap.php b/test/phpunit-bootstrap.php index 25a936c1..77267a08 100644 --- a/test/phpunit-bootstrap.php +++ b/test/phpunit-bootstrap.php @@ -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"; diff --git a/tools/docker-dev/unity-web-portal b/tools/docker-dev/unity-web-portal deleted file mode 160000 index 7087b787..00000000 --- a/tools/docker-dev/unity-web-portal +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 7087b78718a64185ea1ebaf615f4a8b395f39267