def app_configuration(): conf_form = AppConfigForm() sch_form = SchemaForm() config = AppConfiguration.query.first() schemafiles = os.listdir(app.config['SCHEMA_DIR']) if conf_form.update.data and conf_form.validate_on_submit(): replication_dn = "cn={},o=gluu".format(conf_form.replication_dn.data) if not config: config = AppConfiguration() else: if config.replication_dn != replication_dn or \ config.replication_pw != conf_form.replication_pw.data: flash( "You changed Replication Manager information. " "This will break replication. Please re-deploy all LDAP Servers.", "danger") config.replication_dn = replication_dn config.replication_pw = conf_form.replication_pw.data config.gluu_version = conf_form.gluu_version.data config.use_ip = conf_form.use_ip.data config.nginx_host = conf_form.nginx_host.data db.session.add(config) db.session.commit() flash( "Gluu Replication Manager application configuration has been " "updated.", "success") if request.args.get('next'): return redirect(request.args.get('next')) elif sch_form.upload.data and sch_form.validate_on_submit(): f = sch_form.schema.data filename = secure_filename(f.filename) if any(filename in s for s in schemafiles): name, extension = os.path.splitext(filename) matches = [s for s in schemafiles if name in s] filename = name + "_" + str(len(matches)) + extension f.save(os.path.join(app.config['SCHEMA_DIR'], filename)) schemafiles.append(filename) flash("Schema: {0} has been uploaded sucessfully.".format(filename), "success") # request.method == GET gets processed here if config and config.replication_dn: conf_form.replication_dn.data = config.replication_dn.replace( "cn=", "").replace(",o=gluu", "") conf_form.replication_pw.data = config.replication_pw conf_form.nginx_host.data = config.nginx_host conf_form.use_ip.data = config.use_ip if config.gluu_version: conf_form.gluu_version.data = config.gluu_version return render_template('app_config.html', cform=conf_form, sform=sch_form, config=config, schemafiles=schemafiles, next=request.args.get('next'))
def _add_app_config(self): a = AppConfiguration() a.replication_dn = 'rep manager' a.replication_pw = 'secret' with self.app.app_context(): db.session.add(a) db.session.commit()
def app_configuration(): conf_form = AppConfigForm() sch_form = SchemaForm() config = AppConfiguration.query.first() schemafiles = os.listdir(app.config['SCHEMA_DIR']) if conf_form.update.data and conf_form.validate_on_submit(): if not config: config = AppConfiguration() config.replication_dn = "cn={},o=gluu".format( conf_form.replication_dn.data) config.replication_pw = conf_form.replication_pw.data config.certificate_folder = conf_form.certificate_folder.data db.session.add(config) db.session.commit() flash( "Gluu Replication Manager application configuration has been " "updated.", "success") if request.args.get('next'): return redirect(request.args.get('next')) elif sch_form.upload.data and sch_form.validate_on_submit(): f = sch_form.schema.data filename = secure_filename(f.filename) if any(filename in s for s in schemafiles): name, extension = os.path.splitext(filename) matches = [s for s in schemafiles if name in s] filename = name + "_" + str(len(matches)) + extension f.save(os.path.join(app.config['SCHEMA_DIR'], filename)) schemafiles.append(filename) flash("Schema: {0} has been uploaded sucessfully.".format(filename), "success") if config and config.replication_dn: conf_form.replication_dn.data = config.replication_dn.replace( "cn=", "").replace(",o=gluu", "") conf_form.replication_pw.data = config.replication_pw conf_form.certificate_folder.data = config.certificate_folder return render_template('app_config.html', cform=conf_form, sform=sch_form, config=config, schemafiles=schemafiles, next=request.args.get('next'))
def app_configuration(): """This view provides application configuration forms""" # create forms conf_form = AppConfigForm() sch_form = SchemaForm() config = AppConfiguration.query.first() schemafiles = os.listdir(app.config['SCHEMA_DIR']) conf_form.gluu_archive.choices = [ (f, os.path.split(f)[1]) for f in glob.glob( os.path.join(app.config['GLUU_REPO'], 'gluu-server-*')) ] # If the form is submitted and password for replication user was not # not supplied, make password "**dummy**", so don't change # what we have before #external_lb_checked = False external_lb_checked = conf_form.external_load_balancer.data if request.method == 'POST': if conf_form.gluu_version.data < '3.1.4': conf_form.use_ldap_cache.data = False if config and not conf_form.replication_pw.data.strip(): conf_form.replication_pw.validators = [] conf_form.replication_pw_confirm.validators = [] if conf_form.external_load_balancer.data: conf_form.nginx_ip.validators = [] print "OFFLINE", conf_form.offline.data, conf_form.gluu_archive.data if not conf_form.offline.data: del conf_form._fields['gluu_archive'] if not config: #del conf_form.replication_pw #del conf_form.replication_pw_confirm config = AppConfiguration() db.session.add(config) # If form is submitted and validated process it if conf_form.update.data and conf_form.validate_on_submit(): if config.replication_pw: new_replication_passwd = conf_form.replication_pw.data.strip() if conf_form.replication_pw.data: c = None server = Server.query.first() if server: c = RemoteClient(server.hostname, ip=server.ip) try: c.startup() except Exception as e: flash( "Can't establish SSH connection to {}. " "Replication password is not changed".format( server.hostname), "warning") if c: installer = Installer(c, config.gluu_version, server.os) cmd = ( '/opt/opendj/bin/ldappasswordmodify --bindDN ' '\'cn=Directory Manager\' --bindPassword $\'{}\' ' '--port 4444 --newPassword $\'{}\' --authzID ' '\'cn=admin,cn=Administrators,cn=admin data\' ' '--trustAll --useSSL'.format( server.ldap_password.replace("'", "\\'"), new_replication_passwd.replace("'", "\\'"), )) result = installer.run(cmd) if result[1].strip() == \ 'The LDAP password modify operation was successful': flash("Replication password is changed", "success") config.replication_pw = new_replication_passwd config.gluu_version = conf_form.gluu_version.data.strip() config.nginx_host = conf_form.nginx_host.data.strip() config.nginx_ip = conf_form.nginx_ip.data.strip() config.modify_hosts = conf_form.modify_hosts.data config.ldap_update_period = conf_form.ldap_update_period.data config.ldap_update_period_unit = 's' config.external_load_balancer = conf_form.external_load_balancer.data config.use_ldap_cache = conf_form.use_ldap_cache.data if conf_form.offline.data: config.offline = True config.gluu_archive = conf_form.gluu_archive.data else: config.offline = False config.gluu_archive = '' if getattr(conf_form, 'replication_pw'): if conf_form.replication_pw_confirm.data: config.replication_pw = conf_form.replication_pw.data.strip() config.gluu_version = conf_form.gluu_version.data.strip() db.session.commit() flash( "Gluu Cluster Manager application configuration has been " "updated.", "success") elif sch_form.upload.data and sch_form.validate_on_submit(): f = sch_form.schema.data filename = secure_filename(f.filename) if any(filename in s for s in schemafiles): name, extension = os.path.splitext(filename) matches = [s for s in schemafiles if name in s] filename = name + "_" + str(len(matches)) + extension f.save(os.path.join(app.config['SCHEMA_DIR'], filename)) schemafiles.append(filename) flash( "Schema: {0} has been uploaded sucessfully. " "Please edit slapd.conf of primary server and " "re-deploy all servers.".format(filename), "success") # request.method == GET gets processed here if config: conf_form.nginx_host.data = config.nginx_host conf_form.modify_hosts.data = config.modify_hosts conf_form.nginx_ip.data = config.nginx_ip conf_form.external_load_balancer.data = config.external_load_balancer conf_form.use_ldap_cache.data = config.use_ldap_cache conf_form.offline.data = config.offline service_status_update_period = config.ldap_update_period if service_status_update_period and config.ldap_update_period_unit != 's': service_status_update_period = service_status_update_period * 60 conf_form.ldap_update_period.data = str(service_status_update_period) #conf_form.use_ip.data = config.use_ip if config.gluu_version: conf_form.gluu_version.data = config.gluu_version if not config.id: conf_form.use_ldap_cache.data = True #create fake remote class that provides the same interface with RemoteClient fc = FakeRemote() #Getermine local OS type localos = get_os_type(fc) app.jinja_env.globals['use_ldap_cache'] = config.use_ldap_cache return render_template( 'app_config.html', cform=conf_form, sform=sch_form, config=config, schemafiles=schemafiles, localos=localos, external_lb_checked=external_lb_checked, repo_dir=app.config['GLUU_REPO'], next=request.args.get('next'), )
def app_configuration(): """This view provides application configuration forms""" #create forms conf_form = AppConfigForm() sch_form = SchemaForm() config = AppConfiguration.query.first() schemafiles = os.listdir(app.config['SCHEMA_DIR']) #If the form is sumtted and password for replication user was not #not supplied, make password "**dummu**", so don't change #what we have before if request.method == 'POST' and not conf_form.replication_pw.data.strip(): conf_form.replication_pw.data = '**dummy**' conf_form.replication_pw_confirm.data = '**dummy**' #If form is submitted and ladidated process it if conf_form.update.data and conf_form.validate_on_submit(): #If prviously configured and admin changed replcation user (dn) and it's #password .this will break replication, check and war admin. replication_dn = "cn={},o=gluu".format( conf_form.replication_dn.data.strip()) if not config: config = AppConfiguration() else: if config.replication_dn != replication_dn: flash("You changed Replication Manager dn. " "This will break replication. " "Please re-deploy all LDAP Servers.", "danger") if conf_form.replication_pw.data and \ conf_form.replication_pw_confirm.data is not '**dummy**': config.replication_pw = conf_form.replication_pw.data.strip() flash("You changed Replication Manager password. " "This will break replication. " "Please re-deploy all LDAP Servers.", "danger") config.replication_dn = replication_dn config.gluu_version = conf_form.gluu_version.data.strip() config.use_ip = conf_form.use_ip.data config.nginx_host = conf_form.nginx_host.data.strip() config.replication_dn = replication_dn config.gluu_version = conf_form.gluu_version.data.strip() config.use_ip = conf_form.use_ip.data config.nginx_host = conf_form.nginx_host.data.strip() purge_age_day = conf_form.purge_age_day.data purge_age_hour = conf_form.purge_age_hour.data purge_age_min = conf_form.purge_age_min.data purge_interval_day = conf_form.purge_interval_day.data purge_interval_hour = conf_form.purge_interval_hour.data purge_interval_min = conf_form.purge_interval_min.data log_purge = "{}:{}:{} {}:{}:{}".format( purge_age_day, purge_age_hour, purge_age_min, purge_interval_day, purge_interval_hour, purge_interval_min) config.log_purge = log_purge db.session.add(config) db.session.commit() flash("Gluu Replication Manager application configuration has been " "updated.", "success") if request.args.get('next'): return redirect(request.args.get('next')) elif sch_form.upload.data and sch_form.validate_on_submit(): f = sch_form.schema.data filename = secure_filename(f.filename) if any(filename in s for s in schemafiles): name, extension = os.path.splitext(filename) matches = [s for s in schemafiles if name in s] filename = name + "_" + str(len(matches)) + extension f.save(os.path.join(app.config['SCHEMA_DIR'], filename)) schemafiles.append(filename) flash("Schema: {0} has been uploaded sucessfully. " "Please edit slapd.conf of primary server and " "re-deploy all servers.".format(filename), "success") # request.method == GET gets processed here if config and config.replication_dn: conf_form.replication_dn.data = config.replication_dn.replace( "cn=", "").replace(",o=gluu", "") conf_form.replication_pw.data = config.replication_pw conf_form.nginx_host.data = config.nginx_host conf_form.use_ip.data = config.use_ip if config.gluu_version: conf_form.gluu_version.data = config.gluu_version if config.log_purge: a, i = config.log_purge.split() pa = a.split(':') pi = i.split(':') conf_form.purge_age_day.data = pa[0] conf_form.purge_age_hour.data = pa[1] conf_form.purge_age_min.data = pa[2] conf_form.purge_interval_day.data = pi[0] conf_form.purge_interval_hour.data = pi[1] conf_form.purge_interval_min.data = pi[2] return render_template('app_config.html', cform=conf_form, sform=sch_form, config=config, schemafiles=schemafiles, next=request.args.get('next'))
def step1(): pserver = Server.query.filter_by(primary_server=True).first() if pserver and request.args.get('pass_set') != 'true': flash("Oops this service is not for you.", 'warning') return redirect(url_for('index.home')) wform = WizardStep1() if request.method == 'POST': if wform.validate_on_submit(): replication_pw = uuid.uuid4().hex app_conf = AppConfiguration() app_conf.nginx_host = wform.new_hostname.data.strip() app_conf.replication_pw = replication_pw app_conf.nginx_ip = wform.nginx_ip.data.strip() app_conf.modify_hosts = True db.session.add(app_conf) server = Server() server.ip = wform.ip.data.strip() server.hostname = wform.current_hostname.data.strip() server.primary_server = True db.session.add(app_conf) db.session.add(server) db.session.commit() if request.method == 'POST' or request.args.get('pass_set') == 'true': servers = Server.query.all() ask_passphrase = False c = RemoteClient(servers[0].ip, servers[0].hostname) try: c.startup() except ClientNotSetupException as e: if str(e) == 'Pubkey is encrypted.': ask_passphrase = True flash( "Pubkey seems to password protected. " "Please set passphrase.", 'warning') elif str(e) == 'Could not deserialize key data.': ask_passphrase = True flash( "Password your provided for pubkey did not work. " "Please set valid passphrase.", 'warning') else: flash( "SSH connection to {} failed. Please check if your pub key is " "added to /root/.ssh/authorized_keys on this server. Reason: {}" .format(servers[0].hostname, e), 'error') return render_template( 'index_passphrase.html', e=e, ask_passphrase=ask_passphrase, next=url_for('wizard.step1', pass_set='true'), warning_text="Error accessing Stand Allone Server") task = wizard_step1.delay() print "TASK STARTED", task.id servers = Server.query.all() return render_template('wizard/wizard_logger.html', step=1, task_id=task.id, servers=servers) return render_template('wizard/step1.html', wform=wform)