[why] Provide a login port for users by email, determine whether to send the ssh_port message based on the "pub_key".
Signed-off-by: Zhang Yale zhangyale3@huawei.com --- daemon/sshd | 98 ++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 74 insertions(+), 24 deletions(-)
diff --git a/daemon/sshd b/daemon/sshd index 98f31d77..1ebc9d00 100755 --- a/daemon/sshd +++ b/daemon/sshd @@ -1,6 +1,16 @@ #!/bin/sh # pub_key -# email +# my_email +# sshr_port +# sshr_port_len +# sshr_port_base + +. $LKP_SRC/lib/http.sh + +sshr_ip=$LKP_SERVER +[ -n "$sshr_port" ] || sshr_port=5050 +[ -n "$sshr_port_len" ] || sshr_port_len=2000 +[ -n "$sshr_port_base" ] || sshr_port_base=50000
run_ssh() { @@ -11,40 +21,80 @@ run_ssh() systemctl start sshd }
-compose_email() +data_success() { deadline=$(date -d "+$runtime seconds" +"%Y-%m-%d %H:%M:%S") - data="To: $email -Subject: [NOTIFY compass-ci] $testbox ready to ssh - -Dear $email: - Thanks for your participation in Kunpeng and software ecosystem! - According to your application, $testbox has been provisioned. - The datails are as follows: - - Login: - ssh root@$PUB_IP - Due time: - $deadline - - HW: - nr_cpu: $nr_cpu - memory: $memory - testbox: $testbox - OS: - $os $os_version $os_arch + data="To: $my_email +Subject: [NOTIFY Compass-ci] $testbox ready to use + +Dear $my_username: + Thanks for your participation in software ecosystem! + According to your application, $testbox has been provisioned. + The datails are as follows: + + Login: + ssh root@api.compass-ci.openeuler.org -p $port + Due time: + $deadline + HW: + nr_cpu: $nr_cpu + memory: $memory + testbox: $testbox + OS: + $os $os_version $os_arch + +Regards +Compass-Ci +" +} + +data_failure() +{ + data="To: $my_email +Subject: [NOTIFY Compass-ci] Applying $testbox failed + +Dear $my_username: + Sorry to inform you that your application failed. + You may need to wait a moment, or check whether your pub_key exists.
Regards -compass-ci +Compass-Ci " }
+compose_email() +{ + deadline=$(date -d "+$runtime seconds" +"%Y-%m-%d %H:%M:%S") + if [ -n "$port" ]; then + data_success + else + data_failure + fi +} + +set_port() +{ + [ -n "$pub_key" ] || return + + for i in $(seq 1 10) + do + port=$(($(date +%s%N)%"$sshr_port_len"+"$sshr_port_base")) + ssh -o StrictHostKeyChecking=no -o ExitOnForwardFailure=yes -o TCPKeepAlive=yes \ + -Nf -R $port:localhost:22 sshr@"$sshr_ip" -p "$sshr_port" &>/dev/null + [ $? -eq 0 ] && return + done + port="" +} + run_email() { - [ -n "$email" ] || return 0 + [ -n "$my_email" ] || return 0 + my_username=$(echo "$my_email" | awk -F '@' '{print $1}') compose_email - curl -XPOST "$MAIL_HOST:$MAIL_PORT/send_mail_text" -d "$data" + curl -XPOST "${MAIL_HOST:-$LKP_SERVER}:${MAIL_PORT:-11312}/send_mail_text" -d "$data" }
run_ssh +set_port +report_ssh_port $port run_email
On Thu, Oct 22, 2020 at 02:51:21PM +0800, Zhang Yale wrote:
[why] Provide a login port for users by email, determine whether to send the ssh_port message based on the "pub_key".
Signed-off-by: Zhang Yale zhangyale3@huawei.com
daemon/sshd | 98 ++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 74 insertions(+), 24 deletions(-)
diff --git a/daemon/sshd b/daemon/sshd index 98f31d77..1ebc9d00 100755 --- a/daemon/sshd +++ b/daemon/sshd @@ -1,6 +1,16 @@ #!/bin/sh # pub_key -# email +# my_email +# sshr_port +# sshr_port_len +# sshr_port_base
+. $LKP_SRC/lib/http.sh
+sshr_ip=$LKP_SERVER +[ -n "$sshr_port" ] || sshr_port=5050 +[ -n "$sshr_port_len" ] || sshr_port_len=2000 +[ -n "$sshr_port_base" ] || sshr_port_base=50000
run_ssh() { @@ -11,40 +21,80 @@ run_ssh() systemctl start sshd }
-compose_email() +data_success() { deadline=$(date -d "+$runtime seconds" +"%Y-%m-%d %H:%M:%S")
- data="To: $email
-Subject: [NOTIFY compass-ci] $testbox ready to ssh
-Dear $email:
- Thanks for your participation in Kunpeng and software ecosystem!
- According to your application, $testbox has been provisioned.
- The datails are as follows:
- Login:
ssh root@$PUB_IP
- Due time:
$deadline
- HW:
nr_cpu: $nr_cpu
memory: $memory
testbox: $testbox
- OS:
$os $os_version $os_arch
- data="To: $my_email
+Subject: [NOTIFY Compass-ci] $testbox ready to use
+Dear $my_username:
- Thanks for your participation in software ecosystem!
- According to your application, $testbox has been provisioned.
- The datails are as follows:
- Login:
ssh root@api.compass-ci.openeuler.org -p $port
- Due time:
$deadline
- HW:
nr_cpu: $nr_cpu
memory: $memory
testbox: $testbox
- OS:
$os $os_version $os_arch
+Regards +Compass-Ci +" +}
+data_failure() +{
- data="To: $my_email
+Subject: [NOTIFY Compass-ci] Applying $testbox failed
+Dear $my_username:
- Sorry to inform you that your application failed.
- You may need to wait a moment, or check whether your pub_key exists.
Regards -compass-ci +Compass-Ci " }
+compose_email() +{
- deadline=$(date -d "+$runtime seconds" +"%Y-%m-%d %H:%M:%S")
May be the first "+" is unnecessary date -d "$runtime seconds" +"%Y-%m-%d %H:%M:%S"
- if [ -n "$port" ]; then
data_success
- else
data_failure
- fi
+}
+set_port() +{
- [ -n "$pub_key" ] || return
- for i in $(seq 1 10)
- do
port=$(($(date +%s%N)%"$sshr_port_len"+"$sshr_port_base"))
ssh -o StrictHostKeyChecking=no -o ExitOnForwardFailure=yes -o TCPKeepAlive=yes \
-Nf -R $port:localhost:22 sshr@"$sshr_ip" -p "$sshr_port" &>/dev/null
[ $? -eq 0 ] && return
- done
- port=""
+}
run_email() {
- [ -n "$email" ] || return 0
- [ -n "$my_email" ] || return 0
the $my_email is said user? but who is $email?
Thanks, Chenglong
- my_username=$(echo "$my_email" | awk -F '@' '{print $1}') compose_email
- curl -XPOST "$MAIL_HOST:$MAIL_PORT/send_mail_text" -d "$data"
- curl -XPOST "${MAIL_HOST:-$LKP_SERVER}:${MAIL_PORT:-11312}/send_mail_text" -d "$data"
}
run_ssh +set_port +report_ssh_port $port run_email -- 2.23.0
On Thu, Oct 22, 2020 at 04:27:14PM +0800, Wang Chenglong wrote:
On Thu, Oct 22, 2020 at 02:51:21PM +0800, Zhang Yale wrote:
[why] Provide a login port for users by email, determine whether to send the ssh_port message based on the "pub_key".
Signed-off-by: Zhang Yale zhangyale3@huawei.com
daemon/sshd | 98 ++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 74 insertions(+), 24 deletions(-)
diff --git a/daemon/sshd b/daemon/sshd index 98f31d77..1ebc9d00 100755 --- a/daemon/sshd +++ b/daemon/sshd @@ -1,6 +1,16 @@ #!/bin/sh # pub_key -# email +# my_email +# sshr_port +# sshr_port_len +# sshr_port_base
+. $LKP_SRC/lib/http.sh
+sshr_ip=$LKP_SERVER +[ -n "$sshr_port" ] || sshr_port=5050 +[ -n "$sshr_port_len" ] || sshr_port_len=2000 +[ -n "$sshr_port_base" ] || sshr_port_base=50000
run_ssh() { @@ -11,40 +21,80 @@ run_ssh() systemctl start sshd }
-compose_email() +data_success() { deadline=$(date -d "+$runtime seconds" +"%Y-%m-%d %H:%M:%S")
- data="To: $email
-Subject: [NOTIFY compass-ci] $testbox ready to ssh
-Dear $email:
- Thanks for your participation in Kunpeng and software ecosystem!
- According to your application, $testbox has been provisioned.
- The datails are as follows:
- Login:
ssh root@$PUB_IP
- Due time:
$deadline
- HW:
nr_cpu: $nr_cpu
memory: $memory
testbox: $testbox
- OS:
$os $os_version $os_arch
- data="To: $my_email
+Subject: [NOTIFY Compass-ci] $testbox ready to use
+Dear $my_username:
- Thanks for your participation in software ecosystem!
- According to your application, $testbox has been provisioned.
- The datails are as follows:
- Login:
ssh root@api.compass-ci.openeuler.org -p $port
- Due time:
$deadline
- HW:
nr_cpu: $nr_cpu
memory: $memory
testbox: $testbox
- OS:
$os $os_version $os_arch
+Regards +Compass-Ci +" +}
+data_failure() +{
- data="To: $my_email
+Subject: [NOTIFY Compass-ci] Applying $testbox failed
+Dear $my_username:
- Sorry to inform you that your application failed.
- You may need to wait a moment, or check whether your pub_key exists.
Regards -compass-ci +Compass-Ci " }
+compose_email() +{
- deadline=$(date -d "+$runtime seconds" +"%Y-%m-%d %H:%M:%S")
May be the first "+" is unnecessary date -d "$runtime seconds" +"%Y-%m-%d %H:%M:%S"
good! I got it.
Thanks, Yale
- if [ -n "$port" ]; then
data_success
- else
data_failure
- fi
+}
+set_port() +{
- [ -n "$pub_key" ] || return
- for i in $(seq 1 10)
- do
port=$(($(date +%s%N)%"$sshr_port_len"+"$sshr_port_base"))
ssh -o StrictHostKeyChecking=no -o ExitOnForwardFailure=yes -o TCPKeepAlive=yes \
-Nf -R $port:localhost:22 sshr@"$sshr_ip" -p "$sshr_port" &>/dev/null
[ $? -eq 0 ] && return
- done
- port=""
+}
run_email() {
- [ -n "$email" ] || return 0
- [ -n "$my_email" ] || return 0
the $my_email is said user? but who is $email? Thanks, Chenglong
- my_username=$(echo "$my_email" | awk -F '@' '{print $1}') compose_email
- curl -XPOST "$MAIL_HOST:$MAIL_PORT/send_mail_text" -d "$data"
- curl -XPOST "${MAIL_HOST:-$LKP_SERVER}:${MAIL_PORT:-11312}/send_mail_text" -d "$data"
}
run_ssh +set_port +report_ssh_port $port run_email -- 2.23.0