-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1e907a9
commit 0446009
Showing
16 changed files
with
207 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# Verschlüsselte Daten | ||
*.key | ||
*.pem | ||
*.pfx | ||
*.crt | ||
*.certbot | ||
|
||
# Kompilierte Dateien | ||
__pycache__ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# Log-Dateien | ||
*.log | ||
|
||
# Temporäre Dateien | ||
*.tmp | ||
*.swp | ||
*.swo | ||
|
||
# IDE-Spezifische Dateien | ||
.vscode/ | ||
.idea/ | ||
|
||
# Python-Verpackungen | ||
dist/ | ||
build/ | ||
*.egg-info | ||
|
||
# Virtual Environment | ||
venv/ | ||
env/ | ||
ENV/ | ||
|
||
# Lokale Entwicklungsskripte | ||
*.pyc | ||
__init__.py* | ||
*.so | ||
*.dylib | ||
*.dll | ||
|
||
# Test-Ausgaben | ||
test_*.out | ||
*.test | ||
|
||
# Build-Dateien | ||
*.exe | ||
*.exe~ | ||
*.bin | ||
*.class | ||
|
||
# Verschlüsselte Dateien | ||
*.gpg | ||
*.asc | ||
|
||
# Archivierte Dateien | ||
*.tar.gz | ||
*.tar.bz2 | ||
*.tar.xz | ||
*.zip | ||
|
||
# Docker-Dateien | ||
.DS_Store | ||
Thumbs.db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,60 @@ | ||
# opnsense-helper | ||
assign lan interfaces, create vlans, vlan-interfaces and setup dhcp in a single script. | ||
|
||
|
||
## install | ||
## pip | ||
```bash | ||
pip install opnsense-helper | ||
``` | ||
|
||
|
||
## usage | ||
- before you create Vlan-Interfaces you need to add them first using the add_vlan method | ||
- you can also add them via config file but this requires a reboot and it's not yet implemented | ||
- rn i try to find out how to reconfigure the vlans using the backend, but this is on todo list | ||
|
||
```python | ||
from opnsense_helper.classes import Opnsense_Helper | ||
|
||
filepath = '/home/ji/confignew.xml' | ||
output="./config.xml" | ||
conf_path="/conf/config.xml" | ||
vlans=[ | ||
{'if': 'vtnet1', 'tag': '1', 'pcp': '0', 'proto': None, 'descr': 'vlan1', 'vlanif': 'vlan0.1'}, | ||
{'if': 'vtnet1', 'tag': '2', 'pcp': '0', 'proto': None, 'descr': 'vlan2', 'vlanif': 'vlan0.2'} | ||
] | ||
dhcp={ | ||
"opt2": {'enable': '1', 'ddnsdomainalgorithm': 'hmac-md', "range":{'from': '200.0.3.10', '_to': '200.0.3.100'}}, | ||
"opt3": {'enable': '1', 'ddnsdomainalgorithm': 'hmac-md', "range":{'from': '200.0.4.10', '_to': '200.0.4.100'}} | ||
} | ||
interfaces={ | ||
"opt1": {'descr': 'router', 'enable': '1', 'ipaddr': None, 'subnet': None, 'type': None, 'virtual': None, 'spoofmac': '00:00:00:00:02:01',"interface":"vtnet1"}, | ||
"opt2": {'descr': 'vlan1', 'enable': '1', 'ipaddr': '200.0.3.1', 'subnet': '24', 'type': None, 'virtual': None, 'spoofmac': '00:00:00:00:00:01',"interface":"vlan0.1"}, | ||
"opt3": {'descr': 'vlan2', 'enable': '1', 'ipaddr': '200.0.4.1', 'subnet': '24', 'type': None, 'virtual': None, 'spoofmac': '00:00:00:00:00:02', "interface":"vlan0.2"} | ||
} | ||
ssh_auth={ | ||
"user":"root", | ||
"passw":"opnsense", | ||
} | ||
api_auth={ | ||
# ONLY NEED WHEN YOU USE THE API | ||
"api_key" :'ejl4fIU9yfNk+gaQmPk/rqIa15f1yX1snIKgcIEl2QNoJwhbekraWIE0ANRYceh9hey5IFGzlf3da4yJ', | ||
"api_secret" : '5JVVGoatPbaAA+FozLDQY92/T6sRlmKD1+aRNl/YI8KA9/0TNiTDboLveqvd9FU8wFeDo3D3DY5wrUtF', | ||
"ssl": True, | ||
"verify": False | ||
} | ||
host= "192.168.1.103" | ||
def test(): | ||
helper=Opnsense_Helper(host=host,ssh_auth=ssh_auth,api_auth=api_auth,filepath=output, verbose=False) | ||
helper.add_vlans(vlans) | ||
#helper.set_vlans(vlans) | ||
helper.get_conf(conf_path) | ||
helper.initialize() | ||
helper.add_Items("interfaces",interfaces) | ||
helper.add_Items("dhcpd",dhcp) | ||
helper.save(output) | ||
helper.put_file(output,conf_path) | ||
helper.close_con() | ||
|
||
if __name__ == "__main__": | ||
test() | ||
``` | ||
|
||
### contribute | ||
- clone, or fork `[email protected]:the-pod-shop/opnsense-helper.git` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,83 +1,62 @@ | ||
# opnsense-helper | ||
assign lan interfaces, create vlans, vlan-interfaces and setup dhcp in a single script. | ||
|
||
|
||
## install | ||
## pip | ||
```bash | ||
pip install opnsense-helper | ||
``` | ||
|
||
## usage | ||
|
||
### python | ||
|
||
- import and create object | ||
```python | ||
from opnsense_helper.opnsense_helper import OpennsenseHelper | ||
helper=OpennsenseHelper(filepath,True,"root","opnsense","192.168.1.103") | ||
``` | ||
- add some vars we need later | ||
- before you create Vlan-Interfaces you need to add them first using the add_vlan method | ||
- rn i try to find out how to reconfigure the vlans using the backend, but this is on todo list | ||
|
||
```python | ||
from opnsense_helper.classes import Opnsense_Helper | ||
|
||
filepath = '/home/ji/confignew.xml' | ||
output="/home/ji/.ansible/collections/ansible_collections/ji_podhead/podnet/plugins/x.xml" | ||
output="./config.xml" | ||
conf_path="/conf/config.xml" | ||
|
||
# the variables of the things we will modif | ||
vlan3 ={'parentinterface': 'vtnet1', 'tag': '3', 'pcp': '0', 'proto': None, 'descr': 'vlan3', 'vlanif': 'vlan0.3',"attr":{"uuid":"cb503df8-821d-4acd-86ba-66b35e4df17n"}} | ||
vlan4 ={'parentinterface': 'vtnet1', 'tag': '4', 'pcp': '0', 'proto': None, 'descr': 'vlan4', 'vlanif': 'vlan0.4',"attr":{"uuid":"cb503df8-821d-4acd-86ba-66b35e4s7c"}} | ||
opt3_dhcp= {'enable': '1', 'ddnsdomainalgorithm': 'hmac-md', "range":{'from': '200.0.3.10', '_to': '200.0.3.100'},"attr":None} | ||
opt4_dhcp= {'enable': '1', 'ddnsdomainalgorithm': 'hmac-md', "range":{'from': '200.0.4.10', '_to': '200.0.4.100'},"attr":None} | ||
opt3_interface= {'descr': 'vlan3', 'enable': '1', 'ipaddr': '200.0.3.1', 'subnet': '24', 'type': None, 'virtual': None, 'spoofmac': '00:00:00:00:00:03', 'attr': {}} | ||
opt4_interface= {'descr': 'vlan4', 'enable': '1', 'ipaddr': '200.0.3.1', 'subnet': '24', 'type': None, 'virtual': None, 'spoofmac': '00:00:00:00:00:04', 'attr': {}} | ||
|
||
``` | ||
- get the current conf file | ||
- initilaize the values and scan for object | ||
- dumb the object to xml | ||
. put the file back to the ssh-host | ||
- close ssh-connection | ||
```python | ||
helper.get_file(conf_path, output) | ||
helper.initialize() | ||
helper.objects["dhcpd"]["opt3"]=opt3_dhcp | ||
helper.objects["dhcpd"]["opt4"]=opt4_dhcp | ||
helper.objects["vlans"]["vlan3"]=vlan3 | ||
helper.objects["vlans"]["vlan4"]=vlan4 | ||
helper.objects["interfaces"]["opt3"]=opt3_interface | ||
helper.objects["interfaces"]["opt4"]=opt4_interface | ||
helper.save(output) | ||
helper.put_file(output,conf_path) | ||
helper.close_con() | ||
vlans=[ | ||
{'if': 'vtnet1', 'tag': '1', 'pcp': '0', 'proto': None, 'descr': 'vlan1', 'vlanif': 'vlan0.1'}, | ||
{'if': 'vtnet1', 'tag': '2', 'pcp': '0', 'proto': None, 'descr': 'vlan2', 'vlanif': 'vlan0.2'} | ||
] | ||
dhcp={ | ||
"opt2": {'enable': '1', 'ddnsdomainalgorithm': 'hmac-md', "range":{'from': '200.0.3.10', '_to': '200.0.3.100'}}, | ||
"opt3": {'enable': '1', 'ddnsdomainalgorithm': 'hmac-md', "range":{'from': '200.0.4.10', '_to': '200.0.4.100'}} | ||
} | ||
interfaces={ | ||
"opt1": {'descr': 'router', 'enable': '1', 'ipaddr': None, 'subnet': None, 'type': None, 'virtual': None, 'spoofmac': '00:00:00:00:02:01',"interface":"vtnet1"}, | ||
"opt2": {'descr': 'vlan1', 'enable': '1', 'ipaddr': '200.0.3.1', 'subnet': '24', 'type': None, 'virtual': None, 'spoofmac': '00:00:00:00:00:01',"interface":"vlan0.1"}, | ||
"opt3": {'descr': 'vlan2', 'enable': '1', 'ipaddr': '200.0.4.1', 'subnet': '24', 'type': None, 'virtual': None, 'spoofmac': '00:00:00:00:00:02', "interface":"vlan0.2"} | ||
} | ||
ssh_auth={ | ||
"user":"root", | ||
"passw":"opnsense", | ||
} | ||
api_auth={ | ||
# ONLY NEED WHEN YOU USE THE API | ||
"api_key" :'ejl4fIU9yfNk+gaQmPk/rqIa15f1yX1snIKgcIEl2QNoJwhbekraWIE0ANRYceh9hey5IFGzlf3da4yJ', | ||
"api_secret" : '5JVVGoatPbaAA+FozLDQY92/T6sRlmKD1+aRNl/YI8KA9/0TNiTDboLveqvd9FU8wFeDo3D3DY5wrUtF', | ||
"ssl": True, | ||
"verify": False | ||
} | ||
host= "192.168.1.103" | ||
def test(): | ||
helper=Opnsense_Helper(host=host,ssh_auth=ssh_auth,api_auth=api_auth,filepath=output, verbose=False) | ||
helper.add_vlans(vlans) | ||
#helper.set_vlans(vlans) | ||
helper.get_conf(conf_path) | ||
helper.initialize() | ||
helper.add_Items("interfaces",interfaces) | ||
helper.add_Items("dhcpd",dhcp) | ||
helper.save(output) | ||
helper.put_file(output,conf_path) | ||
helper.close_con() | ||
|
||
if __name__ == "__main__": | ||
test() | ||
``` | ||
|
||
### adding vlans | ||
|
||
| tpe | name | | ||
| --- | --- | | ||
| NIC | veth1 | | ||
| Interface | router | | ||
| Vlan | vlan0.1 | | ||
| VlanInterface | vlan1 | | ||
|
||
|
||
- no redundant assigntments allowed | ||
- reset to default config before reassigning | ||
- roll back to snapshot | ||
- old vlans and interfaces must explicitl get deleted and the config cant provide this | ||
- however config gives freedom over runtime changes without entire cloudinit | ||
- keep in mind that violating given rules can cause a broken vm | ||
|
||
### copy the config file to your machine manually | ||
```bash | ||
scp [email protected]:/conf/config.xml /home/user/confignew.xml && chmod +x /home/user/confignew.xml && chown user:user /home/user/confignew.xml | ||
``` | ||
### replace the original file manually | ||
```bash | ||
scp /home/user/config.xml [email protected]:/conf/config.xml | ||
``` | ||
## contribute | ||
### python | ||
### contribute | ||
- clone, or fork `[email protected]:the-pod-shop/opnsense-helper.git` | ||
- build when made changes | ||
- make sure to use the right user | ||
|
@@ -87,6 +66,7 @@ python setup.py bdist_wheel \ | |
&& pip install --upgrade . \ | ||
&& python3 -m pip install --upgrade build #--force | ||
``` | ||
- you can also use the build.sh script | ||
- create pull request | ||
|
||
## motivation | ||
|
@@ -96,4 +76,8 @@ python setup.py bdist_wheel \ | |
- but /conf/config.xml has the answer. | ||
- however for phisical interfaces its the god damn conf.rc | ||
- my opnsense runs in a vm, so it really doesnt matter for me | ||
- i just add the interfaces via libvirt and all i need to do is to enable them, given the /conf/config.xml method | ||
- i just add the interfaces via libvirt and all i need to do is to enable them, given the /conf/config.xml method | ||
xml has the answer. | ||
- however for phisical interfaces its the god damn conf.rc | ||
- my opnsense runs in a vm, so it really doesnt matter for me | ||
- i just add the interfaces via libvirt and all i need to do is to enable them, given the /conf/config.xml method |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
README.md |
Oops, something went wrong.