OPNsense Forum

Archive => 18.7 Legacy Series => Topic started by: chemlud on November 15, 2018, 12:34:56 pm

Title: How to import Aliases?
Post by: chemlud on November 15, 2018, 12:34:56 pm
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?
Title: Re: How to import Aliases?
Post by: mrkev on November 15, 2018, 02:22:30 pm
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 (https://wiki.opnsense.org/manual/aliases.html#import-feature)
Title: Re: How to import Aliases?
Post by: chemlud on November 15, 2018, 03:15:00 pm
You can't even edit an existing Alias, when try to save you get: An alias with this name already exists... :-\
Title: Re: How to import Aliases?
Post by: chemlud on November 15, 2018, 04:41:25 pm
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
Title: Re: How to import Aliases?
Post by: 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
Title: Re: How to import Aliases?
Post by: mrkev on November 15, 2018, 05:29:55 pm
Where is the documentation that shows you how to add aliases via the API? I'm struggling to find it.
Title: Re: How to import Aliases?
Post by: mimugmail on November 15, 2018, 05:33:22 pm
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
Title: Re: How to import Aliases?
Post by: chemlud on November 15, 2018, 06:45:27 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
Title: Re: How to import Aliases?
Post by: jschellevis on November 16, 2018, 01:31:32 am
Aliases can also get copy/pasted from a comma separated list.
Title: Re: How to import Aliases?
Post by: mrkev on November 16, 2018, 07:33:07 am
Aliases can also get copy/pasted from a comma separated list.

Into where? That option has seemed to have disappeared.
Title: Re: How to import Aliases?
Post by: mimugmail on November 16, 2018, 08:08:00 am
Screenshot enclosed ... perhaps it's too easy to find :)
Title: Re: How to import Aliases?
Post by: franco on November 16, 2018, 08:32:44 am
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. :)
Title: Re: How to import Aliases?
Post by: chemlud on November 16, 2018, 12:23:02 pm
...I had no commas, so no copy+paste ;-)
Title: Re: How to import Aliases?
Post by: mrkev on November 16, 2018, 01:18:40 pm
I'm going to try adding some aliases via the API this weekend - if I can figure out the PHP code that is   ???
Title: Re: How to import Aliases?
Post by: snowfall on November 17, 2018, 09:02:57 pm
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.
Title: Re: How to import Aliases?
Post by: mrkev on November 17, 2018, 09:58:42 pm
I just tried it and it works for me. This is a test of what I pasted in

Code: [Select]
1.1.1.1/32,2.2.2.2/32,3.3.3.3/32
Title: Re: How to import Aliases?
Post by: snowfall on November 17, 2018, 10:04:14 pm
I just tried it and it works for me. This is a test of what I pasted in

Code: [Select]
1.1.1.1/32,2.2.2.2/32,3.3.3.3/32

Thanks for the quick reply.
Unfortunately also this doesn't seem to work.
Did you try saving it? I get the error message when trying to save it.
In this case I get again
Code: [Select]
Entry "1.1.1.1/32,2.2.2.2/32,3.3.3.3/32" is not a valid hostname or IP address.
Title: Re: How to import Aliases?
Post by: mrkev on November 17, 2018, 10:26:04 pm
I just tried it again and saved. Seems to work fine.
Title: Re: How to import Aliases?
Post by: snowfall on November 17, 2018, 10:41:32 pm
I just tried it again and saved. Seems to work fine.

Ok, thanks. Seems to be a weired bug. I tried again with the same result. See the screenshot attached
Title: Re: How to import Aliases?
Post by: mrkev on November 17, 2018, 10:47:55 pm
Weird. Might be worth trying another browser. You should see a gap between each entry when you press a comma ','
Title: Re: How to import Aliases?
Post by: snowfall on November 17, 2018, 10:58:27 pm
Weird. Might be worth trying another browser. You should see a gap between each entry when you press a comma ','
Thanks for your help. Now it works. Was something in my browser configuration. Maybe the hardened DOM-storage settings or something like that.
Pressing the comma manually also worked in the other browser config but copy pasting did not.
Title: Re: How to import Aliases?
Post by: virus on December 04, 2018, 05:25:41 am
I had the same problem - is the disabled "dom.event.clipboardevents.enabled" Event in Firefox.

about:config
dom.event.clipboard events.enabled -> true

and it's working again.

You can format the list with the CIDR with notepad++ for example.