Commit abdc67d2 authored by vogelor's avatar vogelor
Browse files

the first remote-action (os update) is implemented (for debian)

parent f836a142
......@@ -38,25 +38,21 @@ class installer_base {
public $is_update = false; // true if it is an update, falsi if it is a new install
public function __construct()
{
public function __construct() {
global $conf; //TODO: maybe $conf should be passed to constructor
//$this->conf = $conf;
}
//: TODO Implement the translation function and language files for the installer.
public function lng($text)
{
public function lng($text) {
return $text;
}
public function error($msg)
{
public function error($msg) {
die("ERROR: ".$msg."\n");
}
public function simple_query($query, $answers, $default)
{
public function simple_query($query, $answers, $default) {
$finished = false;
do {
$answers_str = implode(',', $answers);
......@@ -86,8 +82,7 @@ class installer_base {
return $answer;
}
public function free_query($query,$default)
{
public function free_query($query,$default) {
swrite($this->lng($query).' ['.$default.']: ');
$input = sread();
......@@ -264,8 +259,7 @@ class installer_base {
}
public function grant_master_database_rights()
{
public function grant_master_database_rights() {
global $conf;
if($conf['mysql']['master_slave_setup'] != 'y') return;
......@@ -367,14 +361,13 @@ class installer_base {
}
//** writes postfix configuration files
public function process_postfix_config($configfile)
{
public function process_postfix_config($configfile) {
global $conf;
$config_dir = $conf['postfix']['config_dir'].'/';
$full_file_name = $config_dir.$configfile;
//* Backup exiting file
if(is_file($full_file_name)){
if(is_file($full_file_name)) {
copy($full_file_name, $config_dir.$configfile.'~');
}
$content = rf('tpl/'.$configfile.'.master');
......@@ -386,8 +379,7 @@ class installer_base {
wf($full_file_name, $content);
}
public function configure_jailkit()
{
public function configure_jailkit() {
global $conf;
$cf = $conf['jailkit'];
......@@ -395,8 +387,7 @@ class installer_base {
$jk_init = $cf['jk_init'];
$jk_chrootsh = $cf['jk_chrootsh'];
if (is_dir($config_dir))
{
if (is_dir($config_dir)) {
if(is_file($config_dir.'/'.$jk_init)) copy($config_dir.'/'.$jk_init, $config_dir.'/'.$jk_init.'~');
if(is_file($config_dir.'/'.$jk_chrootsh.".master")) copy($config_dir.'/'.$jk_chrootsh.".master", $config_dir.'/'.$jk_chrootsh.'~');
......@@ -406,13 +397,12 @@ class installer_base {
}
public function configure_postfix($options = '')
{
public function configure_postfix($options = '') {
global $conf;
$cf = $conf['postfix'];
$config_dir = $cf['config_dir'];
if(!is_dir($config_dir)){
if(!is_dir($config_dir)) {
$this->error("The postfix configuration directory '$config_dir' does not exist.");
}
......@@ -530,10 +520,10 @@ class installer_base {
caselog($command.' &> /dev/null', __FILE__, __LINE__, 'EXECUTED: '.$command, 'Failed to execute the command '.$command);
//* Changing maildrop lines in posfix master.cf
if(is_file($config_dir.'/master.cf')){
if(is_file($config_dir.'/master.cf')) {
copy($config_dir.'/master.cf', $config_dir.'/master.cf~');
}
if(is_file($config_dir.'/master.cf~')){
if(is_file($config_dir.'/master.cf~')) {
exec('chmod 400 '.$config_dir.'/master.cf~');
}
$configfile = $config_dir.'/master.cf';
......@@ -545,7 +535,7 @@ class installer_base {
//* Writing the Maildrop mailfilter file
$configfile = 'mailfilter';
if(is_file($cf['vmail_mailbox_base'].'/.'.$configfile)){
if(is_file($cf['vmail_mailbox_base'].'/.'.$configfile)) {
copy($cf['vmail_mailbox_base'].'/.'.$configfile, $cf['vmail_mailbox_base'].'/.'.$configfile.'~');
}
$content = rf("tpl/$configfile.master");
......@@ -612,8 +602,7 @@ class installer_base {
}
public function configure_pam()
{
public function configure_pam() {
global $conf;
$pam = $conf['pam'];
//* configure pam for SMTP authentication agains the ispconfig database
......@@ -632,13 +621,12 @@ class installer_base {
}
public function configure_courier()
{
public function configure_courier() {
global $conf;
$config_dir = $conf['courier']['config_dir'];
//* authmysqlrc
$configfile = 'authmysqlrc';
if(is_file("$config_dir/$configfile")){
if(is_file("$config_dir/$configfile")) {
copy("$config_dir/$configfile", "$config_dir/$configfile~");
}
exec("chmod 400 $config_dir/$configfile~");
......@@ -654,10 +642,10 @@ class installer_base {
//* authdaemonrc
$configfile = $conf['courier']['config_dir'].'/authdaemonrc';
if(is_file($configfile)){
if(is_file($configfile)) {
copy($configfile, $configfile.'~');
}
if(is_file($configfile.'~')){
if(is_file($configfile.'~')) {
exec('chmod 400 '.$configfile.'~');
}
$content = rf($configfile);
......@@ -665,17 +653,16 @@ class installer_base {
wf($configfile, $content);
}
public function configure_dovecot()
{
public function configure_dovecot() {
global $conf;
$config_dir = $conf['dovecot']['config_dir'];
//* Configure master.cf and add a line for deliver
if(is_file($config_dir.'/master.cf')){
if(is_file($config_dir.'/master.cf')) {
copy($config_dir.'/master.cf', $config_dir.'/master.cf~2');
}
if(is_file($config_dir.'/master.cf~')){
if(is_file($config_dir.'/master.cf~')) {
exec('chmod 400 '.$config_dir.'/master.cf~2');
}
$content = rf($conf["postfix"]["config_dir"].'/master.cf');
......@@ -708,14 +695,14 @@ class installer_base {
//* copy dovecot.conf
$configfile = 'dovecot.conf';
if(is_file("$config_dir/$configfile")){
if(is_file("$config_dir/$configfile")) {
copy("$config_dir/$configfile", "$config_dir/$configfile~");
}
copy('tpl/debian_dovecot.conf.master',"$config_dir/$configfile");
//* dovecot-sql.conf
$configfile = 'dovecot-sql.conf';
if(is_file("$config_dir/$configfile")){
if(is_file("$config_dir/$configfile")) {
copy("$config_dir/$configfile", "$config_dir/$configfile~");
}
exec("chmod 400 $config_dir/$configfile~");
......@@ -781,13 +768,12 @@ class installer_base {
}
public function configure_spamassassin()
{
public function configure_spamassassin() {
global $conf;
//* Enable spamasasssin on debian and ubuntu
$configfile = '/etc/default/spamassassin';
if(is_file($configfile)){
if(is_file($configfile)) {
copy($configfile, $configfile.'~');
}
$content = rf($configfile);
......@@ -795,8 +781,7 @@ class installer_base {
wf($configfile, $content);
}
public function configure_getmail()
{
public function configure_getmail() {
global $conf;
$config_dir = $conf['getmail']['config_dir'];
......@@ -814,18 +799,17 @@ class installer_base {
}
public function configure_pureftpd()
{
public function configure_pureftpd() {
global $conf;
$config_dir = $conf['pureftpd']['config_dir'];
//* configure pure-ftpd for MySQL authentication against the ispconfig database
$configfile = 'db/mysql.conf';
if(is_file("$config_dir/$configfile")){
if(is_file("$config_dir/$configfile")) {
copy("$config_dir/$configfile", "$config_dir/$configfile~");
}
if(is_file("$config_dir/$configfile~")){
if(is_file("$config_dir/$configfile~")) {
exec("chmod 400 $config_dir/$configfile~");
}
$content = rf('tpl/pureftpd_mysql.conf.master');
......@@ -855,8 +839,7 @@ class installer_base {
if(!is_file('/etc/pure-ftpd/conf/DontResolve')) exec("echo 'yes' > /etc/pure-ftpd/conf/DontResolve");
}
public function configure_mydns()
{
public function configure_mydns() {
global $conf;
// configure pam for SMTP authentication agains the ispconfig database
......@@ -926,8 +909,7 @@ class installer_base {
public function configure_apache()
{
public function configure_apache() {
global $conf;
//* Create the logging directory for the vhost logfiles
......@@ -990,8 +972,7 @@ class installer_base {
}
public function configure_firewall()
{
public function configure_firewall() {
global $conf;
$dist_init_scripts = $conf['init_scripts'];
......@@ -1010,7 +991,7 @@ class installer_base {
$row = $this->db->queryOneRecord("SELECT * FROM firewall WHERE server_id = ".intval($conf['server_id']));
if(trim($row["tcp_port"]) != '' || trim($row["udp_port"]) != ''){
if(trim($row["tcp_port"]) != '' || trim($row["udp_port"]) != '') {
$tcp_public_services = trim(str_replace(',',' ',$row["tcp_port"]));
$udp_public_services = trim(str_replace(',',' ',$row["udp_port"]));
} else {
......@@ -1051,8 +1032,7 @@ class installer_base {
}
public function configure_vlogger()
{
public function configure_vlogger() {
global $conf;
//** Configure vlogger to use traffic logging to mysql (master) db
......@@ -1077,8 +1057,7 @@ class installer_base {
}
public function configure_apps_vhost()
{
public function configure_apps_vhost() {
global $conf;
//* Create the ispconfig apps vhost user and group
......@@ -1142,8 +1121,7 @@ class installer_base {
}
public function install_ispconfig()
{
public function install_ispconfig() {
global $conf;
$install_dir = $conf['ispconfig_install_dir'];
......@@ -1176,7 +1154,7 @@ class installer_base {
//* Create the config file for ISPConfig interface
$configfile = 'config.inc.php';
if(is_file($install_dir.'/interface/lib/'.$configfile)){
if(is_file($install_dir.'/interface/lib/'.$configfile)) {
copy("$install_dir/interface/lib/$configfile", "$install_dir/interface/lib/$configfile~");
}
$content = rf("tpl/$configfile.master");
......@@ -1198,7 +1176,7 @@ class installer_base {
//* Create the config file for ISPConfig server
$configfile = 'config.inc.php';
if(is_file($install_dir.'/server/lib/'.$configfile)){
if(is_file($install_dir.'/server/lib/'.$configfile)) {
copy("$install_dir/server/lib/$configfile", "$install_dir/interface/lib/$configfile~");
}
$content = rf("tpl/$configfile.master");
......@@ -1218,9 +1196,12 @@ class installer_base {
wf("$install_dir/server/lib/$configfile", $content);
//* Create the config file for remote-actions
$content = "<?php\n$maxid_remote_actions = 1;\n?>";
wf("$install_dir/server/lib/remote_actions.inc.php", $content);
//* Create the config file for remote-actions (but only, if it does not exist, because
// the value is a autoinc-value and so changed by the remoteaction_core_module
if (!file_exists("$install_dir/server/lib/remote_action.inc.php")) {
$content = '<?php' . "\n" . '$maxid_remote_action = 0;' . "\n?>";
wf("$install_dir/server/lib/remote_action.inc.php", $content);
}
//* Enable the server modules and plugins.
// TODO: Implement a selector which modules and plugins shall be enabled.
......@@ -1323,8 +1304,8 @@ class installer_base {
exec("chmod 600 $install_dir/server/lib/$configfile");
exec("chown root:root $install_dir/server/lib/$configfile");
exec("chmod 600 $install_dir/server/lib/remote_actions.inc.php");
exec("chown root:root $install_dir/server/lib/remote_actions.inc.php");
exec("chmod 600 $install_dir/server/lib/remote_action.inc.php");
exec("chown root:root $install_dir/server/lib/remote_action.inc.php");
if(@is_file("$install_dir/server/lib/mysql_clientdb.conf")) {
exec("chmod 600 $install_dir/server/lib/mysql_clientdb.conf");
......@@ -1404,7 +1385,7 @@ class installer_base {
exec('chmod 744 /usr/local/bin/run-getmail.sh');
//* Add Log-Rotation
if (is_dir('/etc/logrotate.d')){
if (is_dir('/etc/logrotate.d')) {
unlink('/etc/logrotate.d/logispc3');
$fh = fopen('/etc/logrotate.d/logispc3', 'w');
fwrite($fh,
......@@ -1426,8 +1407,7 @@ class installer_base {
}
}
public function configure_dbserver()
{
public function configure_dbserver() {
global $conf;
//* If this server shall act as database server for client DB's, we configure this here
......@@ -1450,8 +1430,7 @@ class installer_base {
}
public function install_crontab()
{
public function install_crontab() {
global $conf;
//* Root Crontab
......@@ -1521,8 +1500,7 @@ class installer_base {
* @param bool $tDBCred
* @return string Relative path to the chosen template file
*/
protected function get_template_file($tLocal, $tRf=false, $tDBCred=false)
{
protected function get_template_file($tLocal, $tRf=false, $tDBCred=false) {
global $conf, $dist;
$final_path = '';
......@@ -1553,11 +1531,9 @@ class installer_base {
* @param $tContents
* @return bool
*/
protected function write_config_file($tConf, $tContents)
{
protected function write_config_file($tConf, $tContents) {
// Backup config file before writing new contents and stat file
if ( is_file($tConf) )
{
if ( is_file($tConf) ) {
$stat = exec('stat -c \'%a %U %G\' '.escapeshellarg($tConf), $output, $res);
if ($res == 0) { // stat successfull
list($access, $user, $group) = split(" ", $stat);
......@@ -1606,8 +1582,7 @@ class installer_base {
* @param $tContents
* @return string
*/
protected function insert_db_credentials($tContents)
{
protected function insert_db_credentials($tContents) {
global $conf;
$tContents = str_replace('{mysql_server_ispconfig_user}', $conf["mysql"]["ispconfig_user"], $tContents);
......
......@@ -1159,9 +1159,10 @@ CREATE TABLE `sys_remoteaction` (
`tstamp` int(11) NOT NULL,
`action_type` varchar(20) NOT NULL,
`action_param` mediumtext NOT NULL,
`action_status` enum('pending','ok','warning','error') NOT NULL,
`action_state` enum('pending','ok','warning','error') NOT NULL,
`response` mediumtext NOT NULL,
PRIMARY KEY (`action_id`)
PRIMARY KEY (`action_id`),
KEY `server_id` (`server_id`)
) ENGINE=MyISAM;
-- --------------------------------------------------------
......
<?php
/*
Copyright (c) 2007-2010, 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 remoteaction_core_module {
var $module_name = 'remoteaction_core_module';
var $class_name = 'remoteaction_core_module';
/* No actions at this time. maybe later... */
var $actions_available = array();
//* This function is called during ispconfig installation to determine
// if a symlink shall be created for this plugin.
function onInstall() {
return true;
}
/*
This function is called when the module is loaded
*/
function onLoad() {
/*
* Check for actions to execute
*/
$this->_execActions();
}
/*
This function is called when a change in one of the registered tables is detected.
The function then raises the events for the plugins.
*/
function process($tablename, $action, $data) {
// not needed
} // end function
private function _actionDone($id, $state) {
/*
* First set the state
*/
global $app;
$sql = "UPDATE sys_remoteaction " .
"SET action_state = '" . $app->dbmaster->quote($state) . "' " .
"WHERE action_id = " . intval($id);
$app->dbmaster->query($sql);
/*
* Then save the maxid for the next time...
*/
$fp = fopen(dirname(__FILE__) . "/../lib/remote_action.inc.php", 'wb');
$content = '<?php' . "\n" . '$maxid_remote_action = ' . $id . ';' . "\n?>";
fwrite($fp, $content);
fclose($fp);
}
/**
* This method searches for scheduled actions and exec then
*/
private function _execActions() {
global $app;
global $conf;
/* the id of the server as int */
$server_id = intval($conf["server_id"]);
/*
* First we (till and i, oliver) thought, it was enough to write
* "select from where action_status = 'pending'" and then execute this actions.
* But it is not!
* If a hacker can hack into a server, she can change the valus of action_status
* and so re-exec a action, executed some days bevore. So she can (for example)
* stop a service, a admin stopped some days before! To avoid this, we ignore
* the status (it is only for the interface to show) and use our own maxid
*/
include_once (dirname(__FILE__) . "/../lib/remote_action.inc.php");
/*
* Get all actions this server should execute
*/
$sql = "SELECT action_id, action_type, action_param " .
"FROM sys_remoteaction " .
"WHERE server_id = " . $server_id . " ".
" AND action_id > " . intval($maxid_remote_action) . " ".
"ORDER BY action_id";
$actions = $app->dbmaster->queryAllRecords($sql);
/*
* process all actions
*/
foreach ($actions as $action) {
if ($action['action_type'] == 'os_update') {
/* do the update */
$this->_doOsUpdate($action);
/* this action takes so much time,
* we stop executing the actions not to waste more time */
return;
}
}
}
private function _doOsUpdate($action) {
/*
* Do the update
*/
exec("aptitude update");
exec("aptitude upgrade -y");
/*
* All well done!
*/
$this->_actionDone($action['action_id'], 'ok');
}
}
?>
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment