Seite 1 von 1

Owncloud <-> phpbb3 => Usersync

Verfasst: 28.01.2013 14:24
von Octopus
Hallo,
ich würde die Benutzer unseres Vereinsforum gerne mit meiner Owncloud-Installation auf dem selbens Server synchronisieren. Netter weise gibt es bei Owncloud auch ein entsprechendes Plugin, da liebervoll App genannt. Dieses synchronisiert jedoch alle Forenbenutzer. Ich möchte aber nur eine besonderen Benutzergruppe des Forums synchronisieren.

Hier der Code aus der entsprechenden Owncloud-App. Meine Hoffnung ist das hier jemand relativ einfach sagen kann, wie man das machen könnte (denn der Original-App-Programmierer hat keine Zeit mehr dafür)....

Danke schon mal vor ab nur für´s Beachten :wink:

Code: Alles auswählen

<?php

/**
 * ownCloud
 *
 * @author Patrik Karisch
 * @copyright 2012 Patrik Karisch <patrik.karisch@abimus.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
 *
 * You should have received a copy of the GNU Affero General Public
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

class OC_User_phpbb3 extends OC_User_Backend {
    protected $phpbb3_db_host;
    protected $phpbb3_db_name;
    protected $phpbb3_db_user;
    protected $phpbb3_db_password;
    protected $phpbb3_db_prefix;
    protected $db;
    protected $db_conn;

    function __construct() {
        $this->db_conn = false;
        $this->phpbb3_db_host = OC_Appconfig::getValue('user_phpbb3', 'phpbb3_db_host','');
        $this->phpbb3_db_name = OC_Appconfig::getValue('user_phpbb3', 'phpbb3_db_name','');
        $this->phpbb3_db_user = OC_Appconfig::getValue('user_phpbb3', 'phpbb3_db_user','');
        $this->phpbb3_db_password = OC_Appconfig::getValue('user_phpbb3', 'phpbb3_db_password','');
        $this->phpbb3_db_prefix = OC_Appconfig::getValue('user_phpbb3', 'phpbb3_db_prefix','');

        $errorlevel = error_reporting();
        error_reporting($errorlevel & ~E_WARNING);
        $this->db = new mysqli($this->phpbb3_db_host, $this->phpbb3_db_user, $this->phpbb3_db_password, $this->phpbb3_db_name);
        error_reporting($errorlevel);
        if ($this->db->connect_errno) {
            OC_Log::write('OC_User_phpbb3',
                    'OC_User_phpbb3, Failed to connect to phpbb3 database: ' . $this->db->connect_error,
                    OC_Log::ERROR);
            return false;
        }
        $this->db_conn = true;
        $this->phpbb3_db_prefix = $this->db->real_escape_string($this->phpbb3_db_prefix);
    }

    /**
     * @brief Set email address
     * @param $uid The username
     */
    private function setEmail($uid) {
        if (!$this->db_conn) {
            return false;
        }

        $q = 'SELECT user_email FROM '. $this->phpbb3_db_prefix .'users WHERE username = "'. $this->db->real_escape_string($uid) .'" AND user_type = 0 OR user_type = 3';
        $result = $this->db->query($q);
        $email = $result->fetch_assoc();
        $email = $email['user_email'];
        OC_Preferences::setValue($uid, 'settings', 'email', $email);
    }

    /**
     * @brief Check if the password is correct
     * @param $uid The username
     * @param $password The password
     * @returns true/false
     */
    public function checkPassword($uid, $password){
        if (!$this->db_conn) {
            return false;
        }

        $query = 'SELECT username FROM '. $this->phpbb3_db_prefix .'users WHERE username = "' . $this->db->real_escape_string($uid) . '"';
        $query .= ' AND user_password = "' . md5($this->db->real_escape_string($password)) . '" AND user_type = 0 OR user_type = 3';
        $result = $this->db->query($query);
        $row = $result->fetch_assoc();

        if ($row) {
            $this->setEmail($uid);
            return $row['username'];
        }
        return false;
    }

    /**
     * @brief Get a list of all users
     * @returns array with all uids
     *
     * Get a list of all users
     */
    public function getUsers() {
        $users = array();
        if (!$this->db_conn) {
            return $users;
        }

        $q = 'SELECT username FROM '. $this->phpbb3_db_prefix .'users WHERE user_type = 0 OR user_type = 3';
        $result = $this->db->query($q);
        while ($row = $result->fetch_assoc()) {
            if(!empty($row['username'])) {
                $users[] = $row['username'];
            }
        }
        sort($users);
        return $users;
    }

    /**
     * @brief check if a user exists
     * @param string $uid the username
     * @return boolean
     */
    public function userExists($uid) {
        if (!$this->db_conn) {
            return false;
        }

        $q = 'SELECT username FROM '. $this->phpbb3_db_prefix .'users WHERE username = "'. $this->db->real_escape_string($uid) .'"  AND user_type = 0 OR user_type = 3';
        $result = $this->db->query($q);
        return $result->num_rows > 0;
    }
}
 

