Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from boto.s3.connection import S3Connection
- from optparse import OptionParser
- import requests,json
- parser = OptionParser()
- parser.add_option("-u", "--username", dest="username",
- help="Enter the username")
- (options, args) = parser.parse_args()
- username = 'AWS ACCESS KEY'
- password = 'AWS SECRET KEY'
- jusername = 'username'
- jpassword = 'password'
- url = 'http://serverip:11880/rest/management/'
- #make the connection
- conn = S3Connection(username, password)
- #connect the bucket
- mybucket = conn.get_bucket('hhaxsftp')
- #login
- logindata = '''{
- "username": "'''+jusername+'''",
- "password": "'''+jpassword+'''"
- }'''
- json_data = json.loads(logindata)
- response = requests.post(url + "login/",json=json_data)
- cookieget = response.cookies
- sessionid = cookieget['JSESSIONID']
- #list of the folders
- folder = {'trash':'/Inbox/Trash/',
- 'inbox_remittance':'/Inbox/Remittance/',
- 'authorization':'/Outbox/Authorization/',
- 'billedVisits':'/Outbox/BilledVisits/',
- 'billingExceptions':'/Outbox/BillingExceptions/',
- 'patient':'/Outbox/Patient/',
- 'patientNotes':'/Outbox/PatientNotes/',
- 'poc':'/Outbox/POC/',
- 'preAdjRejections':'/Outbox/PreAdjRejections/',
- 'outbox_remittance':'/Outbox/Remittance/',
- 'responseFiles':'/Outbox/ResponseFiles/',
- 'failed':'/Processed/Failed/',
- 'save':'/Save/'}
- path_folder = {
- 'main':'',
- 'inbox':'/Inbox/',
- 'outbox':'/Outbox/',
- 'processed':'/Processed/',
- 'save':'/Save/'}
- domain = 'hhaexchange'
- path = []
- cookie = {'JSESSIONID': sessionid}
- #create folder in S#
- for key, value in folder.items():
- mybucket.new_key(options.username + value).set_contents_from_string('')
- #create reverse proxy
- for key, value in path_folder.items():
- data = {
- "protocol": "AmazonS3",
- "name": options.username+"_"+key,
- "encryptionRequired": False,
- "username": username,
- "password": password,
- "usingCredentials": False,
- "remoteDirectory": {
- "@type": "REMOTE_PATH",
- "path": "hhaxsftp/"+options.username+value
- },
- "logDirectory": None,
- "tags": [],
- "version": 1,
- "timeToLive": None,
- "host": ""
- }
- json_data = json.loads(json.dumps(data))
- response = requests.post(url + "reverse-proxies/"+domain,json=json_data,cookies=cookie)
- #path for creating the user
- for key, value in path_folder.items():
- path.append({
- "name": options.username+"_"+key,
- "path": value,
- "accessPermissions": {
- "fileDownloadingAllowed": True,
- "fileUploadingAllowed": True,
- "fileDeletionAllowed": False,
- "fileAppendingAllowed": True,
- "fileListingAllowed": True,
- "fileRenamingAllowed": True,
- "directoriesListingAllowed": True,
- "directoryMakingAllowed": True,
- "directoryDeletionAllowed": False,
- "subdirectoriesBrowsingAllowed": True
- },
- "secured": False,
- "denied": False,
- "indexable": False,
- "reverseProxy": options.username+"_"+key,
- })
- #create user
- userdata = {
- "username": options.username,
- "login": options.username,
- "password": options.username,
- "emailAddress": "",
- "company": None,
- "phone": {
- "code": "",
- "number": "",
- "extension": ""
- },
- "owner": None,
- "expirationDate": None,
- "enabled": True,
- "secured": False,
- "groups": [],
- "bindedKeys": [],
- "resources": path,
- "passwordChangingAllowed": True,
- "emailFileTransferAllowed": True,
- "usePhoneAuthentication": False,
- "ignorePasswordAgingRules": False,
- "quotas": {
- "uploadsQuota": None,
- "downloadsQuota": None,
- "transfersQuota": None,
- "maxUploadsPerSession": None,
- "maxDownloadsPerSession": None,
- "maxTransferRate": None
- },
- "ipAccessVerifier": {
- "masks": []
- },
- "administration": None,
- "webOptions": {
- "loginRedirection": {
- "target": "storage"
- },
- "webAccountLinkAvailable": True,
- "webPersonalInformationAvailable": True,
- "webPublicKeyAuthenticationAvailable": True,
- "webOpenPgpEncryptionAvailable": True,
- "webQuotasAvailable": True,
- "webContactsAvailable": True,
- "webAdHocActivityAvailable": True,
- "webDropZonesAvailable": True,
- "webAftpProtocolPreferable": False
- },
- "tags": [],
- "uploadsQuota": None,
- "downloadsQuota": None,
- "transfersQuota": None,
- "maxUploadsPerSession": None,
- "maxDownloadsPerSession": None,
- "maxTransferRate": None,
- "loginRedirection": {
- "target": "storage"
- },
- "webPersonalInformationAvailable": True,
- "webPublicKeyAuthenticationAvailable": True,
- "webQuotasAvailable": True
- }
- json_data = json.dumps(userdata)
- response = requests.post(url + "accounts/"+domain,json=json_data,cookies=cookie)
- print(json_data)
- print(response)
- #logout
- response = requests.post(url + "logout/",cookies=cookie)
Add Comment
Please, Sign In to add comment