-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlibrary.py
508 lines (444 loc) · 22.1 KB
/
library.py
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
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
#!/usr/bin/env python
from google.appengine.api import users
from google.appengine.api import urlfetch
from google.appengine.api.urlfetch import DownloadError
from google.appengine.ext import webapp
from google.appengine.ext import db
from google.appengine.api import memcache
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext.webapp import template
from boto.ec2.connection import *
from boto.ec2 import *
from boto.s3.connection import *
from boto.s3 import *
from dateutil.parser import *
from dateutil.tz import *
from datetime import *
# this is needed for the encyption
from itertools import izip, cycle
import hmac, sha
# this is needed for the encyption
import base64
from ConfigParser import SafeConfigParser
parser = SafeConfigParser()
parser.read('simple.cfg')
from internal.Datastore import *
def xor_crypt_string(data, key):
return ''.join(chr(ord(x) ^ ord(y)) for (x,y) in izip(data, cycle(key)))
def aktuelle_sprache(username):
# Is there an entry for the user that shows that he has already chosen a language?
spracheanfrage = db.GqlQuery("SELECT * FROM OctopusCloudDatenbankSprache WHERE user = :username_db", username_db=username)
ergebnisse = spracheanfrage.fetch(10)
if not ergebnisse:
logindaten = OctopusCloudDatenbankSprache(sprache="en",
user=username)
logindaten.put() # Write into datastore
spracheanfrage = db.GqlQuery("SELECT * FROM OctopusCloudDatenbankSprache WHERE user = :username_db", username_db=username)
ergebnisse = spracheanfrage.fetch(10)
for ergebnis in ergebnisse:
if ergebnis.sprache == "en":
sprache = "en"
elif ergebnis.sprache == "de":
sprache = "de"
else:
sprache = "en"
return sprache
def navigations_bar_funktion(sprache):
if sprache == "de":
navigations_bar = ' \n'
navigations_bar = navigations_bar + '<a href="/regionen" title="Zugansdaten">Zugansdaten</a> | \n'
navigations_bar = navigations_bar + '<a href="/s3" title="Ihre Daten">Ihre Daten</a> | \n'
navigations_bar = navigations_bar + '<a href="/info" title="Info">Info</a> \n'
else:
navigations_bar = ' \n'
navigations_bar = navigations_bar + '<a href="/regionen" title="Credentials">Credentials</a> | \n'
navigations_bar = navigations_bar + '<a href="/s3" title="Your Data">Your Data</a> | \n'
navigations_bar = navigations_bar + '<a href="/info" title="Info">Info</a> \n'
return navigations_bar
# Helper function for formating the error messages
def format_error_message_green(input_error_message):
if input_error_message:
return "<p> </p> <font color='green'>%s</font>" % (input_error_message)
else:
return ""
# Helper function for formating the error messages
def format_error_message_red(input_error_message):
if input_error_message:
return "<p> </p> <font color='red'>%s</font>" % (input_error_message)
else:
return ""
def logins3(username, aktuellezone):
if aktuellezone == "Amazon":
# Die Zugangsdaten des Benutzers holen
zugangsdaten = db.GqlQuery("SELECT * FROM OctopusCloudDatenbank WHERE user = :username_db AND zugangstyp = :zugangstyp_db", username_db=username, zugangstyp_db="Amazon")
aktuellezone = "Amazon"
regionname = "Amazon"
for db_eintrag in zugangsdaten:
accesskey = db_eintrag.accesskey
secretaccesskey = db_eintrag.secretaccesskey
endpointurl = db_eintrag.endpointurl
port = db_eintrag.port
secretaccesskey_base64decoded = base64.b64decode(str(secretaccesskey))
secretaccesskey = xor_crypt_string(secretaccesskey_base64decoded, key=str(username))
conn_s3 = boto.s3.connection.S3Connection(aws_access_key_id=accesskey,
aws_secret_access_key=secretaccesskey,
is_secure=True,
host="s3.amazonaws.com",
calling_format=boto.s3.connection.OrdinaryCallingFormat(),
path="/")
elif aktuellezone == "GoogleStorage":
# Die Zugangsdaten des Benutzers holen
zugangsdaten = db.GqlQuery("SELECT * FROM OctopusCloudDatenbank WHERE user = :username_db AND zugangstyp = :zugangstyp_db", username_db=username, zugangstyp_db="GoogleStorage")
aktuellezone = "GoogleStorage"
regionname = "GoogleStorage"
for db_eintrag in zugangsdaten:
accesskey = db_eintrag.accesskey
secretaccesskey = db_eintrag.secretaccesskey
endpointurl = db_eintrag.endpointurl
#port = db_eintrag.port
secretaccesskey_base64decoded = base64.b64decode(str(secretaccesskey))
secretaccesskey = xor_crypt_string(secretaccesskey_base64decoded, key=str(username))
conn_s3 = boto.s3.connection.S3Connection(aws_access_key_id=accesskey,
aws_secret_access_key=secretaccesskey,
is_secure=True,
host="commondatastorage.googleapis.com",
calling_format=boto.s3.connection.OrdinaryCallingFormat(),
path="/")
else:
# aktuellezone == "Eucalyptus":
zugangsdaten = db.GqlQuery("SELECT * FROM OctopusCloudDatenbank WHERE user = :username_db AND zugangstyp = :zugangstyp_db", username_db=username, zugangstyp_db="Eucalyptus")
aktuellezone = "Eucalyptus"
regionname = "Eucalyptus"
for db_eintrag in zugangsdaten:
accesskey = db_eintrag.accesskey
secretaccesskey = db_eintrag.secretaccesskey
endpointurl = db_eintrag.endpointurl
port = db_eintrag.port
secretaccesskey_base64decoded = base64.b64decode(str(secretaccesskey))
secretaccesskey = xor_crypt_string(secretaccesskey_base64decoded, key=str(username))
conn_s3 = boto.s3.connection.S3Connection(aws_access_key_id=accesskey,
aws_secret_access_key=secretaccesskey,
is_secure=False,
host=endpointurl,
port=int(port),
calling_format=boto.s3.connection.OrdinaryCallingFormat(),
path="/services/Walrus")
return conn_s3, regionname
def aws_access_key_erhalten(username,eucalyptusname):
Anfrage_nach_AWSAccessKeyId = db.GqlQuery("SELECT * FROM OctopusCloudDatenbank WHERE user = :username_db AND eucalyptusname = :eucalyptusname_db", username_db=username, eucalyptusname_db=eucalyptusname)
for db_eintrag in Anfrage_nach_AWSAccessKeyId:
AWSAccessKeyId = db_eintrag.accesskey
return AWSAccessKeyId
def aws_secret_access_key_erhalten(username,eucalyptusname):
Anfrage_nach_AWSSecretAccessKeyId = db.GqlQuery("SELECT * FROM OctopusCloudDatenbank WHERE user = :username_db AND eucalyptusname = :eucalyptusname_db", username_db=username, eucalyptusname_db=eucalyptusname)
for db_eintrag in Anfrage_nach_AWSSecretAccessKeyId:
AWSSecretAccessKeyId = db_eintrag.secretaccesskey
secretaccesskey_base64decoded = base64.b64decode(str(AWSSecretAccessKeyId))
AWSSecretAccessKeyId = xor_crypt_string(secretaccesskey_base64decoded, key=str(username))
return AWSSecretAccessKeyId
def endpointurl_erhalten(username,eucalyptusname):
Anfrage_nach_endpointurl = db.GqlQuery("SELECT * FROM OctopusCloudDatenbank WHERE user = :username_db AND eucalyptusname = :eucalyptusname_db", username_db=username, eucalyptusname_db=eucalyptusname)
for db_eintrag in Anfrage_nach_endpointurl:
endpointurl = db_eintrag.endpointurl
return endpointurl
def port_erhalten(username,eucalyptusname):
Anfrage_nach_port = db.GqlQuery("SELECT * FROM OctopusCloudDatenbank WHERE user = :username_db AND eucalyptusname = :eucalyptusname_db", username_db=username, eucalyptusname_db=eucalyptusname)
for db_eintrag in Anfrage_nach_port:
port = db_eintrag.port
return port
def get_second_list(username,eucalyptusname,aktuellezone):
if aktuellezone == "Amazon":
# It is Amazon S3 ... so we need to connect with Google Storage
Anfrage_nach_zugangsdaten = db.GqlQuery("SELECT * FROM OctopusCloudDatenbank WHERE user = :username_db AND eucalyptusname != :eucalyptusname_db", username_db=username, eucalyptusname_db=eucalyptusname)
for db_eintrag in Anfrage_nach_zugangsdaten:
accesskey = db_eintrag.accesskey
secretaccesskey = db_eintrag.secretaccesskey
endpointurl = db_eintrag.endpointurl
port = db_eintrag.port
secretaccesskey_base64decoded = base64.b64decode(str(secretaccesskey))
secretaccesskey = xor_crypt_string(secretaccesskey_base64decoded, key=str(username))
conn_s3 = boto.s3.connection.S3Connection(aws_access_key_id=accesskey,
aws_secret_access_key=secretaccesskey,
is_secure=True,
host="commondatastorage.googleapis.com",
calling_format=boto.s3.connection.OrdinaryCallingFormat(),
path="/")
# Get values from the config file
# The name of the bucket that is used
# The character "@" cannot be used. Therefore we use "at".
bucketname = str(parser.get('bucket', 'bucketname'))+str(username).replace('@', 'at').replace('.', '-')
try:
# Connect with bucket
bucket_instance = conn_s3.get_bucket(bucketname)
except:
# When it didn't work
if sprache == "de":
bucket_keys_tabelle = '<font color="red">Es ist zu einem Fehler gekommen</font>'
else:
bucket_keys_tabelle = '<font color="red">An error occured</font>'
laenge_liste_keys = 0
else:
# When it worked...
try:
# Get a list of all keys inside the bucket
liste_keys = bucket_instance.get_all_keys()
except:
# When it didn't work
if sprache == "de":
bucket_keys_tabelle = '<font color="red">Es ist zu einem Fehler gekommen</font>'
else:
bucket_keys_tabelle = '<font color="red">An error occured</font>'
laenge_liste_keys = 0
else:
# When it worked...
# Number of keys inside the list
laenge_liste_keys = len(liste_keys)
# When using Walrus (Eucalyptus), we need to erase the stupid "None" entry.
# if aktuellezone != "Amazon":
# liste_keys2 = []
# for i in range(laenge_liste_keys):
# if str(liste_keys[i].name) != 'None':
# liste_keys2.append(liste_keys[i])
# laenge_liste_keys2 = len(liste_keys2)
# laenge_liste_keys = laenge_liste_keys2
# liste_keys = liste_keys2
# If we have keys inside the bucket, we need to create a list that contains the MD5 checksums
if laenge_liste_keys == 0:
# Create an empty List
Main_Liste = []
Second_list = Main_Liste
else:
# if laenge_liste_keys is not 0
# Create an empty List
Main_Liste = []
# Walk through the list of keys
for i in range(laenge_liste_keys):
# In S3 each MD5 checksum is enclosed by double quotes. In Walrus they are not
Main_Liste.append(str(liste_keys[i].etag).replace('"',''))
# Sort the List
Main_Liste.sort()
Second_list = Main_Liste
else:
# It is Google Storage ... so we need to connect with Amazon S3
Anfrage_nach_zugangsdaten = db.GqlQuery("SELECT * FROM OctopusCloudDatenbank WHERE user = :username_db AND eucalyptusname != :eucalyptusname_db", username_db=username, eucalyptusname_db=eucalyptusname)
for db_eintrag in Anfrage_nach_zugangsdaten:
accesskey = db_eintrag.accesskey
secretaccesskey = db_eintrag.secretaccesskey
endpointurl = db_eintrag.endpointurl
port = db_eintrag.port
secretaccesskey_base64decoded = base64.b64decode(str(secretaccesskey))
secretaccesskey = xor_crypt_string(secretaccesskey_base64decoded, key=str(username))
conn_s3 = boto.s3.connection.S3Connection(aws_access_key_id=accesskey,
aws_secret_access_key=secretaccesskey,
is_secure=True,
host="s3.amazonaws.com",
calling_format=boto.s3.connection.OrdinaryCallingFormat(),
path="/")
# The name of the bucket that is used
# The character "@" cannot be used. Therefore we use "at".
bucketname = 'octopus_storage_'+str(username).replace('@', 'at').replace('.', '-')
try:
# Connect with bucket
bucket_instance = conn_s3.get_bucket(bucketname)
except:
# When it didn't work
if sprache == "de":
bucket_keys_tabelle = '<font color="red">Es ist zu einem Fehler gekommen</font>'
else:
bucket_keys_tabelle = '<font color="red">An error occured</font>'
laenge_liste_keys = 0
else:
# When it worked...
try:
# Get a list of all keys inside the bucket
liste_keys = bucket_instance.get_all_keys()
except:
# When it didn't work
if sprache == "de":
bucket_keys_tabelle = '<font color="red">Es ist zu einem Fehler gekommen</font>'
else:
bucket_keys_tabelle = '<font color="red">An error occured</font>'
laenge_liste_keys = 0
else:
# When it worked...
# Number of keys inside the list
laenge_liste_keys = len(liste_keys)
# When using Walrus (Eucalyptus), we need to erase the stupid "None" entry.
# if aktuellezone != "Amazon":
# liste_keys2 = []
# for i in range(laenge_liste_keys):
# if str(liste_keys[i].name) != 'None':
# liste_keys2.append(liste_keys[i])
# laenge_liste_keys2 = len(liste_keys2)
# laenge_liste_keys = laenge_liste_keys2
# liste_keys = liste_keys2
# If we have keys inside the bucket, we need to create a list that contains the MD5 checksums
if laenge_liste_keys == 0:
# Create an empty List
Main_Liste = []
Second_list = Main_Liste
else:
# if laenge_liste_keys is not 0
# Create an empty List
Main_Liste = []
# Walk through the list of keys
for i in range(laenge_liste_keys):
# In S3 each MD5 checksum is enclosed by double quotes. In Walrus they are not
Main_Liste.append(str(liste_keys[i].etag).replace('"',''))
# Sort the List
Main_Liste.sort()
Second_list = Main_Liste
# if aktuellezone == "Amazon":
# # It is Amazon S3 ... so we need to connect with Walrus (Eucalyptus)
# Anfrage_nach_zugangsdaten = db.GqlQuery("SELECT * FROM OctopusCloudDatenbank WHERE user = :username_db AND eucalyptusname != :eucalyptusname_db", username_db=username, eucalyptusname_db=eucalyptusname)
# for db_eintrag in Anfrage_nach_zugangsdaten:
# accesskey = db_eintrag.accesskey
# secretaccesskey = db_eintrag.secretaccesskey
# endpointurl = db_eintrag.endpointurl
# port = db_eintrag.port
#
# secretaccesskey_base64decoded = base64.b64decode(str(secretaccesskey))
# secretaccesskey = xor_crypt_string(secretaccesskey_base64decoded, key=str(username))
# conn_s3 = boto.s3.connection.S3Connection(aws_access_key_id=accesskey,
# aws_secret_access_key=secretaccesskey,
# is_secure=False,
# host=endpointurl,
# port=int(port),
# calling_format=boto.s3.connection.OrdinaryCallingFormat(),
# path="/services/Walrus")
#
# # Get values from the config file
# # The name of the bucket that is used
# # The character "@" cannot be used. Therefore we use "at".
# bucketname = str(parser.get('bucket', 'bucketname'))+str(username).replace('@', 'at')
#
# try:
# # Connect with bucket
# bucket_instance = conn_s3.get_bucket(bucketname)
# except:
# # When it didn't work
# if sprache == "de":
# bucket_keys_tabelle = '<font color="red">Es ist zu einem Fehler gekommen</font>'
# else:
# bucket_keys_tabelle = '<font color="red">An error occured</font>'
# laenge_liste_keys = 0
# else:
# # When it worked...
# try:
# # Get a list of all keys inside the bucket
# liste_keys = bucket_instance.get_all_keys()
# except:
# # When it didn't work
# if sprache == "de":
# bucket_keys_tabelle = '<font color="red">Es ist zu einem Fehler gekommen</font>'
# else:
# bucket_keys_tabelle = '<font color="red">An error occured</font>'
# laenge_liste_keys = 0
# else:
# # When it worked...
# # Number of keys inside the list
# laenge_liste_keys = len(liste_keys)
#
# # When using Walrus (Eucalyptus), we need to erase the stupid "None" entry.
# if aktuellezone != "Amazon":
# liste_keys2 = []
# for i in range(laenge_liste_keys):
# if str(liste_keys[i].name) != 'None':
# liste_keys2.append(liste_keys[i])
# laenge_liste_keys2 = len(liste_keys2)
# laenge_liste_keys = laenge_liste_keys2
# liste_keys = liste_keys2
#
# # If we have keys inside the bucket, we need to create a list that contains the MD5 checksums
# if laenge_liste_keys == 0:
# # Create an empty List
# Main_Liste = []
# Second_list = Main_Liste
# else:
# # if laenge_liste_keys is not 0
# # Create an empty List
# Main_Liste = []
# # Walk through the list of keys
# for i in range(laenge_liste_keys):
# # In S3 each MD5 checksum is enclosed by double quotes. In Walrus they are not
# Main_Liste.append(str(liste_keys[i].etag).replace('"',''))
# # Sort the List
# Main_Liste.sort()
# Second_list = Main_Liste
# else:
# # It is Walrus (Eucalyptus) ... so we need to connect with Amazon S3
# Anfrage_nach_zugangsdaten = db.GqlQuery("SELECT * FROM OctopusCloudDatenbank WHERE user = :username_db AND eucalyptusname != :eucalyptusname_db", username_db=username, eucalyptusname_db=eucalyptusname)
# for db_eintrag in Anfrage_nach_zugangsdaten:
# accesskey = db_eintrag.accesskey
# secretaccesskey = db_eintrag.secretaccesskey
# endpointurl = db_eintrag.endpointurl
# port = db_eintrag.port
#
# secretaccesskey_base64decoded = base64.b64decode(str(secretaccesskey))
# secretaccesskey = xor_crypt_string(secretaccesskey_base64decoded, key=str(username))
# conn_s3 = boto.s3.connection.S3Connection(aws_access_key_id=accesskey,
# aws_secret_access_key=secretaccesskey,
# is_secure=True,
# host="s3.amazonaws.com",
# calling_format=boto.s3.connection.OrdinaryCallingFormat(),
# path="/")
#
# # The name of the bucket that is used
# # The character "@" cannot be used. Therefore we use "at".
# bucketname = 'octopus_storage_'+str(username).replace('@', 'at')
#
# try:
# # Connect with bucket
# bucket_instance = conn_s3.get_bucket(bucketname)
# except:
# # When it didn't work
# if sprache == "de":
# bucket_keys_tabelle = '<font color="red">Es ist zu einem Fehler gekommen</font>'
# else:
# bucket_keys_tabelle = '<font color="red">An error occured</font>'
# laenge_liste_keys = 0
# else:
# # When it worked...
# try:
# # Get a list of all keys inside the bucket
# liste_keys = bucket_instance.get_all_keys()
# except:
# # When it didn't work
# if sprache == "de":
# bucket_keys_tabelle = '<font color="red">Es ist zu einem Fehler gekommen</font>'
# else:
# bucket_keys_tabelle = '<font color="red">An error occured</font>'
# laenge_liste_keys = 0
# else:
# # When it worked...
# # Number of keys inside the list
# laenge_liste_keys = len(liste_keys)
#
# # When using Walrus (Eucalyptus), we need to erase the stupid "None" entry.
# if aktuellezone != "Amazon":
# liste_keys2 = []
# for i in range(laenge_liste_keys):
# if str(liste_keys[i].name) != 'None':
# liste_keys2.append(liste_keys[i])
# laenge_liste_keys2 = len(liste_keys2)
# laenge_liste_keys = laenge_liste_keys2
# liste_keys = liste_keys2
#
# # If we have keys inside the bucket, we need to create a list that contains the MD5 checksums
# if laenge_liste_keys == 0:
# # Create an empty List
# Main_Liste = []
# Second_list = Main_Liste
# else:
# # if laenge_liste_keys is not 0
# # Create an empty List
# Main_Liste = []
# # Walk through the list of keys
# for i in range(laenge_liste_keys):
# # In S3 each MD5 checksum is enclosed by double quotes. In Walrus they are not
# Main_Liste.append(str(liste_keys[i].etag).replace('"',''))
# # Sort the List
# Main_Liste.sort()
# Second_list = Main_Liste
#
return Second_list