def cli_login(self, username, password, ip): indata = self.check_input(username, password, ip) dhcp = Dhcp() auth = Auth(indata['username'],indata['password']) firewall = Firewall() mac = dhcp.find_mac(indata['ip_addr']) data = Data() if mac == False: # ip/mac pair does not exist in leasefile print "FEIL Mac/IP combo" sys.exit(conf.exit_status.ip_mac_mismatch_error) elif auth.login() != True: print "Login failed." self.log.info("LOGIN FAILED: "+indata['username']+" at "+ indata['ip_addr']) #sys.exit(conf.exit_status.login_error) sys.exit(1) dbcheck = data.mark_user_active(indata['username'],mac,indata['ip_addr']) if not dbcheck[0]: print "LOGIN FAILED, duplicates." print "User: %s \nMAC: %s \nIPv4: %s" % (dbcheck[1],dbcheck[2],dbcheck[3]) sys.exit(conf.exit_status.user_already_logged_in) else: firewall.accept_ip4(indata['ip_addr']) ## DATABASE GOES HERE #data.add_row(indata['username'],mac,indata['ip_addr'],"IPv6") self.log.info("LOGIN OK: "+indata['username']+" at "+ indata['ip_addr']) # print lease[1]+" "+lease[0] ### WRITE SOMETHING TO A LOGFILE? (this goes to stdout) print "Login successful, {0} at ip {1}".format(indata['username'], indata['ip_addr']) return True
def ip4(self,username, password, ip): indata = self.check_input(username, password, ip) dhcp = Dhcp() auth = Auth(indata['username'],indata['password']) firewall = Firewall() mac = dhcp.find_mac(indata['ip_addr']) data = Data() if not os.getuid() == 0: cmd = 'sudo /usr/local/bin/dynfw login %s %s %s' % (ip, username, password) #code = subprocess.call(cmd) code = subprocess.call(['sudo', '/usr/local/bin/dynfw', 'login', ip, username, password]) self.log.warn("NEED SUDO. \nCommand: %s \nExit code: %s" % (cmd, code)) return code == 0 if not mac: # ip/mac pair does not exist in leasefile print "FEIL Mac/IP combo" return False # exit(conf.exit_status.ip_mac_mismatch_error) elif auth.login() != True: print "Login failed." self.log.info("LOGIN FAILED: "+indata['username']+" at "+ indata['ip_addr']) return False # exit(conf.exit_status.login_error) dbcheck = data.mark_user_active(indata['username'],mac,indata['ip_addr']) if not dbcheck[0]: self.log.info( "LOGIN FAILED, duplicates.") self.log.info( "User: %s \nMAC: %s \nIPv4: %s" % (dbcheck[3],dbcheck[2],dbcheck[1])) return False else: firewall.accept_ip4(indata['ip_addr']) ## DATABASE GOES HERE self.log.info("LOGIN OK: "+indata['username']+" at "+ indata['ip_addr']) #data.add_row(indata['username'],mac,indata['ip_addr'],"IPv6") # print lease[1]+" "+lease[0] ### WRITE SOMETHING TO A LOGFILE? (this goes to stdout) print "Login successful, {0} at ip {1}".format(indata['username'], indata['ip_addr']) return True