Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

How to install plugin via API ? #2222

Open
mean-cj opened this issue Jun 13, 2023 · 1 comment
Open

How to install plugin via API ? #2222

mean-cj opened this issue Jun 13, 2023 · 1 comment

Comments

@mean-cj
Copy link

mean-cj commented Jun 13, 2023

Hi

How to auto install plugin via API ?
now i know only set enable plugin.

   $_ENV['RAINLOOP_INCLUDE_AS_API'] = true;
    include '/var/www/html/rainloop/index.php';

    $oConfig = \RainLoop\Api::Config();
    $oConfig->SetPassword('xxxxxx');

   $oConfig->set('plugins','enable',true);
   $oConfig->set('plugins','enabled_list','add-x-originating-ip-header,directadmin-change-password');

Thank you

@mean-cj mean-cj changed the title How to install plugin via API How to install plugin via API ? Jun 13, 2023
@mean-cj
Copy link
Author

mean-cj commented Jun 14, 2023

I can fly.

Rainloop auto config , auto install plugins , auto set imap command.

#!/bin/bash

  $RAINLOOP_ADMIN_PASSWORD="";
  $MYSQL_DB="";
  $MYSQL_USER="";
  $MYSQL_PASSWORD="";

 php -r "$(tr -d "\n" <<EOF
    error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING);
    \$_ENV['RAINLOOP_INCLUDE_AS_API'] = true;
    include '/var/www/html/rainloop/index.php';

    \$oConfig = \RainLoop\Api::Config();
    \$oConfig->SetPassword('$RAINLOOP_ADMIN_PASSWORD');

    echo "[OK] Rainloop - Config database [$MYSQL_DB, $MYSQL_USER, $MYSQL_PASSWORD] to rainloop\n";
    \$oConfig->set('contacts','enable',true);
    \$oConfig->set('contacts','pdo_dsn', 'mysql:host=localhost;port=3306;dbname=$MYSQL_DB');
    \$oConfig->set('contacts','pdo_user','$MYSQL_USER');
    \$oConfig->set('contacts','pdo_password','$MYSQL_PASSWORD');

    echo  \$oConfig->Save() ? '[OK] Rainloop - Custom config save. ' : '[ERROR] Cannot save custom config.';
    echo "\\n";

    \$oActions = \RainLoop\Actions::NewInstance();
    \$oActions->SetActionParams([
        'Login' => 'admin',
        'Password' => '$RAINLOOP_ADMIN_PASSWORD',
    ],'DoAdminLogin');
    echo \$oActions->DoAdminLogin() ? '[OK] Rainloop - Admin Logined.' : '[ERROR] Admin cannot login';
    echo "\\n";
   
    echo  \$oActions -> DoAdminContactsTest() ? '[OK] Rainloop - Import Database ' : '[ERROR] Cannot Import Database.';
    echo "\\n";

    /*app/libraries/RainLoop/Model/Domain.php*/
    \$oDomain = \RainLoop\Model\Domain::NewInstance(
        '*',  /*name*/
        '127.0.0.1', 993, 1, 0, /*imap  [host,port,secure,shortlogin]*/
        0 , 0 , 4190 , 0, /*Sieve configuration*/
        '127.0.0.1', 465, 1, 0 , 1, /*smtp [host,port,secure,shortlogin,authentication]*/
        false, ''
    );
    \$oDomainProvider = \$oActions->DomainProvider();
    echo \$oDomainProvider->Save(\$oDomain) ? '[OK] Rainloop - IMAP config save.' : '[ERROR] Cannot save IMAP config';
    echo "\\n";

    \$plugin_packages = (\$plugin_packages = \$oActions->DoAdminPackagesList()) ?  \$plugin_packages['Result']['List'] : [];
    \$plugin_installed = \$oActions->Plugins()->InstalledPlugins();
    \$plugin_installation = array('directadmin-change-password','add-x-originating-ip-header');

    foreach( \$plugin_installation as \$plugin_installation_id )
    {
        if(!in_array_recursive(\$plugin_installation_id,\$plugin_installed)){
            \$plugin = getArrayBySubArrayKey(\$plugin_packages,'id',\$plugin_installation_id);
            if(!\$plugin) continue;

            \$oActions->SetActionParams([
                'Id' => \$plugin['id'],
                'Type' => 'plugin',
                'File' => \$plugin['file']
            ],'AdminPackageInstall');
            echo \$oActions->DoAdminPackageInstall() ? "[OK] Rainloop - Plugin [{\$plugin['id']}] v{\$plugin['version']} installed" : "[ERROR] Cannot install [{\$plugin['id']}]";
            echo "\\n";
        }
    }

    \$oConfig->set('plugins','enable',true);
    \$oConfig->set('plugins','enabled_list', implode(',',\$plugin_installation));
    \$oConfig->Save();

    function getArrayBySubArrayKey(\$array, \$subArrayKey, \$subArrayValue) {
        \$subArray = array_column(\$array, null, \$subArrayKey);
        if (isset(\$subArray[\$subArrayValue])) { return \$subArray[\$subArrayValue]; }
        return null;
    }

    function in_array_recursive(\$needle, \$haystack) {
        \$it = new RecursiveIteratorIterator(new RecursiveArrayIterator(\$haystack));
        foreach(\$it AS \$element) { if(\$element == \$needle) { return true; } } return false;
    }

    echo "\\n";
EOF
)"

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant