1
0
Fork 0
mirror of https://github.com/postmannen/ctrl.git synced 2024-12-14 12:37:31 +00:00

added scripts

This commit is contained in:
postmannen 2021-10-05 09:25:39 +02:00
parent 86c3f3a847
commit 6106e9e3ac
8 changed files with 113 additions and 8 deletions

View file

@ -0,0 +1,28 @@
#!/bin/bash
#user=$(LC_ALL=C tr -dc 'A-Za-z0-9!"#$%&'\''()*+,-./:;<=>?@[\]^_`{|}~' </dev/urandom | head -c 13 ; echo)
#pw=$(LC_ALL=C tr -dc 'A-Za-z0-9!"#$%&'\''()*+,-./:;<=>?@[\]^_`{|}~' </dev/urandom | head -c 13 ; echo)
webuser=$(
LC_ALL=C tr -dc 'A-Za-z0-9' </dev/urandom | head -c 13
echo
)
webpw=$(
LC_ALL=C tr -dc 'A-Za-z0-9' </dev/urandom | head -c 13
echo
)
addr=$(echo $(ifconfig wg0 2>/dev/null | awk '/inet addr:/ {print $2}' | sed 's/addr://'))
port=$(shuf -i 40000-40999 -n 1)
timeout=$1
realuser=$2
if id "$realuser" &>/dev/null; then
echo "$realuser found"
else
echo "$realuser not found, creating user.."
useradd -m $realuser
fi
echo "url: https://$addr:$port"
echo "webuser: $webuser, webpw: $webpw"
timeout $timeout sudo -H -u $realuser /opt/gotty/gotty --tls-crt /opt/gotty/.gotty.crt --tls-key /opt/gotty/.gotty.key --once -a $addr -p $port -t -c $webuser:$webpw -w /bin/bash 2>&1

View file

@ -0,0 +1,6 @@
10.9.3.6,vk.vikingjupiter,nkey-user=UCWJUFIKR4FGGSWPPFMBS7MUX643B7WQMGMHDOPZIMMJ2AOSWIXLFZXK
10.9.3.3,vk.vikingsea,nkey-user=UBXJTWS2SKWBUIJTF4CSN7HAZFGZB3DU425V3HJEBJUTJNU22BUW3PPM
10.9.3.4,vk.vikingsky,nkey-user=UBUNKQ7UFKWU4MFSS2TN22EZRSJQSMHESQYMK52YH2WUA5MPH75BXXAD
10.9.3.8,vk.vikingstar,nkey-user=UCI4NMYOVRKGZYBBMGTNS3LPWNWUVJFKYHJZWNWR3IKWBPJGNZBJI3LO
10.9.3.7,vk.vikingvenus,nkey-user=UAWPTIT4ZQKFSR3YM56BLMLM6WJRYEME4EUHTAETBEXWWN7NQC62YNI2

Binary file not shown.

View file

@ -0,0 +1,3 @@
module test
go 1.17

View file

@ -0,0 +1,56 @@
package main
import (
"bufio"
"os"
"strings"
"text/template"
"log"
)
type data struct {
IP string
Name string
Nkey string
}
const tmpNats string = `
{
# {{.Name}}
nkey: {{.Nkey}}
permissions: {
publish: {
allow: ["central.>","errorCentral.>","{{.Name}}.>"]
}
subscribe: {
allow: ["central.>","errorCentral.>","{{.Name}}.>"]
}
}
}
`
func main() {
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
ss := strings.Split(scanner.Text(), ",")
if len(ss) < 3 {
continue
}
nkey := strings.Split(ss[2], "nkey-user=")
d := data{
IP: ss[0],
Name: ss[1],
Nkey: nkey[1],
}
tmp, err := template.New("myTemplate").Parse(tmpNats)
if err != nil {
log.Printf("error: template parse failed: %v\n", err)
}
tmp.Execute(os.Stdout, d)
}
}

View file

@ -1,3 +1,6 @@
// Example for how to run
// go run main.go --brokerAddress=localhost:42222
package main
import (
@ -5,6 +8,7 @@ import (
"fmt"
"log"
"os"
"path"
"text/template"
)
@ -87,21 +91,29 @@ func main() {
nkeySeedFile := flag.String("nkeySeedFile", "/tmp/seed.txt", "the complete path of the seed file to mount")
socketFolder := flag.String("sockerFolder", "/tmp/tmp/", "the complete path of the socket folder to mount")
flag.Parse()
templateDir := flag.String("templateDir", "./", "the directory path to where the template files are located")
if *brokerAddress == "" {
log.Printf("error: -brokerAddress flag can not be empty\n")
return
}
err := generateEnv("template_env.env", *brokerAddress)
if err != nil {
log.Printf("%v\n", err)
return
{
p := path.Join(*templateDir, "template_env.env")
err := generateEnv(p, *brokerAddress)
if err != nil {
log.Printf("%v\n", err)
return
}
}
err = generateDockerCompose("template_docker-compose.yml", *imageAndVersion, *exposedProfilingPort, *exposedPrometheusPort, *exposedDataFolderPort, *exposedTcpListenerPort, *exposedHttpListenerPort, *nkeySeedFile, *socketFolder)
if err != nil {
log.Printf("%v\n", err)
return
{
p := path.Join(*templateDir, "template_docker-compose.yml")
err := generateDockerCompose(p, *imageAndVersion, *exposedProfilingPort, *exposedPrometheusPort, *exposedDataFolderPort, *exposedTcpListenerPort, *exposedHttpListenerPort, *nkeySeedFile, *socketFolder)
if err != nil {
log.Printf("%v\n", err)
return
}
}
}