add myoffice scripts
This commit is contained in:
89
myoffice_projects/import_mailion/export_groups_from_ldap.py
Executable file
89
myoffice_projects/import_mailion/export_groups_from_ldap.py
Executable file
@@ -0,0 +1,89 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import ldap
|
||||
import json
|
||||
import re
|
||||
|
||||
def write_to_file(filename, group_list):
|
||||
pattern = r'child_\d+'
|
||||
|
||||
#Save group's list in JSON file
|
||||
with open(filename, 'w') as file:
|
||||
json.dump(group_list, file, indent=4)
|
||||
|
||||
with open(filename, 'r') as file:
|
||||
lines = file.readlines()
|
||||
|
||||
lines = lines[1:-1] # delete first and last lines
|
||||
|
||||
# Change "}," to "}"
|
||||
for i in range(len(lines)):
|
||||
lines[i] = lines[i].replace('},', '}')
|
||||
lines[i] = re.sub(pattern, 'child', lines[i])
|
||||
|
||||
with open(filename, 'w') as file:
|
||||
for line in lines:
|
||||
file.write(line)
|
||||
|
||||
# OpenLDAP server config
|
||||
ldap_server = 'ldap://ds.avroid.tech'
|
||||
ldap_port = 389
|
||||
ldap_base_dn = 'dc=avroid,dc=tech'
|
||||
ldap_admin_user = 'uid=ipa,cn=users,cn=accounts,dc=avroid,dc=tech'
|
||||
ldap_admin_password = '<PASSWORD>'
|
||||
|
||||
# LDAP query
|
||||
ldap_filter = '(objectClass=ipantgroupattrs)'
|
||||
|
||||
# Connect to the LDAP server
|
||||
ldap_connection = ldap.initialize(ldap_server + ':' + str(ldap_port))
|
||||
|
||||
try:
|
||||
# Bind to the LDAP server using admin credentials
|
||||
ldap_connection.simple_bind_s(ldap_admin_user, ldap_admin_password)
|
||||
results = ldap_connection.search_s(ldap_base_dn, ldap.SCOPE_SUBTREE, ldap_filter)
|
||||
|
||||
# Prepare a lists for groups
|
||||
groups = []
|
||||
group_links = []
|
||||
i = 0
|
||||
# Extract groups information
|
||||
for dn, entry in results:
|
||||
group = {}
|
||||
|
||||
# Extract and store group attributes
|
||||
if ' ' not in entry.get('cn', [None])[0].decode('utf-8'):
|
||||
group['correlation_id'] = entry.get('gidNumber', [None])[0].decode('utf-8') if entry.get('gidNumber') else None
|
||||
group['name'] = entry.get('cn', [None])[0].decode('utf-8') if entry.get('cn') else None
|
||||
group['description'] = entry.get('description', [None])[0].decode('utf-8') if entry.get('description') else None
|
||||
group['email'] = group['name'] + '@' + dn.split(',')[3].split('=')[1] + '.' + dn.split(',')[4].split('=')[1]
|
||||
|
||||
groups.append(group)
|
||||
|
||||
# Extract and store group attributes
|
||||
for child in entry.get('member', [None]):
|
||||
group_link = {}
|
||||
if child is not None and child.decode('utf-8').split(',')[1].split('=')[1] in ['groups', 'users']:
|
||||
num = str(i)
|
||||
group_link['correlation_id'] = num
|
||||
group_link['parent'] = group['email']
|
||||
child = child.decode('utf-8')
|
||||
group_link['child'] = child.split(',')[0].split('=')[1]
|
||||
group_link['child'] += '@'
|
||||
group_link['child'] += child.split(',')[3].split('=')[1]
|
||||
group_link['child'] += '.'
|
||||
group_link['child'] += child.split(',')[4].split('=')[1]
|
||||
|
||||
group_links.append(group_link)
|
||||
i += 1
|
||||
write_to_file("groups.json", groups)
|
||||
write_to_file("group_links.json", group_links)
|
||||
|
||||
print('Successfully exported groups.')
|
||||
|
||||
except ldap.LDAPError as e:
|
||||
print('LDAP Error:', e)
|
||||
|
||||
finally:
|
||||
# Unbind from the LDAP server
|
||||
ldap_connection.unbind()
|
||||
27
myoffice_projects/import_mailion/import_config.json
Normal file
27
myoffice_projects/import_mailion/import_config.json
Normal file
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"token-name": "ucs-access-token",
|
||||
"admin": {
|
||||
"login": "admin.myoffice",
|
||||
"password": "ideapheeF2Ru3niZ"
|
||||
},
|
||||
"cox": {
|
||||
"compression": "none",
|
||||
"endpoint": "grpc-app.avroid.tech:3142",
|
||||
"load_balanced": false,
|
||||
"request_timeout": "10s",
|
||||
"use_tls": true
|
||||
},
|
||||
"tls_settings": {
|
||||
"ca_file": "/srv/tls/certs/ucs-infra-1.installation.example.net-main-ca.pem",
|
||||
"client_cert_file": "/srv/tls/certs/ministerium.ucs-infra-1.installation.example.net-main-client.pem",
|
||||
"key_file": "/srv/tls/keys/ministerium.ucs-infra-1.installation.example.net-main-key.pem"
|
||||
},
|
||||
"tenant_id": "c25c71b4-5f87-4d58-a38b-a504bf43585e",
|
||||
"region_id": "4ba3c930-5ff9-4933-b0a9-20ff328e2fc5",
|
||||
"gal_tags": [
|
||||
"05ea1eea-e273-55a6-86dd-3a932860211e" ],
|
||||
"user_data_path": "user_profiles.json",
|
||||
"user_data_format": "json",
|
||||
"rejected_users_path": "rejected_profiles.json",
|
||||
"roles": []
|
||||
}
|
||||
7
myoffice_projects/import_mailion/mailion_import.sh
Executable file
7
myoffice_projects/import_mailion/mailion_import.sh
Executable file
@@ -0,0 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
pushd /root/import_mailion
|
||||
./export_groups_from_ldap.py
|
||||
nct_ministerium import_groups --config settings.json
|
||||
nct_ministerium import_groups_links --config settings_links.json
|
||||
popd
|
||||
27
myoffice_projects/import_mailion/settings.json
Normal file
27
myoffice_projects/import_mailion/settings.json
Normal file
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"token-name": "ucs-access-token",
|
||||
"admin": {
|
||||
"login": "admin.myoffice",
|
||||
"password": "ideapheeF2Ru3niZ"
|
||||
},
|
||||
"cox": {
|
||||
"endpoint": "grpc-app.avroid.tech:3142",
|
||||
"service_name": "cox",
|
||||
"load_balanced": false,
|
||||
"use_tls": true,
|
||||
"use_tls_balancer": false,
|
||||
"compression": "none"
|
||||
},
|
||||
"tls_settings": {
|
||||
"ca_file": "/srv/tls/certs/ucs-infra-1.installation.example.net-main-ca.pem",
|
||||
"client_cert_file": "/srv/tls/certs/ministerium.ucs-infra-1.installation.example.net-main-client.pem",
|
||||
"key_file": "/srv/tls/keys/ministerium.ucs-infra-1.installation.example.net-main-key.pem"
|
||||
},
|
||||
"tenant_id": "c25c71b4-5f87-4d58-a38b-a504bf43585e",
|
||||
"region_id": "4ba3c930-5ff9-4933-b0a9-20ff328e2fc5",
|
||||
"gal_tags": [
|
||||
"05ea1eea-e273-55a6-86dd-3a932860211e" ],
|
||||
"groups_data_path": "groups.json",
|
||||
"groups_data_format": "json",
|
||||
"rejected_groups_path": "rejected_groups.json"
|
||||
}
|
||||
27
myoffice_projects/import_mailion/settings_links.json
Normal file
27
myoffice_projects/import_mailion/settings_links.json
Normal file
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"token-name": "ucs-access-token",
|
||||
"admin": {
|
||||
"login": "admin.myoffice",
|
||||
"password": "ideapheeF2Ru3niZ"
|
||||
},
|
||||
"cox": {
|
||||
"endpoint": "grpc-app.avroid.tech:3142",
|
||||
"service_name": "cox",
|
||||
"load_balanced": false,
|
||||
"use_tls": true,
|
||||
"use_tls_balancer": false,
|
||||
"compression": "none"
|
||||
},
|
||||
"tls_settings": {
|
||||
"ca_file": "/srv/tls/certs/ucs-infra-1.installation.example.net-main-ca.pem",
|
||||
"client_cert_file": "/srv/tls/certs/ministerium.ucs-infra-1.installation.example.net-main-client.pem",
|
||||
"key_file": "/srv/tls/keys/ministerium.ucs-infra-1.installation.example.net-main-key.pem"
|
||||
},
|
||||
"tenant_id": "c25c71b4-5f87-4d58-a38b-a504bf43585e",
|
||||
"region_id": "4ba3c930-5ff9-4933-b0a9-20ff328e2fc5",
|
||||
"gal_tags": [
|
||||
"05ea1eea-e273-55a6-86dd-3a932860211e" ],
|
||||
"group_links_data_path": "group_links.json",
|
||||
"group_links_data_format": "json",
|
||||
"rejected_groups_path": "rejected_groups.json"
|
||||
}
|
||||
Reference in New Issue
Block a user