예제 #1
0
 def load(self):
     if not os.path.exists(os.path.expanduser('~/.skarphedadmin/'+self.username)):
         raise ProfileException(ProfileException.get_msg(3))
     profilefile = open(os.path.expanduser('~/.skarphedadmin/'+self.username),'rb')
     cipher = profilefile.read()
     aes = Crypto.Cipher.AES.new(self.password, Crypto.Cipher.AES.MODE_ECB)
     clear = aes.decrypt(cipher)
     if clear[0:4]=="SCOV":
         js = json.decoder.JSONDecoder()
         clear = clear.rstrip("X")
         self.data = js.decode(clear[4:])
         self.state = self.STATE_LOADED
         profilefile.close()
         for server in self.data['server']:
             srv = skarphedadmin.data.Server.createServer()
             srv.setIp(server['ip'])
             srv.setName(server['name'])
             srv.setSSHName(server['ssh_username'])
             srv.setSSHPass(server['ssh_password'])
             srv.setTarget(server['target'])
             srv.establishConnections()
             for instance in server['instances']:
                 instanceType = InstanceType(instance['typename'],instance['typedisp'])
                 createdInstance = srv.createInstance(instanceType,instance['url'],instance['username'],instance['password'])
                 if createdInstance is None or createdInstance == False:
                     continue
                 if instance['typename'] == "database":
                     for schema in instance['schemas']:
                         createdInstance.registerSchema(schema['name'], schema['user'], schema['pass'])
                 elif instance['typename'] == "skarphed":
                     createdInstance.setPublicKey(instance['publickey'])
                 #elif instance['typename'] == "skarphed_repo":
                 #    createdInstance.establishConnections()
              
     else:
         profilefile.close()
         raise ProfileException(ProfileException.get_msg(4))
예제 #2
0
 def create(self):
     if not os.path.exists(os.path.expanduser('~/.skarphedadmin')):
         os.mkdir(os.path.expanduser('~/.skarphedadmin'))
     if os.path.exists(os.path.expanduser('~/.skarphedadmin/'+self.username)):
         raise ProfileException(ProfileException.get_msg(0))
     assert len(self.password)%16 == 0 , "Password not divisible by 16"
     profilefile = open(os.path.expanduser('~/.skarphedadmin/'+self.username),'w')
     
     self.data=self.DATA_STRUCT
     
     aes = Crypto.Cipher.AES.new(self.password, Crypto.Cipher.AES.MODE_ECB)
     js = json.encoder.JSONEncoder()
     clear = "SCOV"+js.encode(self.data)
     padding = "X"*(16-(len(clear)%16))
     profilefile.write(aes.encrypt(clear+padding))
     profilefile.close()
예제 #3
0
 def getPrivateKey(self):
     if self.data.has_key('privatekey') and self.data['privatekey'] != '':
         return self.data['privatekey']
     else:
         raise ProfileException(ProfileException.get_msg(2))
예제 #4
0
 def getPublicKey(self):
     if self.data.has_key('publickey') and self.data['publickey'] != '':
         return self.data['publickey']
     else:
         raise ProfileException(ProfileException.get_msg(1))