vogelor
2010-05-01 abdc67d2c6a8d1978ae2180b357993d9aefbcd01
the first remote-action (os update) is implemented (for debian)
1 files added
2 files modified
240 ■■■■ changed files
install/lib/installer_base.lib.php 97 ●●●●● patch | view | raw | blame | history
install/sql/ispconfig3.sql 5 ●●●●● patch | view | raw | blame | history
server/mods-available/remoteaction_core_module.inc.php 138 ●●●●● patch | view | raw | blame | history
install/lib/installer_base.lib.php
@@ -38,25 +38,21 @@
    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 @@
        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 @@
        
    }
    
    public function grant_master_database_rights()
    {
    public function grant_master_database_rights() {
        global $conf;
        
        if($conf['mysql']['master_slave_setup'] != 'y') return;
@@ -367,8 +361,7 @@
    }
    //** writes postfix configuration files
    public function process_postfix_config($configfile)
    {
    public function process_postfix_config($configfile) {
        global $conf;
        
        $config_dir = $conf['postfix']['config_dir'].'/';
@@ -386,8 +379,7 @@
        wf($full_file_name, $content);
    }
    public function configure_jailkit()
    {
    public function configure_jailkit() {
        global $conf;
        
        $cf = $conf['jailkit'];
@@ -395,8 +387,7 @@
        $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,8 +397,7 @@
        
    }
        
    public function configure_postfix($options = '')
    {
    public function configure_postfix($options = '') {
        global $conf;
        $cf = $conf['postfix'];
        $config_dir = $cf['config_dir'];
@@ -612,8 +602,7 @@
        
    }
    
    public function configure_pam()
    {
    public function configure_pam() {
        global $conf;
        $pam = $conf['pam'];
        //* configure pam for SMTP authentication agains the ispconfig database
@@ -632,8 +621,7 @@
    
    }
    
    public function configure_courier()
    {
    public function configure_courier() {
        global $conf;
        $config_dir = $conf['courier']['config_dir'];
        //* authmysqlrc
@@ -665,8 +653,7 @@
        wf($configfile, $content);
    }
    
    public function configure_dovecot()
    {
    public function configure_dovecot() {
        global $conf;
        
        $config_dir = $conf['dovecot']['config_dir'];
@@ -781,8 +768,7 @@
        
    }
    
    public function configure_spamassassin()
    {
    public function configure_spamassassin() {
        global $conf;
        
        //* Enable spamasasssin on debian and ubuntu
@@ -795,8 +781,7 @@
        wf($configfile, $content);
    }
    
    public function configure_getmail()
    {
    public function configure_getmail() {
        global $conf;
        
        $config_dir = $conf['getmail']['config_dir'];
@@ -814,8 +799,7 @@
    }
    
    
    public function configure_pureftpd()
    {
    public function configure_pureftpd() {
        global $conf;
        
        $config_dir = $conf['pureftpd']['config_dir'];
@@ -855,8 +839,7 @@
        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 @@
    
    
    
    public function configure_apache()
    {
    public function configure_apache() {
        global $conf;
        
        //* Create the logging directory for the vhost logfiles
@@ -990,8 +972,7 @@
        
    }
    
    public function configure_firewall()
    {
    public function configure_firewall() {
        global $conf;
        
        $dist_init_scripts = $conf['init_scripts'];
@@ -1051,8 +1032,7 @@
    }
    
    public function configure_vlogger()
    {
    public function configure_vlogger() {
        global $conf;
        
        //** Configure vlogger to use traffic logging to mysql (master) db
@@ -1077,8 +1057,7 @@
    
    }
    
    public function configure_apps_vhost()
    {
    public function configure_apps_vhost() {
        global $conf;
        
        //* Create the ispconfig apps vhost user and group
@@ -1142,8 +1121,7 @@
    
    }
    
    public function install_ispconfig()
    {
    public function install_ispconfig() {
        global $conf;
        
        $install_dir = $conf['ispconfig_install_dir'];
@@ -1218,9 +1196,12 @@
        
        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 @@
        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");
@@ -1426,8 +1407,7 @@
        }
    }
    
    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 @@
        
    }
    
    public function install_crontab()
    {
    public function install_crontab() {
        global $conf;
        
        //* Root Crontab
@@ -1521,8 +1500,7 @@
     * @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 @@
     * @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 @@
     * @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);
install/sql/ispconfig3.sql
@@ -1159,9 +1159,10 @@
  `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;
-- --------------------------------------------------------
server/mods-available/remoteaction_core_module.inc.php
New file
@@ -0,0 +1,138 @@
<?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');
    }
}
?>