Skip to content

Commit

Permalink
ncp-web: fix port checking
Browse files Browse the repository at this point in the history
Signed-off-by: nachoparker <nacho@ownyourbits.com>
  • Loading branch information
nachoparker committed May 13, 2021
1 parent a950c8a commit ec397d4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
14 changes: 9 additions & 5 deletions bin/ncp-diag
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,19 @@ echo "internet check|$( ping -W 2 -w 1 -q github.com &>/dev/null && echo ok || e

function is_port_open()
{
local PORT=$1
local port=$1
local public_ip
public_ip="$(curl icanhazip.com 2>/dev/null)" || { echo "closed"; return 1; }

local tmp_file=$(mktemp)
local v=$(wget -T2 -t1 -q --keep-session-cookies --save-cookies $tmp_file https://portchecker.co -O - | grep -oP "_csrf\" value=\"\K.*\"")
if [[ "$v" != "" ]]; then
wget -T2 -t1 -q --load-cookies $tmp_file https://portchecker.co --post-data "port=$PORT&_csrf=${v::-1}" -O - \
local token=$(wget -T2 -t1 -qO- --keep-session-cookies --save-cookies $tmp_file https://portchecker.co | grep -oP "_csrf\" value=\"\K.*\"")
rm $tmp_file

if [[ "${token}" != "" ]]; then
wget -T2 -t1 -qO- --load-cookies $tmp_file https://portchecker.co --post-data "target_ip=${public_ip}&port=${port}&_csrf=${token::-1}" \
| grep -q '<span class="green">open</span>' && { echo "open"; return 1; }
fi
echo "closed"
rm $tmp_file
}

echo "port check 80|$( is_port_open 80 )"
Expand Down
6 changes: 4 additions & 2 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@

[v1.36.1](https://github.com/nextcloud/nextcloudpi/commit/8e7579d) (2021-05-09) lamp: allow only TLSv12 and TLSv13
[v1.36.2](https://github.com/nextcloud/nextcloudpi/commit/fccc04c) (2021-05-11) ncp-web: fix port checking

[v1.36.0](https://github.com/nextcloud/nextcloudpi/commit/24b6018) (2020-09-16) Namecheap dynamic DNS client
[v1.36.1](https://github.com/nextcloud/nextcloudpi/commit/c7f2939) (2021-05-09) lamp: allow only TLSv12 and TLSv13

[v1.36.0 ](https://github.com/nextcloud/nextcloudpi/commit/24b6018) (2020-09-16) Namecheap dynamic DNS client

[v1.35.2 ](https://github.com/nextcloud/nextcloudpi/commit/bfab195) (2021-04-29) ncp-web: fix display of big files for 32 bit

Expand Down

0 comments on commit ec397d4

Please sign in to comment.