|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | +Copyright (c) 2017, Florian Schaal, schaal @it UG |
| 5 | +All rights reserved. |
| 6 | +
|
| 7 | +Redistribution and use in source and binary forms, with or without modification, |
| 8 | +are permitted provided that the following conditions are met: |
| 9 | +
|
| 10 | + * Redistributions of source code must retain the above copyright notice, |
| 11 | + this list of conditions and the following disclaimer. |
| 12 | + * Redistributions in binary form must reproduce the above copyright notice, |
| 13 | + this list of conditions and the following disclaimer in the documentation |
| 14 | + and/or other materials provided with the distribution. |
| 15 | + * Neither the name of ISPConfig nor the names of its contributors |
| 16 | + may be used to endorse or promote products derived from this software without |
| 17 | + specific prior written permission. |
| 18 | +
|
| 19 | +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
| 20 | +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 21 | +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 22 | +IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, |
| 23 | +INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| 24 | +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 | +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 26 | +OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 27 | +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, |
| 28 | +EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | +*/ |
| 30 | + |
| 31 | + |
| 32 | +// The purpose of this plugin is to handle the server/plugins-enabled folder |
| 33 | + |
| 34 | +class server_services_plugin { |
| 35 | + |
| 36 | + var $plugin_name = 'server_services_plugin'; |
| 37 | + var $class_name = 'server_services_plugin'; |
| 38 | + |
| 39 | + var $services = array('mail_server', 'web_server', 'dns_server', 'db_server', 'vserver_server', 'xmpp_server'); |
| 40 | + |
| 41 | + var $mail_plugins = array('getmail_plugin', 'mail_plugin', 'mail_plugin_dkim', 'mailman_plugin', 'postfix_filter_plugin', 'postfix_server_plugin'); |
| 42 | + var $courier_plugins = array('maildrop_plugin'); |
| 43 | + var $dovecot_plugins = array('maildeliver_plugin'); |
| 44 | + |
| 45 | + var $web_plugins = array('cron_plugin', 'cron_jailkit_plugin', 'ftpuser_base_plugin', 'shelluser_base_plugin', 'shelluser_jailkit_plugin', 'webserver_plugin'); |
| 46 | + var $apache_plugins = array('apache2_plugin'); |
| 47 | + var $nginx_plugins = array('nginx_plugin', 'nginx_reverseproxy_plugin'); |
| 48 | + |
| 49 | + var $bind_plugins = array('bind_dlz_plugin', 'bind_plugin'); |
| 50 | + var $powerdns_plugins = array('powerdns_plugin'); |
| 51 | + |
| 52 | + var $db_plugins = array('mysql_clientdb_plugin'); |
| 53 | + |
| 54 | + var $openvz_plugins = array('openvz_plugin'); |
| 55 | + |
| 56 | + var $xmpp_plugins = array('xmpp_plugin'); |
| 57 | + |
| 58 | + function onInstall() { |
| 59 | + |
| 60 | + return true; |
| 61 | + |
| 62 | + } |
| 63 | + |
| 64 | + function onLoad() { |
| 65 | + global $app; |
| 66 | + |
| 67 | + $app->plugins->registerEvent('server_insert', 'server_services_plugin', 'insert'); |
| 68 | + $app->plugins->registerEvent('server_update', 'server_services_plugin', 'update'); |
| 69 | + $app->plugins->registerEvent('server_delete', 'server_services_delete', 'delete'); |
| 70 | + |
| 71 | + } |
| 72 | + |
| 73 | + function insert($event_name, $data) { |
| 74 | + |
| 75 | + $this->update($event_name, $data); |
| 76 | + |
| 77 | + } |
| 78 | + |
| 79 | + function delete($event_name, $data) { |
| 80 | + |
| 81 | + $this->update($event_name, $data); |
| 82 | + |
| 83 | + } |
| 84 | + |
| 85 | + function update($event_name, $data) { |
| 86 | + global $app, $conf; |
| 87 | + |
| 88 | + $app->uses('getconf'); |
| 89 | + $old_services = array(); |
| 90 | + $new_services = array(); |
| 91 | + foreach($this->services as $service) { |
| 92 | + $old_services[$service] = $data['old'][$service]; |
| 93 | + $new_services[$service] = $data['new'][$service]; |
| 94 | + } |
| 95 | + $changed_services=array_diff_assoc($new_services,$old_services); |
| 96 | + foreach($changed_services as $service => $value) { |
| 97 | + switch($service) { |
| 98 | + case 'mail_server': |
| 99 | + $config = $app->getconf->get_server_config($conf['server_id'], 'mail'); |
| 100 | + $plugins = @($config['pop3_imap_daemon'] == 'dovecot')?$this->dovecot_plugins:$this->courier_plugins; |
| 101 | + $plugins = array_merge($plugins, $this->mail_plugins); |
| 102 | + $this->change_state($plugins, $value, $config); |
| 103 | + break; |
| 104 | + case 'web_server': |
| 105 | + $config = $app->getconf->get_server_config($conf['server_id'], 'web'); |
| 106 | + $plugins = @($config['server_type'] == 'apache')?$this->apache_plugins:$this->nginx_plugins; |
| 107 | + $plugins = array_merge($plugins, $this->web_plugins); |
| 108 | + $this->change_state($plugins, $value, $config); |
| 109 | + break; |
| 110 | + case 'dns_server': |
| 111 | + $config = $app->getconf->get_server_config($conf['server_id'], 'dns'); |
| 112 | + $plugins = @(isset($config['bind_user']))?$this->bind_plugins:$this->powerdns_plugins; |
| 113 | + $this->change_state($plugins, $value, $config); |
| 114 | + break; |
| 115 | + case 'db_server': |
| 116 | + $this->change_state($this->db_plugins, $value, $config); |
| 117 | + break; |
| 118 | + case 'vserver_server': |
| 119 | + $this->change_state($this->openvz_plugins, $value, $config); |
| 120 | + break; |
| 121 | + case 'xmpp_server': |
| 122 | + $this->change_state($this->xmpp_plugins, $value, $config); |
| 123 | + break; |
| 124 | + } |
| 125 | + } |
| 126 | + |
| 127 | + } |
| 128 | + |
| 129 | + function change_state($plugins, $value, $config) { |
| 130 | + |
| 131 | + $enabled_dir = '/usr/local/ispconfig/server/plugins-enabled/'; |
| 132 | + $available_dir = '/usr/local/ispconfig/server/plugins-available/'; |
| 133 | + |
| 134 | + if($value == 0) { //* disable services |
| 135 | + foreach($plugins as $plugin) { |
| 136 | + if(is_link($enabled_dir.$plugin.'.inc.php')) { |
| 137 | + unlink($enabled_dir.$plugin.'.inc.php'); |
| 138 | + } |
| 139 | + } |
| 140 | + } |
| 141 | + if ($value == 1) { //* enable services |
| 142 | + foreach($plugins as $plugin) { |
| 143 | + if(is_file($available_dir.$plugin.'.inc.php') && !is_link($enabled_dir.$plugin.'.inc.php')) { |
| 144 | + symlink($available_dir.$plugin.'.inc.php', $enabled_dir.$plugin.'.inc.php'); |
| 145 | + } |
| 146 | + } |
| 147 | + } |
| 148 | + |
| 149 | + } |
| 150 | + |
| 151 | +} // end class |
| 152 | + |
| 153 | + |
| 154 | + |
| 155 | +?> |
0 commit comments