better sort ip addresses

This commit is contained in:
deflax 2018-03-16 01:14:48 +02:00
parent 12110949b3
commit 38423754f8
6 changed files with 481 additions and 9 deletions

View file

@ -20,4 +20,5 @@ web panel for proxmaster built with Flask
9. python3 manage.py db init ; python3 manage.py db migrate -m "init" ; python3 manage.py db upgrade ; python3 manage.py deploy
10. chmod +x /home/proxadmin/appserver/proxadmin/cronexec.sh
11. add "00 09 * * * root /home/proxadmin/appserver/proxadmin/cronexec.sh" to /etc/crontab
12. usermod -G proxadmin www-data

View file

@ -26,8 +26,9 @@ class Addr2PoolForm(FlaskForm):
#for region in regions:
# region_choices.expand((region.pid, str(region.description)))
region_choices = [(1, 'Plovdiv, Bulgaria')]
ip = StringField('IP Address:', [validators.DataRequired(), validators.Regexp(message='172.16.0.1', regex='^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$')])
region = SelectField('Region', choices=region_choices, coerce=int)
ip = StringField('IP Address:', [validators.DataRequired(), validators.Regexp(message='172.16.0.1', regex='^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$')])
rdns = StringField('Reverse DNS:', [validators.Regexp(message='must be fqdn', regex='^[a-zA-Z0-9][a-zA-Z0-9-_]{0,61}[a-zA-Z0-9]{0,1}\.([a-zA-Z]{1,6}|[a-zA-Z0-9-]{1,30}\.[a-zA-Z]{2,3})$')])
reserved = BooleanField('Reserved:')
submit = SubmitField('Add IP')

View file

@ -14,7 +14,7 @@ import base64
import string
import random
from datetime import datetime, timedelta, date, time
import ast
import ipaddress
#@admin.before_app_request
#def before_request():
@ -99,8 +99,16 @@ def charge(user_pid=0):
@fresh_login_required
@admin_required
def list_addresses():
alladdresses = Address.query.order_by(Address.ip.asc()).all()
return render_template('admin/list_addresses.html', addresses=alladdresses)
alladdresses = Address.query.all()
alladdrlist = []
for addr in alladdresses:
alladdrlist.append(addr.ip)
ipobjs = sorted(ipaddress.ip_address(addr) for addr in alladdrlist)
ipnrml = []
for ipobj in ipobjs:
ipnrml.append(str(ipobj))
alladdr = sorted(alladdresses, key=lambda o: ipnrml.index(o.ip))
return render_template('admin/list_addresses.html', addresses=alladdr)
@admin.route("/addr2pool", methods=['GET', 'POST'])
@fresh_login_required
@ -110,17 +118,17 @@ def addr2pool():
alladdr = Address.query.all()
for addr in alladdr:
alladdrlist.append(str(addr.ip))
current_app.logger.info('Current IP pool: {}'.format(alladdrlist))
#current_app.logger.info('Current IP pool: {}'.format(alladdrlist))
form = Addr2PoolForm()
if form.validate_on_submit():
if form.ip.data in alladdrlist:
flash('IP address {} is already in the pool!'.format(form.ip.data))
return redirect(url_for('admin.addr2pool'))
address = Address(ip=form.ip.data, region_id=form.region.data, enabled=True, reserved=form.reserved.data)
address = Address(ip=form.ip.data, rdns=form.rdns.data, region_id=form.region.data, enabled=True, reserved=form.reserved.data)
db.session.add(address)
db.session.commit()
flash('Address {} added to region {}'.format(form.ip.data, form.region.data))
return redirect(url_for('admin.list_addresses'))
return redirect(url_for('admin.addr2pool'))
return render_template('admin/addr2pool.html', form=form, alladdresses=alladdrlist)
@admin.route("/listservers", methods=['GET'])

460
app/static/css/theme.css.1 Normal file

File diff suppressed because one or more lines are too long

View file

@ -13,6 +13,8 @@
<div class="panel-heading">Addresses</div>
<div class="panel-body"><p>
{% include "admin/menu_deployments.html" %}
<button class="btn btn-default" onclick="window.location('{{ url_for('admin.addr2pool') }}')"><span class="glyphicon glyphicon-plus" aria-hiddent="true"></span> Add IP to pool</button>
<div class="no-more-tables">
<table class="table table-hover table-striped table-condensed cf">
<thead>
@ -56,7 +58,6 @@
</tr>
</tbody>
</table>
<button class="btn btn-default" onclick="window.open('{{ url_for('admin.addr2pool') }}')"><span class="glyphicon glyphicon-plus" aria-hiddent="true"></span> Add IP to pool</button>
</div>
</div>
</div>

View file

@ -14,8 +14,9 @@
{% block styles %}
{{ super() }}
<link href="{{ url_for('static', filename='css/navbar.css') }}" rel="stylesheet">
<link href="{{ url_for('static', filename='css/style.css') }}" rel="stylesheet">
<link href="{{ url_for('static', filename='css/theme.css') }}" rel="stylesheet">
<link href="{{ url_for('static', filename='css/navbar.css') }}" rel="stylesheet">
<link href="{{ url_for('static', filename='css/range.css') }}" rel="stylesheet">
<link href="{{ url_for('static', filename='css/no-more-tables.css') }}" rel="stylesheet">
<link href="{{ url_for('static', filename='css/panel-transparent.css') }}" rel="stylesheet">