diff options
Diffstat (limited to 'build/lib')
-rw-r--r-- | build/lib/Controller/ExternalApiController.php | 8 | ||||
-rw-r--r-- | build/lib/Controller/SettingsController.php | 11 | ||||
-rw-r--r-- | build/lib/db/README.md | 11 | ||||
-rw-r--r-- | build/lib/db/iqrosterpush.php | 17 | ||||
-rw-r--r-- | build/lib/db/presencemapper.php | 10 | ||||
-rw-r--r-- | build/lib/db/stanza.php | 40 | ||||
-rw-r--r-- | build/lib/db/stanzamapper.php | 6 | ||||
-rw-r--r-- | build/lib/stanzahandlers/iq.php | 8 | ||||
-rw-r--r-- | build/lib/stanzahandlers/message.php | 4 | ||||
-rw-r--r-- | build/lib/stanzahandlers/stanzahandler.php | 1 |
10 files changed, 94 insertions, 22 deletions
diff --git a/build/lib/Controller/ExternalApiController.php b/build/lib/Controller/ExternalApiController.php index f93134b..342fdac 100644 --- a/build/lib/Controller/ExternalApiController.php +++ b/build/lib/Controller/ExternalApiController.php @@ -160,6 +160,12 @@ class ExternalApiController extends SignatureProtectedApiController $userGroups = $this->groupManager->getUserGroups($currentUser); foreach ($userGroups as $userGroup) { + if (method_exists($userGroup, 'getDisplayName')) { + $groupName = $userGroup->getDisplayName(); + } else { + $groupName = $userGroup->getGID(); + } + foreach ($userGroup->getUsers() as $user) { $uidMember = $user->getUID(); @@ -170,7 +176,7 @@ class ExternalApiController extends SignatureProtectedApiController ]; } - $roster[$uidMember]['groups'][] = $userGroup->getDisplayName(); + $roster[$uidMember]['groups'][] = $groupName; } } diff --git a/build/lib/Controller/SettingsController.php b/build/lib/Controller/SettingsController.php index dbd995d..094f6d6 100644 --- a/build/lib/Controller/SettingsController.php +++ b/build/lib/Controller/SettingsController.php @@ -254,6 +254,14 @@ class SettingsController extends Controller return $response; } + /** + * @NoAdminRequired + */ + public function getServerType() + { + return ["serverType" => $this->getAppValue('serverType', 'internal')]; + } + private function getCurrentUser() { $currentUser = false; @@ -322,8 +330,7 @@ class SettingsController extends Controller private function isPasswordConfirmationRequired() { $version = \OCP\Util::getVersion(); - preg_match('/^([0-9]+)\.', $version, $versionMatches); - $majorVersion = intval($versionMatches[1]); + $majorVersion = intval($version[0]); // copied from owncloud/settings/ajax/installapp.php $lastConfirm = (int) \OC::$server->getSession()->get('last-password-confirm'); diff --git a/build/lib/db/README.md b/build/lib/db/README.md index fce2e82..8dea934 100644 --- a/build/lib/db/README.md +++ b/build/lib/db/README.md @@ -14,4 +14,13 @@ The following mappers are used: - StanzaMapper -> parent of all the other mappers - MessageMapper -> used to store Message entities inside the longpolling table. - PresenceMapper -> used to save, update and fetch presences of the users - - IQRoster doesn't have a mapper since this won't be saved in the DB.
\ No newline at end of file + - IQRoster doesn't have a mapper since this won't be saved in the DB. + + +# Important note on userids and jid's + +When users and Stanza's containing users are stored inside the database this must be done using the Nextcloud userid +and not using a jid! So at all times the user 'admin' must be stored as 'admin' and not as 'admin@localhost/internal' even +in the `to` and `from` parameters of raw xml stanzas. This to support multiple domain Nextcloud instances. +The userId's are escaped using the `OCA\OJSXC\AppInfo\Appplication::sanitizeUserId` function to support the XMPP standards. +When the userId is available inside the class the `OJSXC_UserId` paramter of `OCA\OJSXC\AppInfo\Appplication` must be used.
\ No newline at end of file diff --git a/build/lib/db/iqrosterpush.php b/build/lib/db/iqrosterpush.php index 1d8b596..aebf9dc 100644 --- a/build/lib/db/iqrosterpush.php +++ b/build/lib/db/iqrosterpush.php @@ -2,6 +2,7 @@ namespace OCA\OJSXC\Db; +use OCA\OJSXC\AppInfo\Application; use Sabre\Xml\Reader; use Sabre\Xml\Writer; use Sabre\Xml\XmlDeserializable; @@ -13,7 +14,6 @@ use Sabre\Xml\XmlSerializable; * Class IQRosterPush * * @package OCA\OJSXC\Db - * @method void setJid($jid) * @method void setName($name) * @method void setSubscription($subscription) * @method string getJid() @@ -39,6 +39,21 @@ class IQRosterPush extends Stanza implements XmlSerializable */ public $subscription; + /** + * Sets the to user as a `user`. + * + * @see setFullJid + * @param $userId + * @param null $host_and_or_resource + */ + public function setJid($userId, $host_and_or_resource = null) + { + $this->jid = Application::santizeUserId($userId); + if (!is_null($host_and_or_resource)) { + $this->jid .= '@' . $host_and_or_resource; + } + } + public function xmlSerialize(Writer $writer) { $writer->write([ diff --git a/build/lib/db/presencemapper.php b/build/lib/db/presencemapper.php index f34bf92..adc4831 100644 --- a/build/lib/db/presencemapper.php +++ b/build/lib/db/presencemapper.php @@ -109,8 +109,8 @@ class PresenceMapper extends Mapper $stmt = $this->execute("SELECT * FROM `*PREFIX*ojsxc_presence` WHERE `userid` != ?", [$this->userId]); $results = []; while ($row = $stmt->fetch()) { - $row['from'] = $row['userid'] . '@' . $this->host . '/internal'; - $row['to'] = $this->userId . '@' . $this->host . '/internal'; + $row['from'] = [$row['userid'], $this->host . '/internal']; + $row['to'] = [$this->userId, $this->host . '/internal']; $results[] = $this->mapRowToEntity($row); } $stmt->closeCursor(); @@ -196,11 +196,13 @@ class PresenceMapper extends Mapper $presenceToSend->setPresence('unavailable'); $presenceToSend->setFrom($inactiveUser); foreach ($onlineUsers as $user) { + // send to every online user (except the user who initiated the update) $presenceToSend->setTo($user); $this->messageMapper->insert($presenceToSend); } - $presenceToSend->setTo($this->userId . '@' . $this->host . '/internal'); - $presenceToSend->setFrom($inactiveUser . '@' . $this->host . '/internal'); + // and now send it to the user who initiated the update + $presenceToSend->setTo($this->userId, $this->host . '/internal'); + $presenceToSend->setFrom($inactiveUser, $this->host . '/internal'); $this->newContentContainer->addStanza($presenceToSend); } } diff --git a/build/lib/db/stanza.php b/build/lib/db/stanza.php index 673fd02..4998579 100644 --- a/build/lib/db/stanza.php +++ b/build/lib/db/stanza.php @@ -2,6 +2,7 @@ namespace OCA\OJSXC\Db; +use OCA\OJSXC\AppInfo\Application; use \OCP\AppFramework\Db\Entity; use Sabre\Xml\Reader; use Sabre\Xml\Writer; @@ -43,14 +44,45 @@ class Stanza extends Entity implements XmlSerializable return $this->to; } - public function setTo($userId) + /** + * Sets the to user as a `user`. + * + * @see setFullTo + * @param $userId + * @param null $host_and_or_resource + */ + public function setTo($userId, $host_and_or_resource = null) { - $this->to = strtolower($userId); + if (is_array($userId)) { + // support mapFromRow + $host_and_or_resource = $userId[1]; + $userId = $userId[0]; + } + + $this->to = Application::santizeUserId($userId); + if (!is_null($host_and_or_resource)) { + $this->to .= '@' . $host_and_or_resource; + } } - public function setFrom($userId) + /** + * Sets the from user as a `user`. + * + * @see setFullFrom + * @param $userId + * @param null $host_and_or_resource + */ + public function setFrom($userId, $host_and_or_resource = null) { - $this->from = strtolower($userId); + if (is_array($userId)) { + // support mapFromRow + $host_and_or_resource = $userId[1]; + $userId = $userId[0]; + } + $this->from = Application::santizeUserId($userId); + if (!is_null($host_and_or_resource)) { + $this->from .= '@' . $host_and_or_resource; + } } public function getFrom() diff --git a/build/lib/db/stanzamapper.php b/build/lib/db/stanzamapper.php index 6f7ae73..f84a020 100644 --- a/build/lib/db/stanzamapper.php +++ b/build/lib/db/stanzamapper.php @@ -66,9 +66,9 @@ class StanzaMapper extends Mapper $stmt = $this->execute("SELECT stanza, id FROM *PREFIX*ojsxc_stanzas WHERE `to`=?", [$to]); $results = []; while ($row = $stmt->fetch()) { - $row['stanza'] = preg_replace('/to="([^"@]*)"/', "to=\"$1@" .$this->host ."/internal\"", $row['stanza']); - $row['stanza'] = preg_replace('/from="([^"@]*)"/', "from=\"$1@" .$this->host ."/internal\"", $row['stanza']); - $row['stanza'] = preg_replace('/jid="([^"@]*)"/', "jid=\"$1@" .$this->host ."/internal\"", $row['stanza']); + $row['stanza'] = preg_replace('/to="([^"]*)"/', "to=\"$1@" .$this->host ."/internal\"", $row['stanza']); + $row['stanza'] = preg_replace('/from="([^"]*)"/', "from=\"$1@" .$this->host ."/internal\"", $row['stanza']); + $row['stanza'] = preg_replace('/jid="([^"]*)"/', "jid=\"$1@" .$this->host ."\"", $row['stanza']); $results[] = $this->mapRowToEntity($row); } $stmt->closeCursor(); diff --git a/build/lib/stanzahandlers/iq.php b/build/lib/stanzahandlers/iq.php index 9a7293c..9d36cc6 100644 --- a/build/lib/stanzahandlers/iq.php +++ b/build/lib/stanzahandlers/iq.php @@ -7,6 +7,7 @@ use OCP\IConfig; use OCP\IUserManager; use Sabre\Xml\Reader; use Sabre\Xml\Writer; +use OCA\OJSXC\AppInfo\Application; /** * Class IQ @@ -57,11 +58,12 @@ class IQ extends StanzaHandler $id = $stanza['attributes']['id']; $iqRoster = new IQRoster(); $iqRoster->setType('result'); - $iqRoster->setTo($this->from); + $iqRoster->setTo($this->userId); $iqRoster->setQid($id); foreach ($this->userManager->search('') as $user) { - if ($debugMode || (strtolower($user->getUID()) !== $this->userId)) { - $iqRoster->addItem($user->getUID() . '@' . $this->host, $user->getDisplayName()); + $userId = Application::santizeUserId($user->getUID()); + if ($debugMode || ($userId !== $this->userId && $user->isEnabled())) { + $iqRoster->addItem($userId . '@' . $this->host, $user->getDisplayName()); } } return $iqRoster; diff --git a/build/lib/stanzahandlers/message.php b/build/lib/stanzahandlers/message.php index d5f203e..d3c5727 100644 --- a/build/lib/stanzahandlers/message.php +++ b/build/lib/stanzahandlers/message.php @@ -54,7 +54,7 @@ class Message extends StanzaHandler public function handle(array $stanza) { $to = $this->getAttribute($stanza, 'to'); - $pos = strpos($to, '@'); + $pos = strrpos($to, '@'); $this->to = substr($to, 0, $pos); foreach ($stanza['value'] as $keyRaw => $value) { // remove namespace from key as it is unneeded and cause problems @@ -73,7 +73,7 @@ class Message extends StanzaHandler $message = new MessageEntity(); $message->setTo($this->to); - $message->setFrom($this->from); + $message->setFrom($this->userId); $message->setValue($this->values); $message->setType($this->type); $this->messageMapper->insert($message); diff --git a/build/lib/stanzahandlers/stanzahandler.php b/build/lib/stanzahandlers/stanzahandler.php index 6b0d78f..b3b75e4 100644 --- a/build/lib/stanzahandlers/stanzahandler.php +++ b/build/lib/stanzahandlers/stanzahandler.php @@ -37,7 +37,6 @@ class StanzaHandler { $this->userId = $userId; $this->host = $host; - $this->from = $this->userId; } /** |