Marius Cramer
2015-08-06 37b29231e47a0c4458dc1c15d98588f16f07e1e2
commit | author | age
086696 1 <?php
M 2
3 /*
4 Copyright (c) 2007 - 2009, Till Brehm, projektfarm Gmbh
5 All rights reserved.
b1a6a5 6 Modification (c) 2009, Marius Cramer, pixcept KG
086696 7
M 8 Redistribution and use in source and binary forms, with or without modification,
9 are permitted provided that the following conditions are met:
10
11     * Redistributions of source code must retain the above copyright notice,
12       this list of conditions and the following disclaimer.
13     * Redistributions in binary form must reproduce the above copyright notice,
14       this list of conditions and the following disclaimer in the documentation
15       and/or other materials provided with the distribution.
16     * Neither the name of ISPConfig nor the names of its contributors
17       may be used to endorse or promote products derived from this software without
18       specific prior written permission.
19
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
21 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
24 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
27 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
29 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 class webmail_symlink_plugin {
b1a6a5 33
086696 34     var $plugin_name = 'webmail_symlink_plugin';
M 35     var $class_name = 'webmail_symlink_plugin';
b1a6a5 36
MC 37     var $action;
38
086696 39     //* This function is called during ispconfig installation to determine
M 40     //  if a symlink shall be created for this plugin.
41     function onInstall() {
42         global $conf;
b1a6a5 43
MC 44         return false;
45
086696 46     }
b1a6a5 47
MC 48
086696 49     /*
M 50          This function is called when the plugin is loaded
51     */
b1a6a5 52
086696 53     function onLoad() {
M 54         global $app;
b1a6a5 55
086696 56         /*
M 57         Register for the events
58         */
b1a6a5 59
MC 60         $app->plugins->registerEvent('web_domain_insert', $this->plugin_name, 'insert');
61         $app->plugins->registerEvent('web_domain_update', $this->plugin_name, 'update');
086696 62     }
b1a6a5 63
MC 64     function insert($event_name, $data) {
086696 65         global $app, $conf;
b1a6a5 66
086696 67         $this->action = 'insert';
M 68         // just run the update function
b1a6a5 69         $this->update($event_name, $data);
086696 70     }
b1a6a5 71
MC 72     function update($event_name, $data) {
086696 73         global $app, $conf;
b1a6a5 74
086696 75         if($this->action != 'insert') $this->action = 'update';
b1a6a5 76
086696 77         if($data["new"]["type"] != "vhost" && $data["new"]["parent_domain_id"] > 0) {
b1a6a5 78
086696 79             $old_parent_domain_id = intval($data["old"]["parent_domain_id"]);
M 80             $new_parent_domain_id = intval($data["new"]["parent_domain_id"]);
b1a6a5 81
086696 82             // If the parent_domain_id has been chenged, we will have to update the old site as well.
M 83             if($this->action == 'update' && $data["new"]["parent_domain_id"] != $data["old"]["parent_domain_id"]) {
cc7a82 84                 $tmp = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ? AND active = 'y'", $old_parent_domain_id);
086696 85                 $data["new"] = $tmp;
M 86                 $data["old"] = $tmp;
87                 $this->action = 'update';
b1a6a5 88                 $this->update($event_name, $data);
086696 89             }
b1a6a5 90
086696 91             // This is not a vhost, so we need to update the parent record instead.
cc7a82 92             $tmp = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ? AND active = 'y'", $new_parent_domain_id);
086696 93             $data["new"] = $tmp;
M 94             $data["old"] = $tmp;
95             $this->action = 'update';
96         }
b1a6a5 97
086696 98         if($data["new"]["document_root"] == '') {
b1a6a5 99             $app->log("document_root not set", LOGLEVEL_WARN);
086696 100             return 0;
M 101         }
b1a6a5 102
MC 103         $symlink = true;
104         if($data["new"]["php"] == "suphp") $symlink = false;
105         elseif($data["new"]["php"] == "cgi" && $data["new"]["suexec"] == "y") $symlink = false;
106         elseif($data["new"]["php"] == "fast-cgi" && $data["new"]["suexec"] == "y") $symlink = false;
107
108
109         if(!is_dir($data["new"]["document_root"]."/web")) mkdir($data["new"]["document_root"].'/web', 0755, true);
110         if($symlink == false) {
111             if(is_link($data["new"]["document_root"].'/web/webmail')) unlink($data["new"]["document_root"].'/web/webmail');
112         } else {
113             if(!is_link($data["new"]["document_root"]."/web/webmail")) symlink('/var/www/webmail', $data["new"]["document_root"].'/web/webmail');
114             else symlink('/var/www/webmail', $data["new"]["document_root"].'/web/webmail');
115         }
086696 116     }
b1a6a5 117
086696 118
M 119 } // end class
120
8e725d 121 ?>