import libxml2 #;libxml2.debugMemory(1)
import libxslt

import jon.cgi as cgi
#import jon.session as session
import jon.modpy as modpy

import Handler
from Handler import PATH_XML_DOCS
#from Handler import PATH_XSL_DOCS
from Handler import MESSAGE_FORMAT_PAGE

#PATH_XML_DOCS = '/etc/'
##PATH_XML_DOCS = '../htdocs/xmlxsldocs/'
#PATH_XSL_DOCS = '../htdocs/xmlxsldocs/'

class SystemHandler(Handler.Handler):
    _adminPage = 'advancedsecurity.xsl'
    _roPage = 'advancedrosecurity.xsl'
    
    def apply(self, req):
        req.set_header('Content-Type', 'text/html')
    #    req.write('Under Construction')

        if (req.params['admin_pw1'] == req.params['admin_pw2']):
            for node in self._muxconfig.xpathEval2('configuration/user_data/admin_pw'):
                node.setContent(req.params['admin_pw1'])
            self._muxconfig.saveFormatFile(PATH_XML_DOCS + self._configFile, 1)
            self._muxconfig.saveFormatFile(PATH_XML_DOCS + 'webref.xml', 1)
            #self._muxconfig.saveFile(PATH_XML_DOCS + self._configFile)
            #print MESSAGE_FORMAT_PAGE % ('system.py','Success')
            self._message =  'Apply Successful'
        else:
            #print MESSAGE_FORMAT_PAGE % ('system.py','Passwords do not match')
            self._message =  'Passwords do not match'
        self.view(req)    
        

def handler(modpy_request):
    return modpy.Request(SystemHandler).process(modpy_request)
#cgi.CGIRequest(SystemHandler).process()
