forked from JamezQ/Palaver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugins
executable file
·386 lines (379 loc) · 11.9 KB
/
plugins
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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
#!/usr/bin/env python
# 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/>.
import argparse, shutil, os, tarfile
import sqlite3 as sql
parser = argparse.ArgumentParser(description='Install and remove Plugins.')
parser.add_argument('-i', metavar='file', type=str,help='Install a plugin - plugin .sp or .info file',default="")
parser.add_argument('-r', metavar='plugin', type=str,help='Remove the specified plugin',default="")
parser.add_argument('-info', metavar='plugin', type=str,help='Display info on a plugin',default="")
parser.add_argument('-l', dest='listPlugins', action='store_true',default=False,help='List the installed plugins')
args = parser.parse_args()
listPlugins = args.listPlugins
encCode = 5
def sqlDefault(cur):
cur.execute("CREATE TABLE IF NOT EXISTS plugins(id INTEGER PRIMARY KEY, name TEXT, version TEXT, author TEXT, binFiles TEXT, dicts TEXT, actions TEXT, configs TEXT)")
def encrypt(text,code):
try:
p = ''
code = int(code)
for each in text:
i = ord(each)
p = p + str((i+code)*(code*3))
p = p + '12506'
return p[0:-5]
except:
return None
def decrypt(text,code):
try:
l = text.split('12506')
p = ''
c=int(code)
for each in l:
i = int(each)
p = p + chr((i/(c*3)-(c)))
return p
except:
return None
root = ''.join([e+'/' for e in os.path.realpath(__file__).split('/')[0:-1]])
if listPlugins == True:
con = sql.connect(root+"Recognition/config/plugins.db")
with con:
cur = con.cursor()
sqlDefault(cur)
cur.execute("SELECT * FROM plugins")
pluginList = cur.fetchall()
for line in pluginList:
pid,name,version,author,cmdfile,dictionaries,actions,configs = line
actions=decrypt(actions,encCode)
print "\t"+name,"-",version
actions = eval(actions)
for each in actions:
print "\t\t"+each[0]+"\t\t"+each[1].replace('\n','')
elif args.info != '':
con = sql.connect(root+"Recognition/config/plugins.db")
with con:
cur = con.cursor()
sqlDefault(cur)
cur.execute("SELECT * FROM plugins")
pluginList = cur.fetchall()
for line in pluginList:
pid,name,version,author,cmdfile,dictionaries,actions,configs = line
actions=decrypt(actions,encCode)
print "\t"+name,"-",version
if name == args.info:
print name
print "\tAuthor:",author
print "\tVersion:",version
print "\tCommand(s):",str(cmdfile)
print "\tDictionaries:",str(dictionaries)
print "\tActions:"
actions = eval(actions)
for each in actions:
print "\t\t"+each[0]+"\t\t"+each[1].replace('\n','')
print "\tCommands:"
dictionary = open(root+'Recognition/modes/main.dic')
adding = False
for line in dictionary:
if adding == False:
add = False
if line.startswith('#PLUGIN: '):
if line.replace('#PLUGIN: ','').replace('\n','') == args.info:
add = False
adding = True
else:
add = True
if line == "#END\n":
adding = False
add = False
if add == True:
print "\t\t"+line.replace('\n','')
dictionary.close()
elif args.i != '':
filename = args.i
plugins = {}
con = sql.connect(root+"Recognition/config/plugins.db")
with con:
cur = con.cursor()
sqlDefault(cur)
cur.execute("SELECT * FROM plugins")
pluginList = cur.fetchall()
for line in pluginList:
pid,name,version,author,cmdfile,dictionaries,actions,configs = line
plugins[name] = [float(version),eval(cmdfile)]
if filename.endswith('.sp'):
tar = tarfile.open(mode='r:gz',fileobj=file(filename))
data = tar.extractfile('plugin.info')
else:
try:
data = open(filename)
except:
print 'Invalid File - not found'
recActions = False
multiDesc = False
actions = []
depend = []
dictionaries = []
description = ''
for line in data:
if line.startswith("name"):
name = line.replace('name =','').replace(' ','').replace('\n','')
multiDesc = False
recActions = False
elif line.startswith("version"):
version = float(line.replace('version =','').replace(' ','').replace('\n',''))
multiDesc = False
recActions = False
elif line.startswith("description"):
multiDesc = True
recActions = False
elif line.startswith('dictionaries'):
dictionaries = line.replace('dictionaries =','').replace(' ','').replace('\n','')
try:
dictionaries = dictionaries.split(',')
except:
dictionaries = [dictionaries]
recActions = False
multiDesc = False
elif line.startswith('configs'):
configs = line.replace('configs =','').replace(' ','').replace('\n','')
try:
configs = configs.split(',')
except:
configs = [configs]
recActions = False
multiDesc = False
elif line.startswith("file"):
cmdfile = line.replace('file =','').replace(' ','').replace('\n','')
try:
cmdfile = cmdfile.split(",")
except:
cmdfile = [cmdfile]
multiDesc = False
recActions = False
elif line.startswith("author"):
author = line.replace("author =",'').replace('\n','')
if author.startswith(' '):
author = author[1:]
multiDesc = False
recActions = False
elif line.startswith("dependencies"):
depend = line.replace("dependencies = ",'').replace('\n','')
multiDesc = False
recActions = False
try:
depend = depend.split(" ")
except:
depend = [depend]
elif line.startswith("actions"):
recActions = True
multiDesc = False
if multiDesc == True:
if line != '':
description = description + line.replace('description =','').replace('\n','')
if recActions == True:
if line.replace('actions =','').replace('\n','').replace(' ','') != '':
actions.append(line.replace('\n','').split(',',1))
if vars().has_key("configs") == False:
configs = list()
data.close()
install = True
try:
currentVersion = plugins[name][0]
if currentVersion > version:
print "A newer version is already installed"
elif currentVersion == version:
print "This version is already installed"
else:
print "Updating Files Has Not Yet Been Added, please remove the old version with -r and then install again"
#Install Files
except:
for each in plugins:
for exe in plugins[each][1]:
if exe in cmdfile and exe != 'NONE' and len(plugins[each][1]) != 1 and install == True:
print "This plugin has a conflict with",each
print "Please rename the executable"
install = False
if install != False:
print name
print
print description
if type(configs) != list:
configs = eval(configs)
if len(depend) != 0:
print "WARNING: THIS PLUGIN REQUIRES:"
for each in depend:
print each,
print
print
if raw_input("Are you sure you want to continue? [Y/N]").lower() == 'y':
try:
dictionary = open(root+'Recognition/modes/main.dic')
text = dictionary.read()
dictionary.close()
if filename.endswith('.sp'):
command = tar.extractfile('actions.dic').read()
else:
data = open(''.join([e+'/' for e in args.i.split('/')[0:-1]]) + 'actions.dic')
command = data.read()
data.close()
try:
dictionary = open(root+'Recognition/modes/main.dic','w')
dictionary.write("#PLUGIN: "+name+"\n")
dictionary.write(command)
dictionary.write("#END\n")
dictionary.write(text)
except:
print "Error Installing Plugin In main.dic"
dictionary.close()
except:
print "Dictionary Not Found"
if filename.endswith('.sp'):
try:
for dic in dictionaries:
binfile = open(root+"Recognition/modes/"+dic,'w')
binfile.write(tar.extractfile(dic).read())
binfile.close()
print "File Installed to modes",dic
except:
print "Error Installing to modes",dic
try:
for c in configs:
try:
os.system("mkdir "+root+"Recognition/config/"+name+"/")
except:
pass
confile = open(root+"Recognition/config/"+name+"/"+c,'w')
confile.write(tar.extractfile(c).read())
confile.close()
print "File Installed to config",c
except:
print "Error Installing to config",c
else:
src = ''.join([e+'/' for e in filename.split('/')[0:-1]])
try:
for dic in dictionaries:
shutil.copy(src+exe,root+"Recognition/modes/")
print "File Installed to Modes",dic
except:
print "Error Moving File to Modes",dic
try:
for c in config:
try:
os.system("mkdir "+root+"Recognition/config/"+name+"/")
except:
pass
shutil.copy(src+c,root+"Recognition/config/"+args.i+"/")
print "File Installed to Config",c
except:
print "Error Moving File To Config",c
if cmdfile != "NONE":
if filename.endswith('.sp'):
try:
for exe in cmdfile:
binfile = open(root+"Recognition/bin/"+exe,'w')
binfile.write(tar.extractfile(exe).read())
binfile.close()
print "File Installed to Bin",exe
except:
print "Error Installing to Bin",exe
else:
src = ''.join([e+'/' for e in filename.split('/')[0:-1]])
try:
for exe in cmdfile:
shutil.copy(src+exe,root+"Recognition/bin/")
print "File Installed to Bin",exe
except:
print "Error Moving File"
for exe in cmdfile:
os.system("chmod +x "+root+"Recognition/bin/"+exe)
con = sql.connect(root+"Recognition/config/plugins.db")
with con:
cur = con.cursor()
sqlDefault(cur)
execline = "INSERT INTO plugins VALUES(NULL, \""+name+"\", \""+str(version)+"\", \""+author+"\", \""+str(cmdfile)+"\", \""+str(dictionaries)+"\", \""+encrypt(str(actions),encCode)+"\", \""+str(configs)+"\")"
cur.execute(execline)
else:
print "Quiting Installation"
elif args.r != '':
pluginName = args.r
try:
pluginList = open(root+'plugins')
except:
print "Plugins Library Not Found"
good = False
try:
dictionary = open(root+'Recognition/modes/main.dic')
text = ""
deleting = False
for line in dictionary:
if deleting == False:
add = True
if line.startswith('#PLUGIN: '):
if line.replace('#PLUGIN: ','').replace('\n','') == pluginName:
add = False
deleting = True
else:
add = False
if line == "#END\n":
deleting = False
if add == True:
text = text + line
dictionary.close()
try:
dictionary = open(root+'Recognition/modes/main.dic','w')
dictionary.write(text)
except:
print "Error Installing Plugin In main.dic"
dictionary.close()
except:
print "Dictionary Not Found"
found = False
con = sql.connect(root+"Recognition/config/plugins.db")
with con:
cur = con.cursor()
sqlDefault(cur)
cur.execute("SELECT * FROM plugins")
pluginList = cur.fetchall()
for line in pluginList:
pid,name,version,author,cmdfile,dictionaries,actions,configs = line
actions=decrypt(actions,encCode)
cmdfile = eval(cmdfile)
dictionaries = eval(dictionaries)
configs = eval(configs)
if name == pluginName:
good = True
if cmdfile[0] != "NONE":
for exe in cmdfile:
try:
os.remove(root+"Recognition/bin/"+exe)
print "Removed from Bin",exe
except:
print "Couldn't remove "+exe+" from bin"
for dic in dictionaries:
try:
os.remove(root+"Recognition/modes/"+dic)
print 'Removed from Modes',dic
except:
print "Couldn't remove "+dic+" from modes"
for c in configs:
try:
os.remove(root+"Recognition/config/"+args.r+"/"+c)
print 'Removed from Config',c
except:
print "Couldn't remove "+c+" from config"
cur.execute("DELETE FROM plugins WHERE id = "+str(pid))
print name,"Uninstalled"
found = True
if found == False:
print "Plugin Not Installed"
else:
print "No Action Supplied"