diff --git a/jasset/views.py b/jasset/views.py index 57f88fdbe..c5159c8b1 100644 --- a/jasset/views.py +++ b/jasset/views.py @@ -177,7 +177,7 @@ def asset_edit(request): if password == asset.password: password_encode = password else: - password_encode = CRYPTOR.encrypt(password) + password_encode = password else: username = None password_encode = None diff --git a/jperm/ansible_api.py b/jperm/ansible_api.py index 4017cce16..2e89008fc 100644 --- a/jperm/ansible_api.py +++ b/jperm/ansible_api.py @@ -241,6 +241,26 @@ class Tasks(Command): return {"status": "failed","msg": self.msg} if self.msg else {"status": "ok"} + def push_multi_key(self, **user_info): + """ + push multi key + :param user_info: + :return: + """ + ret_failed = [] + ret_success = [] + for user, key_path in user_info.iteritems(): + ret = self.push_key(user, key_path) + if ret.get("status") == "ok": + ret_success.append(ret) + if ret.get("status") == "failed": + ret_failed.append(ret) + + if ret_failed: + return {"status": "failed", "msg": ret_failed} + else: + return {"status": "success", "msg": ret_success} + def del_key(self, user, key_path): """ push the ssh authorized key to target. @@ -260,24 +280,26 @@ class Tasks(Command): return {"status": "failed","msg": self.msg} if self.msg else {"status": "ok"} - def add_multi_user(self, *args): + def add_multi_user(self, **user_info): """ add multi user - :param args: - user + :param user_info: keyword args + {username: password} :return: """ - results = {} - users = {} - action = results["action_info"] = {} - for user in args: - users[user] = get_rand_pass() - for user, password in users.iteritems(): + ret_success = [] + ret_failed = [] + for user, password in user_info.iteritems(): ret = self.add_user(user, password) - action[user] = ret - results["user_info"] = users + if ret.get("status") == "ok": + ret_success.append(ret) + if ret.get("status") == "failed": + ret_failed.append(ret) - return results + if ret_failed: + return {"status": "failed", "msg": ret_failed} + else: + return {"status": "success", "msg": ret_success} def del_user(self, username): """ diff --git a/jperm/role_keys/keys-1703ab96bd964893b13d22fd3a8e8318/id_rsa b/jperm/role_keys/keys-1703ab96bd964893b13d22fd3a8e8318/id_rsa deleted file mode 100644 index 381d06d04..000000000 --- a/jperm/role_keys/keys-1703ab96bd964893b13d22fd3a8e8318/id_rsa +++ /dev/null @@ -1,51 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\ No newline at end of file diff --git a/jperm/role_keys/keys-1703ab96bd964893b13d22fd3a8e8318/id_rsa.pub b/jperm/role_keys/keys-1703ab96bd964893b13d22fd3a8e8318/id_rsa.pub deleted file mode 100644 index 2bc15d96c..000000000 --- a/jperm/role_keys/keys-1703ab96bd964893b13d22fd3a8e8318/id_rsa.pub +++ /dev/null @@ -1 +0,0 @@ -ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDXDRoQwHevjEVqM2JeVgkADM2aVxEm/yQHCpqYqREe0xGGrSSCykEZGp+O+q5FRZwFEgbZkCykJRrI3+3kEr6zB83N3P2oy/qd0pRTkA0tS50uctQA4aIp9kyOQOKLx8Uttmta0+nLwYKBSSPgJPL1xwC+sVMVvMwsIXyWGzgIWV0KZIrjNYjgEpxU0cQ7pJLXCrw5dM+fMdWvP9MDyMfX5iYZwIaYwnnTY1qO+fNewDbiFSDTo5AzcYnAUsNsRjOqWrNazMEB3o6ZoH8fANlJCJ5Jgeu/IV6UcRAYGYXq924I6AwTVENiDVf3o1lfBvAqTmNfIo25TgZCzewFGl0cuRdKVP6j0qps6N1ZBRVE8NtT4fmg8gP05OGHzz9j8rsPzCpsnQXByYJ927u7ypIm2+xCAhvqElsyJeR5yFs9J9SFa6ix9UzO2hEhO0ypU8ioNU99DbMEhZ4jXwRl63sK5AWUzf3akNGzUDLlttw86SIjV9dt6kOyhKpE8oVVB56DrmHx76uC0Dd75QojDyQQUnLX+pd9OngCCIu+VVWB175+LhDduDRBIrWsFsOciqzCS4LwB5rQFj/6dikfDDKt++M5qOzLeVnnKcMGucH8uHK8JVEB8yZMhsTkha4vxvrh1XsoTxwIqSs9JbUVI2ZjARSO+t8JU4meSV/HL+QeCQ== \ No newline at end of file diff --git a/jperm/role_keys/keys-730baf8ef88642c68e7372814d49b5ad/id_rsa b/jperm/role_keys/keys-730baf8ef88642c68e7372814d49b5ad/id_rsa deleted file mode 100644 index 04a1e569c..000000000 --- a/jperm/role_keys/keys-730baf8ef88642c68e7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FPLxNGU8HhFVKBnI= ------END RSA PRIVATE KEY----- \ No newline at end of file diff --git a/jperm/role_keys/keys-730baf8ef88642c68e7372814d49b5ad/id_rsa.pub b/jperm/role_keys/keys-730baf8ef88642c68e7372814d49b5ad/id_rsa.pub deleted file mode 100644 index b776e95a4..000000000 --- a/jperm/role_keys/keys-730baf8ef88642c68e7372814d49b5ad/id_rsa.pub +++ /dev/null @@ -1 +0,0 @@ -ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC5NOm3k5bZLzjsM1YhHskQUvNsk9tGwYTx7+UQ1o1HBJ00C05f+e6FwfyG0wWjVS+WRLVE95JrqLhOKzOFHmxBuA4eA+rSQewjljkJH35ZYhcuqUSpGTU7mSVgQaE7iSJxTfu0vnydsWYbP9IW04LmX5tg2OC69LL5M0NE+LFm07m7rAZTfXpTLs3p4zCKKIfu7jVXtnCwnd3dc5oJpbumuqci2MPKvl4vTIGBBJz3MUqYFxSvsTvBPDop4oV738mso6wuFQQNvVFvt+BCelBkws3Im3Ij0his6OVROAkzw8MLTty3VSPfVcmHM6IEuD/q2GacQafK+BSTADkpmIjyJEKf5U6vftjwW18/rLMJ/CrbFEYigSmNQMSwkY/uOwSzxAPHrW37WA7fxybR8T7o895ELisUd3EhS8al8W4A0QVmkZ+l09uaHW/BrxJ8TuJSPTTfU++vCPfmDb3HQ5A9KH+yO9k8IHuFY5OFwuRGURsUx0kMV8D4YpbsAjwA0xyGw+20zFHC49bgfZj26/tOV2GIPfW9JXR5GXeFgGR9j3QJc6QXJQXgPhLRDzrhtAlyV/iqOeXHOhyq/73lIRu3FWu4IuVuIoIcUQRQfW67ihifywQxIPjlRo6vgXND4J7ugVPZPwHJZ0mCimtMj3vOQ9E6XOFim3+v4dH8M0GZpQ== \ No newline at end of file diff --git a/jperm/role_keys/keys-c57f9962efc94388b783f25d1ebe8a5e/id_rsa b/jperm/role_keys/keys-c57f9962efc94388b783f25d1ebe8a5e/id_rsa deleted file mode 100644 index affaf8328..000000000 --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EYlIqEFhCwRxBtthi5yj7XqcybAE+39bWLkdLhqveYuOfxIN9s/FkGwA== ------END RSA PRIVATE KEY----- \ No newline at end of file diff --git a/jperm/role_keys/keys-c57f9962efc94388b783f25d1ebe8a5e/id_rsa.pub b/jperm/role_keys/keys-c57f9962efc94388b783f25d1ebe8a5e/id_rsa.pub deleted file mode 100644 index 374e2205b..000000000 --- a/jperm/role_keys/keys-c57f9962efc94388b783f25d1ebe8a5e/id_rsa.pub +++ /dev/null @@ -1 +0,0 @@ -ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDBlmj6CGfjmP+1pPxaH5otomnU6ShYLs0Oxo19FpzCsWnSstFZMHv7So3zH0l3qvyfqxQzG38T7rkOwu0Ksdp7I6E7Qqov6GxONpsdpOQQisYgdzMdWzpJ2M+fEru/68QCiKCdLs2PUP3T7JwgIf3S0Vqi+qBxGs/aKALL8m2bpjp8Nvo0TVKdEH6LtpYJ/L1gfrMRSIf/Crt9JEjo3GGeN/U94WCU4iBunZL37g/oQ6U+RlylxFiDrrITBYA1cdXGAEY8ts5lvypKGCU7JFHW3YLv6ZlBZud16y8C9J1RjxSTh9RZc6w1p1j4b1hjyNAWSgHLvlCQEo5TKVMMTGx/sR+yVGR1gL8Cr2cPNJoXeDJhKjqlKYCYIdNLFJHx68C+A5ONYrANeHZbCQwsIgZLqD5Zd5nUxC/5z+5y2RU29SuqNktVeGkDpeofn0cQNH2RYZAKdA+EWnMeebr+zgNloXyp9SgR0loPUMk3dXwiWg714DhUoM3HhE2JhJwhyamFKPd13t5mokpLSMzBIae+o84iFDy5MplFASf66k5ZhnQ4/M9QIB6DgyJmo20HN4PvNg8Wbsz06iPbJqYBP4LgaooKQh5QitrvvQg4KZ/mi8jXBsrbeONxcbVlCuFQ3DUZ3MghGx65k/aGDrDk0nuE8p9iDrl8FKf+wgwS4+fMpw== \ No newline at end of file diff --git a/jperm/role_keys/keys-c7ac2df748254fae992b6081d8351ec3/id_rsa b/jperm/role_keys/keys-c7ac2df748254fae992b6081d8351ec3/id_rsa deleted file mode 100644 index 2ac8750d4..000000000 --- a/jperm/role_keys/keys-c7ac2df748254fae992b6081d8351ec3/id_rsa +++ /dev/null @@ -1,51 +0,0 @@ ------BEGIN RSA PRIVATE KEY----- -MIIJKAIBAAKCAgEAnDdntw2QRFi2XMP9tDKN/R/JXk1IV7IcuyQK4gKCaA34jAMt -n6oRN0W74qQ98XCnGFs61/ZRH6epsNT8krVW3MuzaidLKTJ5zUkKagNE9itsknlc -1TnzIVB0DrMq2lRux4s77UxzcxagTr7nMXXxGgmCsPjVg7EQjiJ/VYwVIyuH5y9q -sXjolj/WbIjmEjR9MJISWD48dLz8VS22w5zpeH0lPg6P2yHqtE2eI2O1z/XLQksU -Fc7WQr0e9AGQXouT6QfZIovwm7IkYKa4/a/MM/06344lk7fidHAY6bHIQ7zqblVz -TKoA/lhdONPFyYF7CmrZsEZenkHPOk7aSjLL4Y/kd3BdxY9kPHyRShpqBx2xt1d2 -dpXNisL43Iw1sMtv7WPG0/biw0GWC8RBlfjI27sf6g8rTAub1lyl1ZtCexQa1svE -aoVm/pUwJu5x9YEnwJK5R2Uch8+PWzFMJGowxUvUHAZndJCfzAyBrIjcYPjBUKyc -15EsPEB4V1kQwzR7uHoeaz22MD1TaG6J5ActyX9Fjwe+arphOybaByynEcpNs1hA -8Eq1WfWfP32mhYfQDFZD/vlgoOUfmpaL5/dOs3F2XotDcfdau/p5ItkTHz/rmbEV -iZZQomc+hnzaekcvLx3ydiufLigh9DhJbqDf9eMFTPkWhBEfhdAnqNEMg2kCAwEA -AQKCAgA+nGpCUPpgmlnFBny564VDTaks1bbIB0hCrWh7O1w/DlJu85smokgyKg3r -Ab8d9PPT7ETCaCQNluqJSGRO/MVqy24Gfuc+BNASulKlONg7/h2O+3t8rrRGxvMt -LRxg03RvH9wN+RVQrGHmDdel2EqhD+zEt4cEOESVYzg79mBGb10SCMwvg3FdPwrX -B2uHImiGvhUCLzeV5mUQUrks38gnlakGnVmFD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/qsGPoMnbx5LwxBYhzlT0gkK33Oe4EqsiC -qzGRNLaHgIl/5ihCKXCYWBq033FKWTIG3IiAZ0YwDzfgovmqdUKORV+kS0g= ------END RSA PRIVATE KEY----- \ No newline at end of file diff --git a/jperm/role_keys/keys-c7ac2df748254fae992b6081d8351ec3/id_rsa.pub b/jperm/role_keys/keys-c7ac2df748254fae992b6081d8351ec3/id_rsa.pub deleted file mode 100644 index c28632239..000000000 --- a/jperm/role_keys/keys-c7ac2df748254fae992b6081d8351ec3/id_rsa.pub +++ /dev/null @@ -1 +0,0 @@ -ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQCcN2e3DZBEWLZcw/20Mo39H8leTUhXshy7JAriAoJoDfiMAy2fqhE3RbvipD3xcKcYWzrX9lEfp6mw1PyStVbcy7NqJ0spMnnNSQpqA0T2K2ySeVzVOfMhUHQOsyraVG7HizvtTHNzFqBOvucxdfEaCYKw+NWDsRCOIn9VjBUjK4fnL2qxeOiWP9ZsiOYSNH0wkhJYPjx0vPxVLbbDnOl4fSU+Do/bIeq0TZ4jY7XP9ctCSxQVztZCvR70AZBei5PpB9kii/CbsiRgprj9r8wz/TrfjiWTt+J0cBjpschDvOpuVXNMqgD+WF0408XJgXsKatmwRl6eQc86TtpKMsvhj+R3cF3Fj2Q8fJFKGmoHHbG3V3Z2lc2KwvjcjDWwy2/tY8bT9uLDQZYLxEGV+Mjbux/qDytMC5vWXKXVm0J7FBrWy8RqhWb+lTAm7nH1gSfAkrlHZRyHz49bMUwkajDFS9QcBmd0kJ/MDIGsiNxg+MFQrJzXkSw8QHhXWRDDNHu4eh5rPbYwPVNobonkBy3Jf0WPB75qumE7JtoHLKcRyk2zWEDwSrVZ9Z8/faaFh9AMVkP++WCg5R+alovn906zcXZei0Nx91q7+nki2RMfP+uZsRWJllCiZz6GfNp6Ry8vHfJ2K58uKCH0OEluoN/14wVM+RaEER+F0Ceo0QyDaQ== \ No newline at end of file diff --git a/jperm/utils.py b/jperm/utils.py index e7826f59e..eaf143e21 100644 --- a/jperm/utils.py +++ b/jperm/utils.py @@ -3,7 +3,7 @@ import random import os.path -from Crypto.PublicKey import RSA +from paramiko.rsakey import RSAKey from os import chmod, mkdir from uuid import uuid4 @@ -49,14 +49,17 @@ def gen_keys(): key_path_dir = os.path.join(KEY_DIR, key_basename) mkdir(key_path_dir, 0700) - key = RSA.generate(4096) + key = RSAKey.generate(2048) private_key = os.path.join(key_path_dir, 'id_rsa') public_key = os.path.join(key_path_dir, 'id_rsa.pub') - with open(private_key, 'w') as content_file: - content_file.write(key.exportKey('PEM')) - with open(public_key, 'w') as content_file: - content_file.write(key.publickey().exportKey('OpenSSH')) + key.write_private_key_file(private_key) + with open(public_key, 'w') as content_file: + for data in [key.get_name(), + " ", + key.get_base64(), + " %s@%s" % ("jumpserver", os.uname()[1])]: + content_file.write(data) return key_path_dir diff --git a/jperm/views.py b/jperm/views.py index a9df09790..03b59397a 100644 --- a/jperm/views.py +++ b/jperm/views.py @@ -283,6 +283,13 @@ def perm_role_delete(request): # 获取参数删除的role对象 role_id = request.POST.get("id") role = PermRole.objects.get(id=role_id) + role_key = role.key_path + # 删除存储的秘钥,以及目录 + key_files = os.listdir(role_key) + for key_file in key_files: + os.remove(os.path.join(role_key, key_file)) + os.rmdir(role_key) + # 数据库里删除记录 role.delete() return HttpResponse(u"删除角色: %s" % role.name) else: @@ -358,34 +365,33 @@ def perm_role_push(request): calc_assets = set(assets_obj) | set(group_assets_obj) # 生成Inventory - hosts = [{"hostname": asset.ip, + push_resource = [{"hostname": asset.ip, "port": asset.port, "username": asset.username, "password": asset.password} for asset in calc_assets] # 获取角色的推送方式,以及推送需要的信息 roles_obj = [PermRole.objects.get(name=role_name) for role_name in role_names] - roles_info = {} + role_pass = {} + role_key = {} for role in roles_obj: - roles_info[role.name] = {"password": role.password, "key": role.key_path} + role_pass[role.name] = role.password + role_key[role.name] = os.path.join(role.key_path, 'id_rsa.pub') - # 推送 + # 调用Ansible API 进行推送 password_push = request.POST.get("use_password") key_push = request.POST.get("use_publicKey") + task = Tasks(push_resource) + ret = {} if password_push: - pass + ret["password_push"] = task.add_multi_user(**role_pass) if key_push: - pass - - - - - # 调用Ansible API 执行 password方式的授权 TODO: Surport sudo - # tasks = Tasks(hosts) - # ret = tasks.add_multi_user(*role_names) - - return HttpResponse(u"未实现") + ret["key_push"] = task.push_multi_key(**role_key) + if ret["password_push"].get("status") == "success" and ret["kye_push"].get("status") == "success": + return HttpResponse(u"推送系统角色: %s" % ','.join(role_names)) + else: + return HttpResponse(u"推送失败")