mirror of
https://github.com/sileht/bird-lg.git
synced 2024-12-22 12:34:42 +01:00
Add error message for empty argument
This commit is contained in:
parent
0549b361a9
commit
d81b45da6e
7
lg.py
7
lg.py
|
@ -10,7 +10,7 @@ from urllib import quote, unquote
|
|||
from toolbox import mask_is_valid, ipv6_is_valid, ipv4_is_valid, resolve
|
||||
|
||||
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.config.from_pyfile('lg.cfg')
|
||||
|
@ -92,6 +92,7 @@ def error_page(text):
|
|||
|
||||
@app.route("/whois/<query>")
|
||||
def whois(query):
|
||||
if not query.strip(): abort(404)
|
||||
try:
|
||||
asnum = int(query)
|
||||
query = "as%d"%asnum
|
||||
|
@ -134,6 +135,8 @@ def summary(hosts, proto="ipv4"):
|
|||
@app.route("/detail/<hosts>/<proto>")
|
||||
def detail(hosts, proto):
|
||||
name = request.args.get('q', '')
|
||||
if not name.strip(): abort(404)
|
||||
|
||||
set_session("detail", hosts, proto, name)
|
||||
command = "show protocols all %s" % name
|
||||
|
||||
|
@ -151,6 +154,7 @@ def detail(hosts, proto):
|
|||
@app.route("/traceroute/<hosts>/<proto>")
|
||||
def traceroute(hosts, proto):
|
||||
q = request.args.get('q', '')
|
||||
if not q.strip(): abort(404)
|
||||
set_session("traceroute", hosts, proto, q)
|
||||
|
||||
infos = {}
|
||||
|
@ -181,6 +185,7 @@ def show_route_for_detail(hosts, proto):
|
|||
|
||||
def show_route(req_type, hosts, proto):
|
||||
expression = unquote(request.args.get('q', ''))
|
||||
if not expression.strip(): abort(404)
|
||||
set_session(req_type, hosts, proto, expression)
|
||||
|
||||
all = (req_type.endswith("detail") and " all" or "" )
|
||||
|
|
|
@ -105,6 +105,11 @@ input#ipopup{
|
|||
width: auto;
|
||||
}
|
||||
|
||||
.error{
|
||||
font-weight:normal;
|
||||
color:red;
|
||||
}
|
||||
|
||||
/* POPUP */
|
||||
.jqifade,
|
||||
.popupfade{
|
||||
|
|
|
@ -15,7 +15,7 @@ $( function() {
|
|||
});
|
||||
|
||||
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","")
|
||||
if (previous_req_type != next_req_type) {
|
||||
$("#request_args").val("")
|
||||
|
@ -40,6 +40,11 @@ $( function() {
|
|||
'<input type="text" id="ipopup" name="ipopup" value="' + $("#request_args").val() + '">') +
|
||||
'<br />History:' +
|
||||
'<ul id="popup_menu">' + menu_html + '</ul>'
|
||||
|
||||
if ( msg != undefined && msg != "" )
|
||||
txt += '<br /><span class="error">Error: ' + msg + '</span>'
|
||||
|
||||
|
||||
$.prompt(txt,
|
||||
{
|
||||
prefix: 'popup',
|
||||
|
@ -104,6 +109,10 @@ $( function() {
|
|||
document.location = "/summary/" + $("#hosts").val() + "/" + $("#proto").val();
|
||||
break;
|
||||
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() ;
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue