better sort ip addresses
This commit is contained in:
parent
12110949b3
commit
38423754f8
6 changed files with 481 additions and 9 deletions
|
@ -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
|
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
|
10. chmod +x /home/proxadmin/appserver/proxadmin/cronexec.sh
|
||||||
11. add "00 09 * * * root /home/proxadmin/appserver/proxadmin/cronexec.sh" to /etc/crontab
|
11. add "00 09 * * * root /home/proxadmin/appserver/proxadmin/cronexec.sh" to /etc/crontab
|
||||||
|
12. usermod -G proxadmin www-data
|
||||||
|
|
||||||
|
|
|
@ -26,8 +26,9 @@ class Addr2PoolForm(FlaskForm):
|
||||||
#for region in regions:
|
#for region in regions:
|
||||||
# region_choices.expand((region.pid, str(region.description)))
|
# region_choices.expand((region.pid, str(region.description)))
|
||||||
region_choices = [(1, 'Plovdiv, Bulgaria')]
|
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)
|
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:')
|
reserved = BooleanField('Reserved:')
|
||||||
submit = SubmitField('Add IP')
|
submit = SubmitField('Add IP')
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ import base64
|
||||||
import string
|
import string
|
||||||
import random
|
import random
|
||||||
from datetime import datetime, timedelta, date, time
|
from datetime import datetime, timedelta, date, time
|
||||||
import ast
|
import ipaddress
|
||||||
|
|
||||||
#@admin.before_app_request
|
#@admin.before_app_request
|
||||||
#def before_request():
|
#def before_request():
|
||||||
|
@ -99,8 +99,16 @@ def charge(user_pid=0):
|
||||||
@fresh_login_required
|
@fresh_login_required
|
||||||
@admin_required
|
@admin_required
|
||||||
def list_addresses():
|
def list_addresses():
|
||||||
alladdresses = Address.query.order_by(Address.ip.asc()).all()
|
alladdresses = Address.query.all()
|
||||||
return render_template('admin/list_addresses.html', addresses=alladdresses)
|
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'])
|
@admin.route("/addr2pool", methods=['GET', 'POST'])
|
||||||
@fresh_login_required
|
@fresh_login_required
|
||||||
|
@ -110,17 +118,17 @@ def addr2pool():
|
||||||
alladdr = Address.query.all()
|
alladdr = Address.query.all()
|
||||||
for addr in alladdr:
|
for addr in alladdr:
|
||||||
alladdrlist.append(str(addr.ip))
|
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()
|
form = Addr2PoolForm()
|
||||||
if form.validate_on_submit():
|
if form.validate_on_submit():
|
||||||
if form.ip.data in alladdrlist:
|
if form.ip.data in alladdrlist:
|
||||||
flash('IP address {} is already in the pool!'.format(form.ip.data))
|
flash('IP address {} is already in the pool!'.format(form.ip.data))
|
||||||
return redirect(url_for('admin.addr2pool'))
|
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.add(address)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
flash('Address {} added to region {}'.format(form.ip.data, form.region.data))
|
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)
|
return render_template('admin/addr2pool.html', form=form, alladdresses=alladdrlist)
|
||||||
|
|
||||||
@admin.route("/listservers", methods=['GET'])
|
@admin.route("/listservers", methods=['GET'])
|
||||||
|
|
460
app/static/css/theme.css.1
Normal file
460
app/static/css/theme.css.1
Normal file
File diff suppressed because one or more lines are too long
|
@ -13,6 +13,8 @@
|
||||||
<div class="panel-heading">Addresses</div>
|
<div class="panel-heading">Addresses</div>
|
||||||
<div class="panel-body"><p>
|
<div class="panel-body"><p>
|
||||||
{% include "admin/menu_deployments.html" %}
|
{% 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">
|
<div class="no-more-tables">
|
||||||
<table class="table table-hover table-striped table-condensed cf">
|
<table class="table table-hover table-striped table-condensed cf">
|
||||||
<thead>
|
<thead>
|
||||||
|
@ -56,7 +58,6 @@
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</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>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -14,8 +14,9 @@
|
||||||
|
|
||||||
{% block styles %}
|
{% block styles %}
|
||||||
{{ super() }}
|
{{ 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/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/range.css') }}" rel="stylesheet">
|
||||||
<link href="{{ url_for('static', filename='css/no-more-tables.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">
|
<link href="{{ url_for('static', filename='css/panel-transparent.css') }}" rel="stylesheet">
|
||||||
|
|
Loading…
Reference in a new issue