dynv6 now defaults to config, discord displays error message on error.
This commit is contained in:
+5
-4
@@ -14,7 +14,7 @@
|
||||
#
|
||||
### Example
|
||||
# Run from CMD or Batch file to transmit the message to Discord:
|
||||
# CMD> powershell.exe -File .\Discord.ps1 -message "Here is some content to send to Discord."
|
||||
# CMD> pwsh -File .\Discord.ps1 -message "Here is some content to send to Discord."
|
||||
# or pipeline in powershell:
|
||||
# PS1> echo "Here is some content to send to Discord" | .\Discord.ps1
|
||||
#
|
||||
@@ -27,9 +27,9 @@
|
||||
|
||||
param (
|
||||
[parameter (ValueFromPipeline = $true)] [string[]] $message,
|
||||
[string] $distinct,
|
||||
[string] $webhook,
|
||||
[string] $botName
|
||||
[string] $distinct = "",
|
||||
[string] $webhook = "",
|
||||
[string] $botName = ""
|
||||
)
|
||||
begin {
|
||||
$chunk = ""
|
||||
@@ -66,6 +66,7 @@ end {
|
||||
# complete last chunk, by queuing it up
|
||||
$chunks += $chunk
|
||||
|
||||
# if distinct, load previous message to check for duplicate message
|
||||
if ($distinct) {
|
||||
$distinctFile = "$PSScriptRoot\\distinct\\$distinct.msg"
|
||||
if (Test-Path -Path $distinctFile) {
|
||||
|
||||
@@ -4,18 +4,19 @@
|
||||
#
|
||||
# Windows Powershell Script for updating Dynamic DNS on Dynv6.com using the
|
||||
# RESTful interface. Use the windows task schedualer to automatically run.
|
||||
# Will use config.ps1 for defaults, if available.
|
||||
#
|
||||
# Script Parameters:
|
||||
# -zone <string> DNS Zone (domain name) to update.
|
||||
# -token <string> HTTP Token, see: https://dynv6.com/keys#token
|
||||
# [-zone] <string> Optional, DNS Zone (domain name) to update, default to config.
|
||||
# [-token] <string> Optional, HTTP Token, see: https://dynv6.com/keys#token defaults to config.
|
||||
# [-netmask] <string> Optional, IPv6 netmask, defaults to 128.
|
||||
# [-logFile] <string|null> Optional, filename to log to, defaults to "~/.dynv6.log", use null to disable logging.
|
||||
# [-logFile] <string|null> Optional, filename to log to, defaults to "~\.dynv6.log", use $null to disable logging.
|
||||
# [-ipv4] <string> Optional, IPv4 override, to skip resolving.
|
||||
# [-ipv6] <string> Optional, IPv6 override, to skip resolving.
|
||||
#
|
||||
### Example
|
||||
# Run from CMD or Batch file to IPv4 and IPv6 with automatic lookup:
|
||||
# powershell.exe -File ./Dynv6.ps1 -zone "ExampleDomain.com" -token "XXXXXX"
|
||||
# CMD> pwsh -File .\Dynv6.ps1 -zone "ExampleDomain.com" -token "XXXXXX"
|
||||
#
|
||||
###################
|
||||
# Copyright 2020 Joe Herbert ( djneonc@gmail.com )
|
||||
@@ -41,14 +42,27 @@
|
||||
|
||||
# we need zone and token, we also accept, netmask, and overrides
|
||||
param(
|
||||
[string] $zone = $(throw "-zone is required"),
|
||||
[string] $token = $(throw "-token is required"),
|
||||
[string] $zone = "",
|
||||
[string] $token = "",
|
||||
[string] $netmask = "128",
|
||||
[object] $logFile = "$env:USERPROFILE\\.dynv6.log",
|
||||
[string] $ipv4 = "",
|
||||
[string] $ipv6 = ""
|
||||
)
|
||||
|
||||
# load in defaults from config
|
||||
$configFile = "$PSScriptRoot\\Config.ps1"
|
||||
if (Test-Path -Path $configFile) {
|
||||
. $configFile
|
||||
|
||||
if ( ! $zone) {
|
||||
$zone = $DYNV6_ZONE
|
||||
}
|
||||
if ( ! $token) {
|
||||
$token = $DYNV6_TOKEN
|
||||
}
|
||||
}
|
||||
|
||||
# we store ip addresses in files, so we only update when there is a change
|
||||
$file4 = "$env:USERPROFILE\\.dynv6.addr4"
|
||||
$file6 = "$env:USERPROFILE\\.dynv6.addr6"
|
||||
@@ -56,13 +70,9 @@ $file6 = "$env:USERPROFILE\\.dynv6.addr6"
|
||||
# load existing ip addresses, when available
|
||||
if (Test-Path -Path $file4) {
|
||||
$old4 = Get-Content -Path $file4
|
||||
} else {
|
||||
$old4 = $null
|
||||
}
|
||||
if (Test-Path -Path $file6) {
|
||||
$old6 = Get-Content -Path $file6
|
||||
} else {
|
||||
$old6 = $null
|
||||
}
|
||||
|
||||
$lookup4 = [System.Uri]'https://ipinfo.io/ip'
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# internal function to transmit a discord chunk
|
||||
# internal function to transmit a chunk of text to Discord
|
||||
function SendDiscordMessage
|
||||
{
|
||||
param (
|
||||
@@ -17,19 +17,21 @@ function SendDiscordMessage
|
||||
$botName = ConvertTo-Json -InputObject $botName
|
||||
|
||||
# rewrite json string, because "\u001b[m" needs to "\u001b[0m" instead
|
||||
# windows is fine with the missing zero, but discord needs it
|
||||
# windows is fine with the missing zero, but Discord needs it
|
||||
$message = $message -Replace "\\u001b\[m", "\u001b[0m"
|
||||
|
||||
# remove wrapping quotes around json string, replace with color-enabled block quotes
|
||||
$message = '"```ansi\n' + $message.SubString(1, $message.length - 2) + '\n```"'
|
||||
|
||||
# {"username": "$botName", "content": "$message"}
|
||||
# build post data: {"username": "$botName", "content": "$message"}
|
||||
$content = "{";
|
||||
if ($botName) {
|
||||
$content += '"username": ' + $botName + ', ';
|
||||
}
|
||||
$content += '"content": ' + $message + '}';
|
||||
|
||||
echo "$content" | curl.exe -s -H "$header" -X "POST" -d "@-" "$webhook" | ConvertFrom-Json | Select-Object -Property id | Out-Host
|
||||
# post data is complex, so we have to pipe it into curl
|
||||
# display the resulting id/message returned from Discord
|
||||
echo "$content" | curl.exe -s -H "$header" -X "POST" -d "@-" "$webhook" | ConvertFrom-Json | Select-Object -Property id, message
|
||||
}
|
||||
|
||||
|
||||
@@ -4,3 +4,7 @@ $DISCORD_SERVER_NAME = "<YOUR_SERVER>"
|
||||
|
||||
$DISCORD_WINDOWS_HOOK = "<WEBHOOK_URL_HERE>?wait=true"
|
||||
|
||||
$DYNV6_ZONE = "<YOUR_DOMAIN>"
|
||||
|
||||
$DYNV6_TOKEN = "<DYNV6_TOKEN>"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user