def http_repo_auth_add(): host = request.form['host'] user = request.form['username'] passwd = request.form['password'] rows = PlatformConfig.get('http_repo_auth', {}) rows[host] = {'username': user, 'password': passwd} PlatformConfig.set('http_repo_auth', rows) return redirect(url_for('configuration'), code=303)
def http_repo_auth_add(): host = request.form['host'] user = request.form['username'] passwd = request.form['password'] rows = PlatformConfig.get('http_repo_auth', {}) rows[host] = { 'username': user, 'password': passwd } PlatformConfig.set('http_repo_auth', rows) return redirect(url_for('configuration'), code=303)
def configuration(): all_config = Configuration.query config = { 'http_repo_auth': PlatformConfig.get('http_repo_auth', {}), 'smtp': PlatformConfig.get('smtp', { 'host': '', 'port': 25, 'ssl': False, 'auth': False, 'username': '', 'password': '' }) } return render_template('configuration.html', all_config=all_config, config=config)
def build_config(self): smtp_config = PlatformConfig.get( 'smtp', { 'host': '', 'port': 25, 'ssl': False, 'auth': False, 'username': '', 'password': '' }) relayhost = self._generate_postfix_relayhost(smtp_config) tls = 'yes' if smtp_config['ssl'] else 'no' auth = 'yes' if smtp_config['auth'] else 'no' postfix_config = render_template('main.cf', relayhost=relayhost, tls=tls, auth=auth, use_auth=smtp_config['auth']) if smtp_config['auth']: with open('/etc/postfix/sasl_passwd', 'w') as password_file: password_file.write("{} {}:{}\n".format( relayhost, smtp_config['username'], smtp_config['password'])) call(['postmap', '/etc/postfix/sasl_passwd']) with open('/etc/postfix/main.cf', 'w') as postfix_configfile: postfix_configfile.write(postfix_config) call(['systemctl', 'reload', 'postfix'])
def configuration(): all_config = Configuration.query config = { 'http_repo_auth': PlatformConfig.get('http_repo_auth', {}), 'smtp': PlatformConfig.get( 'smtp', { 'host': '', 'port': 25, 'ssl': False, 'auth': False, 'username': '', 'password': '' }) } return render_template('configuration.html', all_config=all_config, config=config)
def smtp_save(): config = PlatformConfig.get('smtp', { 'host': '', 'port': 25, 'ssl': False, 'auth': False, 'username': '', 'password': '' }) config['host'] = request.form['host'] config['port'] = int(request.form['port']) config['ssl'] = 'tls' in request.form config['auth'] = 'auth' in request.form config['username'] = request.form['username'] config['password'] = request.form['password'] PlatformConfig.set('smtp', config) MailRelay().build_config() return redirect(url_for('configuration'), code=303)
def smtp_save(): config = PlatformConfig.get( 'smtp', { 'host': '', 'port': 25, 'ssl': False, 'auth': False, 'username': '', 'password': '' }) config['host'] = request.form['host'] config['port'] = int(request.form['port']) config['ssl'] = 'tls' in request.form config['auth'] = 'auth' in request.form config['username'] = request.form['username'] config['password'] = request.form['password'] PlatformConfig.set('smtp', config) MailRelay().build_config() return redirect(url_for('configuration'), code=303)
def build_config(self): smtp_config = PlatformConfig.get('smtp', { 'host': '', 'port': 25, 'ssl': False, 'auth': False, 'username': '', 'password': '' }) relayhost = self._generate_postfix_relayhost(smtp_config) tls = 'yes' if smtp_config['ssl'] else 'no' auth = 'yes' if smtp_config['auth'] else 'no' postfix_config = render_template('main.cf', relayhost=relayhost, tls=tls, auth=auth, use_auth=smtp_config['auth']) if smtp_config['auth']: with open('/etc/postfix/sasl_passwd', 'w') as password_file: password_file.write("{} {}:{}\n".format(relayhost, smtp_config['username'], smtp_config['password'])) call(['postmap', '/etc/postfix/sasl_passwd']) with open('/etc/postfix/main.cf', 'w') as postfix_configfile: postfix_configfile.write(postfix_config) call(['systemctl', 'reload', 'postfix'])
def repositories(): if request.method == "POST": new_label = request.form["label"] new_url = request.form["url"] new_type = request.form["type"] parts = urllib.parse.urlparse(new_url) new_hostname = parts.netloc httpauth = PlatformConfig.get('http_repo_auth', {}) if new_hostname in httpauth: parts = list(parts) username = httpauth[new_hostname]['username'].replace('@', '%40') password = httpauth[new_hostname]['password'].replace('@', '%40') parts[1] = "{}:{}@{}".format(username, password, parts[1]) new_url_auth = urllib.parse.urlunparse(parts) task_id = git_clone_task.delay(new_label, new_url_auth).task_id else: task_id = git_clone_task.delay(new_label, new_url).task_id repo = Repository(type=new_type, label=new_label, url=new_url, task=task_id) db.session.add(repo) db.session.commit() return redirect(url_for('repositories')) repos = Repository.query.order_by(Repository.cloned) dataset = [] for repo in repos: status = "<i class='glyphicon glyphicon-ok'></i> OK" if len(repo.task) > 0: status = get_task_status(repo.task) ref = get_git_current_ref(repo.get_repo_path()) dataset.append({"status": status, "repo": repo, "ref": ref}) return render_template('repositories.html', repositories=dataset)