This repository has been archived on 2022-05-11. You can view files and clone it, but cannot push or open issues or pull requests.
misc/scripts/deadswitch.nim

66 lines
1.7 KiB
Nim
Raw Normal View History

2022-03-07 02:10:56 +00:00
import std/[times, os]
import strutils
# ./deadswitch <file> <yyyy-MM-dd> <HH:mm> <path>
var DATE = ""
var TIME = ""
var FILE = ""
var PATH = ""
proc read_args() =
try:
DATE = paramStr(2)
TIME = paramStr(3)
FILE = paramStr(1)
PATH = paramStr(4)
except:
echo "Please provide commandline arguments in the format:"
echo "<file> <yyyy-MM-dd> <HH:mm> <path>"
quit(QuitFailure)
type PayloadType = enum Plaintext, Encrypted
type Payload = tuple
filename: string
contents: string
proc release_payload(p_type: PayloadType, payload: Payload) =
echo "Releasing payload..."
sleep(1000)
if p_type == PayloadType.Plaintext:
echo payload.filename
echo payload.contents
else:
echo payload.filename
echo "<Encrypted file>"
# copy the file contents
writeFile(PATH & payload.filename, payload.contents)
while true:
read_args()
writeFile(PATH & FILE, DATE) # temp file
let now = now() # get current localtime
let now_date = now.format("yyyy-MM-dd") # extract the date
let now_time = now.format("HH:mm") # extract the time
let file = readFile(FILE) # read in the contents of the payload file
let format = FILE.split('.') # get the format of the file
# check the file type based on it's format
var p_type = PayloadType.Plaintext
case format[high(format)]:
of "age", "pgp", "gpg":
p_type = PayloadType.Encrypted
else:
p_type = PayloadType.Plaintext
if now_date == DATE: #and now_time == TIME: # check if both date & time are the same
let payload: Payload = (filename: FILE, contents: file) # create a new payload object
release_payload(p_type, payload) # release it!
break
echo "Not now :c"
sleep(10000) # wait 10 seconds (10000 milliseconds)