def main(): """ main worker: * gather the input """ param = {} user = "******" password = "******" client1 = RemoteHost(myIP, "testing123", "lselap") client2 = RemoteHost("127.0.0.1", "testing123", "localhost") r_dict = "/etc/linotp2/dictionary" prog = sys.argv[0] try: opts, args = getopt(sys.argv[1:], "d:", ["dict="]) except GetoptError: print "There is an error in your parameter syntax:" usage(prog) sys.exit(1) for opt, arg in opts: if opt in ('-d', '--dict'): if os.path.isfile(arg): r_dict = arg else: print("radius dictionary file <%r> not found!" % arg) params = { "addresses": ["127.0.0.1", myIP], "authport": 18012, "acctport": 18013, "hosts": { myIP: client1, "127.0.0.1": client2 }, } if os.path.isfile(r_dict) == False: ## falback: try the relative one r_dict = "config/dictionary" if os.path.isfile(r_dict): params["dict"] = Dictionary(r_dict) print "[ starting dummy radius server ]" serv = myRadiusServer(**params) return serv.Run()
def testSimpleConstruction(self): host = RemoteHost('address', 'secret', 'name', 'authport', 'acctport') self.assertEqual(host.address, 'address') self.assertEqual(host.secret, 'secret') self.assertEqual(host.name, 'name') self.assertEqual(host.authport, 'authport') self.assertEqual(host.acctport, 'acctport')
def run(): # Check to make sure env variables are set if not all(v in os.environ for v in [ "OKTA_API_KEY", "OKTA_TENANT", "RADIUS_SECRET", "RADIUS_PORT", "OKTA_WKF_ASYNC_MFA_CREATE_TRANSACTION_URL", "OKTA_WKF_ASYNC_MFA_POLL_TRANSACTION_URL" ]): logger.error("Missing environment variables!") sys.exit("Missing environment variables!") # Create server and read the attribute dictionary srv = RadiusServer(os.getenv('OKTA_TENANT'), os.getenv('OKTA_API_KEY'), dict=Dictionary("dictionary"), coa_enabled=False, authport=int(os.getenv('RADIUS_PORT'))) # Add clients (address, secret, name) srv.hosts["0.0.0.0"] = RemoteHost("0.0.0.0", os.getenv("RADIUS_SECRET").encode(), "0.0.0.0") srv.BindToAddress("") logger.info("Starting server...") # Run the RADIUS server srv.Run()
def setUp(self): self.server = Server() self.server.hosts['host'] = RemoteHost('10.0.0.0/24', 'supersecret', 'name') self.packet = TrivialObject() self.packet.code = AccountingRequest self.packet.source = ('10.0.0.1', 'port')
def testNamedConstruction(self): host = RemoteHost(address='address', secret='secret', name='name', authport='authport', acctport='acctport') self.assertEqual(host.address, 'address') self.assertEqual(host.secret, 'secret') self.assertEqual(host.name, 'name') self.assertEqual(host.authport, 'authport') self.assertEqual(host.acctport, 'acctport')
def main(): """ main worker: * gather the input """ param = {} user = "******" password = "******" client1 = RemoteHost(myIP, "testing123", "lselap") client2 = RemoteHost("127.0.0.1", "testing123", "localhost") # Set default values (overwritten by command-line args) r_dict = "/etc/linotp2/dictionary" authport = 18012 acctport = 18013 prog = sys.argv[0] try: opts, args = getopt( sys.argv[1:], "d:t:c:h", [ "dict=", "authport=", "acctport=", "help", ], ) except GetoptError: print "There is an error in your parameter syntax:" usage(prog) sys.exit(1) for opt, arg in opts: if opt in ('-h', '--help'): usage(prog) sys.exit(0) elif opt in ('-d', '--dict'): if os.path.isfile(arg): r_dict = arg else: print("radius dictionary file <%r> not found!" % arg) elif opt in ('-t', '--authport'): authport = int(arg) elif opt in ('-c', '--acctport'): acctport = int(arg) else: print "Unknown option %s" % opt params = { "addresses": ["127.0.0.1", myIP], "authport": authport, "acctport": acctport, "hosts": { myIP: client1, "127.0.0.1": client2 }, } if os.path.isfile(r_dict) is False: ## falback: try the relative one r_dict = "config/dictionary" if os.path.isfile(r_dict): params["dict"] = Dictionary(r_dict) print "[ starting dummy radius server ]" serv = myRadiusServer(**params) return serv.Run()
reply = self.CreateReplyPacket(pkt) # COA NAK reply.code = 45 protocol.send_response(reply, addr) if __name__ == '__main__': # create server and read dictionary loop = asyncio.get_event_loop() server = FakeServer(loop=loop, dictionary=Dictionary('dictionary')) # add clients (address, secret, name) server.hosts["127.0.0.1"] = RemoteHost("127.0.0.1", b"Kah3choteereethiejeimaeziecumi", "localhost") try: # Initialize transports loop.run_until_complete( asyncio.ensure_future( server.initialize_transports(enable_auth=True, enable_acct=True, enable_coa=True))) try: # start server loop.run_forever() except KeyboardInterrupt as k:
except Exception as e: logger.exception("There was a problem with the Okta MFA", e) self.SendReplyPacket(pkt.fd, reply) def HandleAuthPacket(self, pkt): thread = threading.Thread(target=self.auth_handler, args=(pkt, )) thread.start() if __name__ == '__main__': # Check to make sure env variables are set if not all(v in os.environ for v in ["OKTA_API_KEY", "OKTA_TENANT", "RADIUS_SECRET"]): logger.error("Missing environment variables!") sys.exit("Missing environment variables!") # Create server and read the attribute dictionary srv = RadiusServer(dict=Dictionary("dictionary"), coa_enabled=False) # Add clients (address, secret, name) srv.hosts["0.0.0.0/0"] = RemoteHost("0.0.0.0", os.getenv("RADIUS_SECRET").encode(), "0.0.0.0") srv.BindToAddress("") # Run the RADIUS server srv.Run()
from pyrad.server import Server, RemoteHost from netaddr import * #Testing, testing print("Hello!") ip = IPNetwork("192.168.0.1/24") print("version: ", ip.version) print("IP:", ip.ip) print(ip.broadcast) print(ip.netmask) #if (IPAddress("192.168.1.1") in IPNetwork("192.168.0.0/24")): # print("Ip is within subnet") #else: # print("Ip is not within subnet") remoteHost = RemoteHost("10.0.0.138", "pass", "host", 80) server = Server()