MCPcopy Index your code
hub / github.com/TKCERT/pfFocus / output_bbcode

Function output_bbcode

pf_focus/bbcode.py:105–248  ·  view source on GitHub ↗
(doc, stream)

Source from the content-addressed store, hash-verified

103 stream.write("[/table]\n")
104
105def output_bbcode(doc, stream):
106 stream.write(h1("pfSense\n"))
107 stream.write("Version {}\n".format(doc.pfsense.version))
108 stream.write("\n")
109
110 stream.write(h2("System\n"))
111 info = obj_to_dict(doc.pfsense.system, ('hostname', 'domain', 'timeservers', 'timezone', 'language', 'dnsserver'))
112 output_bbcode_table(stream, ('Option', 'Value'), info.items())
113 stream.write("\n")
114
115 if hasattr_r(doc.pfsense, 'interfaces'):
116 stream.write(h2("Interfaces\n"))
117 interfaces = sorted(doc.pfsense.interfaces.data.items(), key=lambda interface: interface[0])
118 interfaces = [[interface_name]+dict_to_list(interface_data, ('enable', 'descr', 'if', 'ipaddr', 'subnet')) for interface_name, interface_data in interfaces]
119 output_bbcode_table(stream, ('Name', 'Enabled', 'Description', 'Interface', 'Address', 'Subnet'), interfaces)
120 stream.write("\n")
121
122 if hasattr_r(doc.pfsense, 'vlans.vlan'):
123 stream.write(h2("VLANs\n"))
124 vlans = [obj_to_list(vlan, ('vlanif', 'tag', 'if', 'descr')) for vlan in doc.pfsense.vlans.vlan]
125 output_bbcode_table(stream, ('Name', 'Tag', 'Interface', 'Description'), vlans)
126 stream.write("\n")
127
128 if hasattr_r(doc.pfsense, 'bridges.bridged'):
129 stream.write(h2("Bridges\n"))
130 bridges = [obj_to_list(bridge, ('bridgeif', 'members', 'descr')) for bridge in doc.pfsense.bridges.bridged]
131 output_bbcode_table(stream, ('Name', 'Members', 'Description'), bridges)
132 stream.write("\n")
133
134 if hasattr_r(doc.pfsense, 'gateways.gateway_item'):
135 stream.write(h2("Gateways\n"))
136 gateways = [obj_to_list(gateway, ('defaultgw', 'name', 'interface', 'gateway', 'weight', 'ipprotocol', 'descr')) for gateway in doc.pfsense.gateways.gateway_item]
137 output_bbcode_table(stream, ('Default', 'Name', 'Interface', 'Gateway', 'Weight', 'IP', 'Description'), gateways)
138 stream.write("\n")
139
140 if hasattr_r(doc.pfsense, 'staticroutes.route'):
141 stream.write(h2("Static routes\n"))
142 routes = [obj_to_list(route, ('network', 'gateway', 'descr')) for route in doc.pfsense.staticroutes.route]
143 output_bbcode_table(stream, ('Network', 'Gateway', 'Description'), routes)
144 stream.write("\n")
145
146 if hasattr_r(doc.pfsense, 'dhcpd'):
147 stream.write(h2("DHCP ranges\n"))
148 for dhcpd_interface_name in sorted(doc.pfsense.dhcpd.data.keys()):
149 dhcpd_interface = PfSenseRuleInterface(parent=doc.pfsense.dhcpd)
150 dhcpd_interface.string = dhcpd_interface_name
151 stream.write(h3("DHCPd configuration for {}\n".format(format_bbcode_cell(dhcpd_interface))))
152 dhcpd = getattr(doc.pfsense.dhcpd, dhcpd_interface_name)
153 dhcpd_dict = obj_to_dict(dhcpd, ('enable', 'defaultleasetime', 'maxleasetime'))
154 output_bbcode_table(stream, ('Option', 'Value'), dhcpd_dict.items())
155 stream.write("\n")
156 if hasattr_r(dhcpd, 'range'):
157 stream.write(h3("Ranges\n"))
158 ranges = [obj_to_list(range, ('from', 'to')) for range in dhcpd.range]
159 output_bbcode_table(stream, ('From', 'To'), ranges)
160 stream.write("\n")
161 if hasattr_r(dhcpd, 'staticmap'):
162 stream.write(h3("Static mappings\n"))

Callers

nothing calls this directly

Calls 10

obj_to_dictFunction · 0.90
hasattr_rFunction · 0.90
dict_to_listFunction · 0.90
obj_to_listFunction · 0.90
h1Function · 0.85
h2Function · 0.85
output_bbcode_tableFunction · 0.85
h3Function · 0.85
format_bbcode_cellFunction · 0.85

Tested by

no test coverage detected