diff --git a/interface/lib/classes/aps_guicontroller.inc.php b/interface/lib/classes/aps_guicontroller.inc.php index 5dae767e4fa9d20d4670fdf12cddbe61db9ae616..cef7cec8fa0126c94ced6184283cb5f3f91d96ba 100644 --- a/interface/lib/classes/aps_guicontroller.inc.php +++ b/interface/lib/classes/aps_guicontroller.inc.php @@ -199,8 +199,8 @@ class ApsGUIController extends ApsBase { global $app; - include_once(ISPC_WEB_PATH.'/sites/tools.inc.php'); - + $app->uses('tools_sites'); + $webserver_id = 0; $websrv = $this->db->queryOneRecord("SELECT * FROM web_domain WHERE domain = '".$this->db->quote($settings['main_domain'])."';"); if(!empty($websrv)) $webserver_id = $websrv['server_id']; @@ -231,8 +231,8 @@ class ApsGUIController extends ApsBase $tmp = array(); $tmp['parent_domain_id'] = $websrv['domain_id']; $tmp['sys_groupid'] = $websrv['sys_groupid']; - $dbname_prefix = replacePrefix($global_config['dbname_prefix'], $tmp); - $dbuser_prefix = replacePrefix($global_config['dbuser_prefix'], $tmp); + $dbname_prefix = $app->tools_sites->replacePrefix($global_config['dbname_prefix'], $tmp); + $dbuser_prefix = $app->tools_sites->replacePrefix($global_config['dbuser_prefix'], $tmp); unset($tmp); //* get the default database server of the client diff --git a/interface/lib/classes/client_templates.inc.php b/interface/lib/classes/client_templates.inc.php new file mode 100644 index 0000000000000000000000000000000000000000..8631db0c02c31ad265d4ff8bc5f469c4864e61c7 --- /dev/null +++ b/interface/lib/classes/client_templates.inc.php @@ -0,0 +1,119 @@ +<?php +/** + * client_templates + * + * @author Marius Cramer <m.cramer@pixcept.de> pixcept KG + * @author (original tools.inc.php) Till Brehm, projektfarm Gmbh + * @author (original tools.inc.php) Oliver Vogel www.muv.com + */ + +class client_templates { + + function apply_client_templates($clientId, $limits = array()) { + global $app; + + if(!is_array($limits)) $limits = array(); + + /* + * Get the master-template for the client + */ + $sql = "SELECT template_master, template_additional FROM client WHERE client_id = " . intval($clientId); + $record = $app->db->queryOneRecord($sql); + $masterTemplateId = $record['template_master']; + $additionalTemplateStr = $record['template_additional']; + + /* + * if the master-Template is custom there is NO changing + */ + if ($masterTemplateId > 0){ + $sql = "SELECT * FROM client_template WHERE template_id = " . intval($masterTemplateId); + $limits = $app->db->queryOneRecord($sql); + } + + /* + * Process the additional tempaltes here (add them to the limits + * if != -1) + */ + $addTpl = explode('/', $additionalTemplateStr); + foreach ($addTpl as $item){ + if (trim($item) != ''){ + $sql = "SELECT * FROM client_template WHERE template_id = " . intval($item); + $addLimits = $app->db->queryOneRecord($sql); + /* maybe the template is deleted in the meantime */ + if (is_array($addLimits)){ + foreach($addLimits as $k => $v){ + /* we can remove this condition, but it is easier to debug with it (don't add ids and other non-limit values) */ + if (strpos($k, 'limit') !== false){ + /* process the numerical limits */ + if (is_numeric($v)){ + /* switch for special cases */ + switch ($k){ + case 'limit_cron_frequency': + if ($v < $limits[$k]) $limits[$k] = $v; + /* silent adjustment of the minimum cron frequency to 1 minute */ + /* maybe this control test should be done via validator definition in tform.php file, but I don't know how */ + if ($limits[$k] < 1) $limits[$k] = 1; + break; + + default: + if ($limits[$k] > -1){ + if ($v == -1){ + $limits[$k] = -1; + } + else { + $limits[$k] += $v; + } + } + } + } + /* process the string limits (CHECKBOXARRAY, SELECT etc.) */ + elseif (is_string($v)){ + switch ($app->tform->formDef["tabs"]["limits"]["fields"][$k]['formtype']){ + case 'CHECKBOXARRAY': + if (!isset($limits[$k])){ + $limits[$k] = array(); + } + + $limits_values = $limits[$k]; + if (is_string($limits[$k])){ + $limits_values = explode($app->tform->formDef["tabs"]["limits"]["fields"][$k]["separator"],$limits[$k]); + } + $additional_values = explode($app->tform->formDef["tabs"]["limits"]["fields"][$k]["separator"],$v); + + /* unification of limits_values (master template) and additional_values (additional template) */ + $limits_unified = array(); + foreach($app->tform->formDef["tabs"]["limits"]["fields"][$k]["value"] as $key => $val){ + if (in_array($key,$limits_values) || in_array($key,$additional_values)) $limits_unified[] = $key; + } + $limits[$k] = implode($app->tform->formDef["tabs"]["limits"]["fields"][$k]["separator"],$limits_unified); + break; + + case 'SELECT': + $limit_values = array_keys($app->tform->formDef["tabs"]["limits"]["fields"][$k]["value"]); + /* choose the lower index of the two SELECT items */ + $limits[$k] = $limit_values[min(array_search($limits[$k], $limit_values), array_search($v, $limit_values))]; + break; + } + } + } + } + } + } + } + + /* + * Write all back to the database + */ + $update = ''; + foreach($limits as $k => $v){ + if ((strpos($k, 'limit') !== false or $k == 'ssh_chroot' or $k == 'web_php_options' or $k == 'force_suexec') && !is_array($v)){ + if ($update != '') $update .= ', '; + $update .= '`' . $k . "`='" . $v . "'"; + } + } + if($update != '') { + $sql = 'UPDATE client SET ' . $update . " WHERE client_id = " . intval($clientId); + $app->db->query($sql); + } + } +} \ No newline at end of file diff --git a/interface/lib/classes/remoting.inc.php b/interface/lib/classes/remoting.inc.php index 8efecc8181d7249842da1618f62efc2725c43fdc..c89f8ed69d281cd44667bbd35ccab4f220d7a4b4 100644 --- a/interface/lib/classes/remoting.inc.php +++ b/interface/lib/classes/remoting.inc.php @@ -1063,7 +1063,7 @@ class remoting { $this->server->fault('permission_denied','You do not have the permissions to access this function.'); return false; } - $affected_rows = $this->klientadd('../client/form/client.tform.php',$reseller_id, $params); + $affected_rows = $this->klientadd('../client/form/' . ($reseller_id ? 'reseller' : 'client') . '.tform.php',$reseller_id, $params); return $affected_rows; } @@ -1077,7 +1077,7 @@ class remoting { $this->server->fault('permission_denied','You do not have the permissions to access this function.'); return false; } - $affected_rows = $this->updateQuery('../client/form/client.tform.php', $reseller_id, $client_id, $params); + $affected_rows = $this->updateQuery('../client/form/' . ($reseller_id ? 'reseller' : 'client') . '.tform.php', $reseller_id, $client_id, $params); $app->remoting_lib->ispconfig_sysuser_update($params,$client_id); @@ -2612,13 +2612,6 @@ class remoting { //* load the user profile of the client $app->remoting_lib->loadUserProfile($reseller_id); - //* load the client template - if(isset($params['template_master']) and $params['template_master'] > 0) - { - $template=$app->db->queryOneRecord("SELECT * FROM client_template WHERE template_id=".intval($params['template_master'])); - if(is_array($template)) $params=array_merge($params,$template); - } - //* Get the SQL query $sql = $app->remoting_lib->getSQL($params,'INSERT',0); @@ -2647,7 +2640,7 @@ class remoting { $this->id = $insert_id; $this->dataRecord = $params; - $app->plugin->raiseEvent('client:client:on_after_insert',$this); + $app->plugin->raiseEvent('client:' . ($reseller_id ? 'reseller' : 'client') . ':on_after_insert',$this); /* if($app->db->errorMessage != '') { diff --git a/interface/lib/classes/tools_monitor.inc.php b/interface/lib/classes/tools_monitor.inc.php new file mode 100644 index 0000000000000000000000000000000000000000..b0b46643eeda77d6392c0f8493c5c4c0675b497d --- /dev/null +++ b/interface/lib/classes/tools_monitor.inc.php @@ -0,0 +1,512 @@ +<?php +/* +Copyright (c) 2007-2008, Till Brehm, projektfarm Gmbh and Oliver Vogel www.muv.com +All rights reserved. + +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 tools_monitor { + + function showServerLoad() { + global $app; + + /* fetch the Data from the DB */ + $record = $app->db->queryOneRecord("SELECT data, state FROM monitor_data WHERE type = 'server_load' and server_id = " . $_SESSION['monitor']['server_id'] . " order by created desc"); + + if(isset($record['data'])) { + $data = unserialize($record['data']); + + /* + Format the data + */ + if (strlen($data['up_minutes']) == "1") $data['up_minutes'] = "0".$data['up_minutes']; + $html = + '<div class="systemmonitor-state state-'.$record['state'].'"> + <div class="systemmonitor-content icons32 ico-'.$record['state'].'"> + <table> + <tr> + <td>' . $app->lng("Server online since").':</td> + <td>' . $data['up_days'] . ' days, ' . $data['up_hours'] . ':' . $data['up_minutes'] . ' hours</center></td> + </tr> + <tr> + <td>' . $app->lng("Users online").':</td> + <td>' . $data['user_online'] . '</td> + </tr>' . + '<tr> + <td>' . $app->lng("System load 1 minute") . ':</td> + <td>' . $data['load_1'] . '</td> + </tr> + <tr> + <td>' . $app->lng("System load 5 minutes") . ':</td> + <td>' . $data['load_5'] . '</td> + </tr> + <tr> + <td>'.$app->lng("System load 15 minutes").':</td> + <td>' . $data['load_15'] . '</td> + </tr> + </table> + </div> + </div>'; + } else { + $html = '<p>'.$app->lng("no_data_serverload_txt").'</p>'; + } + + return $html; + } + + function showDiskUsage () { + global $app; + + /* fetch the Data from the DB */ + $record = $app->db->queryOneRecord("SELECT data, state FROM monitor_data WHERE type = 'disk_usage' and server_id = " . $_SESSION['monitor']['server_id'] . " order by created desc"); + + if(isset($record['data'])) { + $data = unserialize($record['data']); + + /* + Format the data + */ + $html = + '<div class="systemmonitor-state state-'.$record['state'].'"> + <div class="systemmonitor-content icons32 ico-'.$record['state'].'"> + <table> + <tr> + <td>'.$app->lng("monitor_diskusage_filesystem_txt").'</td> + <td>'.$app->lng("monitor_diskusage_type_txt").'</td> + <td>'.$app->lng("monitor_diskusage_size_txt").'</td> + <td>'.$app->lng("monitor_diskusage_used_txt").'</td> + <td>'.$app->lng("monitor_diskusage_available_txt").'</td> + <td>'.$app->lng("monitor_diskusage_usage_txt").'</td> + <td>'.$app->lng("monitor_diskusage_mounted_txt").'</td> + </tr>'; + foreach($data as $line) { + $html .= '<tr>'; + foreach ($line as $item) { + $html .= '<td>' . $item . '</td>'; + } + $html .= '</tr>'; + } + $html .= '</table>'; + $html .= '</div></div>'; + } else { + $html = '<p>'.$app->lng("no_data_diskusage_txt").'</p>'; + } + + + return $html; + } + + function showMemUsage () { + global $app; + + /* fetch the Data from the DB */ + $record = $app->db->queryOneRecord("SELECT data, state FROM monitor_data WHERE type = 'mem_usage' and server_id = " . $_SESSION['monitor']['server_id'] . " order by created desc"); + + if(isset($record['data'])) { + $data = unserialize($record['data']); + + /* + Format the data + */ + $html = + '<div class="systemmonitor-state state-'.$record['state'].'"> + <div class="systemmonitor-content icons32 ico-'.$record['state'].'"> + <table>'; + + foreach($data as $key => $value) { + if ($key != '') { + $html .= '<tr> + <td>' . $key . ':</td> + <td>' . $value . '</td> + </tr>'; + } + } + $html .= '</table>'; + $html .= '</div></div>'; + + } else { + $html = '<p>'.$app->lng("no_data_memusage_txt").'</p>'; + } + + return $html; + } + + function showCpuInfo () { + global $app; + + /* fetch the Data from the DB */ + $record = $app->db->queryOneRecord("SELECT data, state FROM monitor_data WHERE type = 'cpu_info' and server_id = " . $_SESSION['monitor']['server_id'] . " order by created desc"); + + if(isset($record['data'])) { + $data = unserialize($record['data']); + + /* + Format the data + */ + $html = + '<div class="systemmonitor-state state-'.$record['state'].'"> + <div class="systemmonitor-content icons32 ico-'.$record['state'].'"> + <table>'; + foreach($data as $key => $value) { + if ($key != '') { + $html .= '<tr> + <td>' . $key . ':</td> + <td>' . $value . '</td> + </tr>'; + } + } + $html .= '</table>'; + $html .= '</div></div>'; + } else { + $html = '<p>'.$app->lng("no_data_cpuinfo_txt").'</p>'; + } + + return $html; + } + + function showServices () { + global $app; + + /* fetch the Data from the DB */ + $record = $app->db->queryOneRecord("SELECT data, state FROM monitor_data WHERE type = 'services' and server_id = " . $_SESSION['monitor']['server_id'] . " order by created desc"); + + if(isset($record['data'])) { + $data = unserialize($record['data']); + + /* + Format the data + */ + $html = + '<div class="systemmonitor-state state-'.$record['state'].'"> + <div class="systemmonitor-content icons32 ico-'.$record['state'].'"> + <table>'; + + if($data['webserver'] != -1) { + if($data['webserver'] == 1) { + $status = '<span class="online">'.$app->lng("monitor_services_online_txt").'</span>'; + } else { + $status = '<span class="offline">'.$app->lng("monitor_services_offline_txt").'</span>'; + } + $html .= '<tr> + <td>'.$app->lng("monitor_services_web_txt").'</td> + <td>'.$status.'</td> + </tr>'; + } + + + if($data['ftpserver'] != -1) { + if($data['ftpserver'] == 1) { + $status = '<span class="online">'.$app->lng("monitor_services_online_txt").'</span>'; + } else { + $status = '<span class="offline">'.$app->lng("monitor_services_offline_txt").'</span>'; + } + $html .= '<tr> + <td>'.$app->lng("monitor_services_ftp_txt").'</td> + <td>'.$status.'</td> + </tr>'; + } + + if($data['smtpserver'] != -1) { + if($data['smtpserver'] == 1) { + $status = '<span class="online">'.$app->lng("monitor_services_online_txt").'</span>'; + } else { + $status = '<span class="offline">'.$app->lng("monitor_services_offline_txt").'</span>'; + } + $html .= '<tr> + <td>'.$app->lng("monitor_services_smtp_txt").'</td> + <td>'.$status.'</td> + </tr>'; + } + + if($data['pop3server'] != -1) { + if($data['pop3server'] == 1) { + $status = '<span class="online">'.$app->lng("monitor_services_online_txt").'</span>'; + } else { + $status = '<span class="offline">'.$app->lng("monitor_services_offline_txt").'</span>'; + } + $html .= '<tr> + <td>'.$app->lng("monitor_services_pop_txt").'</td> + <td>'.$status.'</td> + </tr>'; + } + + if($data['imapserver'] != -1) { + if($data['imapserver'] == 1) { + $status = '<span class="online">'.$app->lng("monitor_services_online_txt").'</span>'; + } else { + $status = '<span class="offline">'.$app->lng("monitor_services_offline_txt").'</span>'; + } + $html .= '<tr> + <td>'.$app->lng("monitor_services_imap_txt").'</td> + <td>'.$status.'</td> + </tr>'; + } + + if($data['bindserver'] != -1) { + if($data['bindserver'] == 1) { + $status = '<span class="online">'.$app->lng("monitor_services_online_txt").'</span>'; + } else { + $status = '<span class="offline">'.$app->lng("monitor_services_offline_txt").'</span>'; + } + $html .= '<tr> + <td>'.$app->lng("monitor_services_mydns_txt").'</td> + <td>'.$status.'</td> + </tr>'; + } + + if($data['mysqlserver'] != -1) { + if($data['mysqlserver'] == 1) { + $status = '<span class="online">'.$app->lng("monitor_services_online_txt").'</span>'; + } else { + $status = '<span class="offline">'.$app->lng("monitor_services_offline_txt").'</span>'; + } + $html .= '<tr> + <td>'.$app->lng("monitor_services_mysql_txt").'</td> + <td>'.$status.'</td> + </tr>'; + } + + + $html .= '</table></div></div>'; + } else { + $html = '<p>'.$app->lng("no_data_services_txt").'</p>'; + } + + + return $html; + } + + function showSystemUpdate() { + global $app; + + /* fetch the Data from the DB */ + $record = $app->db->queryOneRecord("SELECT data, state FROM monitor_data WHERE type = 'system_update' and server_id = " . $_SESSION['monitor']['server_id'] . " order by created desc"); + + if(isset($record['data'])) { + $html = + '<div class="systemmonitor-state state-'.$record['state'].'"> + <div class="systemmonitor-content icons32 ico-'.$record['state'].'">'; + /* + * First, we have to detect, if there is any monitoring-data. + * If not (because the destribution is not supported) show this. + */ + if ($record['state'] == 'no_state') { + $html .= '<p>'.$app->lng("monitor_updates_nosupport_txt").'</p>'; + } + else { + $data = unserialize($record['data']); + $html .= nl2br(html_entity_decode($data['output'])); + } + $html .= '</div></div>'; + } else { + $html = '<p>'.$app->lng("no_data_updates_txt").'</p>'; + } + + return $html; + } + + + function showOpenVzBeancounter() { + global $app; + + /* fetch the Data from the DB */ + $record = $app->db->queryOneRecord("SELECT data, state FROM monitor_data WHERE type = 'openvz_beancounter' and server_id = " . $_SESSION['monitor']['server_id'] . " order by created desc"); + + if(isset($record['data'])) { + $html = + '<div class="systemmonitor-state state-'.$record['state'].'"> + <div class="systemmonitor-content icons32 ico-'.$record['state'].'">'; + /* + * First, we have to detect, if there is any monitoring-data. + * If not (because the server is not a VE) show this. + */ + $data = unserialize($record['data']); + if ((!isset($data)) || ($data == '')) { + $html .= '<p>'.$app->lng("monitor_beancounter_nosupport_txt").'</p>'; + } + else { + $html .= '<pre>' . nl2br($data) . '</pre>'; + } + $html .= '</div></div>'; + } else { + $html = '<p>'.$app->lng("no_data_updates_txt").'</p>'; + } + + return $html; + } + + function showRaidState() { + global $app; + + /* fetch the Data from the DB */ + $record = $app->db->queryOneRecord("SELECT data, state FROM monitor_data WHERE type = 'raid_state' and server_id = " . $_SESSION['monitor']['server_id'] . " order by created desc"); + + if(isset($record['data'])) { + $html = + '<div class="systemmonitor-state state-'.$record['state'].'"> + <div class="systemmonitor-content icons32 ico-'.$record['state'].'">'; + + /* + * First, we have to detect, if there is any monitoring-data. + * If not (because the RAID-Controler is not supported yet) show this. + */ + if ($record['state'] == 'no_state') { + $html .= '<p>'.$app->lng("monitor_nosupportedraid1_txt").'</p>'; + } + else { + $data = unserialize($record['data']); + $html .= nl2br($data['output']); + } + $html .= '</div></div>'; + + } else { + $html = '<p>'.$app->lng("no_data_raid_txt").'</p>'; + } + + return $html; + } + + function showRKHunter() { + global $app; + + /* fetch the Data from the DB */ + $record = $app->db->queryOneRecord("SELECT data, state FROM monitor_data WHERE type = 'rkhunter' and server_id = " . $_SESSION['monitor']['server_id'] . " order by created desc"); + + if(isset($record['data'])) { + $html = + '<div class="systemmonitor-state state-'.$record['state'].'"> + <div class="systemmonitor-content icons32 ico-'.$record['state'].'">'; + + /* + * First, we have to detect, if there is any monitoring-data. + * If not (because rkhunter is not installed) show this. + */ + $data = unserialize($record['data']); + if ($data['output'] == '') { + $html .= '<p>'.$app->lng("monitor_norkhunter_txt").'</p>'; + } + else { + $html .= nl2br($data['output']); + } + $html .= '</div></div>'; + + } else { + $html = '<p>'.$app->lng("no_data_rkhunter_txt").'</p>'; + } + + return $html; + } + + function showFail2ban() { + global $app; + + /* fetch the Data from the DB */ + $record = $app->db->queryOneRecord("SELECT data, state FROM monitor_data WHERE type = 'log_fail2ban' and server_id = " . $_SESSION['monitor']['server_id'] . " order by created desc"); + + if(isset($record['data'])) { + $html = + '<div class="systemmonitor-state state-'.$record['state'].'"> + <div class="systemmonitor-content icons32 ico-'.$record['state'].'">'; + + /* + * First, we have to detect, if there is any monitoring-data. + * If not (because fail2ban is not installed) show this. + */ + $data = unserialize($record['data']); + if ($data == '') { + $html .= '<p>'. + 'fail2ban is not installed at this server.<br />' . + 'See more (for debian) <a href="http://www.howtoforge.com/fail2ban_debian_etch" target="htf">here...</a>'. + '</p>'; + } + else { + $html .= nl2br($data); + } + $html .= '</div></div>'; + + } else { + $html = '<p>There is no data available at the moment.</p>'; + } + + return $html; + } + + function showIPTables() { + global $app; + $record = $app->db->queryOneRecord("SELECT data, state FROM monitor_data WHERE type = 'iptables_rules' and server_id = " . $_SESSION['monitor']['server_id'] . " order by created desc"); + if(isset($record['data'])) { + $html = + '<div class="systemmonitor-state state-'.$record['state'].'"> + <div class="systemmonitor-content icons32 ico-'.$record['state'].'">'; + $data = unserialize($record['data']); + if ($data == '') { + $html .= '<p>Problem, there are no rules listed for the server</p>'; + } + else { + $html = nl2br($data['output']); + } + $html .= '</div></div>'; + } else { + $html = '<p>There is no data available at the moment.</p>'; + } + return $html; + } + + + function showMailq() { + global $app; + + /* fetch the Data from the DB */ + $record = $app->db->queryOneRecord("SELECT data, state FROM monitor_data WHERE type = 'mailq' and server_id = " . $_SESSION['monitor']['server_id'] . " order by created desc"); + + if(isset($record['data'])) { + $data = unserialize($record['data']); + $html = nl2br($data['output']); + } else { + $html = '<p>'.$app->lng("no_data_mailq_txt").'</p>'; + } + + return $html; + } + + function getDataTime($type) { + global $app; + + /* fetch the Data from the DB */ + $record = $app->db->queryOneRecord("SELECT created FROM monitor_data WHERE type = '" . $type . "' and server_id = " . $_SESSION['monitor']['server_id'] . " order by created desc"); + + /* TODO: datetimeformat should be set somewhat other way */ + $dateTimeFormat = $app->lng("monitor_settings_datetimeformat_txt"); + + if(isset($record['created'])) { + // $res = date('Y-m-d H:i', $record['created']); + $res = date($dateTimeFormat, $record['created']); + } else { + $res = '????-??-?? ??:??'; + } + return $res; + } +} +?> diff --git a/interface/lib/classes/tools_sites.inc.php b/interface/lib/classes/tools_sites.inc.php new file mode 100644 index 0000000000000000000000000000000000000000..8abf2b921ac4b381f415ee7d2a48adbbb6df5920 --- /dev/null +++ b/interface/lib/classes/tools_sites.inc.php @@ -0,0 +1,126 @@ +<?php +/* +Copyright (c) 2008, Till Brehm, projektfarm Gmbh +All rights reserved. + +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 tools_sites { + + function replacePrefix($name, $dataRecord) { + // No input -> no possible output -> go out! + if ($name=="") return ""; + + // Array containing keys to search + $keywordlist=array('CLIENTNAME','CLIENTID','DOMAINID'); + + // Try to match the key within the string + foreach ($keywordlist as $keyword) { + if (substr_count($name, '['.$keyword.']') > 0) { + switch ($keyword) { + case 'CLIENTNAME': + $name=str_replace('['.$keyword.']', $this->getClientName($dataRecord),$name); + break; + case 'CLIENTID': + $name=str_replace('['.$keyword.']', $this->getClientID($dataRecord),$name); + break; + case 'DOMAINID': + $name=str_replace('['.$keyword.']', $dataRecord['parent_domain_id'],$name); + break; + } + } + } + return $name; + } + + function getClientName($dataRecord) { + global $app, $conf; + if($_SESSION["s"]["user"]["typ"] != 'admin' && !$app->auth->has_clients($_SESSION['s']['user']['userid'])) { + // Get the group-id of the user if the logged in user is neither admin nor reseller + $client_group_id = $_SESSION["s"]["user"]["default_group"]; + } else { + // Get the group-id from the data itself + if(isset($dataRecord['client_group_id'])) { + $client_group_id = $dataRecord['client_group_id']; + } elseif (isset($dataRecord['parent_domain_id'])) { + $tmp = $app->db->queryOneRecord("SELECT sys_groupid FROM web_domain WHERE domain_id = " . $dataRecord['parent_domain_id']); + $client_group_id = $tmp['sys_groupid']; + } elseif(isset($dataRecord['sys_groupid'])) { + $client_group_id = $dataRecord['sys_groupid']; + } else { + $client_group_id = 0; + } + } + + $tmp = $app->db->queryOneRecord("SELECT name FROM sys_group WHERE groupid = " . intval($client_group_id)); + $clientName = $tmp['name']; + if ($clientName == "") $clientName = 'default'; + $clientName = $this->convertClientName($clientName); + return $clientName; + } + + function getClientID($dataRecord) { + global $app, $conf; + + if($_SESSION["s"]["user"]["typ"] != 'admin' && !$app->auth->has_clients($_SESSION['s']['user']['userid'])) { + // Get the group-id of the user + $client_group_id = $_SESSION["s"]["user"]["default_group"]; + } else { + // Get the group-id from the data itself + if(isset($dataRecord['client_group_id'])) { + $client_group_id = $dataRecord['client_group_id']; + } elseif (isset($dataRecord['parent_domain_id'])) { + $tmp = $app->db->queryOneRecord("SELECT sys_groupid FROM web_domain WHERE domain_id = " . $dataRecord['parent_domain_id']); + $client_group_id = $tmp['sys_groupid']; + } elseif(isset($dataRecord['sys_groupid'])) { + $client_group_id = $dataRecord['sys_groupid']; + } else { + $client_group_id = 0; + } + } + $tmp = $app->db->queryOneRecord("SELECT client_id FROM sys_group WHERE groupid = " . intval($client_group_id)); + $clientID = $tmp['client_id']; + if ($clientID == '') $clientID = '0'; + return $clientID; + } + + function convertClientName($name){ + $allowed = 'abcdefghijklmnopqrstuvwxyz0123456789_'; + $res = ''; + $name = strtolower(trim($name)); + for ($i=0; $i < strlen($name); $i++){ + if ($name[$i] == ' ') continue; + if (strpos($allowed, $name[$i]) !== false){ + $res .= $name[$i]; + } + else { + $res .= '_'; + } + } + return $res; + } +} + +?> diff --git a/interface/lib/plugins/clients_template_plugin.inc.php b/interface/lib/plugins/clients_template_plugin.inc.php new file mode 100644 index 0000000000000000000000000000000000000000..51f1e98d018175c469445288c77d9f5c1497e2d2 --- /dev/null +++ b/interface/lib/plugins/clients_template_plugin.inc.php @@ -0,0 +1,34 @@ +<?php +/** + * clients_template_plugin plugin + * + * @author Marius Cramer <m.cramer@pixcept.de> pixcept KG + * @author (original tools.inc.php) Till Brehm, projektfarm Gmbh + * @author (original tools.inc.php) Oliver Vogel www.muv.com + */ + +class clients_template_plugin { + + var $plugin_name = 'clients_template_plugin'; + var $class_name = 'clients_template_plugin'; + + + /* + This function is called when the plugin is loaded + */ + function onLoad() { + global $app; + //Register for the events + $app->plugin->registerEvent('client:client:on_after_insert','clients_template_plugin','apply_client_templates'); + $app->plugin->registerEvent('client:client:on_after_update','clients_template_plugin','apply_client_templates'); + $app->plugin->registerEvent('client:reseller:on_after_insert','clients_template_plugin','apply_client_templates'); + $app->plugin->registerEvent('client:reseller:on_after_update','clients_template_plugin','apply_client_templates'); + } + + function apply_client_templates($event_name, $page_form) { + global $app; + + $app->uses('client_templates'); + $app->client_templates->apply_client_templates($page_form->id, $page_form->dataRecord); + } +} \ No newline at end of file diff --git a/interface/web/client/client_circle_edit.php b/interface/web/client/client_circle_edit.php index 629e526e0d66a9cabfd413a06fc85d95e0cae1ba..407efba55096692bee84aced63631f80f3b44db0 100644 --- a/interface/web/client/client_circle_edit.php +++ b/interface/web/client/client_circle_edit.php @@ -40,7 +40,6 @@ $tform_def_file = "form/client_circle.tform.php"; require_once('../../lib/config.inc.php'); require_once('../../lib/app.inc.php'); -require_once('tools.inc.php'); //* Check permissions for module $app->auth->check_module_permissions('client'); diff --git a/interface/web/client/client_edit.php b/interface/web/client/client_edit.php index edb819c412ddc2b2b7673eba907e452b6a53b88a..4c3705a614cff105c74f224df12cba0a532ceca9 100644 --- a/interface/web/client/client_edit.php +++ b/interface/web/client/client_edit.php @@ -40,7 +40,6 @@ $tform_def_file = "form/client.tform.php"; require_once('../../lib/config.inc.php'); require_once('../../lib/app.inc.php'); -require_once('tools.inc.php'); //* Check permissions for module $app->auth->check_module_permissions('client'); @@ -181,8 +180,6 @@ class page_action extends tform_actions { $sql = "UPDATE client SET default_mailserver = $default_mailserver, default_webserver = $default_webserver, default_dnsserver = $default_dnsserver, default_dbserver = $default_dbserver WHERE client_id = ".$this->id; $app->db->query($sql); - /* If there is a client-template, process it */ - applyClientTemplates($this->id); parent::onAfterInsert(); } @@ -239,10 +236,6 @@ class page_action extends tform_actions { $app->db->query($sql); } - /* - * If there is a client-template, process it */ - applyClientTemplates($this->id); - parent::onAfterUpdate(); } } diff --git a/interface/web/client/client_template_edit.php b/interface/web/client/client_template_edit.php index 2de0e6300291d6871e1bfdf8b8319a19bd28c9d6..35f0c2d861b19a7bc2d0e2294bfae7d5442e3f7a 100644 --- a/interface/web/client/client_template_edit.php +++ b/interface/web/client/client_template_edit.php @@ -40,7 +40,6 @@ $tform_def_file = "form/client_template.tform.php"; require_once('../../lib/config.inc.php'); require_once('../../lib/app.inc.php'); -require_once('tools.inc.php'); //* Check permissions for module $app->auth->check_module_permissions('client'); @@ -75,6 +74,7 @@ class page_action extends tform_actions { function onAfterUpdate() { global $app; + $app->uses('client_templates'); /* * the template has changed. apply the new data to all clients */ @@ -86,7 +86,7 @@ class page_action extends tform_actions { $clients = $app->db->queryAllRecords($sql); if (is_array($clients)){ foreach ($clients as $client){ - applyClientTemplates($client['client_id']); + $app->client_templates->apply_client_templates($client['client_id']); } } } diff --git a/interface/web/client/reseller_edit.php b/interface/web/client/reseller_edit.php index 7b451f166cada58948e91e2ea773627911689f61..a58058f330bf99760a0eb862c027d833f15fd7c9 100644 --- a/interface/web/client/reseller_edit.php +++ b/interface/web/client/reseller_edit.php @@ -40,7 +40,6 @@ $tform_def_file = "form/reseller.tform.php"; require_once('../../lib/config.inc.php'); require_once('../../lib/app.inc.php'); -require_once('tools.inc.php'); //* Check permissions for module $app->auth->check_module_permissions('client'); @@ -179,9 +178,6 @@ class page_action extends tform_actions { $sql = "UPDATE client SET default_mailserver = $default_mailserver, default_webserver = $default_webserver, default_dnsserver = $default_dnsserver, default_dbserver = $default_dbserver WHERE client_id = ".$this->id; $app->db->query($sql); - /* If there is a client-template, process it */ - applyClientTemplates($this->id); - parent::onAfterInsert(); } @@ -243,9 +239,6 @@ class page_action extends tform_actions { $sql = "UPDATE sys_user SET modules = '$modules' WHERE client_id = $client_id"; $app->db->query($sql); } - /* - * If there is a client-template, process it */ - applyClientTemplates($this->id); parent::onAfterUpdate(); } diff --git a/interface/web/client/tools.inc.php b/interface/web/client/tools.inc.php deleted file mode 100644 index ac9bde1e46521177dd9d75a70b8b0deb8106fdbb..0000000000000000000000000000000000000000 --- a/interface/web/client/tools.inc.php +++ /dev/null @@ -1,134 +0,0 @@ -<?php -/* -Copyright (c) 2007-2008, Till Brehm, projektfarm Gmbh and Oliver Vogel www.muv.com -All rights reserved. - -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. -*/ - -function applyClientTemplates($clientId){ - global $app,$page; - /* - * Get the master-template for the client - */ - $sql = "SELECT template_master, template_additional FROM client WHERE client_id = " . intval($clientId); - $record = $app->db->queryOneRecord($sql); - $masterTemplateId = $record['template_master']; - $additionalTemplateStr = $record['template_additional']; - - /* - * if the master-Template is custom there is NO changing - */ - if ($masterTemplateId > 0){ - $sql = "SELECT * FROM client_template WHERE template_id = " . intval($masterTemplateId); - $limits = $app->db->queryOneRecord($sql); - } else { - $limits = $page->dataRecord; - } - - /* - * Process the additional tempaltes here (add them to the limits - * if != -1) - */ - $addTpl = explode('/', $additionalTemplateStr); - foreach ($addTpl as $item){ - if (trim($item) != ''){ - $sql = "SELECT * FROM client_template WHERE template_id = " . intval($item); - $addLimits = $app->db->queryOneRecord($sql); - /* maybe the template is deleted in the meantime */ - if (is_array($addLimits)){ - foreach($addLimits as $k => $v){ - /* we can remove this condition, but it is easier to debug with it (don't add ids and other non-limit values) */ - if (strpos($k, 'limit') !== false){ - /* process the numerical limits */ - if (is_numeric($v)){ - /* switch for special cases */ - switch ($k){ - case 'limit_cron_frequency': - if ($v < $limits[$k]) $limits[$k] = $v; - /* silent adjustment of the minimum cron frequency to 1 minute */ - /* maybe this control test should be done via validator definition in tform.php file, but I don't know how */ - if ($limits[$k] < 1) $limits[$k] = 1; - break; - - default: - if ($limits[$k] > -1){ - if ($v == -1){ - $limits[$k] = -1; - } - else { - $limits[$k] += $v; - } - } - } - } - /* process the string limits (CHECKBOXARRAY, SELECT etc.) */ - elseif (is_string($v)){ - switch ($app->tform->formDef["tabs"]["limits"]["fields"][$k]['formtype']){ - case 'CHECKBOXARRAY': - if (!isset($limits[$k])){ - $limits[$k] = array(); - } - - $limits_values = $limits[$k]; - if (is_string($limits[$k])){ - $limits_values = explode($app->tform->formDef["tabs"]["limits"]["fields"][$k]["separator"],$limits[$k]); - } - $additional_values = explode($app->tform->formDef["tabs"]["limits"]["fields"][$k]["separator"],$v); - - /* unification of limits_values (master template) and additional_values (additional template) */ - $limits_unified = array(); - foreach($app->tform->formDef["tabs"]["limits"]["fields"][$k]["value"] as $key => $val){ - if (in_array($key,$limits_values) || in_array($key,$additional_values)) $limits_unified[] = $key; - } - $limits[$k] = implode($app->tform->formDef["tabs"]["limits"]["fields"][$k]["separator"],$limits_unified); - break; - - case 'SELECT': - $limit_values = array_keys($app->tform->formDef["tabs"]["limits"]["fields"][$k]["value"]); - /* choose the lower index of the two SELECT items */ - $limits[$k] = $limit_values[min(array_search($limits[$k], $limit_values), array_search($v, $limit_values))]; - break; - } - } - } - } - } - } - } - - /* - * Write all back to the database - */ - $update = ''; - foreach($limits as $k => $v){ - if ((strpos($k, 'limit') !== false or $k == 'ssh_chroot' or $k == 'web_php_options') && !is_array($v)){ - if ($update != '') $update .= ', '; - $update .= '`' . $k . "`='" . $v . "'"; - } - } - if($update != '') $sql = 'UPDATE client SET ' . $update . " WHERE client_id = " . intval($clientId); - $app->db->query($sql); -} -?> diff --git a/interface/web/monitor/show_data.php b/interface/web/monitor/show_data.php index daf18ca9165f3916f210d79759c4b3f24311d9c6..1cd4baf525418189e028e5c3faabd540631feadf 100644 --- a/interface/web/monitor/show_data.php +++ b/interface/web/monitor/show_data.php @@ -30,11 +30,11 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. require_once('../../lib/config.inc.php'); require_once('../../lib/app.inc.php'); -require_once('tools.inc.php'); //* Check permissions for module $app->auth->check_module_permissions('monitor'); +$app->uses('tools_monitor'); /* Get the dataType to show */ $dataType = $_GET["type"]; @@ -49,85 +49,85 @@ $output = ''; switch($dataType) { case 'server_load': $template = 'templates/show_data.htm'; - $output .= showServerLoad(); - $time = getDataTime('server_load'); + $output .= $app->tools_monitor->showServerLoad(); + $time = $app->tools_monitor->getDataTime('server_load'); $title = $app->lng("Server Load").' ('. $monTransSrv .' : ' . $_SESSION['monitor']['server_name'] . ')'; $description = ''; break; case 'disk_usage': $template = 'templates/show_data.htm'; - $output .= showDiskUsage(); - $time = getDataTime('disk_usage'); + $output .= $app->tools_monitor->showDiskUsage(); + $time = $app->tools_monitor->getDataTime('disk_usage'); $title = $app->lng("Disk usage").' ('. $monTransSrv .' : ' . $_SESSION['monitor']['server_name'] . ')'; $description = ''; break; case 'mem_usage': $template = 'templates/show_data.htm'; - $output .= showMemUsage(); - $time = getDataTime('mem_usage'); + $output .= $app->tools_monitor->showMemUsage(); + $time = $app->tools_monitor->getDataTime('mem_usage'); $title = $app->lng("Memory usage").' ('. $monTransSrv .' : ' . $_SESSION['monitor']['server_name'] . ')'; $description = ''; break; case 'cpu_info': $template = 'templates/show_data.htm'; - $output .= showCpuInfo(); - $time = getDataTime('cpu_info'); + $output .= $app->tools_monitor->showCpuInfo(); + $time = $app->tools_monitor->getDataTime('cpu_info'); $title = $app->lng("monitor_title_cpuinfo_txt").' ('. $monTransSrv .' : ' . $_SESSION['monitor']['server_name'] . ')'; $description = ''; break; case 'services': $template = 'templates/show_data.htm'; - $output .= showServices(); - $time = getDataTime('services'); + $output .= $app->tools_monitor->showServices(); + $time = $app->tools_monitor->getDataTime('services'); $title = $app->lng("Status of services").' ('. $monTransSrv .' : ' . $_SESSION['monitor']['server_name'] . ')'; $description = ''; break; case 'openvz_beancounter': $template = 'templates/show_data.htm'; - $output .= showOpenVzBeanCounter(); - $time = getDataTime('openvz_beancounter'); + $output .= $app->tools_monitor->showOpenVzBeanCounter(); + $time = $app->tools_monitor->getDataTime('openvz_beancounter'); $title = $app->lng("monitor_title_beancounter_txt") . ' (' . $monTransSrv . ' : ' . $_SESSION['monitor']['server_name'] . ')'; $description = ''; break; case 'system_update': $template = 'templates/show_data.htm'; - $output .= showSystemUpdate(); - $time = getDataTime('system_update'); + $output .= $app->tools_monitor->showSystemUpdate(); + $time = $app->tools_monitor->getDataTime('system_update'); $title = $app->lng("monitor_title_updatestate_txt"). ' ('. $monTransSrv .' : ' . $_SESSION['monitor']['server_name'] . ')'; $description = ''; break; case 'mailq': $template = 'templates/show_data.htm'; - $output .= showMailq(); - $time = getDataTime('mailq'); + $output .= $app->tools_monitor->showMailq(); + $time = $app->tools_monitor->getDataTime('mailq'); $title = $app->lng("monitor_title_mailq_txt"). ' ('. $monTransSrv .' : ' . $_SESSION['monitor']['server_name'] . ')'; $description = ''; break; case 'raid_state': $template = 'templates/show_data.htm'; - $output .= showRaidState(); - $time = getDataTime('raid_state'); + $output .= $app->tools_monitor->showRaidState(); + $time = $app->tools_monitor->getDataTime('raid_state'); $title = $app->lng("monitor_title_raidstate_txt"). ' ('. $monTransSrv .' : ' . $_SESSION['monitor']['server_name'] . ')'; $description = ''; break; case 'rkhunter': $template = 'templates/show_data.htm'; - $output .= showRKHunter(); - $time = getDataTime('rkhunter'); + $output .= $app->tools_monitor->showRKHunter(); + $time = $app->tools_monitor->getDataTime('rkhunter'); $title = $app->lng("monitor_title_rkhunterlog_txt"). ' ('. $monTransSrv .' : ' . $_SESSION['monitor']['server_name'] . ')'; $description = ''; break; case 'fail2ban': $template = 'templates/show_data.htm'; - $output .= showFail2ban(); - $time = getDataTime('log_fail2ban'); + $output .= $app->tools_monitor->showFail2ban(); + $time = $app->tools_monitor->getDataTime('log_fail2ban'); $title = $app->lng("monitor_title_fail2ban_txt") . ' (' . $monTransSrv . ' : ' . $_SESSION['monitor']['server_name'] . ')'; $description = ''; break; case 'iptables': $template = 'templates/show_data.htm'; - $output .= showIPTables(); - $time = getDataTime('iptables_rules'); + $output .= $app->tools_monitor->showIPTables(); + $time = $app->tools_monitor->getDataTime('iptables_rules'); $title = $app->lng("monitor_title_iptables_txt") . ' (' . $monTransSrv . ' : ' . $_SESSION['monitor']['server_name'] . ')'; $description = ''; break; diff --git a/interface/web/monitor/show_log.php b/interface/web/monitor/show_log.php index 10abacd1fbcd6c4308ae76b7dc21ef13e75c0f47..fc1ecf4705dc5462b3d3f1cdf685e6fda1c2b56b 100644 --- a/interface/web/monitor/show_log.php +++ b/interface/web/monitor/show_log.php @@ -30,11 +30,12 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. require_once('../../lib/config.inc.php'); require_once('../../lib/app.inc.php'); -require_once('tools.inc.php'); //* Check permissions for module $app->auth->check_module_permissions('monitor'); +$app->uses('tools_monitor'); + // Loading the template $app->uses('tpl'); $app->tpl->newTemplate("form.tpl.htm"); @@ -134,7 +135,7 @@ if(isset($record['data'])) { $app->tpl->setVar("list_head_txt", $title); $app->tpl->setVar("log_id",$logId); $app->tpl->setVar("list_desc_txt", $description); -$app->tpl->setVar("time", getDataTime($logId)); +$app->tpl->setVar("time", $app->tools_monitor->getDataTime($logId)); $app->tpl->setVar("monTransDate", $monTransDate); $app->tpl->setVar("monTransRefreshsq", $monTransRefreshsq); diff --git a/interface/web/monitor/show_sys_state.php b/interface/web/monitor/show_sys_state.php index 43a9cc514196325cbeacaa79c0201df5034a0595..e6dbc92518ee45200e0df72ecc29912402d80575 100644 --- a/interface/web/monitor/show_sys_state.php +++ b/interface/web/monitor/show_sys_state.php @@ -29,7 +29,6 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. require_once('../../lib/config.inc.php'); require_once('../../lib/app.inc.php'); -require_once('tools.inc.php'); /* Check permissions for module */ $app->auth->check_module_permissions('monitor'); diff --git a/interface/web/monitor/tools.inc.php b/interface/web/monitor/tools.inc.php deleted file mode 100644 index 60d006ad8b7d70ff7b7ca06c6afa47920d0da483..0000000000000000000000000000000000000000 --- a/interface/web/monitor/tools.inc.php +++ /dev/null @@ -1,508 +0,0 @@ -<?php -/* -Copyright (c) 2007-2008, Till Brehm, projektfarm Gmbh and Oliver Vogel www.muv.com -All rights reserved. - -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. -*/ -function showServerLoad() { - global $app; - - /* fetch the Data from the DB */ - $record = $app->db->queryOneRecord("SELECT data, state FROM monitor_data WHERE type = 'server_load' and server_id = " . $_SESSION['monitor']['server_id'] . " order by created desc"); - - if(isset($record['data'])) { - $data = unserialize($record['data']); - - /* - Format the data - */ - if (strlen($data['up_minutes']) == "1") $data['up_minutes'] = "0".$data['up_minutes']; - $html = - '<div class="systemmonitor-state state-'.$record['state'].'"> - <div class="systemmonitor-content icons32 ico-'.$record['state'].'"> - <table> - <tr> - <td>' . $app->lng("Server online since").':</td> - <td>' . $data['up_days'] . ' days, ' . $data['up_hours'] . ':' . $data['up_minutes'] . ' hours</center></td> - </tr> - <tr> - <td>' . $app->lng("Users online").':</td> - <td>' . $data['user_online'] . '</td> - </tr>' . - '<tr> - <td>' . $app->lng("System load 1 minute") . ':</td> - <td>' . $data['load_1'] . '</td> - </tr> - <tr> - <td>' . $app->lng("System load 5 minutes") . ':</td> - <td>' . $data['load_5'] . '</td> - </tr> - <tr> - <td>'.$app->lng("System load 15 minutes").':</td> - <td>' . $data['load_15'] . '</td> - </tr> - </table> - </div> - </div>'; - } else { - $html = '<p>'.$app->lng("no_data_serverload_txt").'</p>'; - } - - return $html; -} - -function showDiskUsage () { - global $app; - - /* fetch the Data from the DB */ - $record = $app->db->queryOneRecord("SELECT data, state FROM monitor_data WHERE type = 'disk_usage' and server_id = " . $_SESSION['monitor']['server_id'] . " order by created desc"); - - if(isset($record['data'])) { - $data = unserialize($record['data']); - - /* - Format the data - */ - $html = - '<div class="systemmonitor-state state-'.$record['state'].'"> - <div class="systemmonitor-content icons32 ico-'.$record['state'].'"> - <table> - <tr> - <td>'.$app->lng("monitor_diskusage_filesystem_txt").'</td> - <td>'.$app->lng("monitor_diskusage_type_txt").'</td> - <td>'.$app->lng("monitor_diskusage_size_txt").'</td> - <td>'.$app->lng("monitor_diskusage_used_txt").'</td> - <td>'.$app->lng("monitor_diskusage_available_txt").'</td> - <td>'.$app->lng("monitor_diskusage_usage_txt").'</td> - <td>'.$app->lng("monitor_diskusage_mounted_txt").'</td> - </tr>'; - foreach($data as $line) { - $html .= '<tr>'; - foreach ($line as $item) { - $html .= '<td>' . $item . '</td>'; - } - $html .= '</tr>'; - } - $html .= '</table>'; - $html .= '</div></div>'; - } else { - $html = '<p>'.$app->lng("no_data_diskusage_txt").'</p>'; - } - - - return $html; -} - -function showMemUsage () { - global $app; - - /* fetch the Data from the DB */ - $record = $app->db->queryOneRecord("SELECT data, state FROM monitor_data WHERE type = 'mem_usage' and server_id = " . $_SESSION['monitor']['server_id'] . " order by created desc"); - - if(isset($record['data'])) { - $data = unserialize($record['data']); - - /* - Format the data - */ - $html = - '<div class="systemmonitor-state state-'.$record['state'].'"> - <div class="systemmonitor-content icons32 ico-'.$record['state'].'"> - <table>'; - - foreach($data as $key => $value) { - if ($key != '') { - $html .= '<tr> - <td>' . $key . ':</td> - <td>' . $value . '</td> - </tr>'; - } - } - $html .= '</table>'; - $html .= '</div></div>'; - - } else { - $html = '<p>'.$app->lng("no_data_memusage_txt").'</p>'; - } - - return $html; -} - -function showCpuInfo () { - global $app; - - /* fetch the Data from the DB */ - $record = $app->db->queryOneRecord("SELECT data, state FROM monitor_data WHERE type = 'cpu_info' and server_id = " . $_SESSION['monitor']['server_id'] . " order by created desc"); - - if(isset($record['data'])) { - $data = unserialize($record['data']); - - /* - Format the data - */ - $html = - '<div class="systemmonitor-state state-'.$record['state'].'"> - <div class="systemmonitor-content icons32 ico-'.$record['state'].'"> - <table>'; - foreach($data as $key => $value) { - if ($key != '') { - $html .= '<tr> - <td>' . $key . ':</td> - <td>' . $value . '</td> - </tr>'; - } - } - $html .= '</table>'; - $html .= '</div></div>'; - } else { - $html = '<p>'.$app->lng("no_data_cpuinfo_txt").'</p>'; - } - - return $html; -} - -function showServices () { - global $app; - - /* fetch the Data from the DB */ - $record = $app->db->queryOneRecord("SELECT data, state FROM monitor_data WHERE type = 'services' and server_id = " . $_SESSION['monitor']['server_id'] . " order by created desc"); - - if(isset($record['data'])) { - $data = unserialize($record['data']); - - /* - Format the data - */ - $html = - '<div class="systemmonitor-state state-'.$record['state'].'"> - <div class="systemmonitor-content icons32 ico-'.$record['state'].'"> - <table>'; - - if($data['webserver'] != -1) { - if($data['webserver'] == 1) { - $status = '<span class="online">'.$app->lng("monitor_services_online_txt").'</span>'; - } else { - $status = '<span class="offline">'.$app->lng("monitor_services_offline_txt").'</span>'; - } - $html .= '<tr> - <td>'.$app->lng("monitor_services_web_txt").'</td> - <td>'.$status.'</td> - </tr>'; - } - - - if($data['ftpserver'] != -1) { - if($data['ftpserver'] == 1) { - $status = '<span class="online">'.$app->lng("monitor_services_online_txt").'</span>'; - } else { - $status = '<span class="offline">'.$app->lng("monitor_services_offline_txt").'</span>'; - } - $html .= '<tr> - <td>'.$app->lng("monitor_services_ftp_txt").'</td> - <td>'.$status.'</td> - </tr>'; - } - - if($data['smtpserver'] != -1) { - if($data['smtpserver'] == 1) { - $status = '<span class="online">'.$app->lng("monitor_services_online_txt").'</span>'; - } else { - $status = '<span class="offline">'.$app->lng("monitor_services_offline_txt").'</span>'; - } - $html .= '<tr> - <td>'.$app->lng("monitor_services_smtp_txt").'</td> - <td>'.$status.'</td> - </tr>'; - } - - if($data['pop3server'] != -1) { - if($data['pop3server'] == 1) { - $status = '<span class="online">'.$app->lng("monitor_services_online_txt").'</span>'; - } else { - $status = '<span class="offline">'.$app->lng("monitor_services_offline_txt").'</span>'; - } - $html .= '<tr> - <td>'.$app->lng("monitor_services_pop_txt").'</td> - <td>'.$status.'</td> - </tr>'; - } - - if($data['imapserver'] != -1) { - if($data['imapserver'] == 1) { - $status = '<span class="online">'.$app->lng("monitor_services_online_txt").'</span>'; - } else { - $status = '<span class="offline">'.$app->lng("monitor_services_offline_txt").'</span>'; - } - $html .= '<tr> - <td>'.$app->lng("monitor_services_imap_txt").'</td> - <td>'.$status.'</td> - </tr>'; - } - - if($data['bindserver'] != -1) { - if($data['bindserver'] == 1) { - $status = '<span class="online">'.$app->lng("monitor_services_online_txt").'</span>'; - } else { - $status = '<span class="offline">'.$app->lng("monitor_services_offline_txt").'</span>'; - } - $html .= '<tr> - <td>'.$app->lng("monitor_services_mydns_txt").'</td> - <td>'.$status.'</td> - </tr>'; - } - - if($data['mysqlserver'] != -1) { - if($data['mysqlserver'] == 1) { - $status = '<span class="online">'.$app->lng("monitor_services_online_txt").'</span>'; - } else { - $status = '<span class="offline">'.$app->lng("monitor_services_offline_txt").'</span>'; - } - $html .= '<tr> - <td>'.$app->lng("monitor_services_mysql_txt").'</td> - <td>'.$status.'</td> - </tr>'; - } - - - $html .= '</table></div></div>'; - } else { - $html = '<p>'.$app->lng("no_data_services_txt").'</p>'; - } - - - return $html; -} - -function showSystemUpdate() { - global $app; - - /* fetch the Data from the DB */ - $record = $app->db->queryOneRecord("SELECT data, state FROM monitor_data WHERE type = 'system_update' and server_id = " . $_SESSION['monitor']['server_id'] . " order by created desc"); - - if(isset($record['data'])) { - $html = - '<div class="systemmonitor-state state-'.$record['state'].'"> - <div class="systemmonitor-content icons32 ico-'.$record['state'].'">'; - /* - * First, we have to detect, if there is any monitoring-data. - * If not (because the destribution is not supported) show this. - */ - if ($record['state'] == 'no_state') { - $html .= '<p>'.$app->lng("monitor_updates_nosupport_txt").'</p>'; - } - else { - $data = unserialize($record['data']); - $html .= nl2br(html_entity_decode($data['output'])); - } - $html .= '</div></div>'; - } else { - $html = '<p>'.$app->lng("no_data_updates_txt").'</p>'; - } - - return $html; -} - - -function showOpenVzBeancounter() { - global $app; - - /* fetch the Data from the DB */ - $record = $app->db->queryOneRecord("SELECT data, state FROM monitor_data WHERE type = 'openvz_beancounter' and server_id = " . $_SESSION['monitor']['server_id'] . " order by created desc"); - - if(isset($record['data'])) { - $html = - '<div class="systemmonitor-state state-'.$record['state'].'"> - <div class="systemmonitor-content icons32 ico-'.$record['state'].'">'; - /* - * First, we have to detect, if there is any monitoring-data. - * If not (because the server is not a VE) show this. - */ - $data = unserialize($record['data']); - if ((!isset($data)) || ($data == '')) { - $html .= '<p>'.$app->lng("monitor_beancounter_nosupport_txt").'</p>'; - } - else { - $html .= '<pre>' . nl2br($data) . '</pre>'; - } - $html .= '</div></div>'; - } else { - $html = '<p>'.$app->lng("no_data_updates_txt").'</p>'; - } - - return $html; -} - -function showRaidState() { - global $app; - - /* fetch the Data from the DB */ - $record = $app->db->queryOneRecord("SELECT data, state FROM monitor_data WHERE type = 'raid_state' and server_id = " . $_SESSION['monitor']['server_id'] . " order by created desc"); - - if(isset($record['data'])) { - $html = - '<div class="systemmonitor-state state-'.$record['state'].'"> - <div class="systemmonitor-content icons32 ico-'.$record['state'].'">'; - - /* - * First, we have to detect, if there is any monitoring-data. - * If not (because the RAID-Controler is not supported yet) show this. - */ - if ($record['state'] == 'no_state') { - $html .= '<p>'.$app->lng("monitor_nosupportedraid1_txt").'</p>'; - } - else { - $data = unserialize($record['data']); - $html .= nl2br($data['output']); - } - $html .= '</div></div>'; - - } else { - $html = '<p>'.$app->lng("no_data_raid_txt").'</p>'; - } - - return $html; -} - -function showRKHunter() { - global $app; - - /* fetch the Data from the DB */ - $record = $app->db->queryOneRecord("SELECT data, state FROM monitor_data WHERE type = 'rkhunter' and server_id = " . $_SESSION['monitor']['server_id'] . " order by created desc"); - - if(isset($record['data'])) { - $html = - '<div class="systemmonitor-state state-'.$record['state'].'"> - <div class="systemmonitor-content icons32 ico-'.$record['state'].'">'; - - /* - * First, we have to detect, if there is any monitoring-data. - * If not (because rkhunter is not installed) show this. - */ - $data = unserialize($record['data']); - if ($data['output'] == '') { - $html .= '<p>'.$app->lng("monitor_norkhunter_txt").'</p>'; - } - else { - $html .= nl2br($data['output']); - } - $html .= '</div></div>'; - - } else { - $html = '<p>'.$app->lng("no_data_rkhunter_txt").'</p>'; - } - - return $html; -} - -function showFail2ban() { - global $app; - - /* fetch the Data from the DB */ - $record = $app->db->queryOneRecord("SELECT data, state FROM monitor_data WHERE type = 'log_fail2ban' and server_id = " . $_SESSION['monitor']['server_id'] . " order by created desc"); - - if(isset($record['data'])) { - $html = - '<div class="systemmonitor-state state-'.$record['state'].'"> - <div class="systemmonitor-content icons32 ico-'.$record['state'].'">'; - - /* - * First, we have to detect, if there is any monitoring-data. - * If not (because fail2ban is not installed) show this. - */ - $data = unserialize($record['data']); - if ($data == '') { - $html .= '<p>'. - 'fail2ban is not installed at this server.<br />' . - 'See more (for debian) <a href="http://www.howtoforge.com/fail2ban_debian_etch" target="htf">here...</a>'. - '</p>'; - } - else { - $html .= nl2br($data); - } - $html .= '</div></div>'; - - } else { - $html = '<p>There is no data available at the moment.</p>'; - } - - return $html; -} - -function showIPTables() { - global $app; - $record = $app->db->queryOneRecord("SELECT data, state FROM monitor_data WHERE type = 'iptables_rules' and server_id = " . $_SESSION['monitor']['server_id'] . " order by created desc"); - if(isset($record['data'])) { - $html = - '<div class="systemmonitor-state state-'.$record['state'].'"> - <div class="systemmonitor-content icons32 ico-'.$record['state'].'">'; - $data = unserialize($record['data']); - if ($data == '') { - $html .= '<p>Problem, there are no rules listed for the server</p>'; - } - else { - $html = nl2br($data['output']); - } - $html .= '</div></div>'; - } else { - $html = '<p>There is no data available at the moment.</p>'; - } - return $html; -} - - -function showMailq() { - global $app; - - /* fetch the Data from the DB */ - $record = $app->db->queryOneRecord("SELECT data, state FROM monitor_data WHERE type = 'mailq' and server_id = " . $_SESSION['monitor']['server_id'] . " order by created desc"); - - if(isset($record['data'])) { - $data = unserialize($record['data']); - $html = nl2br($data['output']); - } else { - $html = '<p>'.$app->lng("no_data_mailq_txt").'</p>'; - } - - return $html; -} - -function getDataTime($type) { - global $app; - - /* fetch the Data from the DB */ - $record = $app->db->queryOneRecord("SELECT created FROM monitor_data WHERE type = '" . $type . "' and server_id = " . $_SESSION['monitor']['server_id'] . " order by created desc"); - - /* TODO: datetimeformat should be set somewhat other way */ - $dateTimeFormat = $app->lng("monitor_settings_datetimeformat_txt"); - - if(isset($record['created'])) { -// $res = date('Y-m-d H:i', $record['created']); - $res = date($dateTimeFormat, $record['created']); - } else { - $res = '????-??-?? ??:??'; - } - return $res; -} -?> diff --git a/interface/web/sites/cron_edit.php b/interface/web/sites/cron_edit.php index 54d021a2c32378af8898255276c1acbb122a5b65..8ccf340e9f8da15e175e075e3d94c10ef6d856ce 100644 --- a/interface/web/sites/cron_edit.php +++ b/interface/web/sites/cron_edit.php @@ -191,27 +191,6 @@ class page_action extends tform_actions { } - - function getClientName() { - global $app, $conf; - - if($_SESSION["s"]["user"]["typ"] != 'admin') { - // Get the group-id of the user - $client_group_id = $_SESSION["s"]["user"]["default_group"]; - } else { - // Get the group-id from the data itself - $web = $app->db->queryOneRecord("SELECT sys_groupid FROM web_domain WHERE domain_id = ".intval($this->dataRecord['parent_domain_id'])); - $client_group_id = $web['sys_groupid']; - } - /* get the name of the client */ - $tmp = $app->db->queryOneRecord("SELECT name FROM sys_group WHERE groupid = " . $client_group_id); - $clientName = $tmp['name']; - if ($clientName == "") $clientName = 'default'; - $clientName = convertClientName($clientName); - - return $clientName; - - } } diff --git a/interface/web/sites/database_edit.php b/interface/web/sites/database_edit.php index 08afd85e8fada82283384e4e57f319e49045bebf..1393aaf41b0ad99374caadba93331db7d9c369d0 100644 --- a/interface/web/sites/database_edit.php +++ b/interface/web/sites/database_edit.php @@ -40,7 +40,6 @@ $tform_def_file = "form/database.tform.php"; require_once('../../lib/config.inc.php'); require_once('../../lib/app.inc.php'); -require_once('tools.inc.php'); //* Check permissions for module $app->auth->check_module_permissions('sites'); @@ -111,9 +110,9 @@ class page_action extends tform_actions { */ //* Get the database name and database user prefix - $app->uses('getconf'); + $app->uses('getconf,tools_sites'); $global_config = $app->getconf->get_global_config('sites'); - $dbname_prefix = replacePrefix($global_config['dbname_prefix'], $this->dataRecord); + $dbname_prefix = $app->tools_sites->replacePrefix($global_config['dbname_prefix'], $this->dataRecord); if ($this->dataRecord['database_name'] != ""){ /* REMOVE the restriction */ @@ -180,9 +179,9 @@ class page_action extends tform_actions { if($this->dataRecord['parent_domain_id'] == 0) $app->tform->errorMessage .= $app->tform->lng("database_site_error_empty").'<br />'; //* Get the database name and database user prefix - $app->uses('getconf'); + $app->uses('getconf,tools_sites'); $global_config = $app->getconf->get_global_config('sites'); - $dbname_prefix = replacePrefix($global_config['dbname_prefix'], $this->dataRecord); + $dbname_prefix = $app->tools_sites->replacePrefix($global_config['dbname_prefix'], $this->dataRecord); //* Prevent that the database name and charset is changed $old_record = $app->tform->getDataRecord($this->id); @@ -253,9 +252,9 @@ class page_action extends tform_actions { if($this->dataRecord['database_name'] == '') $app->tform->errorMessage .= $app->tform->wordbook["database_name_error_empty"].'<br />'; //* Get the database name and database user prefix - $app->uses('getconf'); + $app->uses('getconf,tools_sites'); $global_config = $app->getconf->get_global_config('sites'); - $dbname_prefix = replacePrefix($global_config['dbname_prefix'], $this->dataRecord); + $dbname_prefix = $app->tools_sites->replacePrefix($global_config['dbname_prefix'], $this->dataRecord); if(strlen($dbname_prefix . $this->dataRecord['database_name']) > 64) $app->tform->errorMessage .= str_replace('{db}',$dbname_prefix . $this->dataRecord['database_name'],$app->tform->wordbook["database_name_error_len"]).'<br />'; diff --git a/interface/web/sites/database_user_edit.php b/interface/web/sites/database_user_edit.php index 47ba8194636ffbea59c03842722162ded365aef1..651b20814327cf7593ecbf88366352c3273d1a40 100644 --- a/interface/web/sites/database_user_edit.php +++ b/interface/web/sites/database_user_edit.php @@ -40,7 +40,6 @@ $tform_def_file = "form/database_user.tform.php"; require_once('../../lib/config.inc.php'); require_once('../../lib/app.inc.php'); -require_once('tools.inc.php'); //* Check permissions for module $app->auth->check_module_permissions('sites'); @@ -60,9 +59,9 @@ class page_action extends tform_actions { */ //* Get the database user prefix - $app->uses('getconf'); + $app->uses('getconf,tools_sites'); $global_config = $app->getconf->get_global_config('sites'); - $dbuser_prefix = replacePrefix($global_config['dbuser_prefix'], $this->dataRecord); + $dbuser_prefix = $app->tools_sites->replacePrefix($global_config['dbuser_prefix'], $this->dataRecord); if ($_SESSION["s"]["user"]["typ"] != 'admin' && $app->auth->has_clients($_SESSION['s']['user']['userid'])) { // Get the limits of the client @@ -125,9 +124,9 @@ class page_action extends tform_actions { global $app, $conf, $interfaceConf; //* Get the database user prefix - $app->uses('getconf'); + $app->uses('getconf,tools_sites'); $global_config = $app->getconf->get_global_config('sites'); - $dbuser_prefix = replacePrefix($global_config['dbuser_prefix'], $this->dataRecord); + $dbuser_prefix = $app->tools_sites->replacePrefix($global_config['dbuser_prefix'], $this->dataRecord); //* Database username shall not be empty if($this->dataRecord['database_user'] == '') $app->tform->errorMessage .= $app->tform->wordbook["database_user_error_empty"].'<br />'; @@ -136,7 +135,7 @@ class page_action extends tform_actions { //* Check database user against blacklist $dbuser_blacklist = array($conf['db_user'],'mysql','root'); - if(in_array($dbname_prefix . $this->dataRecord['database_user'],$dbname_blacklist)) { + if(in_array($dbuser_prefix . $this->dataRecord['database_user'],$dbuser_blacklist)) { $app->tform->errorMessage .= $app->lng('Database user not allowed.').'<br />'; } @@ -156,15 +155,15 @@ class page_action extends tform_actions { if($this->dataRecord['database_user'] == '') $app->tform->errorMessage .= $app->tform->wordbook["database_user_error_empty"].'<br />'; //* Get the database name and database user prefix - $app->uses('getconf'); + $app->uses('getconf,tools_sites'); $global_config = $app->getconf->get_global_config('sites'); - $dbuser_prefix = replacePrefix($global_config['dbuser_prefix'], $this->dataRecord); + $dbuser_prefix = $app->tools_sites->replacePrefix($global_config['dbuser_prefix'], $this->dataRecord); if(strlen($dbuser_prefix . $this->dataRecord['database_user']) > 16) $app->tform->errorMessage .= str_replace('{user}',$dbuser_prefix . $this->dataRecord['database_user'],$app->tform->wordbook["database_user_error_len"]).'<br />'; //* Check database user against blacklist $dbuser_blacklist = array($conf['db_user'],'mysql','root'); - if(is_array($dbname_blacklist) && in_array($dbname_prefix . $this->dataRecord['database_user'],$dbname_blacklist)) { + if(is_array($dbuser_blacklist) && in_array($dbuser_prefix . $this->dataRecord['database_user'],$dbuser_blacklist)) { $app->tform->errorMessage .= $app->lng('Database user not allowed.').'<br />'; } diff --git a/interface/web/sites/ftp_user_edit.php b/interface/web/sites/ftp_user_edit.php index 2e8d4a7c11ce1c7e257ee24f0d9b7efaa6584160..9a956cc01d92bc6eb7a629d6120aaa8fba4601ff 100644 --- a/interface/web/sites/ftp_user_edit.php +++ b/interface/web/sites/ftp_user_edit.php @@ -40,7 +40,6 @@ $tform_def_file = "form/ftp_user.tform.php"; require_once('../../lib/config.inc.php'); require_once('../../lib/app.inc.php'); -require_once('tools.inc.php'); //* Check permissions for module $app->auth->check_module_permissions('sites'); @@ -74,10 +73,9 @@ class page_action extends tform_actions { * data can be edited */ - $app->uses('getconf'); + $app->uses('getconf,tools_sites'); $global_config = $app->getconf->get_global_config('sites'); - // $ftpuser_prefix = ($global_config['ftpuser_prefix'] == '')?'':str_replace('[CLIENTNAME]', $this->getClientName(), $global_config['ftpuser_prefix']); - $ftpuser_prefix = replacePrefix($global_config['ftpuser_prefix'], $this->dataRecord); + $ftpuser_prefix = $app->tools_sites->replacePrefix($global_config['ftpuser_prefix'], $this->dataRecord); if ($this->dataRecord['username'] != ""){ /* REMOVE the restriction */ @@ -115,10 +113,9 @@ class page_action extends tform_actions { function onBeforeInsert() { global $app, $conf, $interfaceConf; - $app->uses('getconf'); + $app->uses('getconf,tools_sites'); $global_config = $app->getconf->get_global_config('sites'); - //$ftpuser_prefix = ($global_config['ftpuser_prefix'] == '')?'':str_replace('[CLIENTNAME]', $this->getClientName(), $global_config['ftpuser_prefix']); - $ftpuser_prefix = replacePrefix($global_config['ftpuser_prefix'], $this->dataRecord); + $ftpuser_prefix = $app->tools_sites->replacePrefix($global_config['ftpuser_prefix'], $this->dataRecord); if ($app->tform->errorMessage == '') { $this->dataRecord['username'] = $ftpuser_prefix . $this->dataRecord['username']; @@ -150,10 +147,9 @@ class page_action extends tform_actions { * If the names should be restricted -> do it! */ - $app->uses('getconf'); + $app->uses('getconf,tools_sites'); $global_config = $app->getconf->get_global_config('sites'); - //$ftpuser_prefix = ($global_config['ftpuser_prefix'] == '')?'':str_replace('[CLIENTNAME]', $this->getClientName(), $global_config['ftpuser_prefix']); - $ftpuser_prefix = replacePrefix($global_config['ftpuser_prefix'], $this->dataRecord); + $ftpuser_prefix = $app->tools_sites->replacePrefix($global_config['ftpuser_prefix'], $this->dataRecord); /* restrict the names */ if ($app->tform->errorMessage == '') { @@ -180,27 +176,6 @@ class page_action extends tform_actions { } } - - function getClientName() { - global $app, $conf; - - if($_SESSION["s"]["user"]["typ"] != 'admin' && !$app->auth->has_clients($_SESSION['s']['user']['userid'])) { - // Get the group-id of the user - $client_group_id = $_SESSION["s"]["user"]["default_group"]; - } else { - // Get the group-id from the data itself - $web = $app->db->queryOneRecord("SELECT sys_groupid FROM web_domain WHERE domain_id = ".intval($this->dataRecord['parent_domain_id'])); - $client_group_id = $web['sys_groupid']; - } - /* get the name of the client */ - $tmp = $app->db->queryOneRecord("SELECT name FROM sys_group WHERE groupid = " . $client_group_id); - $clientName = $tmp['name']; - if ($clientName == "") $clientName = 'default'; - $clientName = convertClientName($clientName); - return $clientName; - - } - } $page = new page_action; diff --git a/interface/web/sites/shell_user_edit.php b/interface/web/sites/shell_user_edit.php index e09d8dde960585ba3b5bee4c3ff79d559e0a926f..2ce781d4dbd28a1a948edfb72503d6fa123c893d 100644 --- a/interface/web/sites/shell_user_edit.php +++ b/interface/web/sites/shell_user_edit.php @@ -40,7 +40,6 @@ $tform_def_file = "form/shell_user.tform.php"; require_once('../../lib/config.inc.php'); require_once('../../lib/app.inc.php'); -require_once('tools.inc.php'); //* Check permissions for module $app->auth->check_module_permissions('sites'); @@ -74,10 +73,9 @@ class page_action extends tform_actions { * data can be edited */ - $app->uses('getconf'); + $app->uses('getconf,tools_sites'); $global_config = $app->getconf->get_global_config('sites'); - //$shelluser_prefix = ($global_config['shelluser_prefix'] == '')?'':str_replace('[CLIENTNAME]', $this->getClientName(), $global_config['shelluser_prefix']); - $shelluser_prefix = replacePrefix($global_config['shelluser_prefix'], $this->dataRecord); + $shelluser_prefix = $app->tools_sites->replacePrefix($global_config['shelluser_prefix'], $this->dataRecord); if ($this->dataRecord['username'] != ""){ /* REMOVE the restriction */ @@ -136,10 +134,9 @@ class page_action extends tform_actions { */ if ($app->tform->errorMessage == ''){ - $app->uses('getconf'); + $app->uses('getconf,tools_sites'); $global_config = $app->getconf->get_global_config('sites'); - // $shelluser_prefix = ($global_config['shelluser_prefix'] == '')?'':str_replace('[CLIENTNAME]', $this->getClientName(), $global_config['shelluser_prefix']); - $shelluser_prefix = replacePrefix($global_config['shelluser_prefix'], $this->dataRecord); + $shelluser_prefix = $app->tools_sites->replacePrefix($global_config['shelluser_prefix'], $this->dataRecord); /* restrict the names */ $this->dataRecord['username'] = $shelluser_prefix . $this->dataRecord['username']; @@ -183,10 +180,9 @@ class page_action extends tform_actions { /* * If the names should be restricted -> do it! */ - $app->uses('getconf'); + $app->uses('getconf,tools_sites'); $global_config = $app->getconf->get_global_config('sites'); - // $shelluser_prefix = ($global_config['shelluser_prefix'] == '')?'':str_replace('[CLIENTNAME]', $this->getClientName(), $global_config['shelluser_prefix']); - $shelluser_prefix = replacePrefix($global_config['shelluser_prefix'], $this->dataRecord); + $shelluser_prefix = $app->tools_sites->replacePrefix($global_config['shelluser_prefix'], $this->dataRecord); /* restrict the names */ $this->dataRecord['username'] = $shelluser_prefix . $this->dataRecord['username']; @@ -198,28 +194,6 @@ class page_action extends tform_actions { } - - function getClientName() { - global $app, $conf; - - if($_SESSION["s"]["user"]["typ"] != 'admin' && !$app->auth->has_clients($_SESSION['s']['user']['userid'])) { - // Get the group-id of the user - $client_group_id = $_SESSION["s"]["user"]["default_group"]; - } else { - // Get the group-id from the data itself - $web = $app->db->queryOneRecord("SELECT sys_groupid FROM web_domain WHERE domain_id = ".intval($this->dataRecord['parent_domain_id'])); - $client_group_id = $web['sys_groupid']; - } - /* get the name of the client */ - $tmp = $app->db->queryOneRecord("SELECT name FROM sys_group WHERE groupid = " . $client_group_id); - $clientName = $tmp['name']; - if ($clientName == "") $clientName = 'default'; - $clientName = convertClientName($clientName); - - return $clientName; - - } - } $page = new page_action; diff --git a/interface/web/sites/tools.inc.php b/interface/web/sites/tools.inc.php deleted file mode 100644 index 262e2789737eaaf9958b0f400404932c334b29b8..0000000000000000000000000000000000000000 --- a/interface/web/sites/tools.inc.php +++ /dev/null @@ -1,129 +0,0 @@ -<?php -/* -Copyright (c) 2008, Till Brehm, projektfarm Gmbh -All rights reserved. - -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. -*/ - -function replacePrefix($name, $dataRecord) { - // No input -> no possible output -> go out! - if ($name=="") return ""; - - // Array containing keys to search - $keywordlist=array('CLIENTNAME','CLIENTID','DOMAINID'); - - // Try to match the key within the string - foreach ($keywordlist as $keyword) { - if (substr_count($name, '['.$keyword.']') > 0) { - switch ($keyword) { - case 'CLIENTNAME': - $name=str_replace('['.$keyword.']', getClientName($dataRecord),$name); - break; - case 'CLIENTID': - $name=str_replace('['.$keyword.']', getClientID($dataRecord),$name); - break; - case 'DOMAINID': - $name=str_replace('['.$keyword.']', $dataRecord['parent_domain_id'],$name); - break; - } - } - } - return $name; -} - -function getClientName($dataRecord) { - global $app, $conf; - if($_SESSION["s"]["user"]["typ"] != 'admin' && !$app->auth->has_clients($_SESSION['s']['user']['userid'])) { - // Get the group-id of the user if the logged in user is neither admin nor reseller - $client_group_id = $_SESSION["s"]["user"]["default_group"]; - } else { - // Get the group-id from the data itself - if(isset($dataRecord['client_group_id'])) { - $client_group_id = $dataRecord['client_group_id']; - } elseif (isset($dataRecord['parent_domain_id'])) { - $tmp = $app->db->queryOneRecord("SELECT sys_groupid FROM web_domain WHERE domain_id = " . $dataRecord['parent_domain_id']); - $client_group_id = $tmp['sys_groupid']; - } elseif(isset($dataRecord['sys_groupid'])) { - $client_group_id = $dataRecord['sys_groupid']; - } else { - $client_group_id = 0; - } - } - - /* get the name of the client */ - $tmp = $app->db->queryOneRecord("SELECT name FROM sys_group WHERE groupid = " . intval($client_group_id)); - $clientName = $tmp['name']; - if ($clientName == "") $clientName = 'default'; - $clientName = convertClientName($clientName); - return $clientName; -} - -function getClientID($dataRecord) { - global $app, $conf; - - if($_SESSION["s"]["user"]["typ"] != 'admin' && !$app->auth->has_clients($_SESSION['s']['user']['userid'])) { - // Get the group-id of the user - $client_group_id = $_SESSION["s"]["user"]["default_group"]; - } else { - // Get the group-id from the data itself - if(isset($dataRecord['client_group_id'])) { - $client_group_id = $dataRecord['client_group_id']; - } elseif (isset($dataRecord['parent_domain_id'])) { - $tmp = $app->db->queryOneRecord("SELECT sys_groupid FROM web_domain WHERE domain_id = " . $dataRecord['parent_domain_id']); - $client_group_id = $tmp['sys_groupid']; - } elseif(isset($dataRecord['sys_groupid'])) { - $client_group_id = $dataRecord['sys_groupid']; - } else { - $client_group_id = 0; - } - } - /* get the name of the client */ - $tmp = $app->db->queryOneRecord("SELECT client_id FROM sys_group WHERE groupid = " . intval($client_group_id)); - $clientID = $tmp['client_id']; - if ($clientID == '') $clientID = '0'; - return $clientID; -} - -function convertClientName($name){ - /** - * only allow 'a'..'z', '_', '0'..'9' - */ - $allowed = 'abcdefghijklmnopqrstuvwxyz0123456789_'; - $res = ''; - $name = strtolower(trim($name)); - for ($i=0; $i < strlen($name); $i++){ - if ($name[$i] == ' ') continue; - if (strpos($allowed, $name[$i]) !== false){ - $res .= $name[$i]; - } - else { - $res .= '_'; - } - } - return $res; -} - - -?> diff --git a/interface/web/sites/webdav_user_edit.php b/interface/web/sites/webdav_user_edit.php index 2d7dc41165d59df85a99dd0dd184b4f2c660be5f..05756c73803865ec2a42528f30ac9c27ab65b268 100644 --- a/interface/web/sites/webdav_user_edit.php +++ b/interface/web/sites/webdav_user_edit.php @@ -40,7 +40,6 @@ $tform_def_file = "form/webdav_user.tform.php"; require_once('../../lib/config.inc.php'); require_once('../../lib/app.inc.php'); -require_once('tools.inc.php'); //* Check permissions for module $app->auth->check_module_permissions('sites'); @@ -73,9 +72,9 @@ class page_action extends tform_actions { * If the names are restricted -> remove the restriction, so that the * data can be edited */ - $app->uses('getconf'); + $app->uses('getconf,tools_sites'); $global_config = $app->getconf->get_global_config('sites'); - $webdavuser_prefix = replacePrefix($global_config['webdavuser_prefix'], $this->dataRecord); + $webdavuser_prefix = $app->tools_sites->replacePrefix($global_config['webdavuser_prefix'], $this->dataRecord); if ($this->dataRecord['username'] != "") { /* REMOVE the restriction */ @@ -128,9 +127,9 @@ class page_action extends tform_actions { */ if ($app->tform->errorMessage == '') { - $app->uses('getconf'); + $app->uses('getconf,tools_sites'); $global_config = $app->getconf->get_global_config('sites'); - $webdavuser_prefix = replacePrefix($global_config['webdavuser_prefix'], $this->dataRecord); + $webdavuser_prefix = $app->tools_sites->replacePrefix($global_config['webdavuser_prefix'], $this->dataRecord); /* restrict the names */ $this->dataRecord['username'] = $webdavuser_prefix . $this->dataRecord['username'];