1
0
Fork 0
mirror of https://github.com/sileht/bird-lg.git synced 2024-11-22 06:54:43 +01:00

Add error message for empty argument

This commit is contained in:
Mehdi Abaakouk 2012-01-27 11:32:50 +01:00
parent 0549b361a9
commit d81b45da6e
3 changed files with 21 additions and 2 deletions

7
lg.py
View file

@ -10,7 +10,7 @@ from urllib import quote, unquote
from toolbox import mask_is_valid, ipv6_is_valid, ipv4_is_valid, resolve from toolbox import mask_is_valid, ipv6_is_valid, ipv4_is_valid, resolve
from bird import BirdSocketSingleton from bird import BirdSocketSingleton
from flask import Flask, render_template, jsonify, redirect, session, request from flask import Flask, render_template, jsonify, redirect, session, request, abort
app = Flask(__name__) app = Flask(__name__)
app.config.from_pyfile('lg.cfg') app.config.from_pyfile('lg.cfg')
@ -92,6 +92,7 @@ def error_page(text):
@app.route("/whois/<query>") @app.route("/whois/<query>")
def whois(query): def whois(query):
if not query.strip(): abort(404)
try: try:
asnum = int(query) asnum = int(query)
query = "as%d"%asnum query = "as%d"%asnum
@ -134,6 +135,8 @@ def summary(hosts, proto="ipv4"):
@app.route("/detail/<hosts>/<proto>") @app.route("/detail/<hosts>/<proto>")
def detail(hosts, proto): def detail(hosts, proto):
name = request.args.get('q', '') name = request.args.get('q', '')
if not name.strip(): abort(404)
set_session("detail", hosts, proto, name) set_session("detail", hosts, proto, name)
command = "show protocols all %s" % name command = "show protocols all %s" % name
@ -151,6 +154,7 @@ def detail(hosts, proto):
@app.route("/traceroute/<hosts>/<proto>") @app.route("/traceroute/<hosts>/<proto>")
def traceroute(hosts, proto): def traceroute(hosts, proto):
q = request.args.get('q', '') q = request.args.get('q', '')
if not q.strip(): abort(404)
set_session("traceroute", hosts, proto, q) set_session("traceroute", hosts, proto, q)
infos = {} infos = {}
@ -181,6 +185,7 @@ def show_route_for_detail(hosts, proto):
def show_route(req_type, hosts, proto): def show_route(req_type, hosts, proto):
expression = unquote(request.args.get('q', '')) expression = unquote(request.args.get('q', ''))
if not expression.strip(): abort(404)
set_session(req_type, hosts, proto, expression) set_session(req_type, hosts, proto, expression)
all = (req_type.endswith("detail") and " all" or "" ) all = (req_type.endswith("detail") and " all" or "" )

View file

@ -105,6 +105,11 @@ input#ipopup{
width: auto; width: auto;
} }
.error{
font-weight:normal;
color:red;
}
/* POPUP */ /* POPUP */
.jqifade, .jqifade,
.popupfade{ .popupfade{

View file

@ -15,7 +15,7 @@ $( function() {
}); });
previous_req_type = "{{session.req_type}}".replace("_detail","") previous_req_type = "{{session.req_type}}".replace("_detail","")
function update_view(nopopup){ function update_view(nopopup, msg){
next_req_type = $("#req_type").val().replace("_detail","") next_req_type = $("#req_type").val().replace("_detail","")
if (previous_req_type != next_req_type) { if (previous_req_type != next_req_type) {
$("#request_args").val("") $("#request_args").val("")
@ -40,6 +40,11 @@ $( function() {
'<input type="text" id="ipopup" name="ipopup" value="' + $("#request_args").val() + '">') + '<input type="text" id="ipopup" name="ipopup" value="' + $("#request_args").val() + '">') +
'<br />History:' + '<br />History:' +
'<ul id="popup_menu">' + menu_html + '</ul>' '<ul id="popup_menu">' + menu_html + '</ul>'
if ( msg != undefined && msg != "" )
txt += '<br /><span class="error">Error: ' + msg + '</span>'
$.prompt(txt, $.prompt(txt,
{ {
prefix: 'popup', prefix: 'popup',
@ -104,6 +109,10 @@ $( function() {
document.location = "/summary/" + $("#hosts").val() + "/" + $("#proto").val(); document.location = "/summary/" + $("#hosts").val() + "/" + $("#proto").val();
break; break;
default: default:
if (!$.trim($("#request_args").val())) {
update_view(false, "Missing arguments")
return
}
document.location = "/" + $("#req_type").val() + "/" + $("#hosts").val() + "/" + $("#proto").val() + "?q=" + $("#request_args").val() ; document.location = "/" + $("#req_type").val() + "/" + $("#hosts").val() + "/" + $("#proto").val() + "?q=" + $("#request_args").val() ;
break; break;
} }