Changeset 1170


Ignore:
Timestamp:
12/05/06 17:02:24 (6 years ago)
Author:
mglb1
Message:

Further hostapd/radius template integration and administration functionality

Location:
ccsd
Files:
7 added
4 edited

Legend:

Unmodified
Added
Removed
  • ccsd/private/templates/host/clients_conf.tmpl

    r1169 r1170  
    1414commentStartToken = !! 
    1515#end compiler-settings 
    16 !set %radius = %service["radius"] 
     16!set %radius = %services["radius"] 
    1717############################################################# 
    1818# 
  • ccsd/private/templates/host/interfaces.tmpl

    r926 r1170  
    1212#from crcnetd._utils.ccsd_cfengine import ccs_template 
    1313#extends ccs_template 
     14#if "hostapd" in $services.keys() 
     15    #set $hostapd = $services["hostapd"] 
     16#else 
     17    #set $hostapd = None 
     18#end if 
    1419## 
    1520## Real template output starts below here 
     
    5964auto $iface.name 
    6065        #end if 
     66        ## Add hostapd allow- class line if necessary 
     67        #if $hostapd is not None and $hostapd.interfaceEnabled($session_id, $iface.interface_id) 
     68allow-hostapd $iface.name 
     69        #end if 
    6170${c}iface $iface.name inet static 
    6271$c    address $iface.ip_address 
     
    94103        #end if 
    95104$c    wireless_essid $iface.essid 
     105        ## Add hostapd startup stanza if necessary 
     106        #if $hostapd is not None and $hostapd.interfaceEnabled($session_id, $iface.interface_id) 
     107$c    hostapd_config /etc/hostapd/hostapd-${iface.name}.conf 
     108        #end if 
    96109    #end if 
    97110    ## Create bridge interface if required 
  • ccsd/trunk/crcnetd/modules/ccs_hostapd.py

    r1135 r1170  
    3232    pass 
    3333 
     34def hostapdInterfaceEnabled(session_id, interface_id): 
     35    """Returns true if the hostapd service is enabled on the specified iface""" 
     36    session = getSessionE(session_id) 
     37 
     38    r = session.getCountOf("SELECT count(*) FROM hostapd_interface WHERE " \ 
     39            "interface_id=%s", (interface_id)) 
     40    if r == 1: 
     41        return True 
     42 
     43    return False 
     44 
    3445class hostapd_service(ccsd_service): 
    3546    """Configures the hostapd service on a host""" 
     
    4253        # Call base class setup 
    4354        ccsd_service.__init__(self, session_id, service_id) 
     55 
     56    @registerEvent("hostapdInterfaceEnabled") 
     57    @exportViaXMLRPC(SESSION_RW, AUTH_ADMINISTRATOR, True) 
     58    def enableHostAPdInterface(self, host_id, interface_id): 
     59        """Enables HostAPd on the specified interface""" 
     60        session = getSessionE(self._session_id) 
     61         
     62        if hostapdInterfaceEnabled(self._session_id, interface_id): 
     63            raise hostapd_error("HostAPd already enabled on interface!") 
     64         
     65        session.execute("INSERT INTO hostapd_interface (interface_id) " \ 
     66                "VALUES (%s)", (interface_id)) 
     67         
     68        # Raise the event 
     69        triggerHostEvent(self._session_id, "hostapdInterfaceEnabled", \ 
     70                service_id=self.service_id, host_id=host_id, \ 
     71                interface_id=interface_id) 
     72         
     73        return True 
     74 
     75    @registerEvent("hostapdInterfaceDisabled") 
     76    @exportViaXMLRPC(SESSION_RW, AUTH_ADMINISTRATOR, True) 
     77    def disableHostAPdInterface(self, host_id, interface_id): 
     78        """Disables HostAPd on the specified interface""" 
     79        session = getSessionE(self._session_id) 
     80         
     81        session.execute("DELETE FROM hostapd_interface WHERE " \ 
     82                "interface_id=%s", (interface_id)) 
     83         
     84        # Raise the event 
     85        triggerHostEvent(self._session_id, "hostapdInterfaceDisabled", \ 
     86                service_id=self.service_id, host_id=host_id, \ 
     87                interface_id=interface_id) 
     88         
     89        return True 
     90 
     91    def getInterfaces(self, host_id): 
     92        """Returns details about interface that have hostapd enabled on them""" 
     93        session = getSessionE(self._session_id) 
     94 
     95        return session.query("SELECT i.*, CASE WHEN hi.interface_id IS NULL " \ 
     96                "THEN FALSE ELSE TRUE END AS hostapd_enabled " \ 
     97                "FROM interface i LEFT JOIN hostapd_interface hi ON " \ 
     98                "i.interface_id=hi.interface_id WHERE i.host_id=%s AND " \ 
     99                "i.master_interface='t'", (host_id)) 
     100 
     101    @exportViaXMLRPC(SESSION_RO, AUTH_ADMINISTRATOR, True, \ 
     102            "getHostHostAPdDetails") 
     103    def getHostDetails(self, host_id): 
     104        """Returns data relating to HostAPd on a host""" 
     105        session = getSessionE(self._session_id) 
     106 
     107        service = ccsd_service.getHostDetails(self, host_id) 
     108        service["interfaces"] = self.getInterfaces(host_id) 
     109 
     110        return service 
     111 
     112    def getPlans(self): 
     113        session = getSessionE(self._session_id) 
     114 
     115        plans = {} 
     116 
     117        for row in session.query("SELECT * FROM radius_plan", ()): 
     118            plans[row["plan_name"]] = row 
     119 
     120        return plans 
     121 
     122    def getNetworkTemplateVariables(self): 
     123        """Returns a dictionary containing template variables for all hosts 
     124 
     125        See the getTemplateVariables function for more details. 
     126        """ 
     127 
     128        # Call base class to get the basics 
     129        variables = ccsd_service.getNetworkTemplateVariables(self) 
     130 
     131        # Make the function available to templates 
     132        variables["interfaceEnabled"] = hostapdInterfaceEnabled 
     133 
     134        # List of RADIUS plans 
     135        variables["plans"] = self.getPlans() 
     136 
     137        return variables 
    44138 
    45139    @staticmethod 
  • ccsd/trunk/crcnetd/modules/ccs_radius.py

    r1134 r1170  
    2323from crcnetd._utils.ccsd_log import * 
    2424from crcnetd._utils.ccsd_events import * 
     25from crcnetd._utils.ccsd_config import config_get_required 
    2526from crcnetd._utils.ccsd_session import getSession, getSessionE 
    2627from crcnetd._utils.ccsd_service import ccsd_service, registerService, \ 
     
    3132class ccs_radius_error(ccsd_error): 
    3233    pass 
     34 
     35AUTHIP_PROPERTY = "auth_ip" 
     36ACCTIP_PROPERTY = "acct_ip" 
     37AUTHPORT_PROPERTY = "auth_port" 
     38ACCTPORT_PROPERTY = "acct_port" 
    3339 
    3440@catchEvent("serviceAdded") 
     
    7884        for row in res: 
    7985            clients[row["host_name"]] = filter_keys(row) 
    80         print clients 
    8186        return clients 
     87 
     88    def getNetworkTemplateVariables(self): 
     89        variables = ccsd_service.getNetworkTemplateVariables(self) 
     90        variables["clients"] = self.getClients() 
     91        return variables 
    8292 
    8393    def getHostTemplateVariables(self, host_id): 
     
    8999        # Call base class to get the basics 
    90100        variables = ccsd_service.getHostTemplateVariables(self, host_id) 
    91  
    92         variables["clients"] = self.getClients() 
    93  
    94101        return variables 
    95102 
     
    110117            service_id = session.getCountOf("SELECT currval('" \ 
    111118                    "service_service_id_seq') AS server_id", ()) 
     119            default_ip = getIP(config_get_required("network", "server_name")) 
     120            session.execute("INSERT INTO service_prop (service_prop_id, " \ 
     121                "service_id, prop_name, prop_type, default_value, " \ 
     122                "required) VALUES (DEFAULT, %s, %s, 'string', %s, 'f')", \ 
     123                (service_id, AUTHIP_PROPERTY, default_ip)) 
     124            session.execute("INSERT INTO service_prop (service_prop_id, " \ 
     125                "service_id, prop_name, prop_type, default_value, " \ 
     126                "required) VALUES (DEFAULT, %s, %s, 'string', %s, 'f')", \ 
     127                (service_id, ACCTIP_PROPERTY, default_ip)) 
     128            session.execute("INSERT INTO service_prop (service_prop_id, " \ 
     129                "service_id, prop_name, prop_type, default_value, " \ 
     130                "required) VALUES (DEFAULT, %s, %s, 'integer', %s, 'f')", \ 
     131                (service_id, AUTHPORT_PROPERTY, 1812)) 
     132            session.execute("INSERT INTO service_prop (service_prop_id, " \ 
     133                "service_id, prop_name, prop_type, default_value, " \ 
     134                "required) VALUES (DEFAULT, %s, %s, 'integer', %s, 'f')", \ 
     135                (service_id, ACCTPORT_PROPERTY, 1813)) 
    112136                 
    113137            # Commit the changese 
Note: See TracChangeset for help on using the changeset viewer.