From c22662a757e54582f2eed2cfb82e0763b2a80b2e Mon Sep 17 00:00:00 2001 From: Eric Date: Fri, 3 Feb 2023 14:28:35 +0800 Subject: [PATCH] perf: use Chromium browser feat: add code dialog --- apps/terminal/applets/chrome/app.py | 7 ++++ apps/terminal/applets/chrome/code_dialog.py | 37 +++++++++++++++++++ .../deploy_applet_host/playbook.yml | 35 +++++++++++------- 3 files changed, 65 insertions(+), 14 deletions(-) create mode 100644 apps/terminal/applets/chrome/code_dialog.py diff --git a/apps/terminal/applets/chrome/app.py b/apps/terminal/applets/chrome/app.py index 491f1e09d..426320f4f 100644 --- a/apps/terminal/applets/chrome/app.py +++ b/apps/terminal/applets/chrome/app.py @@ -7,6 +7,7 @@ from selenium.webdriver.chrome.service import Service from selenium.webdriver.common.by import By from selenium.webdriver.remote.webelement import WebElement +from code_dialog import CodeDialog from common import (Asset, User, Account, Platform, Step) from common import (BaseApplication) from common import (notify_err_message, block_input, unblock_input) @@ -16,6 +17,7 @@ class Command(Enum): TYPE = 'type' CLICK = 'click' OPEN = 'open' + CODE = 'code' def _execute_type(ele: WebElement, value: str): @@ -62,6 +64,11 @@ class StepAction: ele.click() elif self.command in ['open']: driver.get(self.value) + elif self.command == 'code': + unblock_input() + code_string = CodeDialog(title="Code Dialog", label="Code").wait_string() + block_input() + ele.send_keys(code_string) return True def _execute_command_type(self, ele, value): diff --git a/apps/terminal/applets/chrome/code_dialog.py b/apps/terminal/applets/chrome/code_dialog.py new file mode 100644 index 000000000..b3b93730c --- /dev/null +++ b/apps/terminal/applets/chrome/code_dialog.py @@ -0,0 +1,37 @@ +import tkinter as tk +from tkinter import StringVar, messagebox +from tkinter import ttk + + +class CodeDialog(object): + + def __init__(self, title=None, label="Code Dialog"): + self.root = tk.Tk() + self.root.title(title) + self.code = StringVar() + mainframe = ttk.Frame(self.root, padding="12 12 12 12") + mainframe.grid(column=0, row=0, ) + self.label = ttk.Label(mainframe, text=label, width=10) + self.input = ttk.Entry(mainframe, textvariable=self.code, width=20) + self.button = ttk.Button(mainframe, text="ok", command=self.click_ok, width=5,) + self.label.grid(row=1, column=0) + self.input.grid(row=1, column=1) + self.button.grid(row=2, column=1, sticky=tk.E) + self.root.bind('', self.click_ok) + + def wait_string(self): + # 局中 + self.root.eval('tk::PlaceWindow . center') + self.root.mainloop() + return self.code.get() + + def click_ok(self, *args, **kwargs): + if not self.code.get(): + messagebox.showwarning(title="warning", message="code is empty") + return + self.root.destroy() + + +if __name__ == '__main__': + code = CodeDialog(title="Code Dialog", label="Code: ").wait_string() + print(code) diff --git a/apps/terminal/automations/deploy_applet_host/playbook.yml b/apps/terminal/automations/deploy_applet_host/playbook.yml index 763df39a8..56f6a6b9d 100644 --- a/apps/terminal/automations/deploy_applet_host/playbook.yml +++ b/apps/terminal/automations/deploy_applet_host/playbook.yml @@ -125,33 +125,40 @@ pip install -r '{{ ansible_env.TEMP }}\pip_packages\requirements.txt' --no-index --find-links='{{ ansible_env.TEMP }}\pip_packages' - - name: Download chromedriver (chrome) + - name: Download chromedriver (Chromium) ansible.windows.win_get_url: url: "{{ APPLET_DOWNLOAD_HOST }}/download/applets/chromedriver_win32.zip" dest: "{{ ansible_env.TEMP }}\\chromedriver_win32.zip" - - name: Unzip chromedriver (chrome) + - name: Unzip chromedriver (Chromium) community.windows.win_unzip: src: "{{ ansible_env.TEMP }}\\chromedriver_win32.zip" dest: C:\Program Files\JumpServer\drivers - - name: Set chromedriver on the global system path (chrome) + - name: Download chromium zip package (Chromium) + ansible.windows.win_get_url: + url: "{{ APPLET_DOWNLOAD_HOST }}/download/applets/chrome-win.zip" + dest: "{{ ansible_env.TEMP }}\\chrome-win.zip" + + - name: Unzip chromedriver (Chromium) + community.windows.win_unzip: + src: "{{ ansible_env.TEMP }}\\chrome-win.zip" + dest: C:\Program Files\chrome-win + + - name: Set chromium and driver on the global system path (Chromium) ansible.windows.win_path: elements: + - 'C:\Program Files\chrome-win' - 'C:\Program Files\JumpServer\drivers' - - name: Download chrome msi package (chrome) - ansible.windows.win_get_url: - url: "{{ APPLET_DOWNLOAD_HOST }}/download/applets/googlechromestandaloneenterprise64.msi" - dest: "{{ ansible_env.TEMP }}\\googlechromestandaloneenterprise64.msi" + - name: Set Chromium variables diable Google Api (Chromium) + ansible.windows.win_environment: + level: machine + variables: + GOOGLE_API_KEY: '' + GOOGLE_DEFAULT_CLIENT_ID: '' + GOOGLE_DEFAULT_CLIENT_SECRET: '' - - name: Install chrome (chrome) - ansible.windows.win_package: - path: "{{ ansible_env.TEMP }}\\googlechromestandaloneenterprise64.msi" - state: present - arguments: - - /quiet - - - name: Download navicat161_premium_en package (navicat) ansible.windows.win_get_url: url: "{{ APPLET_DOWNLOAD_HOST }}/download/applets/navicat161_premium_en_x64.exe"