Code Monkey home page Code Monkey logo

pffocus's People

Contributors

dependabot[bot] avatar hugojosefson avatar kendokan avatar khorsmann avatar mback2k avatar rrauenza avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pffocus's Issues

Ubuntu ModuleNotFoundError

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.

Output

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!

VPN config is missing

It would be nice to have the VPN config output as well. Currently that is missing.

format.py is unable to parse rule when alias name is used for ports

$ ./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>

config file doesn't parse - attribute error looking up key 'alias'

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**?

Error when running on windows 10

Issue summary

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

Steps to reproduce

  1. RUN CMD as admin
  2. run C:\pfFocus-master>format.py -i c:\pfFocus-master\config-firewall.123-20170620171532.xml -o c:\pfFocus-master\kk -f yaml

Expected result

Should get formated output

Actual result

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'

Installation

Version and method

  • Windows 10 64 bit
  • Python 3.6.2 (v3.6.2:5fd33b5, Jul 8 2017, 04:14:34) [MSC v.1900 32 bit (Intel)] on win32
  • defusedxml-0.5.0
  • PyYAML-3.12

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.