Standard_index.html functionality

Discussion in 'Installation/Configuration' started by niemand-glaumy, Nov 15, 2021.

  1. Vague title, sorry.
    Issue is, I would like to copy a whole brush of directories and files over to every new webroot I create with ISPC. Not only the one page. I already created it in conf-custom/index/ but how to get ISPC to use it?
     
  2. till

    till Super Moderator Staff Member ISPConfig Developer

    This can't be achieved like that. You'll have to write an ISPConfig server-side plugin instead which binds itself to the 'web_domain_insert' event.
     
  3. Okay. How? :D
    Mind spoonfeeding a little? :3
     
  4. florian030

    florian030 ISPConfig Developer ISPConfig Developer

    in addition to #2 the plugin must be run after most the of the other plugins bound to web_domain_insert. IIRC, they will be executed in alpabetical order.
    Have a look at the apache or nginx-plugin for the code "//* Copy the web skeleton files only when there is no index.php, standard_index.html or index.html file yet"
     
  5. Sorry what? Where? How?
     
  6. Taleman

    Taleman Well-Known Member HowtoForge Supporter

    If you really are going to modify ISPConfig code to add the functionality you need, surely you know to do
    Code:
    grep -r "Copy the web skeleton files only" /usr/local/ispconfig/
    to find the ISPConfig source files @florian030 writes about in #4.
    Don't ask me what modification to make, I do not know that. Plus I do not like coding in PHP.
     
  7. Thank you, I found it. I can do a bit of PHP. We will see if my knowledge will suffice. :3

    Do I understand it correctly, that the whole block is commented out to be disabled because at the moment it is "hard coded"? The default function will be replaced by this if I uncomment?

    Sorry, I need to ask stupid noobish questions. Ubuntu/Linux isn't my natural habitat and somehow I need to learn.
     
  8. atle

    atle Member HowtoForge Supporter

    This is the plugin code I use for a custom skeleton.
    PHP:
    <?php
    // Created: 2021/04/12 17:41:23
    // Last modified: 2021/04/14 09:05:57

    /**
     * Skapa custom skeleton för nya websites.
     *
     * Kopiera denna fil till /usr/local/ispconfig/server/plugins-available
     * och länka den sedan till plugins-enabled
     *
     */
    class z_apache2_customskel {

        
    /**
         * @var string
         */
        
    public $plugin_name 'z_apache2_customskel';
        
    /**
         * @var string
         */
        
    public $class_name 'z_apache2_customskel';

        
    // This function is called during ispconfig installation to determine
        //  if a symlink shall be created for this plugin.
        
    public function onInstall() {
            global 
    $conf;

            if (
    $conf['services']['web'] == true) {
                return 
    true;
            } else {
                return 
    false;
            }

        }

        
    /*
        This function is called when the plugin is loaded
         */

        
    public function onLoad() {
            global 
    $app;

            
    /*
            Register for the events
             */
            
    $app->plugins->registerEvent('web_domain_insert'$this->plugin_name'insert');
            
    $app->plugins->registerEvent('web_domain_update'$this->plugin_name'update');
            
    $app->plugins->registerEvent('web_domain_delete'$this->plugin_name'delete');
        }

        
    /**
         * @param $event_name
         * @param $data
         */
        
    public function insert($event_name$data) {
            global 
    $app$conf;

            
    $this->action 'insert';
            
    // just run the update function
            
    $this->update($event_name$data);

        }

        
    /**
         * @param $event_name
         * @param $data
         */
        
    public function update($event_name$data) {
            global 
    $app$conf;

            if (
    $this->action != 'insert') {
                
    $this->action 'update';
            }
            
    // file_put_contents("./QazQaz.log", var_export($data, true), FILE_APPEND);

            // load the server configuration options
            
    $app->uses('getconf');
            
    $web_config $app->getconf->get_server_config($conf['server_id'], 'web');

            if (
    $data['new']['document_root'] == '') {
                return 
    0;
            }

            if (
    $app->system->is_allowed_user($data['new']['system_user'], $app->system->is_user($data['new']['system_user']), true) == false
                
    || $app->system->is_allowed_group($data['new']['system_group'], $app->system->is_group($data['new']['system_group']), true) == false) {
                return 
    0;
            }
            if (
    trim($data['new']['domain']) == '') {
                return 
    0;
            }

            
    $web_folder     'web';
            
    $old_web_folder 'web';

            if (
    $data['new']['type'] == 'vhostsubdomain' || $data['new']['type'] == 'vhostalias') {
                
    // new one
                
    $tmp            $app->db->queryOneRecord('SELECT `domain` FROM web_domain WHERE domain_id = ?'$data['new']['parent_domain_id']);
                
    $subdomain_host preg_replace('/^(.*)\.' preg_quote($tmp['domain'], '/') . '$/''$1'$data['new']['domain']);
                if (
    $subdomain_host == '') {
                    
    $subdomain_host 'web' $data['new']['domain_id'];
                }

                
    $web_folder $data['new']['web_folder'];
                unset(
    $tmp);

                if (
    $app->system->is_blacklisted_web_path($web_folder)) {
                    return 
    0;
                }

            }

            
    //
            // Och nu kommer koden vi är ute efter
            //

            
    $owner $data['new']['system_user'];
            
    $group $data['new']['system_group'];

            
    // TB Autoconfig

            
    if (is_dir($conf['rootpath'] . '/conf-custom/index/.well-known')) {

                
    $app->system->exec_safe('cp -a ? ?',
                    
    $conf['rootpath'] . '/conf-custom/index/.well-known',
                    
    $data['new']['document_root'] . '/' $web_folder '/'
                
    );

                
    $app->system->exec_safe('chown -R ? ?',
                    
    $owner,
                    
    $data['new']['document_root'] . '/' $web_folder '/.well-known',
                );

                
    $app->system->exec_safe('chgrp -R ? ?',
                    
    $group,
                    
    $data['new']['document_root'] . '/' $web_folder '/.well-known',
                );
            }

            
    // Autodiscover in Outlook 2010

            
    if (is_dir($conf['rootpath'] . '/conf-custom/index/autodiscover')) {

                
    $app->system->exec_safe('cp -a ? ?',
                    
    $conf['rootpath'] . '/conf-custom/index/autodiscover',
                    
    $data['new']['document_root'] . '/' $web_folder '/'
                
    );

                
    $app->system->exec_safe('chown -R ? ?',
                    
    $owner,
                    
    $data['new']['document_root'] . '/' $web_folder '/autodiscover',
                );

                
    $app->system->exec_safe('chgrp -R ? ?',
                    
    $group,
                    
    $data['new']['document_root'] . '/' $web_folder '/autodiscover',
                );
            }

        }

        
    /**
         * @param $event_name
         * @param $data
         */
        
    public function delete($event_name$data) {
            global 
    $app$conf;

            
    // load the server configuration options
            // $app->uses('getconf');
            // $app->uses('system');
            // $web_config     = $app->getconf->get_server_config($conf['server_id'], 'web');
            // $fastcgi_config = $app->getconf->get_server_config($conf['server_id'], 'fastcgi');
        
    }

    }
    The skeleton it copies resides in "/usr/local/ispconfig/server/conf-custom/index/".
    You can use this code as a start.
     

Share This Page