diff --git a/check-certificates.rsc b/check-certificates.rsc index 31d57699..47ed7d67 100644 --- a/check-certificates.rsc +++ b/check-certificates.rsc @@ -30,7 +30,6 @@ :global ScriptLock; :global SendNotification2; :global SymbolForNotification; - :global UrlEncode; :global WaitFullyConnected; :local CheckCertificatesDownloadImport do={ @@ -46,11 +45,10 @@ :global FetchUserAgentStr; :global LogPrint; :global RmFile; - :global UrlEncode; :global WaitForFile; :foreach Type in={ "p12"; "pem" } do={ - :local CertFileName ([ $UrlEncode $FetchName ] . "." . $Type); + :local CertFileName ([ :convert to=url $FetchName ] . "." . $Type); $LogPrint debug $ScriptName ("Trying type '" . $Type . "' for '" . $CertName . \ "' (file '" . $CertFileName . "')..."); @@ -202,7 +200,7 @@ } else={ $LogPrint debug $ScriptName ("Certificate '" . $CertVal->"name" . "' was not updated, but replaced."); - :local CertNew [ /certificate/find where name~("^" . [ $EscapeForRegEx [ $UrlEncode $FetchName ] ] . "\\.(p12|pem)_[0-9]+\$") \ + :local CertNew [ /certificate/find where name~("^" . [ $EscapeForRegEx [ :convert to=url $FetchName ] ] . "\\.(p12|pem)_[0-9]+\$") \ (common-name=($CertVal->"common-name") or subject-alt-name~("(^|\\W)(DNS|IP):" . [ $EscapeForRegEx $LastName ] . "(\\W|\$)")) \ fingerprint!=[ :tostr ($CertVal->"fingerprint") ] ]; :local CertNewVal [ /certificate/get $CertNew ]; diff --git a/daily-psk.capsman.rsc b/daily-psk.capsman.rsc index 8d8a5ee7..2c52ada8 100644 --- a/daily-psk.capsman.rsc +++ b/daily-psk.capsman.rsc @@ -27,7 +27,6 @@ :global ScriptLock; :global SendNotification2; :global SymbolForNotification; - :global UrlEncode; :global WaitForFile; :global WaitFullyConnected; @@ -78,7 +77,7 @@ $LogPrint debug $ScriptName ("Already sent a mail for SSID " . $Ssid . ", skipping."); } else={ :local Link ($DailyPskQrCodeUrl . \ - "?scale=8&level=1&ssid=" . [ $UrlEncode $Ssid ] . "&pass=" . [ $UrlEncode $NewPsk ]); + "?scale=8&level=1&ssid=" . [ :convert to=url $Ssid ] . "&pass=" . [ :convert to=url $NewPsk ]); $SendNotification2 ({ origin=$ScriptName; \ subject=([ $SymbolForNotification "calendar" ] . "daily PSK " . $Ssid); \ message=("This is the daily PSK on " . $Identity . ":\n\n" . \ diff --git a/daily-psk.local.rsc b/daily-psk.local.rsc index 62f4cf42..fd63f873 100644 --- a/daily-psk.local.rsc +++ b/daily-psk.local.rsc @@ -27,7 +27,6 @@ :global ScriptLock; :global SendNotification2; :global SymbolForNotification; - :global UrlEncode; :global WaitForFile; :global WaitFullyConnected; @@ -77,7 +76,7 @@ $LogPrint debug $ScriptName ("Already sent a mail for SSID " . $Ssid . ", skipping."); } else={ :local Link ($DailyPskQrCodeUrl . \ - "?scale=8&level=1&ssid=" . [ $UrlEncode $Ssid ] . "&pass=" . [ $UrlEncode $NewPsk ]); + "?scale=8&level=1&ssid=" . [ :convert to=url $Ssid ] . "&pass=" . [ :convert to=url $NewPsk ]); $SendNotification2 ({ origin=$ScriptName; \ subject=([ $SymbolForNotification "calendar" ] . "daily PSK " . $Ssid); \ message=("This is the daily PSK on " . $Identity . ":\n\n" . \ diff --git a/daily-psk.template.rsc b/daily-psk.template.rsc index 5e569053..92a7f139 100644 --- a/daily-psk.template.rsc +++ b/daily-psk.template.rsc @@ -28,7 +28,6 @@ :global ScriptLock; :global SendNotification2; :global SymbolForNotification; - :global UrlEncode; :global WaitForFile; :global WaitFullyConnected; @@ -93,7 +92,7 @@ $LogPrint debug $ScriptName ("Already sent a mail for SSID " . $Ssid . ", skipping."); } else={ :local Link ($DailyPskQrCodeUrl . \ - "?scale=8&level=1&ssid=" . [ $UrlEncode $Ssid ] . "&pass=" . [ $UrlEncode $NewPsk ]); + "?scale=8&level=1&ssid=" . [ :convert to=url $Ssid ] . "&pass=" . [ :convert to=url $NewPsk ]); $SendNotification2 ({ origin=$ScriptName; \ subject=([ $SymbolForNotification "calendar" ] . "daily PSK " . $Ssid); \ message=("This is the daily PSK on " . $Identity . ":\n\n" . \ diff --git a/daily-psk.wifi.rsc b/daily-psk.wifi.rsc index 66321173..2bcfd9fd 100644 --- a/daily-psk.wifi.rsc +++ b/daily-psk.wifi.rsc @@ -27,7 +27,6 @@ :global ScriptLock; :global SendNotification2; :global SymbolForNotification; - :global UrlEncode; :global WaitForFile; :global WaitFullyConnected; @@ -78,7 +77,7 @@ $LogPrint debug $ScriptName ("Already sent a mail for SSID " . $Ssid . ", skipping."); } else={ :local Link ($DailyPskQrCodeUrl . \ - "?scale=8&level=1&ssid=" . [ $UrlEncode $Ssid ] . "&pass=" . [ $UrlEncode $NewPsk ]); + "?scale=8&level=1&ssid=" . [ :convert to=url $Ssid ] . "&pass=" . [ :convert to=url $NewPsk ]); $SendNotification2 ({ origin=$ScriptName; \ subject=([ $SymbolForNotification "calendar" ] . "daily PSK " . $Ssid); \ message=("This is the daily PSK on " . $Identity . ":\n\n" . \ diff --git a/global-functions.d/deprecated.rsc b/global-functions.d/deprecated.rsc index 8f3e5c89..b263bebf 100644 --- a/global-functions.d/deprecated.rsc +++ b/global-functions.d/deprecated.rsc @@ -7,3 +7,32 @@ # # deprecated global functions # https://rsc.eworm.de/ + +:global UrlEncode; + +# url encoding +:set UrlEncode do={ + :local Input [ :tostr $1 ]; + + :if ([ :len $Input ] = 0) do={ + :return ""; + } + + :local Return ""; + :local Chars ("\n\r !\"#\$%&'()*+,:;<=>?@[\\]^`{|}~"); + :local Subs { "%0A"; "%0D"; "%20"; "%21"; "%22"; "%23"; "%24"; "%25"; "%26"; "%27"; + "%28"; "%29"; "%2A"; "%2B"; "%2C"; "%3A"; "%3B"; "%3C"; "%3D"; "%3E"; "%3F"; + "%40"; "%5B"; "%5C"; "%5D"; "%5E"; "%60"; "%7B"; "%7C"; "%7D"; "%7E" }; + + :for I from=0 to=([ :len $Input ] - 1) do={ + :local Char [ :pick $Input $I ]; + :local Replace [ :find $Chars $Char ]; + + :if ([ :typeof $Replace ] = "num") do={ + :set Char ($Subs->$Replace); + } + :set Return ($Return . $Char); + } + + :return $Return; +} diff --git a/global-functions.rsc b/global-functions.rsc index 8b4d12f0..5cadb24f 100644 --- a/global-functions.rsc +++ b/global-functions.rsc @@ -82,7 +82,6 @@ :global SymbolByUnicodeName; :global SymbolForNotification; :global Unix2Dos; -:global UrlEncode; :global ValidateSyntax; :global VersionToNum; :global WaitDefaultRouteReachable; @@ -1795,33 +1794,6 @@ :return [ :tocrlf [ :tostr $1 ] ]; } -# url encoding -:set UrlEncode do={ - :local Input [ :tostr $1 ]; - - :if ([ :len $Input ] = 0) do={ - :return ""; - } - - :local Return ""; - :local Chars ("\n\r !\"#\$%&'()*+,:;<=>?@[\\]^`{|}~"); - :local Subs { "%0A"; "%0D"; "%20"; "%21"; "%22"; "%23"; "%24"; "%25"; "%26"; "%27"; - "%28"; "%29"; "%2A"; "%2B"; "%2C"; "%3A"; "%3B"; "%3C"; "%3D"; "%3E"; "%3F"; - "%40"; "%5B"; "%5C"; "%5D"; "%5E"; "%60"; "%7B"; "%7C"; "%7D"; "%7E" }; - - :for I from=0 to=([ :len $Input ] - 1) do={ - :local Char [ :pick $Input $I ]; - :local Replace [ :find $Chars $Char ]; - - :if ([ :typeof $Replace ] = "num") do={ - :set Char ($Subs->$Replace); - } - :set Return ($Return . $Char); - } - - :return $Return; -} - # basic syntax validation :set ValidateSyntax do={ :local Code [ :tostr $1 ]; diff --git a/mod/notification-matrix.rsc b/mod/notification-matrix.rsc index 5827e618..004ab1f2 100644 --- a/mod/notification-matrix.rsc +++ b/mod/notification-matrix.rsc @@ -242,7 +242,6 @@ :global FetchUserAgentStr; :global LogPrint; - :global UrlEncode; :global MatrixAccessToken; :global MatrixHomeServer; @@ -251,8 +250,8 @@ :onerror Err { /tool/fetch check-certificate=yes-without-crl output=none \ http-header-field=({ [ $FetchUserAgentStr $0 ] }) http-method=post http-data="" \ - ("https://" . $MatrixHomeServer . "/_matrix/client/r0/rooms/" . [ $UrlEncode $MatrixRoom ] . \ - "/join?access_token=" . [ $UrlEncode $MatrixAccessToken ]) as-value; + ("https://" . $MatrixHomeServer . "/_matrix/client/r0/rooms/" . [ :convert to=url $MatrixRoom ] . \ + "/join?access_token=" . [ :convert to=url $MatrixAccessToken ]) as-value; $LogPrint debug $0 ("Joined the room."); } do={ $LogPrint error $0 ("Failed joining the room: " . $Err); diff --git a/mod/notification-ntfy.rsc b/mod/notification-ntfy.rsc index b3660d8c..25156acd 100644 --- a/mod/notification-ntfy.rsc +++ b/mod/notification-ntfy.rsc @@ -80,7 +80,6 @@ :global IfThenElse; :global LogPrint; :global SymbolForNotification; - :global UrlEncode; :local Server [ $EitherOr ($NtfyServerOverride->($Notification->"origin")) $NtfyServer ]; :local User [ $EitherOr ($NtfyServerUserOverride->($Notification->"origin")) $NtfyServerUser ]; @@ -92,7 +91,7 @@ :return false; } - :local Url ("https://" . $Server . "/" . [ $UrlEncode $Topic ]); + :local Url ("https://" . $Server . "/" . [ :convert to=url $Topic ]); :local Headers ({ [ $FetchUserAgentStr ($Notification->"origin") ]; \ ("Priority: " . [ $IfThenElse ($Notification->"silent") "low" "default" ]); \ ("Title: " . "[" . $IdentityExtra . $Identity . "] " . ($Notification->"subject")) }); diff --git a/mod/notification-telegram.rsc b/mod/notification-telegram.rsc index f3fa6f84..0d0fd6e9 100644 --- a/mod/notification-telegram.rsc +++ b/mod/notification-telegram.rsc @@ -126,7 +126,6 @@ :global LogPrint; :global ProtocolStrip; :global SymbolForNotification; - :global UrlEncode; :local EscapeMD do={ :local Text [ :tostr $1 ]; @@ -203,7 +202,7 @@ } :local Data ([ /tool/fetch check-certificate=yes-without-crl output=user http-method=post \ ("https://api.telegram.org/bot" . $TokenId . "/sendMessage") \ - http-data=($HTTPData . "&text=" . [ $UrlEncode $Text ]) as-value ]->"data"); + http-data=($HTTPData . "&text=" . [ :convert to=url $Text ]) as-value ]->"data"); :set ($TelegramMessageIDs->[ :tostr ([ :deserialize from=json value=$Data ]->"result"->"message_id") ]) 1; } do={ $LogPrint info $0 ("Failed sending Telegram notification: " . $Err . " - Queuing..."); @@ -215,7 +214,7 @@ [ $EscapeMD ("This message was queued since _" . [ /system/clock/get date ] . \ " " . [ /system/clock/get time ] . "_ and may be obsolete.") "plain" "_" ]); :set ($TelegramQueue->[ :len $TelegramQueue ]) { tokenid=$TokenId; - http-data=($HTTPData . "&text=" . [ $UrlEncode $Text ]) }; + http-data=($HTTPData . "&text=" . [ :convert to=url $Text ]) }; :if ([ :len [ /system/scheduler/find where name="_FlushTelegramQueue" ] ] = 0) do={ /system/scheduler/add name="_FlushTelegramQueue" interval=1m start-time=startup \ on-event=(":global FlushTelegramQueue; \$FlushTelegramQueue;");