Commit ccdff244 authored by dmknght's avatar dmknght

Add handling url and file path

parent ea1f0ce1
Pipeline #1132 canceled with stages
# import tables
import os
# import strutils
import .. / cores / paramHandler
type
......@@ -9,11 +9,17 @@ type
wordlist*: string
cookie*: string
agent*: string
paramError*: bool
proc getOptions*(): DirbOptions =
var allOptions: DirbOptions
allOptions = DirbOptions(wordlist: "/usr/share/wordlists/common.txt")
allOptions = DirbOptions(
wordlist: "/usr/share/wordlists/common.txt",
paramError: false
)
let
szArgs = paramCount()
helpKeywords = ["help", "--help", "-h", "--h", "-help"]
......@@ -22,28 +28,29 @@ proc getOptions*(): DirbOptions =
discard # TODO fast help and exit
of 1:
if paramStr(1) in helpKeywords:
discard # TODO fast help and exit
discard # TODO full help and exit
else:
# TODO move this block to 1 proc: add and get url?
allOptions.url = paramStr(1)
# TODO handleURL here
allOptions.url = urlFormat(paramStr(1))
else:
var i = 1
while i < szArgs:
case paramStr(i):
of "-w":
allOptions.wordlist = paramStr(i + 1)
# TODO check if path exist
# TODO check read file perm okay
allOptions.wordlist = validWordlist(paramStr(i + 1))
if allOptions.wordlist == "":
allOptions.paramError = true
break
of "-c":
allOptions.cookie = paramStr(i + 1)
of "-a":
allOptions.agent = paramStr(i + 1)
else:
# TODO move this block to 1 proc: add and get url?
allOptions.url = paramStr(i)
# TODO handle URL here
i -= 1
if paramStr(i) in helpKeywords:
# TODO full help banner and handle exit
discard
else:
allOptions.url = urlFormat(paramStr(1))
i -= 1
i += 2
return allOptions
import strutils
import os
proc urlFormat*(url: string): string =
#[
Return a url with format http://domain.name/
Input: URL: string
Outpt: URL: string
]#
if not url.startsWith("http://") and not url.startsWith("https://"):
echo "[W] Missing protocol in URL. Added http:// by default."
result = "http://" & url
if not result.endsWith("/"):
result &= "/"
proc validWordlist*(path: string): string =
#[
Verify if file path is valid and
file can be read
Input: path: string
Output: path: string or
"" (empty): Path is not valid or
file can't be read
]#
if not fileExists(path):
echo "[E] Invalid wordlist path"
return ""
try:
let f = open(path, fmRead)
f.close()
result = path
except IOError:
echo "[E] Can't read file"
result = ""
except:
echo "[E] Unknown error"
echo getCurrentExceptionMsg()
result = ""
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