Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add initial VNC specific password functionality #25

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions amt/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ def power_status(self):
"PowerState")
return value

def enable_vnc(self):
payload = amt.wsman.enable_remote_kvm(self.uri, self.password)
def enable_vnc(self, passwd):
payload = amt.wsman.enable_remote_kvm(self.uri, passwd)
self.post(payload)
payload = amt.wsman.kvm_redirect(self.uri)
self.post(payload)
Expand Down
34 changes: 30 additions & 4 deletions bin/amtctrl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import argparse
import os
import sys
import getpass
import re

import requests

Expand Down Expand Up @@ -61,6 +63,11 @@ def parse_args_rm():
help='')
return parser.parse_args()

def check_valid_vnc_password(passwd):
if re.search(r'^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{8}\b$', passwd):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather break this up into separate conditionals just to make it easier to understand later. I can do that post merge.

return True
else:
return False

def main():
args = parse_args()
Expand All @@ -78,8 +85,7 @@ def main():
if args.prompt:
host = args.server
if sys.stdin.isatty():
from getpass import getpass
passwd = getpass()
passwd = getpass.getpass()
else:
passwd = sys.stdin.readline().rstrip('\r\n')
else:
Expand All @@ -104,8 +110,28 @@ def main():
elif args.command == "status":
print(amt.wsman.friendly_power_state(client.power_status()))
elif args.command == "vnc":
client.enable_vnc()
print("VNC enabled on port 5900 with AMT password")
if check_valid_vnc_password(passwd):
vncpasswd = passwd
else:
print('Warning, current AMT password does not meet RFBPassword complexity requirements.\n')
print('Password must be EXACTLY 8 characters and have the following:')
print('*) one upper case letter')
print('*) one lower case letter')
print('*) one digit')
print('*) one special character excluding (") (,) (:)')

while True:
vncpasswd = getpass.getpass('VNC Password:')
if check_valid_vnc_password(vncpasswd):
break
else:
print('Invalid password')
client.enable_vnc(vncpasswd)
if vncpasswd == passwd:
print("VNC enabled on port 5900 with AMT password")
else:
print("VNC enabled on port 5900 with non-AMT VNC specific password")

elif args.command == "vncstatus":
print(client.vnc_status())
else:
Expand Down