mirror of
				https://github.com/laurivosandi/certidude
				synced 2025-10-31 09:29:13 +00:00 
			
		
		
		
	* Switch to Python 2.x due to lack of decent LDAP support in Python 3.x * Add LDAP backend for authentication/authorization * Add PAM backend for authentication * Add getent backend for authorization * Add preliminary CSRF protection * Update icons * Update push server documentation, use nchan from now on * Add P12 bundle generation * Add thin wrapper around Python's SQL connectors * Enable mailing subsystem * Add Kerberos TGT renewal cronjob * Add HTTPS server setup commands for nginx
		
			
				
	
	
		
			59 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			59 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
| 
 | |
| import falcon
 | |
| import ipaddress
 | |
| from datetime import datetime
 | |
| from certidude import config
 | |
| from certidude.decorators import serialize
 | |
| from certidude.api.lease import parse_dn
 | |
| 
 | |
| def address_to_identity(conn, addr):
 | |
|     """
 | |
|     Translate currently online client's IP-address to distinguished name
 | |
|     """
 | |
| 
 | |
|     SQL_LEASES = """
 | |
|         select
 | |
|             acquired,
 | |
|             released,
 | |
|             identities.data as identity
 | |
|         from
 | |
|             addresses
 | |
|         right join
 | |
|             identities
 | |
|         on
 | |
|             identities.id = addresses.identity
 | |
|         where
 | |
|             address = %s and
 | |
|             released is not null
 | |
|     """
 | |
| 
 | |
|     cursor = conn.cursor()
 | |
|     import struct
 | |
|     cursor.execute(SQL_LEASES, (struct.pack("!L", int(addr)),))
 | |
| 
 | |
|     for acquired, released, identity in cursor:
 | |
|         cursor.close()
 | |
|         return addr, datetime.utcfromtimestamp(acquired), parse_dn(bytes(identity))
 | |
| 
 | |
|     cursor.close()
 | |
|     return None
 | |
| 
 | |
| 
 | |
| class WhoisResource(object):
 | |
|     @serialize
 | |
|     def on_get(self, req, resp):
 | |
|         conn = config.DATABASE_POOL.get_connection()
 | |
| 
 | |
|         identity = address_to_identity(
 | |
|             conn,
 | |
|             req.context.get("remote_addr")
 | |
|         )
 | |
| 
 | |
|         conn.close()
 | |
| 
 | |
|         if identity:
 | |
|             return dict(address=identity[0], acquired=identity[1], identity=identity[2])
 | |
|         else:
 | |
|             resp.status = falcon.HTTP_403
 | |
|             resp.body = "Failed to look up node %s" % req.context.get("remote_addr")
 |