交互命令

操作不当将导致数据丢失,操作前请仔细确认

操作方法

  1. docker exec -it jms_core bash
  2. cd /opt/jumpserver/apps
  3. python manage.py shell
  1. # 新版本操作之前均需要切换到对应组织, 默认为 Default
  2. from orgs.models import *
  3. Organization.objects.all()
  4. org = Organization.objects.get(name='Default')
  5. org.change_to()

UserAsset

  1. from users.models import *
  2. # 用户
  3. User.objects.all()
  4. User.objects.count() # 数量
  5. # 指定用户查询
  6. user = User.objects.get(username = 'admin')
  7. # 查询用户邮箱
  8. user.email
  9. # 修改用户邮箱
  10. user.email='test@jumpserver.org'
  11. # 修改密码
  12. user.reset_password('test01')
  13. # 保存修改
  14. user.save
  15. # 删除用户 MFA key
  16. user.otp_secret_key=''
  17. user.save
  18. # 创建新用户
  19. User.objects.create(name = '测试用户', username = 'test', email = 'test@jumpserver.org')
  20. # 测试用户是否重名, 不存在就创建
  21. User.objects.get_or_create(name = '测试用户', username = 'test', email = 'test@jumpserver.org')
  22. user = User.objects.get(username = 'test')
  23. user.delete()
  24. # 更优雅的删除方法
  25. User.objects.all().filter(username='test').delete()
  1. # 用户组
  2. UserGroup.objects.all()
  3. UserGroup.objects.count()
  4. # 创建用户组
  5. UserGroup.objects.create(name = 'Test')
  6. group = UserGroup.objects.get(name = 'Test')
  7. # 用户组添加用户
  8. user = User.objects.get(username='test')
  9. group.users.add(user)
  10. group.save
  11. # 用户组删除用户
  12. user = User.objects.get(username='test')
  13. group.users.remove(user)
  14. group.save
  15. # 删除用户组
  16. UserGroup.objects.all().filter(name='Test').delete()
  1. from assets.models import *
  2. # 资产
  3. Asset.objects.all()
  4. Asset.objects.count()
  5. # 创建
  6. asset = Asset.objects.create(hostname = 'test', ip = '172.16.0.1')
  7. # 删除
  8. asset = Asset.objects.get(hostname = 'test')
  9. asset.delete()
  1. # 节点
  2. Node.objects.all()
  3. Node.objects.count()
  4. node = Node.objects.get(value = 'Test')
  5. asset = Asset.objects.get(hostname = 'test')
  6. # 添加资产到节点
  7. node.assets.add(asset)
  8. # 从节点删除资产
  9. node.assets.remove(asset)
  10. node.delete()

数据解密

