Перейти к основному контенту

Custome Applet structure for RemoteApp

What is an applet?

An applet is a set of files that describe the process of installing and launching an application on Microsoft RDS via RemoteApp. This is necessary for JumpServer to initiate an access session to this application, automatically log in, and hide the authorization parameters from the user.

Applet Structure

Each applet must include the following files:

AppletName
  ├── i18n.yml
  ├── icon.png
  ├── main.py
  ├── manifest.yml
  └── setup.yml

main.py - script for launching and logging into the application

icon.png - applet icon

manifest.yml - metadata, i.e., applet description

setup.yml - file describing the installation process

i18n.yml - file for translation into various languages

File manifest.yml

Example based on the MySQL Workbench applet

The file manifest.yml contains general information about the applet and specifies its type and protocol.

# (required)
name: mysql_workbench8
display_name: "{{ 'MySQL Workbench' | trans }}"
comment: "{{ 'A tool for working with MySQL, to execute SQL and design tables' | trans }}"
# (required)
version: 0.1.1
# (required)
exec_type: python
# (required)
author: Eric
# general or web (required)
type: general
update_policy: always
edition: community
# (required)
tags:
  - database
# (required)
protocols:
  - mysqlworkbench

# translations into other languages
i18n:
  MySQL Workbench:
    en: MySQL Workbench
    zh: MySQL Workbench
    ja: MySQL Workbench

  A tool for working with MySQL, to execute SQL and design tables:
    en: A tool for working with MySQL, to execute SQL and design tables
    zh: 用于与MySQL一起工作的工具,用于执行SQL和设计表
    ja: MySQLでSQLを実行し、テーブルを設計するためのツール

File setup.yml

The file setup.yml describes the parameters for installing the applet on the RDS server.

# software installation type - msi, exe, zip, manual
type: msi
# URL to download the software distribution or file name if the distribution is included with the applet archive
source: mysql-workbench-community-8.0.31-winx64.msi
# installation arguments
arguments:
  - /qn
  - /norestart
# installation directory
destination: C:\Program Files\MySQL\MySQL Workbench 8.0 CE
# path and name of the executable file
program: C:\Program Files\MySQL\MySQL Workbench 8.0 CE\MySQLWorkbench.exe
md5: d628190252133c06dad399657666974a
Script main.py

main.py - the main script of the applet

The application is launched by running the command:

python main.py base64_json_data

That is, the main.py script is launched, and the launch parameters are passed to it. The base64_json_data structure looks approximately as follows:

{
  "app_name": "mysql_workbench8",
  "protocol": "mysql",
  "user": {
    "id": "2647CA35-5CAD-4DDF-8A88-6BD88F39BB30",
    "name": "Administrator",
    "username": "admin"
  },
  "asset": {
    "asset_id": "46EE5F50-F1C1-468C-97EE-560E3436754C",
    "asset_name": "test_mysql",
    "address": "192.168.1.1",
    "protocols": [
      {
        "id": 2,
        "name": "mysql",
        "port": 3306
      }
    ]
  },
  "account": {
    "account_id": "9D5585DE-5132-458C-AABE-89A83C112A83",
    "username": "root",
    "secret": "test"
  },
  "platform": {
    "charset": "UTF-8"
  }
}
Contents of main.py
import sys

from common import (block_input, unblock_input)  # Import functions for blocking/unblocking input
from common import convert_base64_to_dict  # Import function to convert Base64 string to a dictionary (array)
from app import AppletApplication  # Import main application

def main():
    base64_str = sys.argv[1]  # Get the Base64 string from command-line arguments
    data = convert_base64_to_dict(base64_str)  # Convert Base64 string to a dictionary
    # The data dictionary contains all the parameters for launching the application: account, server name, database name, etc., depending on the application type
    applet_app = AppletApplication(**data)  # Pass dictionary data to the application launch function
    block_input()  # Block user input
    applet_app.run()  # Launch the application
    unblock_input()  # Unblock user input
    applet_app.wait()  # Wait for the application to complete

if __name__ == '__main__':
    try:
        main()  # Launch the main function
    except Exception as e:
        print(e)  # Output the error if it occurs

Contents of app.py

App.py typically contains all the main code for launching the application with the required parameters, making it the most important and complex part when developing a new applet. It is easier to base it on one of the scripts of existing applets that are similar in structure/type to the new applet being developed.

import sys  # Import the sys module to work with system functions

if sys.platform == 'win32':  # Check if the operating system is Windows
    from pywinauto import Application  # Import library for automating Windows GUI applications
    from pywinauto.controls.uia_controls import (ButtonWrapper, EditWrapper, MenuItemWrapper,
                                                 MenuWrapper, ComboBoxWrapper, ToolbarWrapper)
    # Import various controls for interacting with the application interface

from common import (BaseApplication, wait_pid, )  # Import the