Owncloud <-> phpbb3 => Usersync

In diesem Forum kann man Fragen zur Programmierung stellen, die bei der Entwicklung von Mods für phpBB 3.0.x oder dem Modifizieren des eigenen Forums auftauchen.
Forumsregeln
phpBB 3.0 hat das Ende seiner Lebenszeit überschritten
phpBB 3.0 wird nicht mehr aktiv unterstützt. Insbesondere werden - auch bei Sicherheitslücken - keine Patches mehr bereitgestellt. Der Einsatz von phpBB 3.0 erfolgt daher auf eigene Gefahr. Wir empfehlen einen Umstieg auf die neuste phpBB-Version, welches aktiv weiterentwickelt wird und für welches regelmäßig Updates zur Verfügung gestellt werden.
Antworten
Octopus
Mitglied
Beiträge: 32
Registriert: 10.09.2005 15:43
Wohnort: Siegen

Owncloud <-> phpbb3 => Usersync

Beitrag 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;
    }
}
 
Benutzeravatar
Miriam
Mitglied
Beiträge: 12310
Registriert: 13.10.2004 07:18
Kontaktdaten:

Re: Owncloud <-> phpbb3 => Usersync

Beitrag von Miriam »

ist denn diese Gruppe die Hauptgruppe des users oder ist er nur Mitglied dieser Gruppe, ohne dass diese die Hauptgruppe ist?
Gruss, Miriam.
Ich schmeiß' alles hin und...
... lasse es liegen
Octopus
Mitglied
Beiträge: 32
Registriert: 10.09.2005 15:43
Wohnort: Siegen

Re: Owncloud <-> phpbb3 => Usersync

Beitrag 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....
Benutzeravatar
Miriam
Mitglied
Beiträge: 12310
Registriert: 13.10.2004 07:18
Kontaktdaten:

Re: Owncloud <-> phpbb3 => Usersync

Beitrag 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';
Gruss, Miriam.
Ich schmeiß' alles hin und...
... lasse es liegen
Octopus
Mitglied
Beiträge: 32
Registriert: 10.09.2005 15:43
Wohnort: Siegen

Re: Owncloud <-> phpbb3 => Usersync

Beitrag von Octopus »

Wow, danke, so schnell hätte ich mit keiner Antwort gerechnet..... :-)

Werde ich die Tage ausprobieren und dann eine Rückmeldung geben....
Octopus
Mitglied
Beiträge: 32
Registriert: 10.09.2005 15:43
Wohnort: Siegen

Re: Owncloud <-> phpbb3 => Usersync

Beitrag 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 :-(
Gast234254
Gesperrt
Beiträge: 1999
Registriert: 08.02.2009 22:58

Re: Owncloud <-> phpbb3 => Usersync

Beitrag von Gast234254 »

Vielleicht hilft der Link weiter

https://github.com/patkar/user_phpbb3
Octopus
Mitglied
Beiträge: 32
Registriert: 10.09.2005 15:43
Wohnort: Siegen

Re: Owncloud <-> phpbb3 => Usersync

Beitrag 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:
Benutzeravatar
MikeatOSX
Mitglied
Beiträge: 12
Registriert: 22.09.2012 10:30

Re: Owncloud <-> phpbb3 => Usersync

Beitrag 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?
* Apple-User seit 1992 *
* phpBB 3.0.11, Mac OS X 10.6.8 Server, Apache 2.2.22, PHP 5.3.15, MySQL(i) 5.0.92, webtrees 1.3.2 *
Antworten

Zurück zu „[3.0.x] Mod Bastelstube“