Skip to content

Commit

Permalink
Merge pull request #95 from freifunk-berlin/add_v6_as_default
Browse files Browse the repository at this point in the history
Updates
  • Loading branch information
nicolasberens authored Apr 8, 2024
2 parents 0608e64 + da45499 commit 69511ec
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 27 deletions.
2 changes: 0 additions & 2 deletions app/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

from flask import Flask, render_template
from .exts import db, mail, migrate
from .expert import expert
Expand Down
1 change: 1 addition & 0 deletions app/expert.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def expert_form():
create_select_field(ExpertForm, 'ipv6_pool', 'Wahlkreis', 'kein IPv6',
current_app.config['API_POOL_IPV6'], 'ipv4_prefix')


form = ExpertForm()
if form.validate_on_submit():
prefixes_v4 = [(current_app.config['API_POOL_HNA'], int(form.ipv4_prefix.data))] \
Expand Down
5 changes: 3 additions & 2 deletions app/forms.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from sqlalchemy.orm import validates
from sqlalchemy import func
from flask_wtf import FlaskForm
from wtforms import StringField, HiddenField, SelectField, EmailField
from wtforms.validators import Email, AnyOf, Length, DataRequired, ValidationError
Expand Down Expand Up @@ -33,7 +34,7 @@ def validate_email(self, field):
if r is None:
raise ValidationError("Ungültige Anfrage")

if field.data != r.email:
if field.data.lower() != r.email.lower():
raise ValidationError("E-Mail stimmt nicht überein.")
return field

Expand Down Expand Up @@ -63,7 +64,7 @@ class SummaryForm(FlaskForm):

@validates("email")
def validate_email(self, field):
r = IPRequest.query.filter_by(email=field.data)
r = IPRequest.query.filter(func.lower(IPRequest.email) == func.lower(field.data))
if r is None:
raise ValidationError("Ungültige Anfrage")
return field
Expand Down
2 changes: 1 addition & 1 deletion app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class IPRequest(db.Model):
id = db.Column(db.Integer, primary_key=True)
email = db.Column(db.String(120))
name = db.Column(db.String(120), unique=True)
router_id = db.Column(db.String(120))
# router_id = db.Column(db.String(120))
verified = db.Column(db.Boolean(), default=False)
token = db.Column(db.String(128), unique=True)
created_at = db.Column(db.DateTime(), default=datetime.now)
Expand Down
24 changes: 15 additions & 9 deletions app/simplemode.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
from .utils import request_create, send_email, activate_and_redirect
from .forms import EmailForm
from .exts import db
from wtforms.validators import DataRequired

simplemode = Blueprint('simplemode', __name__)


@simplemode.route('/simplemode/activate/<int:request_id>/<signed_token>')
def simplemode_activate(request_id, signed_token):
template = 'simplemode/email.txt'
Expand All @@ -14,34 +16,38 @@ def simplemode_activate(request_id, signed_token):

@simplemode.route('/simplemode', methods=['GET', 'POST'])
def simplemode_form():
# add location type field dynamically (values are set in config)
prefix_defaults = current_app.config['PREFIX_DEFAULTS']
choices = [(k, k) for k in list(prefix_defaults.keys())]
setattr(EmailForm, 'location_type', SelectField('Ort', choices=choices))

# add location field dynamically (values are set in config)
v6pool = current_app.config['API_POOL_IPV6_SIMPLE']
v6_choices = [("", "Bitte Stadteil wählen")] + [(k, k) for k in list(v6pool.keys())]

setattr(EmailForm, 'ipv6_pool', SelectField('Stadtteil', choices=v6_choices, validators=[DataRequired()]))
form = EmailForm()

if form.validate_on_submit():
mesh_num = 3
pool_mesh = current_app.config['API_POOL_MESH']
prefixes_mesh = [(pool_mesh, 32)] * mesh_num
prefixes_mesh = [(pool_mesh, 32)] * 3

# hna network
pool_hna = current_app.config['API_POOL_HNA']
prefixes_hna = [(pool_hna, prefix_defaults[form.location_type.data])]
prefixes_hna = [(pool_hna, '27')]

prefixes_v6 = [(v6pool[form.ipv6_pool.data], None)]

r = request_create(form.hostname.data, form.email.data,
prefixes_mesh + prefixes_hna, [])
prefixes_mesh + prefixes_hna, prefixes_v6)

