diff --git a/afu/README.ARCH.md b/afu/README.ARCH.md index 2e87ece..24102d3 100644 --- a/afu/README.ARCH.md +++ b/afu/README.ARCH.md @@ -172,9 +172,9 @@ Set the **console keyboard layout**, make the changes persistent in *vconsole.co # echo KEYMAP=de-latin1 > /etc/vconsole.conf -### Set Hostname *debian* (or any other name) +### Set Hostname *archlinux* (or any other name) - # echo debian > /etc/hostname + # echo archlinux > /etc/hostname ### Enable the DHCP, the Dynamic Host Configuration Protocol Run diff --git a/afu/README.md b/afu/README.md index 74e0928..58fa63a 100644 --- a/afu/README.md +++ b/afu/README.md @@ -66,7 +66,7 @@ If it is not already installed, then: Afterwards, selenium is installed: $ sudo apt install python3-selenium - + #### SSH key generation The program `openssh` is preinstalled on Debian systems. But there is no private/public key installed yet. Best practices generating the key pair: @@ -103,29 +103,24 @@ Clone the repository `script` to your site with: ~/gitea$ git clone ssh://git@kuschel.at:21861/public/scripts.git +### Check and Test a Website +Either go to the directory `~/gitea/scripts/afu/` and run the file `test.py` or create a similar one: + #!/usr/bin/python3 + from selenium import webdriver + from selenium.webdriver.chrome.service import Service as ChromiumService + print('We try to connect to https://kuschel.at and get an answer "Family Kuschel and friends"') + options = webdriver.ChromeOptions() + options.add_argument('--headless') + options.add_argument('--no-sandbox') + options.add_argument('--disable-dev-shm-usage') + driver = webdriver.Chrome(options=options) + driver.get("https://kuschel.at") + print(driver.title) + driver.close() - - - - -Ensure you can run `pip` from command line - - $ python3 -m pip --version - -If pip isn’t already installed ("No module named pip"), then first try to bootstrap it from the standard library - - $ python3 -m ensurepip --default-pip - -If this does not work, install the package - - $ sudo apt install python3-pip - -Also `sudo apt install pip` should work. - - $ pip install webdriver-manager - +-- @@ -156,10 +151,72 @@ Because Arch linux is a rolling distribution, simply update the version to the l $ sudo pacman -Syuv +#### Installing of yay (package manager yet another yogurt) + $ sudo pacman -Sy --needed git base-devel + $ cd + $ git clone https://aur.archlinux.org/yay.git + $ cd yay + $ makepkg -si - sudo pacman -S python +#### Python3 +Check if Python is already installed in Arch Linux: -Alternative when `yay` is installed: + $ python --version + Python 3.12.3 + +If it is not already installed, then: + + $ yay -S python + +#### Chromium Browser + + $ yay -S chromium + +#### Manager (selenium) +Afterwards, selenium is installed: + + $ yay -S python-selenium + + $ yay -S selenium-manager + +#### SSH key generation + +The program `openssh` is not preinstalled on Arch Linux. Also, there is no private/public key installed yet. + + $ yay -S openssh + + Best practices generating the key pair: + + $ ssh-keygen -t ed25519 -C "your_email@example.com" + +Personally, I don't use a different name for the keys, I just click through the process. +The same applies to the passphrase. +Now go to the website https://git.kuschel.at and copy the content of the public key from ~/.ssh/id__ed25519.pub to the "Manage SSH keys" -- via "Add Key". + + $ cat .ssh/id_ed25519.pub + +#### Git installation and clone the scripts from git.kuschel.at + + $ yay -S git less + +You have to globally configure your `git` with: + + $ git config --global user.name "John Doe" + $ git config --global user.email your_email@example.com +Checking the git configuration with: + + $ git config -l + user.name= + user.email= + etc. + +Now create a folder and cd into it + + $ mkdir gitea + $ cd gitea + +Clone the repository `script` to your site with: + + ~/gitea$ git clone ssh://git@kuschel.at:21861/public/scripts.git - yay -S python diff --git a/afu/callbook.py b/afu/callbook.py new file mode 100755 index 0000000..01097c0 --- /dev/null +++ b/afu/callbook.py @@ -0,0 +1,115 @@ +#!/usr/bin/env python3 +# Thomas Kuschel, following with more .... +# changes to python-seleniumbase 4.25/4.27.5-1 python-selenium 4.21.0-1 (installed) +# changes: +# #001 The Tab URL at phpmyadmin has changed from server_export to server/export +# #002 The the visibility of the site is critically, so we have to put in the line option.add_argument('window-size=1200x600') + +import argparse +#import datetime +import os +import time +#import re +import sys + +#import grab +# yay extra/python-pip +# pip install selenium +# ! pip install webdriver-manager +# yay geckodriver (for Firefox browser) + +import selenium + +from selenium import webdriver +from selenium.webdriver.common.by import By +from selenium.webdriver.common.keys import Keys +from selenium.webdriver.chrome.service import Service + +__version__ = '2.0.1' + +def call_website(url,username,password,server,verbose=0,interactive=False): + # using Chrome to access web + # driver = webdriver.Firefox(executable_path=r'/usr/bin/geckodriver') + + if(interactive): + print('Interactive') + driver = webdriver.Chrome() + else: # do a headless script base work (default) + print('Headless Script') + service = Service(executable_path='/usr/bin/chromedriver') + option = webdriver.ChromeOptions() + option.add_argument('headless') + option.add_argument('window-size=1200x600') + driver = webdriver.Chrome(options=option, service=service) + + driver.get(url) + assert "phpMyAdmin" in driver.title + + print('Driver-Title: ' + driver.title) + elem = driver.find_element(By.ID, "input_username") + elem.clear() + elem.send_keys(username) + elem = driver.find_element(By.ID, "input_password") + elem.clear() + elem.send_keys(password) + elem = driver.find_element(By.ID, "select_server") + from selenium.webdriver.support.ui import Select + select = Select(driver.find_element(By.ID, 'select_server')) + select.select_by_visible_text(server) + driver.find_element(By.ID, "input_go").click() + time.sleep(1) + #driver.find_element(By.LINK_TEXT, "Export").click() + #driver.find_element_by_xpath('//a[contains(@href,"server_export")]').click() + #print(driver.page_source.encode("utf-8")) + element = driver.find_element(By.XPATH,'//a[contains(@href,"server/export")]') + print("Element is visible? " + str(element.is_displayed())) + element.click() + time.sleep(5) + driver.find_element(By.ID, "buttonGo").click() + time.sleep(1) + print(driver.current_window_handle) + + #w = driver.window_handles[1] + #driver.switch_to.window(child) + #driver.fullscreen_window() + try: + # WebDriverWait(browser, 3).until(EC.alert_is_present(), + # 'Timed out waiting for PA creation ' + + # 'confirmation popup to appear.') + alert = driver.switch_to.alert + alert.accept() + print("alert accepted") + except: + print("no alert") + + time.sleep(20) + driver.close() + +if __name__ == '__main__': + parser = argparse.ArgumentParser( + description='Automates the download of the amateur radio callsign list from Austria', + epilog=''' + Written by Thomas Kuschel, + Version {} + '''.format(__version__)) + + parser.add_argument('--interactive', '-i', action='store_true', default=False) + parser.add_argument('--verbose', '-v', action='count', default=0) + parser.add_argument('--version', action='version', version='{} {}'.format(os.path.split(__file__)[1],__version__)) + # parser.parse_args(['--version']) + parser.add_argument('url', metavar='URL', help='phpMyAdmin login page URL') + parser.add_argument('--username', '-u', default='', help='phpMyAdmin login username', required=False) + parser.add_argument('--password', '-p', default='', help='phpMyAdmin login password', required=False) + parser.add_argument('--server', '-s', default='kreios', required=False) + + args = parser.parse_args() + + try: + print(f'Try calling {args.url}') + filename = call_website(**vars(args)) + sys.exit(0) + except Exception as e: + print('Error: {}'.format(e), file=sys.stderr) + sys.exit(1) + + print('Verbose level: {}'.format(args.verbose)) diff --git a/afu/mi2.py b/afu/mi2.py new file mode 100755 index 0000000..ad8e545 --- /dev/null +++ b/afu/mi2.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +# Thomas Kuschel, following with more .... +# changes to python-seleniumbase 4.25/4.27.5-1 python-selenium 4.21.0-1 (installed) +# changes: +# #001 The Tab URL at phpmyadmin has changed from server_export to server/export +# #002 The the visibility of the site is critically, so we have to put in the line option.add_argument('window-size=1200x600') + +import argparse +#import datetime +import os +import time +#import re +import sys + +#import grab +# yay extra/python-pip +# pip install selenium +# ! pip install webdriver-manager +# yay geckodriver (for Firefox browser) + +import selenium + +from selenium import webdriver +from selenium.webdriver.common.by import By +from selenium.webdriver.common.keys import Keys +from selenium.webdriver.chrome.service import Service + +__version__ = '2.0.1' + +def call_website(url,username,password,server,verbose=0,interactive=False): + # using Chrome to access web + # driver = webdriver.Firefox(executable_path=r'/usr/bin/geckodriver') + + if(interactive): + print('Interactive') + driver = webdriver.Chrome() + else: # do a headless script base work (default) + print('Headless Script') + service = Service(executable_path='/usr/bin/chromedriver') + option = webdriver.ChromeOptions() + option.add_argument('headless') + option.add_argument('window-size=1200x600') + driver = webdriver.Chrome(options=option, service=service) + + driver.get(url) + assert "phpMyAdmin" in driver.title + + print('Driver-Title: ' + driver.title) + elem = driver.find_element(By.ID, "input_username") + elem.clear() + elem.send_keys(username) + elem = driver.find_element(By.ID, "input_password") + elem.clear() + elem.send_keys(password) + elem = driver.find_element(By.ID, "select_server") + from selenium.webdriver.support.ui import Select + select = Select(driver.find_element(By.ID, 'select_server')) + select.select_by_visible_text(server) + driver.find_element(By.ID, "input_go").click() + time.sleep(1) + #driver.find_element(By.LINK_TEXT, "Export").click() + #driver.find_element_by_xpath('//a[contains(@href,"server_export")]').click() + #print(driver.page_source.encode("utf-8")) + element = driver.find_element(By.XPATH,'//a[contains(@href,"server/export")]') + print("Element is visible? " + str(element.is_displayed())) + element.click() + time.sleep(5) + driver.find_element(By.ID, "buttonGo").click() + time.sleep(1) + print(driver.current_window_handle) + + #w = driver.window_handles[1] + #driver.switch_to.window(child) + #driver.fullscreen_window() + try: + # WebDriverWait(browser, 3).until(EC.alert_is_present(), + # 'Timed out waiting for PA creation ' + + # 'confirmation popup to appear.') + alert = driver.switch_to.alert + alert.accept() + print("alert accepted") + except: + print("no alert") + + time.sleep(20) + driver.close() + +if __name__ == '__main__': + parser = argparse.ArgumentParser( + description='Automates downloading the SQL dump via phpMyAdmin', + epilog=''' + Written by Thomas Kuschel, + inspired by Christoph Haunschmidt et al., + Version {} + '''.format(__version__)) + + parser.add_argument('--interactive', '-i', action='store_true', default=False) + parser.add_argument('--verbose', '-v', action='count', default=0) + parser.add_argument('--version', action='version', version='{} {}'.format(os.path.split(__file__)[1],__version__)) + # parser.parse_args(['--version']) + parser.add_argument('url', metavar='URL', help='phpMyAdmin login page URL') + parser.add_argument('--username', '-u', default='', help='phpMyAdmin login username', required=False) + parser.add_argument('--password', '-p', default='', help='phpMyAdmin login password', required=False) + parser.add_argument('--server', '-s', default='kreios', required=False) + + args = parser.parse_args() + + try: + print(f'Try calling {args.url}') + filename = call_website(**vars(args)) + sys.exit(0) + except Exception as e: + print('Error: {}'.format(e), file=sys.stderr) + sys.exit(1) + + print('Verbose level: {}'.format(args.verbose))