Re: Owncloud <-> phpbb3 => Usersync

Verfasst: 28.01.2013 18:06
von Miriam
ist denn diese Gruppe die Hauptgruppe des users oder ist er nur Mitglied dieser Gruppe, ohne dass diese die Hauptgruppe ist?

Re: Owncloud <-> phpbb3 => Usersync

Verfasst: 28.01.2013 20:24
von Octopus
Also das sind überwiegend Mitglieder einer Gruppe, d.h. es ist nicht die Hauptgruppe dieser Benutzer (das ist bei fast allen "registrierter Benutzer")...

Die Lösung müsste auch nicht so komplett idiotensicher sein, mir würde schon reichen wenn ich im php-code irgendwo einen group_id eintragen könnte oder so....

Re: Owncloud <-> phpbb3 => Usersync

Verfasst: 28.01.2013 22:15
von Miriam
Probier' mal diese modifizierte Funktion:

Code: Alles auswählen

    public function getUsers($gid) {
        $users = array();
        $sql_and = '';
        if (!$this->db_conn) {
            return $users;
        }
        if ((int)$gid))
        {
            $sql_and = 'AND user_id IN ( SELECT user_id FROM ' . $this->phpbb3_db_prefix . 'user_group WHERE group_id = ' . (int)$gid . ' )';
        }
        $q = 'SELECT username FROM '. $this->phpbb3_db_prefix .'users WHERE user_type = 0 OR user_type = 3' . $sql_and;
        $result = $this->db->query($q);
        while ($row = $result->fetch_assoc()) {
            if(!empty($row['username'])) {
                $users[] = $row['username'];
            }
        }
        sort($users);
        return $users;
    }
Wenn Du diesen mit der Gruppen-ID als Parameter aufrufst, werden die User der Gruppe herausgesucht, wenn Du sie ohne Parameter aufrufst, werden alle User ausgegeben und wenn Du sie mit einer nicht existenten Gruppen-ID aufrufst, werden garkeine User ausgegeben.

Mich wundert, daß das hier klappt:

Code: Alles auswählen

$query .= ' AND user_password = "' . md5($this->db->real_escape_string($password)) . '" AND user_type = 0 OR user_type = 3';

Re: Owncloud <-> phpbb3 => Usersync

Verfasst: 28.01.2013 23:01
von Octopus
Wow, danke, so schnell hätte ich mit keiner Antwort gerechnet..... :-)

Werde ich die Tage ausprobieren und dann eine Rückmeldung geben....

Re: Owncloud <-> phpbb3 => Usersync

Verfasst: 28.03.2013 11:52
von Octopus
Schade, kann es nicht mehr ausprobieren, da der Autor der Owncloud-Erweiterung nicht mehr am Projekt arbeitet und seine Version nicht mit aktuellem Owncloud 4.5 bzw. 5 kompatibel ist :-(

Re: Owncloud <-> phpbb3 => Usersync

Verfasst: 28.03.2013 12:03
von Gast234254
Vielleicht hilft der Link weiter

https://github.com/patkar/user_phpbb3

Re: Owncloud <-> phpbb3 => Usersync

Verfasst: 29.03.2013 20:19
von Octopus
Ja genau das ist ja die oben aufgeführte Owncloud-Erweiterung.
Lt. Github seit sieben Monaten nicht mehr geändert worden und der Autor reagiert leider auch nicht auf E-Mails... :cry:

Re: Owncloud <-> phpbb3 => Usersync

Verfasst: 08.05.2013 10:06
von MikeatOSX
Octopus hat geschrieben:reagiert leider auch nicht auf E-Mails... :cry:
Das Thema würde mich auch interessieren.
Gibt es eigentlich sonst irgendwelche Probleme im Zusammenspiel zwischen phpBB und ownCloud?