mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
SSOwat conf fixes
This commit is contained in:
parent
c65e37216b
commit
94ff91f24f
4 changed files with 73 additions and 72 deletions
|
@ -200,11 +200,6 @@ domain:
|
|||
help: ""
|
||||
pattern: '^([a-zA-Z0-9]{1}([a-zA-Z0-9\-]*[a-zA-Z0-9])*)(\.[a-zA-Z0-9]{1}([a-zA-Z0-9\-]*[a-zA-Z0-9])*)*(\.[a-zA-Z]{1}([a-zA-Z0-9\-]*[a-zA-Z0-9])*)$'
|
||||
|
||||
### domain_ssowatconf()
|
||||
ssowatconf:
|
||||
action_help: Regenerate SSOwat configuration file
|
||||
api: PUT /ssowatconf
|
||||
|
||||
|
||||
#############################
|
||||
# App #
|
||||
|
@ -373,6 +368,11 @@ app:
|
|||
full: --sql
|
||||
help: Initial SQL file
|
||||
|
||||
### app_ssowatconf()
|
||||
ssowatconf:
|
||||
action_help: Regenerate SSOwat configuration file
|
||||
api: PUT /ssowatconf
|
||||
|
||||
### app_addaccess() TODO: Write help
|
||||
addaccess:
|
||||
action_help: Grant access right to users (everyone by default)
|
||||
|
|
|
@ -33,8 +33,8 @@ import time
|
|||
import re
|
||||
import socket
|
||||
from yunohost import YunoHostError, YunoHostLDAP, win_msg, random_password, is_true, validate
|
||||
from yunohost_domain import domain_list, domain_add, domain_ssowatconf
|
||||
from yunohost_user import user_info
|
||||
from yunohost_domain import domain_list, domain_add
|
||||
from yunohost_user import user_info, user_list
|
||||
from yunohost_hook import hook_exec
|
||||
|
||||
repo_path = '/var/cache/yunohost/repo'
|
||||
|
@ -456,7 +456,7 @@ def app_addaccess(apps, users):
|
|||
|
||||
app_setting(app, 'allowed_users', new_users.strip())
|
||||
|
||||
domain_ssowatconf()
|
||||
app_ssowatconf()
|
||||
|
||||
|
||||
def app_removeaccess(apps, users):
|
||||
|
@ -492,7 +492,7 @@ def app_removeaccess(apps, users):
|
|||
|
||||
app_setting(app, 'allowed_users', new_users.strip())
|
||||
|
||||
domain_ssowatconf()
|
||||
app_ssowatconf()
|
||||
|
||||
|
||||
def app_setting(app, key, value=None):
|
||||
|
@ -609,6 +609,65 @@ def app_initdb(user, password=None, db=None, sql=None):
|
|||
win_msg(_("Database initiliazed"))
|
||||
|
||||
|
||||
def app_ssowatconf():
|
||||
"""
|
||||
Regenerate SSOwat conf from YunoHost settings
|
||||
|
||||
Keyword argument:
|
||||
|
||||
"""
|
||||
|
||||
with open('/etc/yunohost/current_host', 'r') as f:
|
||||
main_domain = f.readline().rstrip()
|
||||
|
||||
domains = domain_list()['Domains']
|
||||
|
||||
apps = {}
|
||||
for app, v in app_list(raw=True).items():
|
||||
app_settings = app_info(raw=True, app=app)['settings']
|
||||
if 'domain' in app_settings:
|
||||
if 'path' not in app_settings:
|
||||
app_settings['path'] = '/'
|
||||
if 'mode' not in app_settings:
|
||||
app_settings['mode'] = 'private'
|
||||
if 'allowed_users' not in app_settings:
|
||||
app_settings['allowed_users'] = ''
|
||||
|
||||
apps[app] = {
|
||||
'domain': app_settings['domain'],
|
||||
'path': app_settings['path'],
|
||||
'mode': app_settings['mode'],
|
||||
'allowed_users': app_settings['allowed_users']
|
||||
}
|
||||
|
||||
users = {}
|
||||
for user in user_list()['Users']:
|
||||
users[user['Username']] = app_map(user=user['Username'])
|
||||
|
||||
conf_dict = {
|
||||
'portal_domain': main_domain,
|
||||
'portal_path': '/ynhsso/',
|
||||
'portal_port': '443',
|
||||
'portal_scheme': 'https',
|
||||
'additional_headers': {
|
||||
'Auth-User': 'uid',
|
||||
'Remote-User': 'uid',
|
||||
'Name': 'cn',
|
||||
'Email': 'mail'
|
||||
},
|
||||
'domains': domains,
|
||||
'skipped_urls': ['https://'+ main_domain +'/ynhadmin'],
|
||||
'unprotected_urls': [],
|
||||
'apps': apps,
|
||||
'users': users
|
||||
}
|
||||
|
||||
with open('/etc/ssowat/conf.json', 'wb') as f:
|
||||
json.dump(conf_dict, f)
|
||||
|
||||
win_msg(_('SSOwat configuration generated'))
|
||||
|
||||
|
||||
def _extract_app_from_file(path, remove=False):
|
||||
"""
|
||||
Unzip or untar application tarball in app_tmp_folder, or copy it from a directory
|
||||
|
|
|
@ -31,7 +31,6 @@ import shutil
|
|||
import json
|
||||
from urllib import urlopen
|
||||
from yunohost import YunoHostError, YunoHostLDAP, win_msg, colorize, validate, get_required_args
|
||||
#from yunohost_app import app_list, app_info, app_map
|
||||
|
||||
|
||||
def domain_list(filter=None, limit=None, offset=None):
|
||||
|
@ -206,7 +205,7 @@ def domain_add(domains, main=False):
|
|||
raise YunoHostError(169, _("An error occured during domain creation"))
|
||||
|
||||
|
||||
domain_ssowatconf()
|
||||
os.system('yunohost app ssowatconf')
|
||||
|
||||
win_msg(_("Domain(s) successfully created"))
|
||||
|
||||
|
@ -253,67 +252,9 @@ def domain_remove(domains):
|
|||
else:
|
||||
raise YunoHostError(169, _("An error occured during domain deletion"))
|
||||
|
||||
domain_ssowatconf()
|
||||
os.system('yunohost app ssowatconf')
|
||||
|
||||
win_msg(_("Domain(s) successfully deleted"))
|
||||
|
||||
return { 'Domains' : result }
|
||||
|
||||
|
||||
def domain_ssowatconf():
|
||||
"""
|
||||
Regenerate SSOwat conf from YunoHost settings
|
||||
|
||||
Keyword argument:
|
||||
|
||||
"""
|
||||
|
||||
with open('/etc/yunohost/current_host', 'r') as f:
|
||||
main_domain = f.readline().rstrip()
|
||||
|
||||
domains = domain_list()['Domains']
|
||||
|
||||
#apps = {}
|
||||
#for app, v in app_list(raw=True):
|
||||
# app_settings = app_info(raw=True, app=app)['settings']
|
||||
# if 'domain' in app_settings:
|
||||
# if 'path' not in app_settings:
|
||||
# app_settings['path'] = '/'
|
||||
# if 'mode' not in app_settings:
|
||||
# app_settings['mode'] = 'private'
|
||||
# if 'allowed_users' not in app_settings:
|
||||
# app_settings['allowed_users'] = ''
|
||||
|
||||
# apps[app] = {
|
||||
# 'domain': app_settings['domain'],
|
||||
# 'path': app_settings['path'],
|
||||
# 'mode': app_settings['mode'],
|
||||
# 'allowed_users': app_settings['allowed_users']
|
||||
# }
|
||||
|
||||
#users = {}
|
||||
#for user, v in user_list()['Users']:
|
||||
# users[user] = app_map(user=user)
|
||||
|
||||
conf_dict = {
|
||||
'portal_domain': main_domain,
|
||||
'portal_path': '/ynhsso/',
|
||||
'portal_port': '443',
|
||||
'portal_scheme': 'https',
|
||||
'additional_headers': {
|
||||
'Auth-User': 'uid',
|
||||
'Remote-User': 'uid',
|
||||
'Name': 'cn',
|
||||
'Email': 'mail'
|
||||
},
|
||||
'domains': domains,
|
||||
'skipped_urls': ['https://'+ main_domain +'/ynhadmin'],
|
||||
'unprotected_urls': [],
|
||||
# 'apps': apps,
|
||||
# 'users': users
|
||||
}
|
||||
|
||||
with open('/etc/ssowat/conf.json', 'wb') as f:
|
||||
json.dump(conf_dict, f)
|
||||
|
||||
win_msg(_('SSOwat configuration generated'))
|
||||
|
|
|
@ -32,9 +32,10 @@ import subprocess
|
|||
import requests
|
||||
import json
|
||||
from yunohost import YunoHostError, YunoHostLDAP, validate, colorize, get_required_args, win_msg
|
||||
from yunohost_domain import domain_add, domain_list, domain_ssowatconf
|
||||
from yunohost_domain import domain_add, domain_list
|
||||
from yunohost_dyndns import dyndns_subscribe
|
||||
from yunohost_backup import backup_init
|
||||
from yunohost_app import app_ssowatconf
|
||||
|
||||
|
||||
def tools_ldapinit(password=None):
|
||||
|
@ -276,7 +277,7 @@ def tools_postinstall(domain, password, dyndns=False):
|
|||
tools_maindomain(old_domain='yunohost.org', new_domain=domain, dyndns=dyndns)
|
||||
|
||||
# Generate SSOwat configuration file
|
||||
domain_ssowatconf()
|
||||
app_ssowatconf()
|
||||
|
||||
# Change LDAP admin password
|
||||
tools_adminpw(old_password='yunohost', new_password=password)
|
||||
|
|
Loading…
Add table
Reference in a new issue