try:
url = url_for(".simplemode_activate", request_id=r.id,
signed_token=r.token_activation, _external=True)
subject = "[Freifunk Berlin] Aktivierung - %s" % r.name
data = {'name': r.name, 'url': url}
send_email(r.email, subject, "activation.txt", data)
except:
except Exception as e:
# if send_mail fails we delete the already saved request
db.session.delete(r)
db.session.commit()
current_app.logger.error(f'Error sending mail!\n {e}')
raise

return render_template('confirmation.html')
Expand Down
8 changes: 4 additions & 4 deletions app/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@

<p class="col-md-12 text-center">
<a class="button" href="{{url_for('simplemode.simplemode_form')}}">
IP-Vergabe (Standard/Wizard)
IP-Vergabe
</a>

<a class="button" href="{{url_for('expert.expert_form')}}">
IP-Vergabe (f&uuml;r Experten_innen)
IP-Vergabe (f&uuml;r Expert_innen)
</a>

<br/>
Expand All @@ -46,12 +46,12 @@

<p class="col-md-12 text-center">
Bei Bugs oder Anregungen erstelle bitte ein Issue auf
<a href="https://github.com/freifunk-berlin/nipap-wizard/issues">Github</a>
<a href="https://github.com/freifunk-berlin/config.berlin.freifunk.net/issues">Github</a>
oder schreib eine
<a href="mailto:[email protected]">Mail</a>
an unsere Mailingliste.
Für Infos bezüglich dieses Dienstes, siehe die
<a href="https://github.com/freifunk-berlin/nipap-wizard/blob/master/README.md">README</a>
<a href="https://github.com/freifunk-berlin/config.berlin.freifunk.net/blob/main/README.md">README</a>
oder durchstöbere unsere
<a href="https://wiki.freifunk.net/Berlin:Servers">Wiki</a>.
</p>
Expand Down
2 changes: 1 addition & 1 deletion app/templates/simplemode/form.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
{{ form.csrf_token }}
{{ render_bootstrap_field(form.hostname, "Spitzname des Routers", "Ein kurzer und eindeutiger Name für deinen Router (z.B. <em>funkenpumpe</em> oder <em>HermannStr42_VH</em>). Dieser Name wird nur intern für dich hinterlegt und muss zwischen 4 und 32 Zeichen lang sein.") }}
{{ render_bootstrap_field(form.email, "Kontaktadresse", "Notwendig, damit wir dir die Router-Konfiguration per E-Mail zuschicken können. Benutze am besten immer die gleiche Adresse, auch falls du mehrere Router hast; dann kannst du die IPs hier gesammelt verwalten.") }}
{{ render_bootstrap_field(form.location_type, help="Je nach Standort benutzen mehr oder weniger viele Menschen zur selben Zeit den Freifunk-Router. Cafés und Kneipen haben mehr gleichzeitige Benutzer_innen und brauchen so mehr IP-Adressen als ein Router zu Hause.") }}
{{ render_bootstrap_field(form.ipv6_pool, help="Dies wird ben&oumltigt um Verbindungen im Netzwerk zu optimieren", placeholder="Bitte Stadtteil ausw&auml;hlen, html" ) }}
{{ render_bootstrap_field(form.captcha, "Hauptstadt Deutschlands?", "Wird benötigt, um Spam-Bots auszuschließen.") }}

<div class="form-group">
Expand Down
4 changes: 2 additions & 2 deletions app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from werkzeug.exceptions import BadRequest
from .nipap import NipapApi
from .exts import mail
from sqlalchemy import func


def get_api():
Expand Down Expand Up @@ -80,8 +81,7 @@ def ip_request_get(request_id):

def ip_request_for_email(email):
from .models import IPRequest

r = IPRequest.query.filter_by(email=email, verified=True)
r = IPRequest.query.filter(func.lower(IPRequest.email) == func.lower(email), IPRequest.verified == True)
if r.count() == 0:
raise BadRequest("Kein Eintrag für diese E-Mail")
return r
Expand Down
4 changes: 0 additions & 4 deletions default.cfg
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
# -*- coding: utf-8 -*-
PREFIX_DEFAULTS = {
'Wohnung (max. 14 Clients)' : 28,
'Kneipe/Cafe (max. 30 Clients)' : 27
}

EXPERT_MAX_PREFIX = 24

Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ Flask-Migrate==3.1.0
Flask-SQLAlchemy==3.1.1
Flask-Script==2.0.6
Flask-WTF==1.2.1
SQLAlchemy==2.0.23
SQLAlchemy==2.0.29
Jinja2==3.1.3
psycopg2-binary==2.9.9
WTForms==3.1.1
email-validator==1.3.1
prettytable==3.9.0
markupsafe==2.1.3
markupsafe==2.1.3

0 comments on commit 69511ec

Please sign in to comment.