1<?php
2    /*
3     * $Id: domainsettings.php 1439 2009-11-17 23:31:04Z dmorton $
4     *
5     * MAIA MAILGUARD LICENSE v.1.0
6     *
7     * Copyright 2004 by Robert LeBlanc <rjl@renaissoft.com>
8     *                   David Morton   <mortonda@dgrmm.net>
9     * All rights reserved.
10     *
11     * PREAMBLE
12     *
13     * This License is designed for users of Maia Mailguard
14     * ("the Software") who wish to support the Maia Mailguard project by
15     * leaving "Maia Mailguard" branding information in the HTML output
16     * of the pages generated by the Software, and providing links back
17     * to the Maia Mailguard home page.  Users who wish to remove this
18     * branding information should contact the copyright owner to obtain
19     * a Rebranding License.
20     *
21     * DEFINITION OF TERMS
22     *
23     * The "Software" refers to Maia Mailguard, including all of the
24     * associated PHP, Perl, and SQL scripts, documentation files, graphic
25     * icons and logo images.
26     *
27     * GRANT OF LICENSE
28     *
29     * Redistribution and use in source and binary forms, with or without
30     * modification, are permitted provided that the following conditions
31     * are met:
32     *
33     * 1. Redistributions of source code must retain the above copyright
34     *    notice, this list of conditions and the following disclaimer.
35     *
36     * 2. Redistributions in binary form must reproduce the above copyright
37     *    notice, this list of conditions and the following disclaimer in the
38     *    documentation and/or other materials provided with the distribution.
39     *
40     * 3. The end-user documentation included with the redistribution, if
41     *    any, must include the following acknowledgment:
42     *
43     *    "This product includes software developed by Robert LeBlanc
44     *    <rjl@renaissoft.com>."
45     *
46     *    Alternately, this acknowledgment may appear in the software itself,
47     *    if and wherever such third-party acknowledgments normally appear.
48     *
49     * 4. At least one of the following branding conventions must be used:
50     *
51     *    a. The Maia Mailguard logo appears in the page-top banner of
52     *       all HTML output pages in an unmodified form, and links
53     *       directly to the Maia Mailguard home page; or
54     *
55     *    b. The "Powered by Maia Mailguard" graphic appears in the HTML
56     *       output of all gateway pages that lead to this software,
57     *       linking directly to the Maia Mailguard home page; or
58     *
59     *    c. A separate Rebranding License is obtained from the copyright
60     *       owner, exempting the Licensee from 4(a) and 4(b), subject to
61     *       the additional conditions laid out in that license document.
62     *
63     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS
64     * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
65     * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
66     * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
67     * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
68     * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
69     * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
70     * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
71     * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
72     * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
73     * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
74     *
75     */
76
77    require_once ("core.php");
78    require_once ("authcheck.php");
79    require_once ("display.php");
80    require_once ("maia_db.php");
81    $display_language = get_display_language($euid);
82    require_once ("./locale/$display_language/display.php");
83    require_once ("./locale/$display_language/db.php");
84    require_once ("./locale/$display_language/domainsettings.php");
85
86    require_once ("smarty.php");
87
88    // A domain ID value *must* be supplied.
89    if (isset($_GET["domain"])) {
90       $domain_id = trim($_GET["domain"]);
91    } else {
92       header("Location: admindomains.php" . $sid);
93    }
94
95    // Only administrators with rights to this domain should be here.
96    if (!is_admin_for_domain($uid, $domain_id)) {
97       header("Location: index.php" . $sid);
98       exit();
99    }
100
101    $sth = $dbh->prepare("SELECT virus_lover, " .
102                     "spam_lover, " .
103                     "banned_files_lover, " .
104                     "bad_header_lover, " .
105                     "bypass_virus_checks, " .
106                     "bypass_spam_checks, " .
107                     "bypass_banned_checks, " .
108                     "bypass_header_checks, " .
109                     "discard_viruses, " .
110  	             "discard_spam, " .
111  	             "discard_banned_files, " .
112  	             "discard_bad_headers, " .
113                     "spam_modifies_subj, " .
114                     "spam_tag_level, " .
115                     "spam_tag2_level, " .
116                     "spam_kill_level, " .
117                     "email, " .
118                     "policy_id " .
119              "FROM users, policy " .
120              "WHERE users.policy_id = policy.id " .
121              "AND users.maia_domain_id = ?");
122
123    $system_default = false;
124    $res = $sth->execute(array($domain_id));
125    if (PEAR::isError($sth)) {
126        die($sth->getMessage());
127    }
128    if ($row = $res->fetchRow()) {
129        $address = $row["email"];
130        if ($address == "@.") {
131            $smarty->assign('address', $lang['text_system_default'] . " (@.)");
132            $system_default = true;
133        } else {
134			$smarty->assign('address', $address);
135        }
136        $smarty->assign("system_default", $system_default);
137        $smarty->assign('policy_id', $row["policy_id"]);
138        $smarty->assign('level1', $row["spam_tag_level"]);
139        $smarty->assign('level2', $row["spam_tag2_level"]);
140        $smarty->assign('level3', $row["spam_kill_level"]);
141        if ($row["virus_lover"] == 'Y') {
142            $smarty->assign('v_l_checked', "checked");
143            $smarty->assign('v_q_checked', "");
144            $smarty->assign('v_d_checked', "");
145        } else {
146            $smarty->assign('v_l_checked', "");
147            if ($row["discard_viruses"] == 'Y') {
148		$smarty->assign('v_q_checked', "");
149		$smarty->assign('v_d_checked', "checked");
150	    } else {
151		$smarty->assign('v_q_checked', "checked");
152		$smarty->assign('v_d_checked', "");
153	    }
154        }
155        if ($row["spam_lover"] == 'Y') {
156            $smarty->assign('s_l_checked', "checked");
157            $smarty->assign('s_q_checked', "");
158            $smarty->assign('s_d_checked', "");
159        } else {
160            $smarty->assign('s_l_checked', "");
161            if ($row["discard_spam"] == 'Y') {
162		$smarty->assign('s_q_checked', "");
163		$smarty->assign('s_d_checked', "checked");
164	    } else {
165		$smarty->assign('s_q_checked', "checked");
166		$smarty->assign('s_d_checked', "");
167	    }
168        }
169        if ($row["banned_files_lover"] == 'Y') {
170            $smarty->assign('b_l_checked', "checked");
171            $smarty->assign('b_q_checked', "");
172            $smarty->assign('b_d_checked', "");
173        } else {
174            $smarty->assign('b_l_checked', "");
175            if ($row["discard_banned_files"] == 'Y') {
176		$smarty->assign('b_q_checked', "");
177		$smarty->assign('b_d_checked', "checked");
178	    } else {
179		$smarty->assign('b_q_checked', "checked");
180		$smarty->assign('b_d_checked', "");
181	    }
182        }
183        if ($row["bad_header_lover"] == 'Y') {
184            $smarty->assign('h_l_checked', "checked");
185            $smarty->assign('h_q_checked', "");
186            $smarty->assign('h_d_checked', "");
187        } else {
188            $smarty->assign('h_l_checked', "");
189            if ($row["discard_bad_headers"] == 'Y') {
190		$smarty->assign('h_q_checked', "");
191		$smarty->assign('h_d_checked', "checked");
192	    } else {
193		$smarty->assign('h_q_checked', "checked");
194		$smarty->assign('h_d_checked', "");
195	    }
196        }
197        if ($row["bypass_virus_checks"] == 'Y') {
198            $smarty->assign('bv_y_checked', "");
199            $smarty->assign('bv_n_checked', "checked");
200        } else {
201            $smarty->assign('bv_y_checked', "checked");
202            $smarty->assign('bv_n_checked', "");
203        }
204        if ($row["bypass_spam_checks"] == 'Y') {
205            $smarty->assign('bs_y_checked', "");
206            $smarty->assign('bs_n_checked', "checked");
207        } else {
208            $smarty->assign('bs_y_checked', "checked");
209            $smarty->assign('bs_n_checked', "");
210        }
211        if ($row["bypass_banned_checks"] == 'Y') {
212            $smarty->assign('bb_y_checked', "");
213            $smarty->assign('bb_n_checked', "checked");
214        } else {
215            $smarty->assign('bb_y_checked', "checked");
216            $smarty->assign('bb_n_checked', "");
217        }
218        if ($row["bypass_header_checks"] == 'Y') {
219            $smarty->assign('bh_y_checked', "");
220            $smarty->assign('bh_n_checked', "checked");
221        } else {
222            $smarty->assign('bh_y_checked', "checked");
223            $smarty->assign('bh_n_checked', "");
224        }
225        if ($row["spam_modifies_subj"] == 'Y') {
226            $smarty->assign('sms_y_checked', "checked");
227            $smarty->assign('sms_n_checked', "");
228        } else {
229            $smarty->assign('sms_y_checked', "");
230            $smarty->assign('sms_n_checked', "checked");
231        }
232
233    }
234    $sth->free();
235
236    //get list of themes
237    $sth = $dbh->prepare("SELECT id, name FROM maia_themes");
238    $res = $sth->execute();
239    if (PEAR::isError($sth)) {
240        die($sth->getMessage());
241    }
242
243    $themes = array();
244    while ($row = $res->fetchrow()) {
245       $themes[$row['id']] = $row['name'];
246    }
247    $smarty->assign("themes", $themes);
248    $sth->free();
249
250    $sth = $dbh->prepare("SELECT maia_users.discard_ham, maia_domains.enable_user_autocreation, maia_users.theme_id " .
251  	                   "FROM maia_users, maia_domains " .
252  	                   "WHERE maia_domains.domain = maia_users.user_name " .
253  	                   "AND maia_domains.id = ?");
254    $res = $sth->execute(array($domain_id));
255    if ($row = $res->fetchrow()) {
256        $smarty->assign('theme_id', $row["theme_id"]);
257        if ($row["discard_ham"] == 'Y') {
258            $smarty->assign('dh_y_checked', "");
259            $smarty->assign('dh_n_checked', "checked");
260        } else {
261            $smarty->assign('dh_y_checked', "checked");
262            $smarty->assign('dh_n_checked', "");
263        }
264        if (get_config_value("enable_user_autocreation") == 'Y') {
265            $smarty->assign("system_enable_user_autocreation", true);
266            if ($row["enable_user_autocreation"] == 'Y') {
267                $smarty->assign('ua_y_checked', "checked");
268                $smarty->assign('ua_n_checked', "");
269            } else {
270                $smarty->assign('ua_y_checked', "");
271                $smarty->assign('ua_n_checked', "checked");
272            }
273        } else {
274            $smarty->assign("system_enable_user_autocreation", false);
275        }
276    }
277    $sth->free();
278
279    $sth = $dbh->prepare("SELECT maia_users.user_name, maia_users.id " .
280              "FROM maia_users, maia_domain_admins " .
281              "WHERE maia_users.id = maia_domain_admins.admin_id " .
282              "AND maia_domain_admins.domain_id = ? " .
283              "ORDER BY maia_users.user_name ASC");
284    $res = $sth->prepare(array($domain_id));
285    if (PEAR::isError($sth)) {
286        die($sth->getMessage());
287    }
288    $admins = array();
289    if (($rowcount = $res->numrows()) > 0) {
290        while ($row = $res->fetchrow()) {
291            $admins[] = array(
292                'id' => $row["id"],
293                'name' => $row["user_name"],
294                'var_name' => $row["user_name"]
295            );
296        }
297    }
298    $smarty->assign('admins', $admins);
299
300    $sth->free();
301
302    $sth = $dbh->prepare("SELECT maia_users.id " .
303              "FROM maia_users, maia_domain_admins " .
304              "WHERE maia_users.id = maia_domain_admins.admin_id " .
305              "AND maia_domain_admins.domain_id = ?");
306    $res = $sth->execute(array($domain_id));
307    if (PEAR::isError($sth)) {
308        die($sth->getMessage());
309    }
310    $id_list = "";
311    while($row = $res->fetchRow()) {
312        if (!empty($id_list)) {
313            $id_list .= "," . $row["id"];
314        } else {
315            $id_list = $row["id"];
316        }
317    }
318    $sth->free();
319
320    $select = "SELECT user_name, id " .
321              "FROM maia_users " .
322              "WHERE user_level <> 'S' " .
323              "AND user_name NOT like '@%' ";
324    if (!empty($id_list)) {
325        $select .= "AND id NOT IN (" . $id_list . ") ";
326    }
327    $select .= "ORDER BY user_name ASC";
328    $sth->prepare($select);
329    $res = $sth->execute();
330    if (PEAR::isError($sth)) {
331        die($sth->getMessage());
332    }
333
334    if ($res->numrows()) {
335        $add_admins = array();
336        while ($row = $res->fetchrow()) {
337            $add_admins[] = array(
338                'id' => $row["id"],
339                'name' => $row["user_name"]
340            );
341        }
342        $smarty->assign('add_admins', $add_admins);
343    }
344    $sth->free();
345    $smarty->assign('domain_id', $domain_id);
346    $smarty->display('domainsettings.tpl');
347
348?>
349