Commit e2d6ed95 authored by tbrehm's avatar tbrehm

- added basic update script

- improved several functions in site module
- added server classes to restart services
parent b4c75070
......@@ -115,17 +115,19 @@ calmd
spamd
*/
exec("/etc/init.d/mysql restart");
exec("/etc/init.d/postfix restart");
exec("/etc/init.d/saslauthd restart");
exec("/etc/init.d/amavis restart");
exec("/etc/init.d/clamav-daemon restart");
exec("/etc/init.d/courier-authdaemon restart");
exec("/etc/init.d/courier-imap restart");
exec("/etc/init.d/courier-imap-ssl restart");
exec("/etc/init.d/courier-pop restart");
exec("/etc/init.d/courier-pop-ssl restart");
exec("/etc/init.d/apache2 restart");
swriteln('Restarting services ...');
system("/etc/init.d/mysql restart");
system("/etc/init.d/postfix restart");
system("/etc/init.d/saslauthd restart");
system("/etc/init.d/amavis restart");
system("/etc/init.d/clamav-daemon restart");
system("/etc/init.d/courier-authdaemon restart");
system("/etc/init.d/courier-imap restart");
system("/etc/init.d/courier-imap-ssl restart");
system("/etc/init.d/courier-pop restart");
system("/etc/init.d/courier-pop-ssl restart");
system("/etc/init.d/apache2 restart");
system("/etc/init.d/pure-ftpd-mysql restart");
echo "Installation finished.\n";
......
......@@ -467,6 +467,8 @@ maildrop unix - n n - - pipe
wf($conf["dist_pureftpd_config_dir"].'/'.$configfile,$content);
exec('chmod 600 '.$conf["dist_pureftpd_config_dir"].'/'.$configfile);
exec('chown root:root '.$conf["dist_pureftpd_config_dir"].'/'.$configfile);
// enable chrooting
exec('echo "yes" > /etc/pure-ftpd/conf/ChrootEveryone');
}
......
......@@ -404,6 +404,8 @@ CREATE TABLE `server` (
-- Daten für Tabelle `server`
--
INSERT INTO `server` (`server_id`, `sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `server_name`, `mail_server`, `web_server`, `dns_server`, `file_server`, `db_server`, `vserver_server`, `config`, `updated`, `active`) VALUES (1, 1, 1, 'riud', 'riud', 'r', 'Server 1', 1, 1, 1, 1, 1, 1, '[global]\nwebserver=apache\nmailserver=postfix\ndnsserver=mydns\n\n[mail]\nmodule=postfix_mysql\nmaildir_path=/home/vmail/[domain]/[localpart]/\nhomedir_path=/home/vmail/\nmailuser_uid=5000\nmailuser_gid=5000\nmailuser_name=vmail\nmailuser_group=vmail\n\n[getmail]\ngetmail_config_dir=/etc/getmail\n\n[web]\nwebsite_path=/var/clients/client[client_id]/web[website_id]\nwebsite_symlinks=/var/www/[website_domain]/:/var/clients/client[client_id]/[website_domain]/\n\n', 0, 1);
-- --------------------------------------------------------
--
......
<?php
/*
Copyright (c) 2007, 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.
*/
/*
ISPConfig 3 installer.
*/
// Include the library with the basic installer functions
require_once('lib/install.lib.php');
// Include the base class of the installer class
require_once('lib/installer_base.lib.php');
$distname = get_distname();
include_once("/usr/local/ispconfig/server/lib/config.inc.php");
$conf_old = $conf;
unset $conf;
// Include the distribution specific installer class library
// and configuration
include_once('dist/lib/'.$distname.'.lib.php');
include_once('dist/conf/'.$distname.'.conf.php');
// Set the mysql login information
$conf["mysql_server_host"] = $conf_old["db_host"];
$conf["mysql_server_database"] = $conf_old["db_database"];
$conf["mysql_server_ispconfig_user"] = $conf_old["db_user"];
$conf["mysql_server_ispconfig_password"] = $conf_old["db_password"];
$inst = new installer();
echo "This application will update ISPConfig 3 on your server.\n";
// $conf["language"] = $inst->request_language();
// TODO: all other queries, for testing I will setup everything in $conf
// Initialize the MySQL server connection
include_once('lib/mysql.lib.php');
$inst->db = new db();
// Database update is a bit brute force and should be rebuild later ;)
// export the current database data
exec("mysqldump -h $conf[mysql_server_host] -u $conf[mysql_server_ispconfig_user] -p$conf[mysql_server_ispconfig_password] -c -t --add-drop-table --add-locks --all --quick --lock-tables $conf[mysql_server_database] > existing_db.sql &> /dev/null");
// Delete the old database
exec("/etc/init.d/mysql stop");
exec("rm -rf /var/lib/mysql/".$conf["db_database"]);
exec("/etc/init.d/mysql start");
// Create the mysql database
$inst->configure_database();
// empty all databases
$db_tables = $inst->db->getTables();
foreach($db_tables as $table) {
$inst->db->query("TRUNCATE $table");
}
// load old data back into database
exec("mysql -h $conf[mysql_server_host] -u $conf[mysql_server_ispconfig_user] -p$conf[mysql_server_ispconfig_password] $conf[mysql_server_database] < existing_db.sql &> /dev/null");
// Configure postfix
$inst->configure_postfix();
// Configure saslauthd
swriteln('Configuring SASL');
$inst->configure_saslauthd();
// Configure PAM
swriteln('Configuring PAM');
$inst->configure_pam();
// Configure courier
swriteln('Configuring Courier');
$inst->configure_courier();
// Configure Spamasassin
swriteln('Configuring Spamassassin');
$inst->configure_spamassassin();
// Configure Amavis
swriteln('Configuring Amavisd');
$inst->configure_amavis();
// Configure Getmail
swriteln('Configuring Getmail');
$inst->configure_getmail();
// Configure Getmail
swriteln('Configuring Pureftpd');
$inst->configure_pureftpd();
// Configure ISPConfig
swriteln('Installing ISPConfig');
$inst->install_ispconfig();
// Configure ISPConfig
swriteln('Installing Crontab');
$inst->install_crontab();
/*
Restart services:
*/
swriteln('Restarting services ...');
system("/etc/init.d/mysql restart");
system("/etc/init.d/postfix restart");
system("/etc/init.d/saslauthd restart");
system("/etc/init.d/amavis restart");
system("/etc/init.d/clamav-daemon restart");
system("/etc/init.d/courier-authdaemon restart");
system("/etc/init.d/courier-imap restart");
system("/etc/init.d/courier-imap-ssl restart");
system("/etc/init.d/courier-pop restart");
system("/etc/init.d/courier-pop-ssl restart");
system("/etc/init.d/apache2 restart");
system("/etc/init.d/pure-ftpd-mysql restart");
echo "Update finished.\n";
?>
\ No newline at end of file
......@@ -766,9 +766,7 @@ class tform {
$app->error("Primary ID fehlt!");
}
}
// Daten in History tabelle speichern
if($this->errorMessage == '' and $this->formDef['db_history'] == 'yes') $this->datalogSave($action,$primary_id,$record);
return $sql;
}
......@@ -839,11 +837,16 @@ class tform {
// Set Wordbook for this form
$app->tpl->setVar($this->wordbook);
}
}
function getDataRecord($primary_id) {
global $app;
$sql = "SELECT * FROM ".$escape.$this->formDef['db_table'].$escape." WHERE ".$this->formDef['db_table_idx']." = ".$primary_id;
return $app->db->queryOneRecord($sql);
}
function datalogSave($action,$primary_id,$record_new) {
function datalogSave($action,$primary_id, $record_old, $record_new) {
global $app,$conf;
// Fge Backticks nur bei unvollstndigen Tabellennamen ein
......@@ -852,17 +855,19 @@ class tform {
} else {
$escape = '`';
}
if($action == "UPDATE") {
/*
if($action == "UPDATE" or $action == "DELETE") {
$sql = "SELECT * FROM ".$escape.$this->formDef['db_table'].$escape." WHERE ".$this->formDef['db_table_idx']." = ".$primary_id;
$record_old = $app->db->queryOneRecord($sql);
} else {
$record_old = array();
}
*/
$diffrec = array();
if(is_array($record_new)) {
if(is_array($record_new) && count($record_new) > 0) {
foreach($record_new as $key => $val) {
if($record_old[$key] != $val) {
// Record has changed
......@@ -870,13 +875,22 @@ class tform {
'new' => $val);
}
}
} elseif(is_array($record_old)) {
foreach($record_old as $key => $val) {
if($record_new[$key] != $val) {
// Record has changed
$diffrec[$key] = array('new' => $record_new[$key],
'old' => $val);
}
}
}
$this->diffrec = $diffrec;
// Full diff records for ISPConfig, they have a different format then the simple diffrec
$diffrec_full = array();
if(is_array($record_old)) {
if(is_array($record_old) && count($record_old) > 0) {
foreach($record_old as $key => $val) {
if(isset($record_new[$key]) && $record_new[$key] != $val) {
// Record has changed
......@@ -887,6 +901,17 @@ class tform {
$diffrec_full['new'][$key] = $val;
}
}
} elseif(is_array($record_new)) {
foreach($record_new as $key => $val) {
if(isset($record_new[$key]) && $record_old[$key] != $val) {
// Record has changed
$diffrec_full['new'][$key] = $val;
$diffrec_full['old'][$key] = $record_old[$key];
} else {
$diffrec_full['new'][$key] = $val;
$diffrec_full['old'][$key] = $val;
}
}
}
/*
......@@ -903,7 +928,11 @@ class tform {
$diffstr = $app->db->quote(serialize($diffrec_full));
$username = $app->db->quote($_SESSION["s"]["user"]["username"]);
$dbidx = $this->formDef['db_table_idx'].":".$primary_id;
$action = ($action == 'INSERT')?'i':'u';
// $action = ($action == 'INSERT')?'i':'u';
if($action == 'INSERT') $action = 'i';
if($action == 'UPDATE') $action = 'u';
if($action == 'DELETE') $action = 'd';
$sql = "INSERT INTO sys_datalog (dbtable,dbidx,server_id,action,tstamp,user,data) VALUES ('".$this->formDef['db_table']."','$dbidx','$server_id','$action','".time()."','$username','$diffstr')";
$app->db->query($sql);
}
......
......@@ -102,9 +102,13 @@ class tform_actions {
$ext_where = '';
$sql = $app->tform->getSQL($this->dataRecord,$app->tform->getCurrentTab(),'UPDATE',$this->id,$ext_where);
if($app->tform->errorMessage == '') {
if($app->tform->formDef['db_history'] == 'yes') {
$old_data_record = $app->tform->getDataRecord($this->id);
}
if(!empty($sql)) {
$app->db->query($sql);
$app->db->query($sql);
if($app->db->errorMessage != '') die($app->db->errorMessage);
}
......@@ -118,6 +122,14 @@ class tform_actions {
}
$this->onAfterUpdate();
// Write data history (sys_datalog)
if($app->tform->formDef['db_history'] == 'yes') {
$new_data_record = $app->tform->getDataRecord($this->id);
$app->tform->datalogSave('UPDATE',$this->id,$old_data_record,$new_data_record);
unset($new_data_record);
unset($old_data_record);
}
if($_REQUEST["next_tab"] == '') {
$list_name = $_SESSION["s"]["form"]["return_to"];
......@@ -176,6 +188,13 @@ class tform_actions {
$this->onAfterInsert();
// Write data history (sys_datalog)
if($app->tform->formDef['db_history'] == 'yes') {
$new_data_record = $app->tform->getDataRecord($this->id);
$app->tform->datalogSave('INSERT',$this->id,array(),$new_data_record);
unset($new_data_record);
}
if($_REQUEST["next_tab"] == '') {
$list_name = $_SESSION["s"]["form"]["return_to"];
......@@ -260,20 +279,10 @@ class tform_actions {
$record_old = $app->db->queryOneRecord("SELECT * FROM ".$liste["table"]." WHERE ".$liste["table_idx"]." = ".$this->id);
// Saving record to datalog when db_history enabled
if($form["db_history"] == 'yes') {
$diffrec = array();
foreach($record_old as $key => $val) {
// Record has changed
$diffrec[$key] = array('old' => $val,
'new' => '');
}
$diffstr = $app->db->quote(serialize($diffrec));
$username = $app->db->quote($_SESSION["s"]["user"]["username"]);
$dbidx = $app->tform->formDef['db_table_idx'].":".$this->id;
$sql = "INSERT INTO sys_datalog (dbtable,dbidx,action,tstamp,user,data) VALUES ('".$app->tform->formDef['db_table']."','$dbidx','d','".time()."','$username','$diffstr')";
$app->db->query($sql);
if($app->tform->formDef["db_history"] == 'yes') {
$old_data_record = $app->tform->getDataRecord($this->id);
$app->tform->datalogSave('DELETE',$this->id,$old_data_record,array());
unset($old_data_record);
}
$app->db->query("DELETE FROM ".$liste["table"]." WHERE ".$liste["table_idx"]." = ".$this->id);
......
......@@ -99,6 +99,7 @@ $form["tabs"]['ftp'] = array (
'password' => array (
'datatype' => 'VARCHAR',
'formtype' => 'PASSWORD',
'encryption' => 'CRYPT',
'default' => '',
'value' => '',
'width' => '30',
......@@ -138,26 +139,26 @@ $form["tabs"]['advanced'] = array (
# Begin Datatable fields
##################################
'uid' => array (
'datatype' => 'INTEGER',
'datatype' => 'VARCHAR',
'formtype' => 'TEXT',
'validators' => array ( 0 => array ( 'type' => 'NOTEMPTY',
'errmsg'=> 'uid_error_empty'),
),
'default' => '0',
'value' => '',
'width' => '5',
'maxlength' => '5'
'width' => '30',
'maxlength' => '255'
),
'gid' => array (
'datatype' => 'INTEGER',
'datatype' => 'VARCHAR',
'formtype' => 'TEXT',
'validators' => array ( 0 => array ( 'type' => 'NOTEMPTY',
'errmsg'=> 'uid_error_empty'),
),
'default' => '0',
'value' => '',
'width' => '5',
'maxlength' => '5'
'width' => '30',
'maxlength' => '255'
),
'dir' => array (
'datatype' => 'VARCHAR',
......
<table width="500" border="0" cellspacing="0" cellpadding="2">
<tr>
<td class="frmText11">{tmpl_var name='uid_txt'}:</td>
<td class="frmText11"><input name="uid" type="text" class="text" value="{tmpl_var name='uid'}" size="5" maxlength="5"></td>
<td class="frmText11"><input name="uid" type="text" class="text" value="{tmpl_var name='uid'}" size="30" maxlength="255"></td>
</tr>
<tr>
<td class="frmText11">{tmpl_var name='gid_txt'}:</td>
<td class="frmText11"><input name="gid" type="text" class="text" value="{tmpl_var name='gid'}" size="5" maxlength="5"></td>
<td class="frmText11"><input name="gid" type="text" class="text" value="{tmpl_var name='gid'}" size="30" maxlength="255"></td>
</tr>
<tr>
<td class="frmText11">{tmpl_var name='dir_txt'}:</td>
......
......@@ -167,7 +167,8 @@ class page_action extends tform_actions {
// Get configuration for the web system
$app->uses("getconf");
$web_config = $app->getconf->get_server_config(intval($this->dataRecord["server_id"]),'web');
$web_rec = $app->tform->getDataRecord($this->id);
$web_config = $app->getconf->get_server_config(intval($web_rec["server_id"]),'web');
$document_root = str_replace("[website_id]",$this->id,$web_config["website_path"]);
// get the ID of the client
......@@ -202,7 +203,8 @@ class page_action extends tform_actions {
// Get configuration for the web system
$app->uses("getconf");
$web_config = $app->getconf->get_server_config(intval($this->dataRecord["server_id"]),'web');
$web_rec = $app->tform->getDataRecord($this->id);
$web_config = $app->getconf->get_server_config(intval($web_rec["server_id"]),'web');
$document_root = str_replace("[website_id]",$this->id,$web_config["website_path"]);
// get the ID of the client
......@@ -211,7 +213,7 @@ class page_action extends tform_actions {
$client = $app->db->queryOneRecord("SELECT client_id FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id");
$client_id = intval($client["client_id"]);
} else {
$client_id = intval($this->dataRecord["client_group_id"]);
$client_id = intval($web_rec["client_group_id"]);
$client = $app->db->queryOneRecord("SELECT client_id FROM sys_group WHERE sys_group.groupid = ".intval($this->dataRecord["client_group_id"]));
$client_id = intval($client["client_id"]);
}
......
NameVirtualHost *:80
# NameVirtualHost *:80
<VirtualHost <tmpl_var name='ip_address'>:80>
DocumentRoot <tmpl_var name='document_root'>
ServerName <tmpl_var name='domain'>
ServerAlias <tmpl_var name='alias'>
<tmpl_if name='cgi'>
</tmpl_if>
<tmpl_if name='ssi'>
</tmpl_if>
<tmpl_if name='suexec'>
</tmpl_if>
<tmpl_if name='php' op='==' value='mod'>
</tmpl_if>
<tmpl_if name='php' op='==' value='suphp'>
</tmpl_if>
<tmpl_if name='php' op='==' value='cgi'>
</tmpl_if>
<tmpl_if name='cgi'>
# cgi enabled
</tmpl_if>
<tmpl_if name='ssi'>
# ssi enabled
</tmpl_if>
<tmpl_if name='suexec'>
# suexec enabled
</tmpl_if>
<tmpl_if name='php' op='==' value='mod'>
# mod_php enabled
</tmpl_if>
<tmpl_if name='php' op='==' value='suphp'>
# suphp enabled
</tmpl_if>
<tmpl_if name='php' op='==' value='cgi'>
# php as cgi enabled
</tmpl_if>
</VirtualHost>
\ No newline at end of file
This diff is collapsed.
<?php
/*
Copyright (c) 2007, projektfarm Gmbh, Till Brehm, Falko Timme
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 services {
var $registered_services = array();
var $delayed_restarts = array();
// This function adds a request for restarting
// a service at the end of the configuration run.
function restartServiceDelayed($service_name,$action = 'restart') {
global $app;
if(is_array($this->registered_services[$service_name])) {
$this->delayed_restarts[$service_name] = $action;
} else {
$app->log("Unable to add a delayed restart for '$service_name'. Service '$service_name' is not registered.",LOGLEVEL_WARNING);
}
}
// This function restarts a service when the function is called
function restartService($service_name,$action = 'restart') {
global $app;
if(is_array($this->registered_services[$service_name])) {
$module_name = $this->registered_services[$service_name]["module"];
$function_name = $this->registered_services[$service_name]["function"];
$app->log("Call function '$function_name' in module '$module_name'.",LOGLEVEL_DEBUG);
call_user_method($function_name,$app->loaded_modules[$module_name],$action);
} else {
$app->log("Unable to restart $service_name. Service $service_name is not registered.",LOGLEVEL_WARNING);
}
}
// This function is used to register callback functions for services that can be restarted
function registerService($service_name,$module_name, $function_name) {
global $app;
$this->registered_services[$service_name] = array('module' => $module_name, 'function' => $function_name);
$app->log("Registered Service '$service_name' in module '$module_name' for processing function '$function_name'",LOGLEVEL_DEBUG);
}
// This function is called at the end of the server script to restart services.
function processDelayedActions() {
global $app;
foreach($this->delayed_restarts as $service_name => $action) {
$this->restartService($service_name,$action);
}
}
}
?>
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// | PHP version 4.0 |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002 Active Fish Group |
// +----------------------------------------------------------------------+
// | Authors: Kelvin Jones <kelvin@kelvinjones.co.uk> |
// +----------------------------------------------------------------------+
//
// $Id: cache.php,v 1.1 2003/07/08 12:32:06 platinum Exp $
/**
* Class uses all of vlibTemplate's functionality but caches the template files.
* It creates an identical tree structure to your filesystem but with cached files.
*
* @author Kelvin Jones <kelvin@kelvinjones.co.uk>
* @since 22/02/2002
* @package vLIB
* @access public
*/
class tplc extends tpl {
/*-----------------------------------------------------------------------------\
| DO NOT TOUCH ANYTHING IN THIS CLASS, IT MAY NOT WORK OTHERWISE |
\-----------------------------------------------------------------------------*/
var $_cache = 1; // tells vlibTemplate that we're caching
var $_cachefile; // full path to current cache file (even if it doesn't yet exist)
var $_cacheexists; // has this file been cached before
var $_cachefilelocked; // is this file currently locked whilst writing
var $_cachefiledir; // dir of current cache file
var $_clearcache = 0;