-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWordPress_Plugin_Enum.vbs
More file actions
273 lines (219 loc) · 8.43 KB
/
WordPress_Plugin_Enum.vbs
File metadata and controls
273 lines (219 loc) · 8.43 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
'enumerates WordPress plugin directory documenting plugin name and version. Does not enum plugin provided libraries, dependencies, etc.
'Pass folder path to plugin directory in quotes as parameter to script
'Example:
'WordPress_Plugin_Enum.vbs "d:\wp\apps\wordpress\htdocs\wp-content\plugins"
'Copyright (c) 2018 Ryan Boyle randomrhythm@rhythmengineering.com.
'This program is free software: you can redistribute it and/or modify
'it under the terms of the GNU General Public License as published by
'the Free Software Foundation, either version 3 of the License, or
'(at your option) any later version.
'This program is distributed in the hope that it will be useful,
'but WITHOUT ANY WARRANTY; without even the implied warranty of
'MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
'GNU General Public License for more details.
'You should have received a copy of the GNU General Public License
'along with this program. If not, see <http://www.gnu.org/licenses/>.
Const forwriting = 2
Const ForAppending = 8
Const ForReading = 1
Dim strLoggingCache
Dim strEnumFolder 'Folder path to WordPress plugin directory
strEnumFolder = "" 'add folder path here or pass as parameter to not be prompted for folder path
Set objFSO = CreateObject("Scripting.FileSystemObject")
CurrentDirectory = GetFilePath(wscript.ScriptFullName)
if WScript.Arguments.count <> 0 then
if WScript.Arguments(0) <> "" then
if objFSO.folderexists(WScript.Arguments(0)) = True then
strEnumFolder = WScript.Arguments(0)
end if
end if
end if
if strEnumFolder = "" then
msgbox "select plugin folder. Example: .\wordpress\htdocs\wp-content\plugins"
strEnumFolder = SelectFolder("")
end if
if strEnumFolder = "" or strEnumFolder = vbNull then
Msgbox "No folder was selected. Exiting"
wscript.quit
end if
set enumDir = objFSO.GetFolder(strEnumFolder)
'enumerate plugin folder directory
For Each Subfolder in enumDir.SubFolders
'Wscript.Echo Subfolder.Path
GetVersionInfo Subfolder.Path, Subfolder.name
Next
msgbox "Finished parsing plugins. Output file located at " & Chr(34) & CurrentDirectory & "\WP_Plugins.txt" & chr(34)
sub GetVersionInfo(strFolderPath, strFolderName)
Set objFolder = objFSO.GetFolder(strFolderPath)
Set colFiles = objFolder.Files
boolVersionLogged = False
strLoggingCache = ""
For Each objFile in colFiles
if instr(lcase(strFolderName), lcase(objFile.Name)) > 0 then
boolVersionLogged = LogVersionNumber (strFolderPath, strFolderName, objFile.Name, boolVersionLogged)
elseif instr(replace(lcase(objFile.Name), ".php", ""), lcase(strFolderName)) > 0 then
boolVersionLogged = LogVersionNumber (strFolderPath, strFolderName, objFile.Name, boolVersionLogged)
elseif instr(lcase(objFile.Name), ".php") > 0 and boolVersionLogged = False then
boolVersionLogged = LogVersionNumber (strFolderPath, strFolderName, objFile.Name, boolVersionLogged)
end if
Next
if boolVersionLogged = False then
LogData CurrentDirectory & "\WP_Plugins.txt", strLoggingCache, false
end if
end sub
Function LogVersionNumber(strFolderPath, strFolderName, strFileName, boolAlreadyLogged)
set readfilePath = objFSO.OpenTextFile(strFolderPath & "\" & strFileName, 1, false)
if not readfilePath.AtEndOfStream then dataresults = readfilepath.readall
readfilePath.close
set readfilePath = Nothing
strVersion = getdata(lcase(dataresults), vblf, "version:")
strVersion = RemoveTLS(strVersion)
if boolAlreadyLogged = False then
stroutput = strFolderName & "|" & strFileName & "|" & strVersion
if isVersion(strVersion) = False then
strLoggingCache = AppendValuesList(strLoggingCache, stroutput, vbCrLf)
else
LogData CurrentDirectory & "\WP_Plugins.txt", stroutput, false
end if
end if
if isVersion(strVersion) = False and boolAlreadyLogged = False then
LogVersionNumber = False
else
LogVersionNumber = True
end if
end Function
Function isVersion(strIPaddress)
boolIsVersion = False
if len(strIPaddress) > 1 then
if isnumeric(left(strIPaddress, 1)) = True then
boolIsVersion = True
elseif len(strIPaddress) > 2 then
if left(strIPaddress, 1) = "." then
if isnumeric(mid(strIPaddress, 2, 1)) then
boolIsVersion = True
end if
end if
end if
end if
isVersion = boolIsVersion
end function
Function AppendValuesList(strAggregate,strAppend,strSeparator)
if strAggregate = "" then
strAggregate = strAppend
else
strAggregate = strAggregate & strSeparator & strAppend
end if
AppendValuesList = strAggregate
end Function
Function GetData(contents, ByVal EndOfStringChar, ByVal MatchString)
MatchStringLength = Len(MatchString)
x= instr(contents, MatchString)
if X >0 then
strSubContents = Mid(contents, x + MatchStringLength, len(contents) - MatchStringLength - x +1)
if instr(strSubContents,EndOfStringChar) > 0 then
GetData = Mid(contents, x + MatchStringLength, instr(strSubContents,EndOfStringChar) -1)
'msgbox "success:" & Mid(contents, x + MatchStringLength, instr(Mid(contents, x + MatchStringLength, len(contents) -x),EndOfStringChar) -1)
exit function
else
GetData = Mid(contents, x + MatchStringLength, len(contents) -x -1)
'msgbox "failed match:" & Mid(contents, x + MatchStringLength, len(contents) -x -1)
exit function
end if
end if
GetData = ""
end Function
Function RemoveTLS(strTLS)
dim strTmpTLS
if len(strTLS) > 0 then
for rmb = 1 to len(strTLS)
if mid(strTLS, rmb, 1) <> " " then
strTmpTLS = right(strTLS,len(strTLS) - RMB +1)
exit for
end if
next
end if
if len(strTmpTLS) > 0 then
for rmb = len(strTmpTLS) to 1 step -1
if mid(strTmpTLS, rmb, 1) <> " " then
strTmpTLS = left(strTmpTLS,len(strTmpTLS) - (len(strTmpTLS) - RMB))
exit for
end if
next
end if
strTmpTLS = replace(strTmpTLS, vbcr, "")
strTmpTLS = replace(strTmpTLS, vbLf, "")
RemoveTLS = strTmpTLS
end function
function LogData(TextFileName, TextToWrite,EchoOn)
Set fsoLogData = CreateObject("Scripting.FileSystemObject")
if EchoOn = True then wscript.echo TextToWrite
If fsoLogData.fileexists(TextFileName) = False Then
'Creates a replacement text file
on error resume next
fsoLogData.CreateTextFile TextFileName, True
if err.number <> 0 and err.number <> 53 then msgbox "Logging error: " & err.number & " " & err.description & vbcrlf & TextFileName
on error goto 0
End If
if TextFileName <> "" then
Set WriteTextFile = fsoLogData.OpenTextFile(TextFileName,ForAppending, False)
on error resume next
WriteTextFile.WriteLine TextToWrite
if err.number <> 0 then
on error goto 0
WriteTextFile.Close
Dim objStream
Set objStream = CreateObject("ADODB.Stream")
objStream.CharSet = "utf-16"
objStream.Open
objStream.WriteText TextToWrite
on error resume next
objStream.SaveToFile TextFileName, 2
if err.number <> 0 then msgbox err.number & " - " & err.message & " Problem writting to " & TextFileName
if err.number <> 0 then msgbox "problem writting text: " & TextToWrite
on error goto 0
Set objStream = nothing
end if
end if
Set fsoLogData = Nothing
End Function
Function GetFilePath (ByVal FilePathName)
found = False
Z = 1
Do While found = False and Z < Len((FilePathName))
Z = Z + 1
If InStr(Right((FilePathName), Z), "\") <> 0 And found = False Then
mytempdata = Left(FilePathName, Len(FilePathName) - Z)
GetFilePath = mytempdata
found = True
End If
Loop
end function
Function SelectFolder( myStartFolder )
' This function opens a "Select Folder" dialog and will
' return the fully qualified path of the selected folder
'
' Argument:
' myStartFolder [string] the root folder where you can start browsing;
' if an empty string is used, browsing starts
' on the local computer
'
' Returns:
' A string containing the fully qualified path of the selected folder
'
' Written by Rob van der Woude
' http://www.robvanderwoude.com
' Standard housekeeping
Dim objFolder, objItem, objShell
' Custom error handling
On Error Resume Next
SelectFolder = vbNull
' Create a dialog object
Set objShell = CreateObject( "Shell.Application" )
Set objFolder = objShell.BrowseForFolder( 0, "Select Folder", 0, myStartFolder )
' Return the path of the selected folder
If IsObject( objfolder ) Then SelectFolder = objFolder.Self.Path
' Standard housekeeping
Set objFolder = Nothing
Set objshell = Nothing
On Error Goto 0
End Function