add url encode / secure isipv4
This commit is contained in:
@@ -41,6 +41,7 @@ isipv4()
|
|||||||
{
|
{
|
||||||
# Set up local variables
|
# Set up local variables
|
||||||
local ip=$1
|
local ip=$1
|
||||||
|
[[ -z $ip ]] && return 1
|
||||||
|
|
||||||
# Start with a regex format test
|
# Start with a regex format test
|
||||||
if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
|
if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
|
||||||
@@ -83,5 +84,24 @@ isipv6()
|
|||||||
}
|
}
|
||||||
export -f isipv6
|
export -f isipv6
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
# Encode a string so it can be used as a URL parameter
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
urlencode() {
|
||||||
|
local LANG=C
|
||||||
|
local str="$*"
|
||||||
|
local length="${#str}"
|
||||||
|
for (( i = 0; i < length; i++ )); do
|
||||||
|
local c="${str:i:1}"
|
||||||
|
case "$c" in
|
||||||
|
[a-zA-Z0-9.~_-]) printf "$c" ;;
|
||||||
|
' ') printf '+' ;;
|
||||||
|
*) printf '%%%02X' "'$c" #| cut -d' ' -f2 ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
}
|
||||||
|
export -f urlencode
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# EOF
|
# EOF
|
||||||
|
|||||||
Reference in New Issue
Block a user