def settings(id): form = AddForm() tunnel = get_tunnels(id) if form.validate_on_submit(): if form.delete.data: if vpn_del(id): message = u'删除隧道%s :成功!' % tunnel[0]['name'] flash(message, 'success') return redirect(url_for('sts.index')) if form.save.data: if vpn_settings(form, id): flash(u'修改隧道配置成功!', 'success') return redirect(url_for('sts.settings', id=id)) form.local_subnet.data = tunnel[0]['rules']['leftsubnet'] form.remote_subnet.data = tunnel[0]['rules']['rightsubnet'] form.start_type.data = tunnel[0]['rules']['auto'] # Backward compatible v1.1.0 esp_settings = tunnel[0]['rules']['esp'].split('-') form.esp_encryption_algorithm.data = esp_settings[0] form.esp_integrity_algorithm.data = esp_settings[1] form.esp_dh_algorithm.data = esp_settings[2] if len(esp_settings) == 3 else 'null' ike_settings = tunnel[0]['rules'].get('ike', 'aes128-sha1-modp2048').split('-') form.ike_encryption_algorithm.data = ike_settings[0] form.ike_integrity_algorithm.data = ike_settings[1] form.ike_dh_algorithm.data = ike_settings[2] return render_template('sts/view.html', tunnel=tunnel[0], form=form)
def settings(id): form = AddForm() tunnel = get_tunnels(id) if form.validate_on_submit(): if form.delete.data: if vpn_del(id): message = u'删除隧道%s :成功!' % tunnel[0]['name'] flash(message, 'success') return redirect(url_for('sts.index')) if form.save.data: if vpn_settings(form, id): flash(u'修改隧道配置成功!', 'success') return redirect(url_for('sts.settings', id=id)) form.local_subnet.data = tunnel[0]['rules']['leftsubnet'] form.remote_subnet.data = tunnel[0]['rules']['rightsubnet'] form.start_type.data = tunnel[0]['rules']['auto'] # Backward compatible v1.1.0 esp_settings = tunnel[0]['rules']['esp'].split('-') form.esp_encryption_algorithm.data = esp_settings[0] form.esp_integrity_algorithm.data = esp_settings[1] form.esp_dh_algorithm.data = esp_settings[2] if len( esp_settings) == 3 else 'null' ike_settings = tunnel[0]['rules'].get('ike', 'aes128-sha1-modp2048').split('-') form.ike_encryption_algorithm.data = ike_settings[0] form.ike_integrity_algorithm.data = ike_settings[1] form.ike_dh_algorithm.data = ike_settings[2] return render_template('sts/view.html', tunnel=tunnel[0], form=form)
def add(): form = AddForm() if form.validate_on_submit(): if not Tunnels.query.filter_by(name=form.tunnel_name.data).first(): if vpn_settings(form): message = u'添加Site-to-Site 隧道成功!' flash(message, 'success') return redirect(url_for('sts.index')) else: message = u'该隧道已经存在:%s' % form.tunnel_name.data flash(message, 'alert') return render_template('sts/add.html', form=form)