Commit aa0a7d66 authored by dmknght's avatar dmknght

echo with color

parent e0fea860
Pipeline #1197 failed with stages
......@@ -4,7 +4,7 @@ import os
import displays / noti
import modules / [myip, changeid]
import .. / utils / services
import cli / [cores, help, killapp]
import cli / [cores, help, killapp, print]
proc checkIP() =
......@@ -15,19 +15,19 @@ proc checkIP() =
if isDesktop:
sendNotify("Error why checking IP", info[1], "error")
else:
echo "[x] Error while checking IP\n" & info[1]
msgErr("Error while checking IP\n" & info[1])
# If program runs but user didn't connect to tor
elif info[0].startsWith("Sorry"):
if isDesktop:
sendNotify("You are not under Tor network", info[1], "security-low")
else:
echo "[!] You are not connecting to Tor network\n" & info[1]
msgWarn("You are not connecting to Tor network\n" & info[1])
# Connected to tor
else:
if isDesktop:
sendNotify("You are under Tor network", info[1], "security-high")
else:
echo "[!] You are under Tor network\n" & info[1]
msgWarn("You are under Tor network\n" & info[1])
proc killApps() =
......@@ -36,12 +36,12 @@ proc killApps() =
if isDesktop:
sendNotify("AnonSurf", "Killed dangerous application", "security-high")
else:
echo "[*] Killed dangerous applications"
msgOk("Killed dangerous applications")
elif killResult != -1:
if isDesktop:
sendNotify("AnonSurf", "Error while trying to kill applications", "security-medium")
else:
echo "[!] Error while trying to kill dangerous applications"
msgWarn("Error while trying to kill dangerous applications")
proc start() =
......@@ -53,7 +53,7 @@ proc start() =
if isDesktop:
sendNotify("AnonSurf", "AnonSurf is running. Can't start it again", "security-low")
else:
echo "[x] AnonSurf is running. Can't start it again."
msgErr("AnonSurf is running. Can't start it again.")
return
killApps()
......@@ -65,12 +65,12 @@ proc start() =
if isDesktop:
sendNotify("AnonSurf", "You are under Tor network", "security-high")
else:
echo "[x] You are under Tor network."
msgErr("You are under Tor network.")
else:
if isDesktop:
sendNotify("AnonSurf", "AnonSurf Daemon is not running", "security-low")
else:
echo "[x] AnonSurf Daemon is not running."
msgErr("AnonSurf Daemon is not running.")
proc stop() =
......@@ -82,7 +82,7 @@ proc stop() =
if isDesktop:
sendNotify("AnonSurf", "AnonSurf is not running. Can't stop it", "security-low")
else:
echo "[x] AnonSurf is not running. Can't stop it."
msgErr("AnonSurf is not running. Can't stop it.")
return
runOSCommand(command, "Stop AnonSurf Daemon")
killApps()
......@@ -95,7 +95,7 @@ proc restart() =
if isDesktop:
sendNotify("AnonSurf", "AnonSurf is not running. Can't restart it", "security-low")
else:
echo "[x] AnonSurf is not running. Can't restart it."
msgErr("AnonSurf is not running. Can't restart it.")
return
runOSCommand(command, "Restart AnonSurf Daemon")
......@@ -105,17 +105,9 @@ proc checkBoot() =
# check if it is started with boot and show popup
let bootResult = isServEnabled("anonsurfd.service")
if bootResult:
echo "[*] AnonSurf is enabled at boot"
# if isDesktop:
# sendNotify("AnonSurf", "AnonSurf is enabled at boot", "security-high")
# else:
# echo "[*] AnonSurf is enabled at boot"
msgOk("AnonSurf is enabled at boot")
else:
echo "[!] AnonSurf is not enabled at boot"
# if isDesktop:
# sendNOtify("AnonSurf", "AnonSurf is not enabled at boot", "security-medium")
# else:
# echo "[!] AnonSurf is not enabled at boot"
msgWarn("AnonSurf is not enabled at boot")
proc enableBoot() =
......@@ -124,7 +116,7 @@ proc enableBoot() =
command = "/usr/bin/systemctl enable anonsurfd"
# enable anosnurf at boot (systemd only for now)
if isServEnabled("anonsurfd.service"):
echo "[x] AnonSurf is already enabled!"
msgErr("AnonSurf is already enabled!")
else:
runOSCommand(command, "Enable AnonSurf at boot")
......@@ -135,7 +127,7 @@ proc disableBoot() =
const
command = "/usr/bin/systemctl disable anonsurfd"
if not isServEnabled("anonsurfd.service"):
echo "[x] AnonSurf is already disabled!"
msgErr("AnonSurf is already disabled!")
else:
runOSCommand(command, "Disable AnonSurf at boot")
......@@ -146,7 +138,7 @@ proc changeID() =
if isDesktop:
sendNotify("AnonSurf", "AnonSurf is not running. Can't change ID", "error")
else:
echo "[x] AnonSurf is not running. Can't change your ID"
msgErr("AnonSurf is not running. Can't change your ID")
return
let conf = "/etc/anonsurf/nyxrc"
......@@ -157,30 +149,30 @@ proc changeID() =
if isDesktop:
sendNotify("Identity Change Error", recvData[0], "error")
else:
echo "[x] Failed to change Identity"
msgErr("Failed to change Identity")
else:
if recvData[1] != "250 OK\c":
if isDesktop:
sendNotify("Identity Change Error", recvData[1], "error")
else:
echo "[x] Failed to change Identity"
msgErr("Failed to change Identity")
else:
# Success. Show okay
if isDesktop:
sendNotify("Identity Change Success", "You have a new identity", "security-high")
else:
echo "[*] Change Identity success"
msgOk("Change Identity success")
except:
if isDesktop:
sendNotify("Identity Change Error", "Error while connecting to control port", "security-low")
else:
echo "[x] Error while changing ID"
msgErr("Error while changing ID")
echo getCurrentExceptionMsg()
else:
if isDesktop:
sendNotify("Identity Change Error", "File not found", "error")
else:
echo "[x] Config file not found"
msgErr("Config file not found")
proc status() =
......@@ -189,19 +181,19 @@ proc status() =
if isDesktop:
sendNotify("AnonSurf", "AnonSurf is not running", "security-low")
else:
echo "[x] AnonSurf is not running."
msgErr("AnonSurf is not running.")
else:
if not fileExists("/etc/anonsurf/nyxrc"):
if isDesktop:
sendNotify("AnonSurf", "Can't find nyx configuration", "error")
else:
echo "[x] Can't find nyx configuration"
msgErr("Can't find nyx configuration")
else:
discard execCmd("/usr/bin/nyx --config /etc/anonsurf/nyxrc")
proc dns() =
echo "[!] Please use DNS tool instead"
msgWarn("Please use DNS tool instead")
proc checkOptions() =
......@@ -237,6 +229,6 @@ proc checkOptions() =
if isDesktop:
sendNotify("AnonSurf", "Invalid option " & paramStr(1), "error")
else:
echo "[x] Invalid option " & paramStr(1)
msgErr("Invalid option " & paramStr(1))
checkOptions()
\ No newline at end of file
import os
import osproc
import .. / displays / noti
import print
let isDesktop* = if getEnv("XDG_CURRENT_DESKTOP") == "": false else: true
......@@ -16,9 +17,9 @@ proc runOSCommand*(command, commandName: string) =
else:
cmdResult = execCmd("sudo " & command)
if cmdResult == 0:
echo "[*] " & commandName & " success"
msgOk(commandName & " success")
else:
echo "[x] " & commandName & " failed"
msgErr(commandName & " failed")
proc cliUserAsk*(): bool =
......@@ -30,4 +31,4 @@ proc cliUserAsk*(): bool =
elif input == "n" or input == "N":
return false
else:
echo "[!] Invalid option. Please use Y / n"
msgWarn("Invalid option. Please use Y / n")
import strformat
const
B_MAGENTA = "\e[95m"
B_GREEN = "\e[92m"
B_RED = "\e[91m"
B_CYAN = "\e[96m"
B_BLUE = "\e[94m"
RESET = "\e[0m"
proc msgOk*(msg: string) =
echo fmt"[{B_GREEN}*{RESET}] {B_GREEN}{msg}{RESET}"
proc msgWarn*(msg: string) =
echo fmt"[{B_MAGENTA}!{RESET}] {B_BLUE}{msg}{RESET}"
proc msgErr*(msg: string) =
echo fmt"[{B_RED}x{RESET}] {B_CYAN}{msg}{RESET}"
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