Guest User

usercreate.py

a guest
May 16th, 2018
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.79 KB | None | 0 0
  1. from boto.s3.connection import S3Connection
  2. from optparse import OptionParser
  3. import requests,json
  4.  
  5. parser = OptionParser()
  6. parser.add_option("-u", "--username", dest="username",
  7. help="Enter the username")
  8. (options, args) = parser.parse_args()
  9.  
  10. username = 'AWS ACCESS KEY'
  11. password = 'AWS SECRET KEY'
  12. jusername = 'username'
  13. jpassword = 'password'
  14. url = 'http://serverip:11880/rest/management/'
  15.  
  16. #make the connection
  17. conn = S3Connection(username, password)
  18.  
  19. #connect the bucket
  20. mybucket = conn.get_bucket('hhaxsftp')
  21.  
  22. #login
  23. logindata = '''{
  24. "username": "'''+jusername+'''",
  25. "password": "'''+jpassword+'''"
  26. }'''
  27. json_data = json.loads(logindata)
  28. response = requests.post(url + "login/",json=json_data)
  29. cookieget = response.cookies
  30. sessionid = cookieget['JSESSIONID']
  31.  
  32.  
  33. #list of the folders
  34. folder = {'trash':'/Inbox/Trash/',
  35. 'inbox_remittance':'/Inbox/Remittance/',
  36. 'authorization':'/Outbox/Authorization/',
  37. 'billedVisits':'/Outbox/BilledVisits/',
  38. 'billingExceptions':'/Outbox/BillingExceptions/',
  39. 'patient':'/Outbox/Patient/',
  40. 'patientNotes':'/Outbox/PatientNotes/',
  41. 'poc':'/Outbox/POC/',
  42. 'preAdjRejections':'/Outbox/PreAdjRejections/',
  43. 'outbox_remittance':'/Outbox/Remittance/',
  44. 'responseFiles':'/Outbox/ResponseFiles/',
  45. 'failed':'/Processed/Failed/',
  46. 'save':'/Save/'}
  47.  
  48. path_folder = {
  49. 'main':'',
  50. 'inbox':'/Inbox/',
  51. 'outbox':'/Outbox/',
  52. 'processed':'/Processed/',
  53. 'save':'/Save/'}
  54.  
  55. domain = 'hhaexchange'
  56. path = []
  57. cookie = {'JSESSIONID': sessionid}
  58.  
  59. #create folder in S#
  60. for key, value in folder.items():
  61. mybucket.new_key(options.username + value).set_contents_from_string('')
  62.  
  63. #create reverse proxy
  64. for key, value in path_folder.items():
  65. data = {
  66. "protocol": "AmazonS3",
  67. "name": options.username+"_"+key,
  68. "encryptionRequired": False,
  69. "username": username,
  70. "password": password,
  71. "usingCredentials": False,
  72. "remoteDirectory": {
  73. "@type": "REMOTE_PATH",
  74. "path": "hhaxsftp/"+options.username+value
  75. },
  76. "logDirectory": None,
  77. "tags": [],
  78. "version": 1,
  79. "timeToLive": None,
  80. "host": ""
  81. }
  82.  
  83. json_data = json.loads(json.dumps(data))
  84. response = requests.post(url + "reverse-proxies/"+domain,json=json_data,cookies=cookie)
  85.  
  86. #path for creating the user
  87. for key, value in path_folder.items():
  88. path.append({
  89. "name": options.username+"_"+key,
  90. "path": value,
  91. "accessPermissions": {
  92. "fileDownloadingAllowed": True,
  93. "fileUploadingAllowed": True,
  94. "fileDeletionAllowed": False,
  95. "fileAppendingAllowed": True,
  96. "fileListingAllowed": True,
  97. "fileRenamingAllowed": True,
  98. "directoriesListingAllowed": True,
  99. "directoryMakingAllowed": True,
  100. "directoryDeletionAllowed": False,
  101. "subdirectoriesBrowsingAllowed": True
  102. },
  103. "secured": False,
  104. "denied": False,
  105. "indexable": False,
  106. "reverseProxy": options.username+"_"+key,
  107. })
  108.  
  109. #create user
  110. userdata = {
  111. "username": options.username,
  112. "login": options.username,
  113. "password": options.username,
  114. "emailAddress": "",
  115. "company": None,
  116. "phone": {
  117. "code": "",
  118. "number": "",
  119. "extension": ""
  120. },
  121. "owner": None,
  122. "expirationDate": None,
  123. "enabled": True,
  124. "secured": False,
  125. "groups": [],
  126. "bindedKeys": [],
  127. "resources": path,
  128. "passwordChangingAllowed": True,
  129. "emailFileTransferAllowed": True,
  130. "usePhoneAuthentication": False,
  131. "ignorePasswordAgingRules": False,
  132. "quotas": {
  133. "uploadsQuota": None,
  134. "downloadsQuota": None,
  135. "transfersQuota": None,
  136. "maxUploadsPerSession": None,
  137. "maxDownloadsPerSession": None,
  138. "maxTransferRate": None
  139. },
  140. "ipAccessVerifier": {
  141. "masks": []
  142. },
  143. "administration": None,
  144. "webOptions": {
  145. "loginRedirection": {
  146. "target": "storage"
  147. },
  148. "webAccountLinkAvailable": True,
  149. "webPersonalInformationAvailable": True,
  150. "webPublicKeyAuthenticationAvailable": True,
  151. "webOpenPgpEncryptionAvailable": True,
  152. "webQuotasAvailable": True,
  153. "webContactsAvailable": True,
  154. "webAdHocActivityAvailable": True,
  155. "webDropZonesAvailable": True,
  156. "webAftpProtocolPreferable": False
  157. },
  158. "tags": [],
  159. "uploadsQuota": None,
  160. "downloadsQuota": None,
  161. "transfersQuota": None,
  162. "maxUploadsPerSession": None,
  163. "maxDownloadsPerSession": None,
  164. "maxTransferRate": None,
  165. "loginRedirection": {
  166. "target": "storage"
  167. },
  168. "webPersonalInformationAvailable": True,
  169. "webPublicKeyAuthenticationAvailable": True,
  170. "webQuotasAvailable": True
  171. }
  172. json_data = json.dumps(userdata)
  173. response = requests.post(url + "accounts/"+domain,json=json_data,cookies=cookie)
  174. print(json_data)
  175. print(response)
  176.  
  177. #logout
  178. response = requests.post(url + "logout/",cookies=cookie)
Add Comment
Please, Sign In to add comment