tkcert / pffocus Goto Github PK
View Code? Open in Web Editor NEWGenerate meaningful output from your pfSense configuration backup, like Markdown documentation.
License: GNU General Public License v3.0
Generate meaningful output from your pfSense configuration backup, like Markdown documentation.
License: GNU General Public License v3.0
Get errors when running
C:\pfFocus-master>format.py -i c:\pfFocus-master\config-firewall.123-20170620171532.xml -o c:\pfFocus-master\kk -f yaml
Should get formated output
C:\pfFocus-master>format.py -i c:\pfFocus-master\config-firewall.123-20170620171532.xml -o c:\pfFocus-master\kk -f yaml
โ Parsing "c:\pfFocus-master\config-firewall.123-20170620171532.xml" ...
Traceback (most recent call last):
File "C:\pfFocus-master\format.py", line 73, in
main()
File "C:\pfFocus-master\format.py", line 66, in main
step_parse(args, doc)
File "C:\pfFocus-master\format.py", line 39, in step_parse
parse_pfsense(args.input_path, doc)
File "C:\pfFocus-master\parse.py", line 75, in parse_pfsense
parse(input_file, handler)
File "C:\Python\Python36-32\lib\site-packages\defusedxml-0.5.0-py3.6.egg\defusedxml\sax.py", line 26, in parse
File "C:\Python\Python36-32\lib\xml\sax\expatreader.py", line 111, in parse
xmlreader.IncrementalParser.parse(self, source)
File "C:\Python\Python36-32\lib\xml\sax\xmlreader.py", line 125, in parse
self.feed(buffer)
File "C:\Python\Python36-32\lib\xml\sax\expatreader.py", line 217, in feed
self._parser.Parse(data, isFinal)
File "..\Modules\pyexpat.c", line 282, in CharacterData
File "C:\pfFocus-master\parse.py", line 50, in characters
cur(stack_chars.getvalue())
File "C:\pfFocus-master\pfsense.py", line 50, in call
self.integer = int(content)
ValueError: invalid literal for int() with base 10: '1024:65535'
C:\pfFocus-master>parse.py config-firewall.123-20170620171532.xml
Traceback (most recent call last):
File "C:\pfFocus-master\parse.py", line 89, in
main()
File "C:\pfFocus-master\parse.py", line 85, in main
parse_pfsense(args.input_path, doc)
File "C:\pfFocus-master\parse.py", line 75, in parse_pfsense
parse(input_file, handler)
File "C:\Python\Python36-32\lib\site-packages\defusedxml-0.5.0-py3.6.egg\defusedxml\sax.py", line 26, in parse
File "C:\Python\Python36-32\lib\xml\sax\expatreader.py", line 111, in parse
xmlreader.IncrementalParser.parse(self, source)
File "C:\Python\Python36-32\lib\xml\sax\xmlreader.py", line 125, in parse
self.feed(buffer)
File "C:\Python\Python36-32\lib\xml\sax\expatreader.py", line 217, in feed
self._parser.Parse(data, isFinal)
File "..\Modules\pyexpat.c", line 282, in CharacterData
File "C:\pfFocus-master\parse.py", line 50, in characters
cur(stack_chars.getvalue())
File "C:\pfFocus-master\pfsense.py", line 50, in call
self.integer = int(content)
ValueError: invalid literal for int() with base 10: '1024:65535'
$ ./format.py -i ~/Desktop/config.xml -f md -o ~/Desktop/config.md
\u268b Parsing "C:/Users/x/Desktop/config.xml" ...
Traceback (most recent call last):
File "./format.py", line 73, in <module>
main()
File "./format.py", line 66, in main
step_parse(args, doc)
File "./format.py", line 39, in step_parse
parse_pfsense(args.input_path, doc)
File "C:\Users\x\Projects\pfFocus\parse.py", line 75, in parse_pfsense
parse(input_file, handler)
File "C:\Users\x\AppData\Local\Programs\Python\Python36-32\lib\site-packages\defusedxml\sax.py", line 26, in parse
parser.parse(source)
File "C:\Users\x\AppData\Local\Programs\Python\Python36-32\lib\xml\sax\expatreader.py", line 111, in parse
xmlreader.IncrementalParser.parse(self, source)
File "C:\Users\x\AppData\Local\Programs\Python\Python36-32\lib\xml\sax\xmlreader.py", line 125, in parse
self.feed(buffer)
File "C:\Users\x\AppData\Local\Programs\Python\Python36-32\lib\xml\sax\expatreader.py", line 217, in feed
self._parser.Parse(data, isFinal)
File "..\Modules\pyexpat.c", line 282, in CharacterData
File "C:\Users\x\Projects\pfFocus\parse.py", line 50, in characters
cur(stack_chars.getvalue())
File "C:\Users\x\Projects\pfFocus\pfsense.py", line 51, in __call__
self.integer = int(content)
ValueError: invalid literal for int() with base 10: 'Photon_External'
Relevant section of config.xml:
<rule>
<source>
<any></any>
</source>
<destination>
<network>wanip</network>
<port>Photon_External</port>
I was about to go write something similar (but more rudimentary...) - thank you for this!
My config file doesn't parse. I'd rather not post it in case I haven't scrubbed it -- I can send it to you offline if you wish.
First error is in NAT parsing:
File "./format.py", line 73, in <module>
main()
File "./format.py", line 68, in main
step_stdout(args, doc, output_func)
File "./format.py", line 48, in step_stdout
output_func(doc, output_file)
File "/home/rrauenza/src/pfFocus/markdown.py", line 148, in output_markdown
output_markdown_table(stream, ('Disabled', 'Interface', 'Source', 'Destination', 'Protocol', 'Target', 'Local port', 'Description'), rules)
File "/home/rrauenza/src/pfFocus/markdown.py", line 73, in output_markdown_table
stream.write(" | ".join(map(format_markdown_cell, row)))
File "/home/rrauenza/src/pfFocus/markdown.py", line 36, in format_markdown_cell
if cell is None or (isinstance(cell, PfSenseNode) and cell.data is None):
File "/home/rrauenza/src/pfFocus/pfsense.py", line 16, in __getattr__
return super().__getattribute__(name)
File "/home/rrauenza/src/pfFocus/util.py", line 13, in data
data[key] = value.data
File "/home/rrauenza/src/pfFocus/pfsense.py", line 16, in __getattr__
return super().__getattribute__(name)
File "/home/rrauenza/src/pfFocus/pfsense.py", line 86, in data
for alias in self.rootdoc.pfsense.aliases.alias:
File "/home/rrauenza/src/pfFocus/pfsense.py", line 16, in __getattr__
return super().__getattribute__(name)
AttributeError: 'PfSenseAliases' object has no attribute 'alias'
I started off just putting in hacky patches to see if it was something simple.
--- a/pfsense.py
+++ b/pfsense.py
@@ -11,8 +11,12 @@ class PfSenseNode(DataNode):
self._parent = parent
def __getattr__(self, name):
# This trick hides PyLint error messages...
- return super().__getattribute__(name)
+ This trick hides PyLint error messages...
+ try:
+ return super().__getattribute__(name)
+ except AttributeError:
+ if name == 'alias':
+ return None
Which actually made things worse. Ah! I think I've walked myself into a fix:
@@ -79,9 +83,12 @@ class PfSenseAliasString(PfSenseString):
@property
def data(self):
data = super().data
- for alias in self.rootdoc.pfsense.aliases.alias:
- if alias.name.string == data:
- return {'alias': alias.data}
+ try:
+ for alias in self.rootdoc.pfsense.aliases.alias:
+ if alias.name.string == data:
+ return {'alias': alias.data}
+ except AttributeError:
+ pass
return data
class PfSensePortString(PfSenseAliasString):
@@ -136,9 +143,12 @@ class PfSenseRuleAlias(PfSenseString):
if interface_name == alias_name:
interface_data['name'] = data
return {'interface': interface_data}
- for alias in self.rootdoc.pfsense.aliases.alias:
- if alias.name.string == data:
- return {'alias': alias.data}
+ try:
+ for alias in self.rootdoc.pfsense.aliases.alias:
+ if alias.name.string == data:
+ return {'alias': alias.data}
+ except AttributeError:
+ pass
return data
That's kind of ugly -- maybe a if is needed to see if the attribute exists or get('alias', []) ... or is this just a typo/mistake and you should be iterating instead on self.rootdoc.pfsense.aliases not self.rootdoc.pfsense.aliases**.alias**?
<dnsserver>1.1.1.1</dnsserver>
<dnsserver>1.0.0.1</dnsserver>
| dnsserver | 1.0.0.1 |
Not sure if this is a know issue or not. :)
It would be nice to have the VPN config output as well. Currently that is missing.
Installed on Ubuntu ,
I'm getting a ModuleNotFoundError : No Module named 'pf_focus' when trying to run pf-format.
I'm sure this is a noob mistake, but I can't figure it out.
Firstly, thanks for sharing this :)
Second, the output in .md format has columns issues, what did you use to show your .md file in the screenshots? No matter what I open the file with (on macOS), the columns are always misaligned.
EDIT: Nevermind, didn't know markdown files were more than just a textile. Using a markdown editor it displays as expected.
Thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.