Skip to content

antony@notes:~/container$ cat "批次建帳號-Apache-Guacamole.md"

批次建帳號 - Apache Guacamole

2023-02-24· container ·Apache Guacamole

批次建帳號 - Apache Guacamole

:::warning

:::spoiler 目錄

[TOC]

:::

Prepare

下載 Guacamole 套件

$ git clone https://gitlab.com/flysangel/oss_gmm.git

切換工作目錄

cd oss_gmm/rest-api

檢視工作目錄內容

$ ls -al
total 28
drwxr-sr-x 3 bigred bigred 4096 Jan 10 11:38 .
drwxr-sr-x 6 bigred bigred 4096 Jan 10 11:38 ..
-rw-r--r-- 1 bigred bigred  280 Jan 10 11:38 mapping.list
drwxr-sr-x 2 bigred bigred 4096 Jan 10 11:38 postman
-rw-r--r-- 1 bigred bigred  121 Jan 10 11:38 rest-api.conf
-rwxr-xr-x 1 bigred bigred 7360 Jan 10 11:38 rest-api.sh
  • mapping.list ,儲存要建立的帳號資訊
  • rest-api.conf,儲存 rest-api 程式執行時,要用什麼帳號登入哪一座落地雲的資訊
  • rest-api.shrest-api 程式本體

修改 rest-api.conf

$ nano rest-api.conf

修改內容

GUACAMOLESERVER='https://j509.flymks.com/#/'
DATASOURCE='mysql'
GUACADMIN='guacadmin'
GUACPASS='sreAa123456'
PASSLENGTH='10'
  • GUACAMOLESERVER,設定 Guacamole 的網址
  • GUACADMIN,設定 Guacamole 的管理員帳號
  • GUACPASS,設定 Guacamole 的管理員密碼
  • PASSLENGTH,設定使用者預設密碼長度幾個字元

測試 rest-api.sh 連線是否正常

$ ./rest-api.sh test

正常的螢幕輸出 :

Token: 37298158CF67FA0F7F5F60B752F999627A9B599CF128F607B3F017E3DC376886

設定要建立的 Connection 和 User

$ nano mapping.list

範例

# userAccount, userPassword, connGroup, connName, connProtocol, connIP, connPort, connAccount, connPassword
# ssh
guacadmin,,Manager.SSH,bigred.t1.01,ssh,192.168.1.01,22,bigred,!QAZ2wsx#EDC!!,
# rdp
guacadmin,,Manager.RDP,bigred.t2.11,rdp,192.168.1.11,3389,bigred,!QAZ2wsx#EDC!!,

:::spoiler 小確幸程式

  • 密碼需自行填寫
#!/bin/bash

[[ "$1" == "" ]] && echo "pls give a number, thx!" && exit 1

#example
#mj03b,,Manager.RDP,bigred.03,rdp,120.96.143.3,2599,bigred,!QAZ2wsx  ,

declare -i i=1

for ((i=1;i<=$1;i=i+1))
do
  if [[ "$i" -le "9"  ]]; then
    echo "mj0${i}b,,Manager.RDP,bigred.0${i},rdp,120.96.143.${i},2599,bigred,,"
  else
    echo "mj${i}b,,Manager.RDP,bigred.${i},rdp,120.96.143.${i},2599,bigred,,"
  fi
done

:::

執行程式批次建立帳號

$ ./rest-api.sh create