Beispiel #1
0
def add(host_id=None):
    db = getdb()
    data = {}
    if request.method == "POST":
        for item in request.form:
            if item == "submit":
                action = request.form[item]
            else:
                data[item] = request.form[item]
        data["status"] = get_status(data["inputIP"])
        if host_id:
            if action == "delete":
                db.remove(eids=[host_id])
                return redirect(url_for("index"))
            else:
                db.update(data, eids=[host_id])
        else:
            host_id = db.insert(data)

        if action == "save":
            return redirect(url_for("add", host_id=host_id))
        else:
            return redirect(url_for("index"))
    else:
        if host_id:
            data = db.get(eid=host_id)
    return Menu.render("add.html", data=data, host_id=host_id)
Beispiel #2
0
def update_status(host_id=None):
    db = getdb()
    if host_id:
        hosts = [db.get(eid=host_id)]
    else:
        hosts = db.all()
    for host in hosts:
        status = get_status(host["inputIP"])
        db.update({"status": status}, eids=[host.eid])
    return redirect(url_for("index"))
Beispiel #3
0
def delete(host_id):
    db = getdb()
    db.remove(eids=[host_id])
    return redirect(url_for("index"))
Beispiel #4
0
def index():
    db = getdb()
    data = db.all()
    return Menu.render("index.html", data=data)
Beispiel #5
0
def wakeup(host_id):
    db = getdb()
    host = db.get(eid=host_id)
    wakehost(host["inputMAC"])
    return redirect(url_for("index"))