2024-02-10 15:45:44 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
import requests
|
|
|
|
import socket
|
|
|
|
import platform
|
|
|
|
import argparse
|
|
|
|
|
|
|
|
parser = argparse.ArgumentParser(description='Process some integers.')
|
|
|
|
parser.add_argument('-d', '--debug', dest='debug', action='store_true',
|
|
|
|
help='debug: show what would be sent')
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
hostname = socket.gethostname()
|
|
|
|
hostname = socket.getfqdn()
|
|
|
|
fqdn = socket.getfqdn()
|
|
|
|
ip = socket.gethostbyname(hostname)
|
|
|
|
|
|
|
|
API_ENDPOINT = "http://192.168.0.140:5000/register"
|
|
|
|
|
|
|
|
def get_ip():
|
|
|
|
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
|
|
|
try:
|
|
|
|
# doesn't even have to be reachable
|
|
|
|
s.connect(('10.255.255.255', 1))
|
|
|
|
IP = s.getsockname()[0]
|
|
|
|
except Exception:
|
|
|
|
IP = '127.0.0.1'
|
|
|
|
finally:
|
|
|
|
s.close()
|
|
|
|
return IP
|
|
|
|
|
|
|
|
ip = get_ip()
|
|
|
|
|
|
|
|
if ip.startswith("127.0"):
|
|
|
|
raise ValueError("you need a fully qualified hostname")
|
|
|
|
|
|
|
|
if platform.system() == "Windows":
|
|
|
|
os = "win"
|
|
|
|
elif platform.system() == "Linux":
|
|
|
|
os = "linux"
|
|
|
|
else:
|
|
|
|
raise ValueError
|
|
|
|
|
2024-02-10 16:25:42 +00:00
|
|
|
if not "." in fqdn:
|
2024-02-10 16:08:08 +00:00
|
|
|
fqdn += ".liebchen.fkp"
|
2024-02-10 15:45:44 +00:00
|
|
|
|
|
|
|
data = {
|
|
|
|
"client":hostname,
|
|
|
|
"os":os,
|
|
|
|
"ip":fqdn
|
|
|
|
}
|
|
|
|
|
|
|
|
if args.debug:
|
|
|
|
print(data, "sent to:", API_ENDPOINT)
|
|
|
|
else:
|
|
|
|
r = requests.post(url = API_ENDPOINT, data = data)
|
|
|
|
print(r.text)
|
|
|
|
|
|
|
|
if platform.system() == "Windows":
|
|
|
|
with open("C:/Program Files/Bacula/bacula-fd.conf","w") as f:
|
|
|
|
f.write(r.text)
|
|
|
|
elif platform.system() == "Linux":
|
|
|
|
with open("/etc/bacula/bacula-fd.conf","w") as f:
|
|
|
|
f.write(r.text)
|