def main():
    powma=PowerManagementAndroid()
    powm=PowerManager()
    form=cgi.FieldStorage()
    if 'xml' not in form:
        raise InvalidXMLException('No xml request', InvalidXMLException.CALLED_FROM_BROWSER)
    req=ET.fromstring(form['xml'].value)
    el_authentication_list = req.findall('authentication')
    if len(el_authentication_list) == 0:
        raise InvalidXMLException('Post might be called from browser',\
         InvalidXMLException.AUTH_ERROR)
    el_authentication = el_authentication_list[0]
    sas = SimpleAuthenticationRequest(el_authentication,str(random()).split('.')[1])
    sas.doTransaction()
    el_pair = req.findall('pair')[0]
    req_key=el_pair.find('key')
    req_value=el_pair.find('value')
    if (req_key.text=='def://power_management'):
        if (req_value.text=='default'):
            response = powma.getDefaultView()
        else:
            raise Exception
    elif (req_key.text=='powma://power_list'):
        if (req_value.text=='Restart'):
            response = powma.getSuccessView('Restarting')
            powm.execute_command(power_management.RESTART)
        elif (req_value.text=='Shut down'):
            response = powma.getSuccessView('Shutting down')
            powm.execute_command(power_management.POWEROFF)
        else:
            raise Exception
    else:
        raise Exception
    
    composeXMLDocument(response.getroot())
예제 #2
0
def main():
    form = cgi.FieldStorage()
    if 'xml' not in form:
        ixe = InvalidXMLException('Post might be called from browser',\
         InvalidXMLException.CALLED_FROM_BROWSER)
        raise ixe
    request_xml = ET.fromstring(form['xml'].value)
    el_authentication_list = request_xml.findall('authentication')
    if len(el_authentication_list) == 0:
        raise InvalidXMLException('Post might be called from browser',\
         InvalidXMLException.AUTH_ERROR)
    el_authentication = el_authentication_list[0]       
    menu_file = "/usr/share/pi-web-agent/api/xml/action_menu.xml"
    xml = ET.parse(menu_file)
    sar = SimpleAuthenticationRequest(el_authentication, str(random()).split('.')[1])
    sar.doTransaction()  
    composeXMLDocument(xml.getroot())
예제 #3
0
def main():
    form = cgi.FieldStorage()
    if "xml" not in form:
        ixe = InvalidXMLException("Post might be called from browser", InvalidXMLException.CALLED_FROM_BROWSER)
        raise ixe
    request_xml = ET.fromstring(form["xml"].value)
    el_authentication_list = request_xml.findall("authentication")
    if len(el_authentication_list) == 0:
        raise InvalidXMLException("Post might be called from browser", InvalidXMLException.AUTH_ERROR)
    el_authentication = el_authentication_list[0]
    sar = SimpleAuthenticationRequest(el_authentication, str(random()).split(".")[1])
    sar.doTransaction()
    el_format = request_xml.find("format")
    if el_format == None:
        raise InvalidXMLException("Bad tag", InvalidXMLException.BAD_TAG)

    xml = ET.parse(FORMAT_PATH + el_format.text)
    composeXMLDocument(xml.getroot())