- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFilePathNameTest.py
More file actions
Latest commit
97 lines (87 loc) · 2.69 KB
/
Copy pathFilePathNameTest.py
File metadata and controls
97 lines (87 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# Import libraries
importsys
importrequests
importos
importtime
importxmltodict
importurllib.parseasurlparse
# End imports
strConf_File="QSInput.ini"
defisInt (CheckValue):
# function to safely check if a value can be interpreded as an int
ifisinstance(CheckValue,int):
returnTrue
elifisinstance(CheckValue,str):
ifCheckValue.isnumeric():
returnTrue
else:
returnFalse
else:
returnFalse
print ("This is a Qualys Scan Report generator. This is running under Python Version {0}.{1}.{2}".format(sys.version_info[0],sys.version_info[1],sys.version_info[2]))
now=time.asctime()
print ("The time now is {}".format(now))
sa=sys.argv
lsa=len(sys.argv)
iflsa>1:
strSearchCrit=sa[1]
else:
print ("Project keyword was not provided and is required to continue. Project keyword can be partial but unique string.\n REQ1234 and 1234 are both acceptable.")
strSearchCrit=input("Please provide project keyword: ")
ifos.path.isfile(strConf_File):
print ("Configuration File exists")
else:
print ("Can't find configuration file QSInput.ini, make sure it is the same directory as this script")
sys.exit(4)
strLine=" "
print ("Reading in configuration")
objINIFile=open(strConf_File,"r")
strLines=objINIFile.readlines()
objINIFile.close()
forstrLineinstrLines:
strLine=strLine.strip()
if"="instrLine:
strConfParts=strLine.split("=")
ifstrConfParts[0] =="APIBaseURL":
strBaseURL=strConfParts[1]
ifstrConfParts[0] =="APIRequestHeader":
strHeadReq=strConfParts[1]
ifstrConfParts[0] =="ShowNumDays":
ifisInt(strConfParts[1]):
iNumDays=int(strConfParts[1])
else:
print ("Invalid value: {}".format(strLine))
sys.exit(5)
ifstrConfParts[0] =="ShowStartTime":
strTimeLastNight=str(strConfParts[1])
ifstrConfParts[0] =="QUserID":
strUserName=strConfParts[1]
ifstrConfParts[0] =="QUserPWD":
strPWD=strConfParts[1]
ifstrConfParts[0] =="FilterByUser":
strFilterUser=strConfParts[1]
ifstrConfParts[0] =="SecondsBeetweenChecks":
ifisInt(strConfParts[1]):
iSecSleep=int(strConfParts[1])
else:
print ("Invalid value: {}".format(strLine))
sys.exit(5)
ifstrConfParts[0] =="ReportSaveLocation":
strSaveLoc=strConfParts[1]
defisInt (CheckValue):
# function to safely check if a value can be interpreded as an int
ifisinstance(CheckValue,int):
returnTrue
elifisinstance(CheckValue,str):
ifCheckValue.isnumeric():
returnTrue
else:
returnFalse
else:
returnFalse
strFileDT=time.strftime("%m-%d-%Y-%H-%M")
ifstrSaveLoc[-1:] !="\\":
strSaveLoc+="\\"
strOutFile="{}Qualys Report {} {}".format(strSaveLoc,strSearchCrit,strFileDT)
strOutFile+=".csv"
print (strOutFile)