How to import Aliases?

Started by chemlud, November 15, 2018, 12:34:56 PM

Previous topic - Next topic
November 15, 2018, 12:34:56 PM Last Edit: November 15, 2018, 01:31:04 PM by chemlud
Hello again!

I'm a little lost on this, have a large list of Aliases and wanted to import to an opnsense (from the dark side of the sense-universe, I must confess).

I see no option to import aliases in the respective drop-down, thought they might be imported with the firewall rules (seems to make sense), but is apparently not the case.

An easy way to get the aliases to be imported?

PS: Found this here:

https://forum.opnsense.org/index.php?topic=10199.0

Maybe someone?
kind regards
chemlud
____
"The price of reliability is the pursuit of the utmost simplicity."
C.A.R. Hoare

felix eichhorns premium katzenfutter mit der extraportion energie

A router is not a switch - A router is not a switch - A router is not a switch - A rou....

I would like to know that as well as I may need to re-import my aliases that have disappeared from the Firewall-Aliases view. I'm sure there was an import facility before  and you could just past in a list.

The documentation mentions an import feature but I can no longer find it:

https://wiki.opnsense.org/manual/aliases.html#import-feature

You can't even edit an existing Alias, when try to save you get: An alias with this name already exists... :-\
kind regards
chemlud
____
"The price of reliability is the pursuit of the utmost simplicity."
C.A.R. Hoare

felix eichhorns premium katzenfutter mit der extraportion energie

A router is not a switch - A router is not a switch - A router is not a switch - A rou....

November 15, 2018, 04:41:25 PM #3 Last Edit: November 15, 2018, 05:04:05 PM by chemlud
One option would be to edit the aliases directly in the exported config.xml, but I guess vi in BSD is the only editing tool not breaking the file? Or is there sumfink to edit config.xml in Linux?

OK, to answer my own question:

I created all the Aliases I need in the GUI, but added only the first 3 hosts or whatever.

Then I exported the config and opened the .xml in nano and added the other entry for the various keeping exactly the syntax as for the first three entries. Imported the complete config back into sense and had a look: Seemed to work!

After reboot everything looks fine! :-D
kind regards
chemlud
____
"The price of reliability is the pursuit of the utmost simplicity."
C.A.R. Hoare

felix eichhorns premium katzenfutter mit der extraportion energie

A router is not a switch - A router is not a switch - A router is not a switch - A rou....


Where is the documentation that shows you how to add aliases via the API? I'm struggling to find it.

Seems it's not yet documented. The actions are here:

https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/controllers/OPNsense/Firewall/Api/AliasController.php

You can grab a different example and try to use the actions in the Api Controller above

Quote from: mimugmail on November 15, 2018, 05:22:02 PM
Now that Aliases are API enabled you could also add them via API :)

https://docs.opnsense.org/development/how-tos/api.html

No idea how to do that! :-D
kind regards
chemlud
____
"The price of reliability is the pursuit of the utmost simplicity."
C.A.R. Hoare

felix eichhorns premium katzenfutter mit der extraportion energie

A router is not a switch - A router is not a switch - A router is not a switch - A rou....

Aliases can also get copy/pasted from a comma separated list.

Quote from: jschellevis on November 16, 2018, 01:31:32 AM
Aliases can also get copy/pasted from a comma separated list.

Into where? That option has seemed to have disappeared.

Screenshot enclosed ... perhaps it's too easy to find :)

It's non-obvious drag+drop of text into the content field. It also works as "foobar,testing,hello" by doing CTRL+C and CTRL+V into that same field. :)

...I had no commas, so no copy+paste ;-)
kind regards
chemlud
____
"The price of reliability is the pursuit of the utmost simplicity."
C.A.R. Hoare

felix eichhorns premium katzenfutter mit der extraportion energie

A router is not a switch - A router is not a switch - A router is not a switch - A rou....

I'm going to try adding some aliases via the API this weekend - if I can figure out the PHP code that is   ???

November 17, 2018, 09:02:57 PM #14 Last Edit: November 17, 2018, 09:04:46 PM by snowfall
Quote from: jschellevis on November 16, 2018, 01:31:32 AM
Aliases can also get copy/pasted from a comma separated list.

I tried this for networks in CIDR notation but couldn't get this to work. It is never separation them but trying to parse the whole sequence as a single IP address. Hence I get the error "is not a valid hostname or IP address.".

Any tips on how to work around this?
I tried carriage return separated and comma separated and nothing works anymore.
One or two versions ago there was the alias import feature which worked perfectly for me.