Skip to content

Commit a47eb2f

Browse files
authored
Merge pull request danielmiessler#974 from molangning/patch-checker-scripts
Fix of danielmiessler#939
2 parents 2ea39c1 + 5fbcb2f commit a47eb2f

8 files changed

+523
-67
lines changed

.bin/check-file-for-starting-slash

Lines changed: 0 additions & 17 deletions
This file was deleted.

.bin/checkers/README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
All the files here will be run by `validators.sh` as part of the check pipeline
2+
3+
## Specifications
4+
Scripts will be passed a space separated list of files to check
5+
e.g `./script.sh "Discovery/Web-Content/trickest-robots-disallowed-wordlists/top-100.txt"`
6+
7+
If you want your output to be parsed by the caller script, follow the below specs,else the output will be displayed raw in actions summaries
8+
9+
## Wrapped calls
10+
11+
### Wrapped calls checks
12+
13+
- - -
14+
15+
Scripts should check if its being run by the caller script. The environment variable `IS_RUNNING_UNDER_CALLER_SCRIPT` will be set to one
16+
17+
### Wrapped calls Specifications
18+
19+
- - -
20+
21+
Checker scripts will now have to print out the name of the check followed by a new line
22+
23+
Example `New line checker`
24+
25+
This value will be used as the checker title
26+
27+
After that, the descriptions will need to be printed out
28+
29+
Example `To fix the error, you have to remove the empty lines or new lines at the end of the file`
30+
31+
This is for contributors to understand why the checks failed
32+
33+
- - -
34+
35+
Outputs from now on will have to be in separate lines for each warnings or errors
36+
37+
This is the format for errors
38+
39+
Example `E,filename,line_number`
40+
41+
In the above example, `E` stands for errors. Accepted values are `E` and `W` for errors and warnings respectively
42+
43+
filename is the name of the file that the error comes from.
44+
45+
line_number is the line the script detected the error in.
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/usr/bin/python3
2+
3+
import os,sys
4+
5+
if not sys.argv[1]:
6+
exit(0)
7+
8+
IS_WRAPPED=False
9+
10+
if "IS_RUNNING_UNDER_CALLER_SCRIPT" in os.environ:
11+
IS_WRAPPED=os.environ['IS_RUNNING_UNDER_CALLER_SCRIPT']=="1"
12+
13+
def print_normal(msg):
14+
15+
if IS_WRAPPED:
16+
return
17+
print(msg)
18+
19+
def print_err(file,line_number):
20+
21+
if IS_WRAPPED:
22+
print("E,%s,%s"%(file,line_number))
23+
24+
def print_warn(file,line_number):
25+
26+
if IS_WRAPPED:
27+
print("W,%s,%s"%(file,line_number))
28+
29+
print_normal("[+] Entries starting with slash checker")
30+
if IS_WRAPPED:
31+
print("Entries starting with slash check")
32+
print("The warning are more for informative purposes and does not actually serve as a check. You can ignore this.")
33+
34+
files=sys.argv[1].split(" ")
35+
36+
for i in files:
37+
if not os.path.isfile(i):
38+
print_err(i,0)
39+
print_normal("[!] %s does not exist!"%(i))
40+
exit(2)
41+
42+
pass_status=True
43+
44+
for i in files:
45+
contents=open(i,"rb").read()
46+
counter=1
47+
48+
for line in contents.splitlines():
49+
if line.startswith(b'/'):
50+
print_normal("[!] Warning: %s starts with a slash on line %i!"%(i,counter))
51+
print_warn(i,counter)
52+
pass_status=False
53+
54+
counter+=1
55+
print_normal("[+] %s passed no starting slash check!"%(i))
56+
57+
if pass_status:
58+
print_normal("[+] All files passed checks")
59+
exit(0)
60+
61+
print_normal("[!] Warning: One or more files failed to pass the checks")
62+
63+
if IS_WRAPPED:
64+
exit(0)
65+
else:
66+
exit(2)
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#!/usr/bin/env python3
2+
3+
import os,sys
4+
5+
if not sys.argv[1]:
6+
exit(0)
7+
8+
IS_WRAPPED=False
9+
10+
if "IS_RUNNING_UNDER_CALLER_SCRIPT" in os.environ:
11+
IS_WRAPPED=os.environ['IS_RUNNING_UNDER_CALLER_SCRIPT']=="1"
12+
13+
def print_normal(msg):
14+
15+
if IS_WRAPPED:
16+
return
17+
print(msg)
18+
19+
def print_err(file,line_number):
20+
21+
if IS_WRAPPED:
22+
print("E,%s,%s"%(file,line_number))
23+
24+
def print_warn(file,line_number):
25+
26+
if IS_WRAPPED:
27+
print("W,%s,%s"%(file,line_number))
28+
29+
print_normal("[+] New line and empty line check")
30+
if IS_WRAPPED:
31+
print("New line and empty line check")
32+
print("To fix the error, you would have to remove the empty lines or new lines at the end of the file.")
33+
34+
files=sys.argv[1].split(" ")
35+
36+
for i in files:
37+
if not os.path.isfile(i):
38+
print_err(i,0)
39+
print_normal("[!] %s does not exist!"%(i))
40+
exit(2)
41+
42+
overall_pass_status=True
43+
44+
for i in files:
45+
46+
contents=open(i,"rb").read()
47+
line_number=len(contents.split(b'\n'))+1
48+
49+
if contents[-1:] == b'\n':
50+
print_normal("[!] Warning: %s ends with a new line!"%(i))
51+
print_warn(i,line_number)
52+
overall_pass_status=False
53+
else:
54+
print_normal("[+] %s passed new line check!"%(i))
55+
56+
counter=1
57+
58+
line_pass_status=True
59+
60+
for line in contents.splitlines():
61+
if not line:
62+
print_normal("[!] Warning: %s has an empty entry on line %i!"%(i,counter))
63+
print_warn(i,counter)
64+
pass_status=False
65+
line_pass_status=False
66+
continue
67+
68+
elif not line.strip():
69+
print_normal("[!] Warning: %s has an whitespace only entry on line %i!"%(i,counter))
70+
print_warn(i,counter)
71+
pass_status=False
72+
line_pass_status=False
73+
continue
74+
75+
counter+=1
76+
if line_pass_status:
77+
print_normal("[+] %s passed empty line check!"%(i))
78+
79+
if overall_pass_status:
80+
print_normal("[+] All files passed checks")
81+
exit(0)
82+
83+
print_normal("[!] Warning: One or more files failed to pass the checks")
84+
85+
if IS_WRAPPED:
86+
exit(0)
87+
else:
88+
exit(2)

.bin/new-line-and-empty-line-checker.py

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)