Skip to content
This repository has been archived by the owner on Aug 6, 2018. It is now read-only.

Some bug fixes #29

Open
wants to merge 2 commits 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
11 changes: 10 additions & 1 deletion yah3c/eapauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,16 @@ class EAPAuth:
def __init__(self, login_info):
# bind the h3c client to the EAP protocal
self.client = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.htons(ETHERTYPE_PAE))
self.client.bind((login_info['ethernet_interface'], ETHERTYPE_PAE))
try:
self.client.bind((login_info['ethernet_interface'], ETHERTYPE_PAE))
except Exception,e:
print "Error Info:"
print e
print "Maybe you have entered a wrong ethernet device name."
print "Sometimes the ethernet device name is not eth0, but eno1, enp0s25 or something else."
print "Please use \"ifconfig\" to confirm your ethernet device name."
print "After that, use \"sudo vim /etc/yah3c.conf\" to modify your ethernet_interface.\n"
exit(-1)
# get local ethernet card address
self.mac_addr = self.client.getsockname()[4]
self.ethernet_header = get_ethernet_header(self.mac_addr, PAE_GROUP_ADDR, ETHERTYPE_PAE)
Expand Down
45 changes: 25 additions & 20 deletions yah3c/yah3c.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,33 +70,38 @@ def enter_interactive_usermanager():
if um.get_user_number() == 0:
choice = raw_input('No user conf file found, creat a new one?\n<Y/N>: ')
if choice == 'y' or choice == 'Y':
login_info = prompt_user_info()
um.add_user(login_info)
user_info = prompt_user_info()
um.add_user(user_info)
else:
exit(-1)

# user has been created or already have users
users_info = um.get_all_users_info()

print '0 - add a new user'
for i, user_info in enumerate(users_info):
print '%d - %s(%s)' %(i + 1, user_info['username'], user_info['ethernet_interface'])

while True:
users_info = um.get_all_users_info()
print 'Press Ctrl+C to exit'
print '0 - add a new user'
for i, user_info in enumerate(users_info):
print '%d - %s(%s)' %(i + 1, user_info['username'], user_info['ethernet_interface'])

try:
choice = int(raw_input('Your choice: '))
except ValueError:
print 'Please input a valid number!'
else: break;
if choice == 0:
try:
user_info = prompt_user_info()
um.add_user(user_info)
except ConfigParser.DuplicateSectionError:
print 'User already exist!'
exit(-1)
else:
return users_info[choice - 1]
except ValueError,e:
print '\nPlease input a valid number!\n'
continue
if choice == 0:
try:
user_info = prompt_user_info()
um.add_user(user_info)
continue
except ConfigParser.DuplicateSectionError:
print '\nUser already exist!\n'
continue
elif choice <= len(users_info):
return users_info[choice - 1]
else:
print '\nPlease input a valid number!\n'
continue


def start_yah3c(login_info):
yah3c = eapauth.EAPAuth(login_info)
Expand Down