HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials

HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials (http://www.howtoforge.com/forums/index.php)
-   Installation/Configuration (http://www.howtoforge.com/forums/forumdisplay.php?f=27)
-   -   automatic webmail link (http://www.howtoforge.com/forums/showthread.php?t=34917)

admins 13th May 2009 09:17

automatic webmail link
 
Hi till
Hi all

I want when I create a new site, that ISPConfig automatic set a Symlink to
/var/www/webmail in the webpart of the new customer.

So that I do not must everytime set the symlink.

thanks for ideas.
admins

till 13th May 2009 10:11

E.g. you can write a plugin for that.

admins 13th May 2009 10:16

How could I do this?
Could you do this for me? Is this a big work?

Thanks
admins

3cwired_com 30th May 2009 19:25

I would like this feature also. thanks.

SamTzu 3rd June 2009 22:35

Friends, please.
If You want Falco or Till to work for You, You should at least pay them for their work.
Just my humble opinion. I find it difficult to get people to work free for me (or if they do, the deadlines are just horrible.)

Croydon 4th June 2009 10:13

I got a plugin ready for this.

Just copy the content to a file
Code:

/usr/local/ispconfig/server/plugins-available/webmail_symlink_plugin.inc.php
and create a symlink in plugins-enabled
Code:

ln -s /usr/local/ispconfig/server/plugins-available/webmail_symlink_plugin.inc.php /usr/local/ispconfig/server/plugins-enabled/webmail_symlink_plugin.inc.php
Please note: the symlink is automatically removed / not created if suphp is enabled for this website as suphp doesn't allow symlinks outside the docroot.

PHP Code:

<?php

/*
Copyright (c) 2007 - 2009, Till Brehm, projektfarm Gmbh
All rights reserved.
Modification (c) 2009, Marius Cramer, pixcept KG

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright notice,
      this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
    * Neither the name of ISPConfig nor the names of its contributors
      may be used to endorse or promote products derived from this software without
      specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

class webmail_symlink_plugin {
    
    var 
$plugin_name 'webmail_symlink_plugin';
    var 
$class_name 'webmail_symlink_plugin';
    
    var 
$action;
    
    
//* This function is called during ispconfig installation to determine
    //  if a symlink shall be created for this plugin.
    
function onInstall() {
        global 
$conf;
        
        if(
$conf['services']['web'] == true) {
            return 
true;
        } else {
            return 
false;
        }
        
    }
    
        
    
/*
         This function is called when the plugin is loaded
    */
    
    
function onLoad() {
        global 
$app;
        
        
/*
        Register for the events
        */
        
        
$app->plugins->registerEvent('web_domain_insert',$this->plugin_name,'insert');
        
$app->plugins->registerEvent('web_domain_update',$this->plugin_name,'update');
    }
    
    function 
insert($event_name,$data) {
        global 
$app$conf;
        
        
$this->action 'insert';
        
// just run the update function
        
$this->update($event_name,$data);
    }
    
    function 
update($event_name,$data) {
        global 
$app$conf;
        
        if(
$this->action != 'insert'$this->action 'update';
        
        if(
$data["new"]["type"] != "vhost" && $data["new"]["parent_domain_id"] > 0) {
            
            
$old_parent_domain_id intval($data["old"]["parent_domain_id"]);
            
$new_parent_domain_id intval($data["new"]["parent_domain_id"]);
            
            
// If the parent_domain_id has been chenged, we will have to update the old site as well.
            
if($this->action == 'update' && $data["new"]["parent_domain_id"] != $data["old"]["parent_domain_id"]) {
                
$tmp $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ".$old_parent_domain_id." AND active = 'y'");
                
$data["new"] = $tmp;
                
$data["old"] = $tmp;
                
$this->action 'update';
                
$this->update($event_name,$data);
            }
            
            
// This is not a vhost, so we need to update the parent record instead.
            
$tmp $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ".$new_parent_domain_id." AND active = 'y'");
            
$data["new"] = $tmp;
            
$data["old"] = $tmp;
            
$this->action 'update';
        }
        
        if(
$data["new"]["document_root"] == '') {
            
$app->log("document_root not set",LOGLEVEL_WARN);
            return 
0;
        }
        
        if(!
is_dir($data["new"]["document_root"]."/web")) exec("mkdir -p ".$data["new"]["document_root"]."/web");
        if(
$data["new"]["php"] == "suphp") {
            if(
is_link($data["new"]["document_root"]."/web/webmail")) exec("rm -f ".$data["new"]["document_root"]."/web/webmail");
        } else {
            if(!
is_link($data["new"]["document_root"]."/web/webmail")) exec("ln -s /var/www/webmail ".$data["new"]["document_root"]."/web/webmail");
            else 
exec("ln -sf /var/www/webmail ".$data["new"]["document_root"]."/web/webmail");
        }
    }
    

// end class

?>


till 4th June 2009 10:43

Thank you very much for the plugin!

Also the combination php as cgi + suexec or php-fcgi + suexec might have the same problem as suphp if the scripts for the webmail application are not within /var/www or do not belong to the admin user of the site, so it might be a good idea to exclude these combinations also from symlinking?

Croydon 4th June 2009 10:47

Quote:

Originally Posted by till (Post 192047)
Thank you very much for the plugin!

Also the combination php as cgi + suexec or php-fcgi + suexec might have the same problem as suphp if the scripts for the webmail application are not within /var/www or do not belong to the admin user of the site, so it might be a good idea to exclude these combinations also from symlinking?

I tested the plugin with a site with cgi, fast-cgi, modphp enabled and had no problems yet. But maybe you are right that there are some functions that would not work correctly. I am really not sure about that.


edit: sorry, you are right! i didn't set the suexec option so you are right. with that enabled there might be problems. I'll change the plugin.

Croydon 4th June 2009 11:10

Here is the updated plugin.

Symlink is now disabled when
  • suPHP is used
  • CGI is used with suexec
  • Fast-CGI is used with suexec

PHP Code:

<?php

/*
Copyright (c) 2007 - 2009, Till Brehm, projektfarm Gmbh
All rights reserved.
Modification (c) 2009, Marius Cramer, pixcept KG 

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright notice,
      this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
    * Neither the name of ISPConfig nor the names of its contributors
      may be used to endorse or promote products derived from this software without
      specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

class webmail_symlink_plugin {
    
    var 
$plugin_name 'webmail_symlink_plugin';
    var 
$class_name 'webmail_symlink_plugin';
    
    var 
$action;
    
    
//* This function is called during ispconfig installation to determine
    //  if a symlink shall be created for this plugin.
    
function onInstall() {
        global 
$conf;
        
        if(
$conf['services']['web'] == true) {
            return 
true;
        } else {
            return 
false;
        }
        
    }
    
        
    
/*
         This function is called when the plugin is loaded
    */
    
    
function onLoad() {
        global 
$app;
        
        
/*
        Register for the events
        */
        
        
$app->plugins->registerEvent('web_domain_insert',$this->plugin_name,'insert');
        
$app->plugins->registerEvent('web_domain_update',$this->plugin_name,'update');
    }
    
    function 
insert($event_name,$data) {
        global 
$app$conf;
        
        
$this->action 'insert';
        
// just run the update function
        
$this->update($event_name,$data);
    }
    
    function 
update($event_name,$data) {
        global 
$app$conf;
        
        if(
$this->action != 'insert'$this->action 'update';
        
        if(
$data["new"]["type"] != "vhost" && $data["new"]["parent_domain_id"] > 0) {
            
            
$old_parent_domain_id intval($data["old"]["parent_domain_id"]);
            
$new_parent_domain_id intval($data["new"]["parent_domain_id"]);
            
            
// If the parent_domain_id has been chenged, we will have to update the old site as well.
            
if($this->action == 'update' && $data["new"]["parent_domain_id"] != $data["old"]["parent_domain_id"]) {
                
$tmp $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ".$old_parent_domain_id." AND active = 'y'");
                
$data["new"] = $tmp;
                
$data["old"] = $tmp;
                
$this->action 'update';
                
$this->update($event_name,$data);
            }
            
            
// This is not a vhost, so we need to update the parent record instead.
            
$tmp $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ".$new_parent_domain_id." AND active = 'y'");
            
$data["new"] = $tmp;
            
$data["old"] = $tmp;
            
$this->action 'update';
        }
        
        if(
$data["new"]["document_root"] == '') {
            
$app->log("document_root not set",LOGLEVEL_WARN);
            return 
0;
        }
        
        
$symlink true;
        if(
$data["new"]["php"] == "suphp"$symlink false;
        elseif(
$data["new"]["php"] == "cgi" && $data["new"]["suexec"] == "y"$symlink false;
        elseif(
$data["new"]["php"] == "fast-cgi" && $data["new"]["suexec"] == "y"$symlink false;
        
        
        if(!
is_dir($data["new"]["document_root"]."/web")) exec("mkdir -p ".$data["new"]["document_root"]."/web");
        if(
$symlink == false) {
            if(
is_link($data["new"]["document_root"]."/web/webmail")) exec("rm -f ".$data["new"]["document_root"]."/web/webmail");
        } else {
            if(!
is_link($data["new"]["document_root"]."/web/webmail")) exec("ln -s /var/www/webmail ".$data["new"]["document_root"]."/web/webmail");
            else 
exec("ln -sf /var/www/webmail ".$data["new"]["document_root"]."/web/webmail");
        }
    }
    

// end class

?>


pmcdougl 14th June 2009 21:41

Hi, I just tried this and when I try to access any of the websites I create and go to the webmail directory, I get a 403 forbidden...did I do something wrong?

for example, I have site1.something.com, and site2.something.com...when I go to site1.something.com/webmail I get a 403 forbidden (in site2 as well). The symlinks are in the web directories of both the sites, but I still get the 403. Also, when I login via FTP it says that webmail is a broken link, but I suspect this to be normal, as my ftp login cannot see into other directories on the system.

Any words of wisdom?
Thanks in advance


All times are GMT +2. The time now is 00:11.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.