Alternc  3.2
Alternc logiel libre pour l'h├ębergement
 All Data Structures Namespaces Files Functions Variables Pages
m_roundcube.php
Go to the documentation of this file.
1 <?php
2 /*
3  ----------------------------------------------------------------------
4  AlternC - Web Hosting System
5  Copyright (C) 2000-2012 by the AlternC Development Team.
6  https://alternc.org/
7  ----------------------------------------------------------------------
8  LICENSE
9 
10  This program is free software; you can redistribute it and/or
11  modify it under the terms of the GNU General Public License (GPL)
12  as published by the Free Software Foundation; either version 2
13  of the License, or (at your option) any later version.
14 
15  This program is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU General Public License for more details.
19 
20  To read the license please visit http://www.gnu.org/copyleft/gpl.html
21  ----------------------------------------------------------------------
22  Purpose of file: Manage Roundcube webmail configuration
23  ----------------------------------------------------------------------
24 */
25 
26 /**
27 * This class handle roundcube's webmail
28 * hook the main panel page to add a link to the webmail
29 */
30 class m_roundcube {
31 
32  /* ----------------------------------------------------------------- */
33  /** Hook called by the homepage or the /webmail link
34  * to redirect the user to a known webmail url.
35  * the variable 'webmail_redirect' tells which webmail has the priority.
36  * @return string the URL of the webmail
37  */
38  function hook_admin_webmail() {
39  global $db;
40  // Search for the domain where the panel is hosted, then search for a webmail in it.
41  $i=2;
42  $domain="";
43  if (!empty($_SERVER["HTTP_HOST"])) {
44  do { // for each domain part (search panel.alternc.org then alternc.org then org, if the current panel is at www.panel.alternc.org)
45  $expl=explode(".",$_SERVER["HTTP_HOST"],$i);
46  if (count($expl)>=2) {
47  list($host,$dompart)=$expl;
48  // We search for a 'squirrelmail' subdomain in that domain
49  $db->query("SELECT * FROM sub_domaines s WHERE s.domaine='".addslashes($dompart)."' AND s.type='roundcube';");
50  if ($db->next_record()) {
51  $domain=$db->Record;
52  return "http://".$domain["sub"].(($domain["sub"])?".":"").$domain["domaine"];
53  }
54  }
55  $i++;
56  } while (strpos($dompart,'.')!==false);
57  }
58 
59  // not found: search for a webmail in the admin user account
60  $db->query("SELECT * FROM sub_domaines s WHERE s.compte=2000 AND s.type='roundcube';");
61  if ($db->next_record()) {
62  $domain=$db->Record;
63  return "http://".$domain["sub"].(($domain["sub"])?".":"").$domain["domaine"];
64  }
65 
66  }
67 
68 
69  /* ----------------------------------------------------------------- */
70  /** Hook called when an email is REALLY deleted (by the cron, not just in the panel)
71  * @param mail_id integer the ID of the mail in the AlternC database
72  * @param fullmail string the deleted mail himself in the form of john@domain.tld
73  * @return boolean
74  */
75  function hook_mail_delete_for_real($mail_id, $fullmail) {
76  // Include Roundcube configuration
77  // Delete from the roundcube configuration
78 
79  // Use cleandb.sh filled by roundcube ? http://trac.roundcube.net/browser/github/bin/cleandb.sh
80 
81  include_once("/etc/roundcube/debian-db.php");
82 
83  switch ($dbtype) {
84  case "sqlite":
85  $rcdb = "sqlite:///$basepath/$dbname?mode=0640";
86  $dbh = new PDO("sqlite:/$basepath/$dbname");
87  break;
88  default:
89  if ($dbport != '') $dbport=":$dbport";
90  if ($dbserver == '') $dbserver="localhost";
91  $dbh= new PDO("$dbtype:host=$dbserver;dbname=$dbname;dbport=$dbport", $dbuser, $dbpass);
92  $rcdb = "$dbtype:$dbuser:$dbpass@$dbserver$dbport/$dbname";
93  break;
94  }
95 
96  $req = $dbh->query("SELECT user_id FROM users WHERE username = '$fullmail'");
97 
98  foreach ( $req->fetchAll() as $t ) {
99  if (empty($t['user_id'])) continue ;
100  $rcuser_id=$t['user_id'];
101 
102  $dbh->query("DELETE from contactgroupmembers where contactgroup_id in (select contactgroup_id from contactgroups where user_id = $rcuser_id) ; ");
103  $dbh->query("DELETE from contactgroups where user_id = $rcuser_id ; ");
104  $dbh->query("DELETE from contacts where user_id = $rcuser_id ; ");
105  $dbh->query("DELETE from identities where user_id = $rcuser_id ; ");
106  $dbh->query("DELETE from users where user_id = $rcuser_id ; ");
107  } //foreach
108 
109  }
110 
111 } /* Class Roundcube */
112 
113 
114 
115 
116