/
/
Creating a demo ispmanager panel

Creating a demo ispmanager panel

A demo panel clearly demonstrates ispmanager capabilities. Use it to demonstrate the panel to end clients and facilitate their familiarization with the product.

Step 1. Installing and configuring the panel

  1. Install ispmanager on the server.
  2. If necessary, configure an SSL certificate and domain.
  3. Create a user template named demo and set the desired limits for it.
  4. Create an administrator named sitedemo with access permissions to the Users section.

Step 2. Configuring demo display

Option 1

Configure a proxy on the website where the demo will be displayed. Applicable if a domain is not configured for ispmanager.

  1. Copy the value of the ForwardedSecret parameter from the panel's configuration file /usr/local/mgr5/etc/ispmgr.conf.

    If ForwardedSecret is not specified

    If the ForwardedSecret parameter is not in the configuration file, specify the value and copy it.

    After saving the changes, restart ispmanager via the console with the command:

    /usr/local/mgr5/sbin/mgrctl -m ispmgr exit
  2. In the server settings, add the following to the nginx configuration file: 

    location ~ ^/(ispmgr|manimg|mancgi|notify)(/.*)?$ {
        proxy_pass https://{PANEL_ADDRESS}:1500;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Secret {ForwardedSecret};
        chunked_transfer_encoding off;
    }

    where {PANEL_ADDRESS} is the IP address of the demo panel, and {ForwardedSecret} is the copied line from step 1.

  3. Add a button on the website page where you plan to host the demo. When clicked, it will send a request to the script: the script will create a user and return the login and password for logging into the demo panel. Here's an example JS handler for the button:

    document.querySelector('.js-start-demo').addEventListener('click', e => {
        e.preventDefault();
        const iframe = document.createElement('iframe');
        const wrapper = document.querySelector('.js-demo-wrapper');
    
        fetch('/start_demo.php').then(res => res.json()).then(res => {
            if (res.status === 'success') {
                iframe.src = '/ispmgr?lang=' + document.documentElement.lang;
                wrapper.append(iframe);
            } else {
                alert(res.message);
            }
        });
    });
    

    An example of a PHP script start_demo.php:

    <?php
    
    const PANEL_USERNAME = 'sitedemo'; // Administartor name
    const PANEL_PASSWORD = ''; // Administrator password
    const PANEL_ADDRESS = ''; // Panel address (IP or domain)
    
    /**
    * Generating password
    */
    function generate_password(int $length = 16) {
        $arr = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','1','2','3','4','5','6','7','8','9','0'];
        $pass = '';
        $count = count($arr);
        for($i = 0; $i < $length; $i++) {
            $pass .= $arr[random_int(0, $count-1)];
        }
        return $pass;
    }
    
    try {
        if (!empty($_COOKIE['ispmgr_demo_auth'])) {
            $authinfo = explode(':', $_COOKIE['ispmgr_demo_auth']);
            $name = $authinfo[0];
            $passwd = $authinfo[1];
        } else {
            $name = 'demo' . strtolower(generate_password(5)) . '_' . (time() + 3600);
            $passwd = generate_password();
            $create_user = file_get_contents('https://' . PANEL_ADDRESS . '/ispmgr?func=user.add.finish&sok=ok&authinfo=' . PANEL_USERNAME . ':' . PANEL_PASSWORD . '&out=bjson&preset=demo&addinfo=off&name=' . $name . '&passwd=' . $passwd);
            if (empty($create_user)) throw new \Exception('Error while create user');
            $create_user = json_decode($create_user, true);
            if (!empty($create_user['error']['msg'])) throw new \Exception($create_user['error']['msg']);
            setcookie('ispmgr_demo_auth', $name . ':' . $passwd, time() + 3600, '/', '', true);
        }
    
        $response = file_get_contents('https://' . $domain . '/ispmgr?func=auth&auth=' . ($_COOKIE['ispmgrses5'] ?? '') . '&username=' . $name . '&password=' . $passwd . '&out=bjson');
        if (empty($response)) throw new \Exception('Error while auth');
        $response = json_decode($response, true);
        if (!empty($response['error']['msg'])) throw new \Exception($response['error']['msg']);
        if (!empty($response['model']['auth'])) setcookie('ispmgrses5', $response['model']['auth'], time() + 3600, '/', '', true, true);
    
        $out = [
            'status' => 'success',
            'auth' => $response['model']['auth'],
        ];
    } catch (\Throwable $th) {
        $out = [
            'status' => 'error',
            'message' => $th->getMessage(),
        ];
    }
    
    echo json_encode($out);

Option 2

