modules/jabber/include/jabberaccounts.php
dcee94d9
 <?php
c208bd90
 /*
 This file belongs to the Webinterface of schokokeks.org Hosting
 
cf54502a
 Written 2008-2018 by schokokeks.org Hosting, namely
c208bd90
   Bernd Wurst <bernd@schokokeks.org>
   Hanno Böck <hanno@schokokeks.org>
 
 To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty.
 
2626dd47
 You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see
c208bd90
 http://creativecommons.org/publicdomain/zero/1.0/
 
 Nevertheless, in case you use a significant part of this code, we ask (but not require, see the license) that you keep the authors' names in place and return your changes to the public. We would be especially happy if you tell us what you're going to do with this code.
 */
dcee94d9
 
 require_once("inc/debug.php");
010bf846
 require_once("inc/security.php");
dcee94d9
 
efdfc2b2
 require_once('class/domain.php');
dcee94d9
 
2626dd47
 function get_jabber_accounts()
 {
     require_role(ROLE_CUSTOMER);
     $customerno = (int) $_SESSION['customerinfo']['customerno'];
     $result = db_query("SELECT id, `create`, created, lastactivity, local, domain FROM jabber.accounts WHERE customerno=? AND `delete`=0", array($customerno));
     $accounts = array();
     if (@$result->rowCount() > 0) {
         while ($acc = @$result->fetch()) {
             array_push($accounts, $acc);
         }
     }
     return $accounts;
dcee94d9
 }
 
 
 
 function get_jabberaccount_details($id)
 {
2626dd47
     require_role(ROLE_CUSTOMER);
     $args = array(":customerno" => $_SESSION['customerinfo']['customerno'],
c0def067
                 ":id" => $id);
dcee94d9
 
2626dd47
     $result = db_query("SELECT id, local, domain FROM jabber.accounts WHERE customerno=:customerno AND id=:id", $args);
     if ($result->rowCount() != 1) {
         system_failure("Invalid account");
     }
     $data = $result->fetch();
     if ($data['domain'] == null) {
         $data['domain'] = config('masterdomain');
     } else {
         $dom = new Domain((int) $data['domain']);
         $dom->ensure_customerdomain();
         $data['domain'] = $dom->fqdn;
     }
     return $data;
dcee94d9
 }
 
 
f41624f5
 function valid_jabber_password($pass)
 {
2626dd47
     // Hier könnten erweiterte Checks stehen wenn nötig.
     /*$foo = ereg_replace('["\']', '', $pass);
     DEBUG("\$foo = {$foo} / \$pass = {$pass}");
     return ($foo == $pass);
     */
     return true;
f41624f5
 }
 
dcee94d9
 
 function create_jabber_account($local, $domain, $password)
 {
2626dd47
     require_role(ROLE_CUSTOMER);
     $data = array(":customerno" => $_SESSION['customerinfo']['customerno'],
51e1fd48
                 ":local" => filter_input_username(strtolower($local)),
c0def067
                 ":domain" => $domain);
2626dd47
     if (! valid_jabber_password($password)) {
         input_error('Das Passwort enthält Zeichen, die aufgrund technischer Beschränkungen momentan nicht benutzt werden können.');
         return;
     }
     $data[':password'] = $password;
9086c9ad
 
2626dd47
     if ($domain > 0) {
         $args = array(":domain" => $data[":domain"], ":customerno" => $data[":customerno"]);
         $result = db_query("SELECT id FROM kundendaten.domains WHERE kunde=:customerno AND jabber=1 AND id=:domain", $args);
         if ($result->rowCount() == 0) {
             logger(LOG_WARNING, "modules/jabber/include/jabberaccounts", "jabber", "attempt to create account for invalid domain »{$domain}«");
             system_failure("Invalid domain!");
         }
     }
 
     $args = array(":domain" => $data[":domain"], ":local" => $data[":local"]);
     $domainquery = "domain=:domain";
     if ($domain == 0) {
         unset($args[":domain"]);
         $data[":domain"] = null;
         $domainquery = 'domain IS NULL';
     }
     $result = db_query("SELECT id FROM jabber.accounts WHERE local=:local AND {$domainquery}", $args);
     if ($result->rowCount() > 0) {
         logger(LOG_WARNING, "modules/jabber/include/jabberaccounts", "jabber", "attempt to create already existing account »{$local}@{$domain}«");
         system_failure("Diesen Account gibt es bereits!");
dcee94d9
     }
2626dd47
 
     db_query("INSERT INTO jabber.accounts (customerno,local,domain,password) VALUES (:customerno, :local, :domain, :password);", $data);
     logger(LOG_INFO, "modules/jabber/include/jabberaccounts", "jabber", "created account »{$local}@{$domain}«");
dcee94d9
 }
 
 
17c7269a
 
f41624f5
 function change_jabber_password($id, $password)
17c7269a
 {
2626dd47
     require_role(ROLE_CUSTOMER);
     if (! valid_jabber_password($password)) {
         input_error('Das Passwort enthält Zeichen, die aufgrund technischer Beschränkungen momentan nicht benutzt werden können.');
         return;
     }
     $args = array(":customerno" => $_SESSION['customerinfo']['customerno'],
c0def067
                 ":id" => $id,
                 ":password" => $password);
9086c9ad
 
2626dd47
     db_query("UPDATE jabber.accounts SET password=:password WHERE customerno=:customerno AND id=:id", $args);
     logger(LOG_INFO, "modules/jabber/include/jabberaccounts", "jabber", "changed password for account  »{$id}«");
17c7269a
 }
 
 
 
dcee94d9
 function delete_jabber_account($id)
 {
2626dd47
     require_role(ROLE_CUSTOMER);
9086c9ad
 
2626dd47
     $args = array(":customerno" => $_SESSION['customerinfo']['customerno'],
c0def067
                 ":id" => $id);
dcee94d9
 
2626dd47
     db_query("UPDATE jabber.accounts SET `delete`=1 WHERE customerno=:customerno AND id=:id", $args);
     logger(LOG_INFO, "modules/jabber/include/jabberaccounts", "jabber", "deleted account »{$id}«");
dcee94d9
 }
 
e74237eb
 
 function new_jabber_domain($id)
 {
2626dd47
     $d = new Domain((int) $id);
     $d->ensure_customerdomain();
     db_query("UPDATE kundendaten.domains SET jabber=2 WHERE jabber=0 AND id=?", array($d->id));
e74237eb
 }