debugging some verifying errors...
This commit is contained in:
parent
e2f7b29287
commit
c2e6fe1a04
@ -46,11 +46,58 @@ class aifgen(object):
|
||||
def __init__(self, args):
|
||||
self.args = args
|
||||
|
||||
def webFetch(self, uri, auth = False): # TODO: add commandline args support for extra auth?
|
||||
# Sanitize the user specification and find which protocol to use
|
||||
prefix = uri.split(':')[0].lower()
|
||||
if uri.startswith('/'):
|
||||
prefix = 'file'
|
||||
# Use the urllib module
|
||||
if prefix in ('http', 'https', 'file', 'ftp'):
|
||||
if auth:
|
||||
if 'user' in auth.keys() and 'password' in auth.keys():
|
||||
# Set up Basic or Digest auth.
|
||||
passman = urlrequest.HTTPPasswordMgrWithDefaultRealm()
|
||||
if not 'realm' in auth.keys():
|
||||
passman.add_password(None, uri, auth['user'], auth['password'])
|
||||
else:
|
||||
passman.add_password(auth['realm'], uri, auth['user'], auth['password'])
|
||||
if auth['type'] == 'digest':
|
||||
httpauth = urlrequest.HTTPDigestAuthHandler(passman)
|
||||
else:
|
||||
httpauth = urlrequest.HTTPBasicAuthHandler(passman)
|
||||
httpopener = urlrequest.build_opener(httpauth)
|
||||
urlrequest.install_opener(httpopener)
|
||||
with urlrequest.urlopen(uri) as f:
|
||||
data = f.read()
|
||||
elif prefix == 'ftps':
|
||||
if auth:
|
||||
if 'user' in auth.keys():
|
||||
username = auth['user']
|
||||
else:
|
||||
username = 'anonymous'
|
||||
if 'password' in auth.keys():
|
||||
password = auth['password']
|
||||
else:
|
||||
password = 'anonymous'
|
||||
filepath = '/'.join(uri.split('/')[3:])
|
||||
server = uri.split('/')[2]
|
||||
content = StringIO()
|
||||
ftps = FTP_TLS(server)
|
||||
ftps.login(username, password)
|
||||
ftps.prot_p()
|
||||
ftps.retrlines("RETR " + filepath, content.write)
|
||||
data = content.getvalue()
|
||||
else:
|
||||
exit('{0} is not a recognised URI type specifier. Must be one of http, https, file, ftp, or ftps.'.format(prefix))
|
||||
return(data)
|
||||
|
||||
def getXSD(self):
|
||||
pass
|
||||
xsdobj = etree.fromstring(self.webFetch(xsd).decode('utf-8'))
|
||||
return(xsdobj)
|
||||
|
||||
def getXML(self):
|
||||
pass
|
||||
xmlobj = etree.fromstring(self.webFetch(self.args['cfgfile']).decode('utf-8'))
|
||||
return(xmlobj)
|
||||
|
||||
def getOpts(self):
|
||||
# This whole thing is ugly. Really, really ugly. Patches 100% welcome.
|
||||
|
11
aif.xsd
11
aif.xsd
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
|
||||
targetNamespace="https://aif.square-r00t.net"
|
||||
xmlns="https://aif.square-r00t.net"
|
||||
targetNamespace="http://aif.square-r00t.net"
|
||||
xmlns="http://aif.square-r00t.net"
|
||||
elementFormDefault="qualified">
|
||||
<xs:annotation>
|
||||
<xs:documentation>
|
||||
@ -104,7 +104,8 @@
|
||||
</xs:simpleType>
|
||||
|
||||
<xs:simpleType name="pacuri">
|
||||
<xs:restriction base="xs:anyURI">
|
||||
<!-- <xs:restriction base="xs:anyURI"> -->
|
||||
<xs:restriction base="xs:token">
|
||||
<xs:pattern value="(file|https?)://.*" />
|
||||
</xs:restriction>
|
||||
</xs:simpleType>
|
||||
@ -263,7 +264,7 @@
|
||||
</xs:sequence>
|
||||
<xs:attribute name="timezone" type="xs:string" use="required" />
|
||||
<xs:attribute name="locale" type="xs:string" use="required" />
|
||||
<xs:attribute name="chrootpath" type="xs:string" user="required" />
|
||||
<xs:attribute name="chrootpath" type="xs:string" use="required" />
|
||||
<xs:attribute name="kbd" type="xs:token" />
|
||||
<xs:attribute name="reboot" type="xs:boolean" />
|
||||
</xs:complexType>
|
||||
@ -332,7 +333,7 @@
|
||||
<xs:complexType>
|
||||
<xs:attribute name="uri" type="scripturi" use="required" />
|
||||
<xs:attribute name="order" type="xs:integer" use="required" />
|
||||
<xs:attribute name="execution" type="xs:scripttype" use="required" />
|
||||
<xs:attribute name="execution" type="scripttype" use="required" />
|
||||
<xs:attribute name="user" type="xs:string" />
|
||||
<xs:attribute name="password" type="xs:string" />
|
||||
<xs:attribute name="realm" type="xs:string" />
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<aif xmlns:aif="https://aif.square-r00t.net"
|
||||
<aif xmlns:aif="http://aif.square-r00t.net/"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="https://aif.square-r00t.net aif.xsd">
|
||||
xsi:schemaLocation="http://aif.square-r00t.net aif.xsd">
|
||||
<storage>
|
||||
<disk device="/dev/sda" diskfmt="gpt">
|
||||
<part num="1" start="0%" size="10%" fstype="ef00" />
|
||||
|
Loading…
Reference in New Issue
Block a user