Configuration of a proxy in the panel. Applicable if a domain is configured for ispmanager.

  1. In the /etc/nginx/modules-includes/nginx_proxy/nginx_proxy_ssl.conf configuration file, add the following lines into location @ispmgr:

    proxy_cookie_path / "/; SameSite=None";
    add_header Content-Security-Policy "frame-ancestors 'self' {SITE_DOMAIN}";

    where {SITE_DOMAIN} is the domain of the website where the demo will be displayed.

  2. Go to the Web server settings section of the demo panel and click Save.
  3. Add a button on the website page where you plan to host the demo. When clicked, it will send a request to the script: the script will create a user and return the login and password for logging into the demo panel. Example JS handler for the button:

    document.querySelector('.js-start-demo').addEventListener('click', e => {
        e.preventDefault();
        const iframe = document.createElement('iframe');
        const wrapper = document.querySelector('.js-demo-wrapper');
    
        fetch('/start_demo.php').then(res => res.json()).then(res => {
            if (res.status === 'success') {
                iframe.src = res.url + '/ispmgr?lang=' + document.documentElement.lang + '&func=auth&username=' + res.username + '&password=' + res.password;
                wrapper.append(iframe);
            } else {
                alert(res.message);
            }
        });
    });

    An example of a PHP script start_demo.php:

    <?php
    
    const PANEL_USERNAME = 'sitedemo'; // Administrator name
    const PANEL_PASSWORD = ''; // Administrator password
    const PANEL_DOMAIN = ''; // Panel domain
    
    /**
    * Generating password
    */
    function generate_password(int $length = 16) {
        $arr = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','1','2','3','4','5','6','7','8','9','0'];
        $pass = '';
        $count = count($arr);
        for($i = 0; $i < $length; $i++) {
            $pass .= $arr[random_int(0, $count-1)];
        }
        return $pass;
    }
    
    try {
        if (!empty($_COOKIE['ispmgr_demo_auth'])) {
            $authinfo = explode(':', $_COOKIE['ispmgr_demo_auth']);
            $name = $authinfo[0];
            $passwd = $authinfo[1];
        } else {
            $name = 'demo' . strtolower(generate_password(5)) . '_' . (time() + 3600);
            $passwd = generate_password();
            $create_user = file_get_contents('https://' . PANEL_DOMAIN . '/ispmgr?func=user.add.finish&sok=ok&authinfo=' . PANEL_USERNAME . ':' . PANEL_PASSWORD . '&out=bjson&preset=demo&addinfo=off&name=' . $name . '&passwd=' . $passwd);
            if (empty($create_user)) throw new \Exception('Error while create user');
            $create_user = json_decode($create_user, true);
            if (!empty($create_user['error']['msg'])) throw new \Exception($create_user['error']['msg']);
            setcookie('ispmgr_demo_auth', $name . ':' . $passwd, time() + 3600, '/', '', true);
        }
    
        $out = [
            'status' => 'success',
            'url' => 'https://' . PANEL_DOMAIN,
            'username' => $name,
            'password' => $passwd,
        ];
    } catch (\Throwable $th) {
        $out = [
            'status' => 'error',
            'message' => $th->getMessage(),
        ];
    }
    
    echo json_encode($out);
    

Step 3. Configuring deletion of demo users

Create a script to delete demo users via CRON jobs in the demo panel every 5 minutes. 

An example of a PHP script:

<?php

const PANEL_USERNAME = 'sitedemo'; // Administrator name
const PANEL_PASSWORD = ''; // Administrator password
const PANEL_ADDRESS = ''; // Panel address (IP or domain)

$response = file_get_contents('https:// ' . PANEL_ADDRESS . '/ispmgr?func=user&authinfo=' . PANEL_USERNAME . ':' . PANEL_PASSWORD . '&out=bjson&p_cnt=1000');
if (empty($response)) throw new \Exception('Error while get users');
$response = json_decode($response, true);
if (!empty($response['error']['msg'])) throw new \Exception($response['error']['msg']);
if (empty($response['elem'])) exit;
$delete_users = [];
foreach ($response['elem'] as $user) {
	$name = explode('_', $user['name']);
	if (empty($name[1]) || $name[1] <= time()) $delete_users[] = $user['name'];
}
if (empty($delete_users)) exit;
$chunks = array_chunk($delete_users, 10);
foreach ($chunks as $users) {
	$elid = rawurlencode(implode(', ', $users));
	file_get_contents('https:// ' . PANEL_ADDRESS . '/ispmgr?func=user.delete&authinfo=' . PANEL_USERNAME . ':' . PANEL_PASSWORD . '&out=bjson&elid=' . $elid);
}