系统用户指定资产的系统用户

  1. docker exec -it jms_core bash
  2. cd /opt/jumpserver/apps
  3. python manage.py shell
  1. from assets.models import SystemUser
  2. # 81aef7ac-e432-4d1b-aaf5-a3bc37c2b230 为你要查询系统用户的 id, 在 web 页面的系统用户详情里面有该字段
  3. u = SystemUser.objects.get(id='81aef7ac-e432-4d1b-aaf5-a3bc37c2b230')
  1. u.password
  1. Out[4]: 'YVo87b+AvwpnAX2igWRTHdAlP0hL'
  1. u.private_key
  1. Out[6]: '-----BEGIN RSA PRIVATE KEY-----
  2. MIIEpAIBAAKCAQEAxg4C1KKD5mz+3arCKETugJggR4HzEvIjAutKv+zZwAYm5SbB
  3. 3IGXoEzdXbk/9u1btyTGbmTpKubsJh5MeGlHWExqzA2n9NsC/3hYenjwm1OP1Vhc
  4. bGZYnZTqbUGTiWiRhtXUCOC2yzgSdLiCLGS5XdIVEhCO3AvWZCvauhEQYu3PLlUN
  5. Xuc7JZBLGrZ+YVo87b+AvwpnAX2igWRTHdAlP0hL+MWoN3lzba90Jox1zJNeyZ64
  6. M/u1TsiMGGWs/H35SqpH9jerCl5+1Mqw5oryidYApuNOilN8ucYa6XDueweEXkHk
  7. oY8QxwaC8GFLZErb0Ov8lzEhlpALsCYgekiecQIDAQABAoIBAQC5W/OaPl9kES6X
  8. F3GPbrQo9jd/tUdhu+y4lq3m4i0JYriUTqmxTjgydr3XMcGDwLHNvkVYnGj9FhJ9
  9. um2nZCC5qwto3n8K1s8DegaU2QuXLX64FXKqoT8efLjKeE00lQFeSFGh3W4208uy
  10. Idzy33H9NNkzhvutRgboyYJ0EfRcIL/wyxc0ndMKt/bVYH8T14aWViVRF7OyiIkd
  11. eFx7tdnVscBSujNX027ycmjElwRf9TPNFUFwF5XGf3xwWjPmBNWr91XxPcF9VecG
  12. gyd9qxNd12YYGcX4SR6V0p+36Av+rZoHB0405b/ZncmevSStUCu6fTtQYwdCZj0p
  13. PgTradABAoGBAOVjCRleXfO9OVc4Y7sM2+1i/So5dmp66foC76j6CDKzztA2b5FX
  14. tduNhoObeNYdnV32WvW3/xXcFWFnbWf0Eymx2DMuxMfWlTvM0InParq0TpeVMWMP
  15. uxW+7YNZ9IWuuLMs3jfY1lRQBUgVlcb0zA7tjWZO/n/mKW5Fd2rItvmRAoGBAN0I
  16. YzFGEPoKgGqYme58KpebM1jt1XoyLtbH1ygRvaPlnLfPDBsBhrqLCyR3+oK0kFlM
  17. f7Neqo86hCQ/aqVC1lMu2o3htg52b1Mj2T0YUTNsPTwx+8lHciRnqJZytHRjwfFC
  18. 4UySAzWKDDQZcIQGTAsdoXngkAZFITMBZBdRz+bhAoGAfytphvvvIEq+eGFVwQR/
  19. BNtFOVyEDsI35xgrn8WGN/3BYWNcdPpoYuDSOzI9So8+iDIk+WbZb1gFLmv1lpUU
  20. 7p+fGbkK9TM8ptuEnXI1XG7Lx3O53o6BDKw95vz+98IGuabdR57aLAH0+6Kj15ot
  21. avU92ANhSqziOTUf4D6IWlECgYAe+kr0n+5HLOuchPCl9O7/Ongy0Xpm2tunrHBi
  22. JEJg0xBoznLS5h7gzBXusYYBhY7phQgsumrLEhdtARpQORa/Q8TLt8ONOVoW2+JZ
  23. ZqwSuevHIPY52nKL2Z9OHptd6JFI3+e1lI0wlr1pG9uiFUPZFvkHnMpypoOlo19E
  24. yWmK4QKBgQCVmBTLSA+M3WJqDBK2Z6lUaDCaAjwn2Q5RSq2B/lLjzaod6WYWyecY
  25. NASeo6CC4fxOCfMJN1DT5CLyW4XpRk3GeR4QKSfFkwD2yRqk+7opm8PppdMuLZKU
  26. LQMMI90AWvU3Cx9aAbl1bLSIT0qRoc5FGwmLEL12yDBZA2l3vYhnaw==
  27. -----END RSA PRIVATE KEY-----'
  1. docker exec -it jms_core bash
  2. cd /opt/jumpserver/apps
  3. python manage.py shell
  1. from assets.models import SystemUser, Asset
  2. # 81aef7ac-e432-4d1b-aaf5-a3bc37c2b230 为你要查询系统用户的 id, 在 web 页面的系统用户详情里面有该字段
  3. user = SystemUser.objects.get(id='81aef7ac-e432-4d1b-aaf5-a3bc37c2b230')
  4. # 5ae0c750-91e3-4a32-81d3-6576068b74f3 为要查询资产的 id, 资产列表的资产详情里面有
  5. asset = Asset.objects.get(id='5ae0c750-91e3-4a32-81d3-6576068b74f3')
  6. # 切换到系统用户的组织
  7. user.org.change_to()
  8. u = user.get_asset_user(asset)
  1. u.password
  1. Out[7]: 'YVo87b+AvwpnAX2igWRTHdAlP0hL'
  1. u.private_key
  1. Out[9]: '-----BEGIN RSA PRIVATE KEY-----
  2. MIIEpAIBAAKCAQEAxg4C1KKD5mz+3arCKETugJggR4HzEvIjAutKv+zZwAYm5SbB
  3. 3IGXoEzdXbk/9u1btyTGbmTpKubsJh5MeGlHWExqzA2n9NsC/3hYenjwm1OP1Vhc
  4. bGZYnZTqbUGTiWiRhtXUCOC2yzgSdLiCLGS5XdIVEhCO3AvWZCvauhEQYu3PLlUN
  5. Xuc7JZBLGrZ+YVo87b+AvwpnAX2igWRTHdAlP0hL+MWoN3lzba90Jox1zJNeyZ64
  6. M/u1TsiMGGWs/H35SqpH9jerCl5+1Mqw5oryidYApuNOilN8ucYa6XDueweEXkHk
  7. oY8QxwaC8GFLZErb0Ov8lzEhlpALsCYgekiecQIDAQABAoIBAQC5W/OaPl9kES6X
  8. F3GPbrQo9jd/tUdhu+y4lq3m4i0JYriUTqmxTjgydr3XMcGDwLHNvkVYnGj9FhJ9
  9. um2nZCC5qwto3n8K1s8DegaU2QuXLX64FXKqoT8efLjKeE00lQFeSFGh3W4208uy
  10. Idzy33H9NNkzhvutRgboyYJ0EfRcIL/wyxc0ndMKt/bVYH8T14aWViVRF7OyiIkd
  11. eFx7tdnVscBSujNX027ycmjElwRf9TPNFUFwF5XGf3xwWjPmBNWr91XxPcF9VecG
  12. gyd9qxNd12YYGcX4SR6V0p+36Av+rZoHB0405b/ZncmevSStUCu6fTtQYwdCZj0p
  13. PgTradABAoGBAOVjCRleXfO9OVc4Y7sM2+1i/So5dmp66foC76j6CDKzztA2b5FX
  14. tduNhoObeNYdnV32WvW3/xXcFWFnbWf0Eymx2DMuxMfWlTvM0InParq0TpeVMWMP
  15. uxW+7YNZ9IWuuLMs3jfY1lRQBUgVlcb0zA7tjWZO/n/mKW5Fd2rItvmRAoGBAN0I
  16. YzFGEPoKgGqYme58KpebM1jt1XoyLtbH1ygRvaPlnLfPDBsBhrqLCyR3+oK0kFlM
  17. f7Neqo86hCQ/aqVC1lMu2o3htg52b1Mj2T0YUTNsPTwx+8lHciRnqJZytHRjwfFC
  18. 4UySAzWKDDQZcIQGTAsdoXngkAZFITMBZBdRz+bhAoGAfytphvvvIEq+eGFVwQR/
  19. BNtFOVyEDsI35xgrn8WGN/3BYWNcdPpoYuDSOzI9So8+iDIk+WbZb1gFLmv1lpUU
  20. 7p+fGbkK9TM8ptuEnXI1XG7Lx3O53o6BDKw95vz+98IGuabdR57aLAH0+6Kj15ot
  21. avU92ANhSqziOTUf4D6IWlECgYAe+kr0n+5HLOuchPCl9O7/Ongy0Xpm2tunrHBi
  22. JEJg0xBoznLS5h7gzBXusYYBhY7phQgsumrLEhdtARpQORa/Q8TLt8ONOVoW2+JZ
  23. ZqwSuevHIPY52nKL2Z9OHptd6JFI3+e1lI0wlr1pG9uiFUPZFvkHnMpypoOlo19E
  24. yWmK4QKBgQCVmBTLSA+M3WJqDBK2Z6lUaDCaAjwn2Q5RSq2B/lLjzaod6WYWyecY
  25. NASeo6CC4fxOCfMJN1DT5CLyW4XpRk3GeR4QKSfFkwD2yRqk+7opm8PppdMuLZKU
  26. LQMMI90AWvU3Cx9aAbl1bLSIT0qRoc5FGwmLEL12yDBZA2l3vYhnaw==
  27. -----END RSA PRIVATE KEY-----'