[SOLVED] Extract Blacklist and White?

killmasta93

Renowned Member
Aug 13, 2017
973
57
68
31
Hi,
I was wondering if someone knows how to extract the white list and blacklist from PMG into a txt?
or how to backup only the blacklist and whitelist as for the backup if i restore on another PMG it restores everything which i only need those 2 things.

What i do know is how to import into PMG just dont know how to extract it

Thank you


Code:
pmgsh get /config/ruledb/who



while read line;do pmgsh create /config/ruledb/who/48/email --email "$line" ; done < /root/blacklist.txt
 
pmg's api (and thus pmgsh) offers json output - you can use any json parser to get the information in a comfortable way.

keep in mind that the who objects can contain multiple entries (and not every entry is an e-mail (there are also domains, ip addresses....))

I personally like using `jq` for such tasks (the cheatsheet at https://lzone.de/cheat-sheet/jq provides a quick guide and should contain most things you need)

If you want a list of all emails in one particular who object you need to get it's 'id' first. assuming the object is called 'Blacklist' :
Code:
 pmgsh get /config/ruledb/who/ | jq '.[] | select( .name == "Blacklist") |.id'

with that id (let's say 103) you can get all entries, which have an email attribute defined like this:
Code:
pmgsh get /config/ruledb/who/103/objects | jq '.[] | select(.email != null) | .email'

you can use the interactive mode of pmgsh to look around a bit (just run `pmgsh` without any arguments)
additionally the apiviewer should help in getting an overview of how the api looks like:
https://pmg.proxmox.com/pmg-docs/api-viewer/index.html

I hope this helps!
 
Thank you so much. so quick question so it shows me the emails but a way to show me without the " quotes

Thank you
 
@Stoiko Ivanov hi there, i was re trying to export a list but went back to this post but forgot completely how i did this before


when i try to export the list i get this, not sure where does it saves the file?

Code:
root@mail:/tmp# pmgsh get /config/ruledb/who/22/objects | jq '.[] | select(.domain != null) | .domain'
200 OK
 
this should output on the terminal

does object 22 have any objects where the domain is set?
Code:
pmgsh get /config/ruledb/who/22/objects

if you simply want to redirect the output:
Code:
pmgsh get /config/ruledb/who/22/objects | jq '.[] | select(.domain != null) | .domain' > /tmp/domain-file.txt

I hope this helps!
 
  • Like
Reactions: killmasta93

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!