Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migration from Esmith smarthosts to sqlite relayrules #102

Merged
merged 3 commits into from
Apr 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions imageroot/actions/import-module/50import_smarthosts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env python3

#
# Copyright (C) 2024 Nethesis S.r.l.
# SPDX-License-Identifier: GPL-3.0-or-later
#

import sys
import json
import agent
import mail

# Global stdout redirection:
sys.stdout = sys.stderr

sdb = mail.pcdb_connect()
sdb.set_trace_callback(lambda m: print(agent.SD_DEBUG + m))

# import the Esmith smarthosts database
with sdb:
cur = sdb.cursor()

print(agent.SD_INFO + "Importing smarthosts...", file=sys.stderr)
for smart in json.load(open('smarthosts.json')):

vals = {
'rule_type':smart['type'],
'rule_subject': smart['name'].removeprefix('@'),
'host': smart['props'].get('Host'),
'port': smart['props'].get('Port'),
'mandatory_tls': 'encrypt' if smart['props'].get('TlsStatus') == 'enabled' else 'may',
'username': smart['props'].get('Username'),
'password': smart['props'].get('Password'),
'enabled': True if smart['props'].get('status') == 'enabled' else False,
}
cur.execute("""INSERT INTO relayrules (rule_type, rule_subject , host, port, tls, username, password, enabled)
VALUES (:rule_type, :rule_subject, :host, :port, :mandatory_tls, :username, :password, :enabled)""", vals)
Loading