Commit 02d5b71b authored by dmknght's avatar dmknght
Browse files

Better module of changeid

parent 072fcba9
......@@ -3,6 +3,7 @@ import .. / modules / [myip, changeid]
import .. / displays / noti
import strutils
import system
import os
type
MyIP = object
......@@ -66,7 +67,25 @@ proc onClickChangeID*(b: Button) =
2. Get ControlPort from Torrc
3. Send authentication request + NewNYM command
]#
doChangeID()
let conf = "/etc/anonsurf/nyxrc"
if fileExists(conf):
try:
let recvData = doChangeID(conf)
if recvData[0] != "250 OK\c":
sendNotify("Identity Change Error", recvData[0], "error")
else:
if recvData[1] != "250 OK\c":
sendNotify("Identity Change Error", recvData[1], "error")
else:
# Success. Show okay
sendNotify("Identity Change Success", "You have a new identity", "security-high")
# else:
# sendNotify("Identity Change Error", "Can parse settings", "error")
except:
sendNotify("Identity Change Error", "Error while connecting to control port", "security-low")
echo getCurrentExceptionMsg()
else:
sendNotify("Identity Change Error", "File not found", "error")
proc onClickTorStatus*(b: Button) =
......
import strscans
import os
import net
import torPorts
import strutils
import .. / displays / noti
proc doChangeID*() =
let conf = "/etc/anonsurf/nyxrc"
if fileExists(conf):
var
tmp, passwd: string
sock = net.newSocket()
if scanf(readFile(conf), "$w $w", tmp, passwd):
try:
let controlPort = getTorrcPorts().controlPort
# sock.connect("127.0.0.1", Port(9051))
if ":" in controlPort:
sock.connect("127.0.0.1", Port(parseInt(controlPort.split(":")[1])))
else:
sock.connect("127.0.0.1", Port(parseInt(controlPort)))
sock.send("authenticate \"" & passwd & "\"\nsignal newnym\nquit\n")
let recvData = sock.recv(256).split("\n")
sock.close()
# Check authentication status
if recvData[0] != "250 OK\c":
sendNotify(
"Identity Change Error",
recvData[0],
"error"
)
return
# Check command status
if recvData[1] != "250 OK\c":
sendNotify(
"Identity Change Error",
recvData[1],
"error"
)
return
# Success. Show okay
sendNotify(
"Identity Change Success",
"You have a new identity",
"security-high"
)
except:
sendNotify(
"Identity Change Error",
"Error while connecting to control port",
"security-low"
)
echo getCurrentExceptionMsg()
proc doChangeID*(conf: string): seq[string] =
var
tmp, passwd: string
sock = net.newSocket()
if scanf(readFile(conf), "$w $w", tmp, passwd):
let controlPort = getTorrcPorts().controlPort
# sock.connect("127.0.0.1", Port(9051))
if ":" in controlPort:
sock.connect("127.0.0.1", Port(parseInt(controlPort.split(":")[1])))
else:
sendNotify(
"Identity Change Error",
"Can parse settings",
"error"
)
else:
sendNotify(
"Identity Change Error",
"File not found",
"error"
)
\ No newline at end of file
sock.connect("127.0.0.1", Port(parseInt(controlPort)))
sock.send("authenticate \"" & passwd & "\"\nsignal newnym\nquit\n")
let recvData = sock.recv(256).split("\n")
sock.close()
return recvData
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment