summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrent s <r00t@square-r00t.net>2017-05-13 07:27:58 -0400
committerbrent s <r00t@square-r00t.net>2017-05-13 07:27:58 -0400
commitc2e6fe1a0453e81c91f0ff7240faae13dcebcdb5 (patch)
tree8e67617823373488362c92933d7fc9fc49f457c9
parente2f7b2928728d67dea6b19d50f82b4ea5081da1f (diff)
downloadAIF-NG-c2e6fe1a0453e81c91f0ff7240faae13dcebcdb5.tar.xz
debugging some verifying errors...
-rwxr-xr-xaif-config.py51
-rw-r--r--aif.xsd23
-rw-r--r--docs/examples/aif-secure.xml4
3 files changed, 63 insertions, 15 deletions
diff --git a/aif-config.py b/aif-config.py
index dfb37bd..266aad9 100755
--- a/aif-config.py
+++ b/aif-config.py
@@ -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.
diff --git a/aif.xsd b/aif.xsd
index 84770d8..3909fe0 100644
--- a/aif.xsd
+++ b/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>
@@ -9,7 +9,7 @@
</xs:documentation>
</xs:annotation>
<!-- GLOBAL CUSTOM DATA TYPES -->
- <xs:simpleType name="diskdev">
+ <xs:simpleType name="diskdev">
<xs:annotation>
<xs:documentation>
This element specifies a type to be used for validating storage devices, such as hard disks or mdadm-managed devices.
@@ -104,16 +104,17 @@
</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>
- <xs:simpleType name="scripttype">
- <xs:restriction base="xs:token">
- <xs:pattern value="(pre|post|pkg)" />
- </xs:restriction>
- </xs:simpleType>
+ <xs:simpleType name="scripttype">
+ <xs:restriction base="xs:token">
+ <xs:pattern value="(pre|post|pkg)" />
+ </xs:restriction>
+ </xs:simpleType>
<xs:simpleType name="bootloaders">
<xs:restriction base="xs:token">
@@ -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" />
diff --git a/docs/examples/aif-secure.xml b/docs/examples/aif-secure.xml
index b609d05..81c1457 100644
--- a/docs/examples/aif-secure.xml
+++ b/docs/examples/aif-secure.xml
@@ -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" />