Exemplo n.º 1
0
    def logincheck():
        import hashlib
        if request.forms.get("login_user") and request.forms.get(
                "login_password"):
            user = request.forms.get("login_user")
            password = hashlib.md5(
                request.forms.get("login_password")).hexdigest()

            database = "users.db"
            conn = sqlite3.connect(database)
            isUser = conn.cursor().execute(
                "SELECT COUNT(username) FROM users WHERE username = ? and password = ?",
                (user, password)).fetchone()
            conn.close()

            if isUser[0] == 1:
                response.set_cookie("loggedin",
                                    request.forms.get('login_user'),
                                    secret='sm2345-45634')
                if request.forms.get("remember") and request.forms.get(
                        "remember") == "yes":
                    exp = datetime.datetime(2025, 1, 1, 00, 00, 00)
                    response.set_cookie("remember",
                                        request.forms.get('login_user'),
                                        expires=exp)
                else:
                    response.delete_cookie("remember")
                redirect('/')
            else:
                redirect('/login?action=error')
Exemplo n.º 2
0
    def eventpage():
        username = request.get_cookie("loggedin", secret='sm2345-45634')
        if username:
            database = check_config("OUTPUT_SQLITE3_DB_PATH=")
            conn = sqlite3.connect(database)
            #Get Thresholds
            lmax = conn.cursor().execute(
                "SELECT max from thresholds WHERE tname = 'low'").fetchone()
            med = conn.cursor().execute(
                "SELECT min,max from thresholds WHERE tname = 'med'").fetchone(
                )
            hmin = conn.cursor().execute(
                "SELECT min from thresholds WHERE tname = 'high'").fetchone()

            alows = conn.cursor().execute(
                "select count(id) from alerts where weight <= ?",
                (lmax[0], )).fetchone()
            amediums = conn.cursor().execute(
                "select count(id) from alerts where weight between ? and ?",
                (med[0], med[1])).fetchone()
            ahighs = conn.cursor().execute(
                "select count(id) from alerts where weight >= ?",
                (hmin[0], )).fetchone()
            conn.close()
            return template('alerts',
                            total_alert_highs=ahighs[0],
                            total_alert_mediums=amediums[0],
                            total_alert_lows=alows[0])
        else:
            redirect('/login')
Exemplo n.º 3
0
	def eventpage():
		username = request.get_cookie("loggedin", secret='sm2345-45634')
		if username:
			database = check_config("OUTPUT_SQLITE3_DB_PATH=")
			conn = sqlite3.connect(database)
			#Get Thresholds
			lmax = conn.cursor().execute("SELECT max from thresholds WHERE tname = 'low'").fetchone()
			med = conn.cursor().execute("SELECT min,max from thresholds WHERE tname = 'med'").fetchone()
			hmin = conn.cursor().execute("SELECT min from thresholds WHERE tname = 'high'").fetchone()

			alows = conn.cursor().execute("select count(id) from alerts where weight <= ?", (lmax[0],)).fetchone() 
			amediums = conn.cursor().execute("select count(id) from alerts where weight between ? and ?", (med[0],med[1])).fetchone() 
			ahighs = conn.cursor().execute("select count(id) from alerts where weight >= ?", (hmin[0],)).fetchone() 
			conn.close()
			return template('alerts', total_alert_highs=ahighs[0], total_alert_mediums=amediums[0], total_alert_lows=alows[0])
		else:
			redirect('/login')
Exemplo n.º 4
0
	def keywordspage():
		username = request.get_cookie("loggedin", secret='sm2345-45634')
		if username:
			database = check_config("OUTPUT_SQLITE3_DB_PATH=")
			conn = sqlite3.connect(database)
			lmax = conn.cursor().execute("select max from thresholds where tname = \'low\'").fetchone()
			hmin = conn.cursor().execute("select min from thresholds where tname = \'high\'").fetchone()
			sliderp = "[%s,%s]," % (lmax[0],hmin[0])
			rows = conn.cursor().execute("select id, keyword, weight from keywords order by weight DESC").fetchall()
			conn.close()
			trRows = ""
	
			for row in rows:
				trRows = trRows + '<tr id=\'%s\'><td>%s</td><td>%s</td></tr>' % (row[0],row[1],row[2])

			return template('set-keywords', dataRows=trRows, slider=sliderp)
		else:
			redirect('/login')
Exemplo n.º 5
0
	def logincheck():
		import hashlib
		if request.forms.get("login_user") and request.forms.get("login_password"):
			user = request.forms.get("login_user")
			password = hashlib.md5(request.forms.get("login_password")).hexdigest()

			database = "users.db"
			conn = sqlite3.connect(database)
			isUser = conn.cursor().execute("SELECT COUNT(username) FROM users WHERE username = ? and password = ?", (user,password)).fetchone()
			conn.close()

			if isUser[0] == 1:
				response.set_cookie("loggedin", request.forms.get('login_user'), secret='sm2345-45634')
				if request.forms.get("remember") and request.forms.get("remember") == "yes":
					exp = datetime.datetime(2025, 1, 1, 00, 00, 00)
					response.set_cookie("remember", request.forms.get('login_user'), expires=exp)
				else:
					response.delete_cookie("remember")
				redirect('/')
			else:
				redirect('/login?action=error')
Exemplo n.º 6
0
    def keywordspage():
        username = request.get_cookie("loggedin", secret='sm2345-45634')
        if username:
            database = check_config("OUTPUT_SQLITE3_DB_PATH=")
            conn = sqlite3.connect(database)
            lmax = conn.cursor().execute(
                "select max from thresholds where tname = \'low\'").fetchone()
            hmin = conn.cursor().execute(
                "select min from thresholds where tname = \'high\'").fetchone(
                )
            sliderp = "[%s,%s]," % (lmax[0], hmin[0])
            rows = conn.cursor().execute(
                "select id, keyword, weight from keywords order by weight DESC"
            ).fetchall()
            conn.close()
            trRows = ""

            for row in rows:
                trRows = trRows + '<tr id=\'%s\'><td>%s</td><td>%s</td></tr>' % (
                    row[0], row[1], row[2])

            return template('set-keywords', dataRows=trRows, slider=sliderp)
        else:
            redirect('/login')
Exemplo n.º 7
0
    def mainview():
        username = request.get_cookie("loggedin", secret='sm2345-45634')
        if username:
            database = check_config("OUTPUT_SQLITE3_DB_PATH=")
            conn = sqlite3.connect(database)
            #Get Thresholds
            lmax = conn.cursor().execute(
                "SELECT max from thresholds WHERE tname = 'low'").fetchone()
            med = conn.cursor().execute(
                "SELECT min,max from thresholds WHERE tname = 'med'").fetchone(
                )
            hmin = conn.cursor().execute(
                "SELECT min from thresholds WHERE tname = 'high'").fetchone()

            events = conn.cursor().execute(
                'select count(id) from spicymango').fetchone()
            high_events = conn.cursor().execute(
                'select count(id) from alerts where weight >= ?',
                (hmin[0], )).fetchone()
            medium_events = conn.cursor().execute(
                'select count(id) from alerts where weight between ? and ?',
                (med[0], med[1])).fetchone()
            low_events = conn.cursor().execute(
                'select count(id) from alerts where weight <= ?',
                (lmax[0], )).fetchone()
            chart_highs = conn.cursor().execute(
                "select count(s.id), strftime('%H', s.timeStamp) from spicymango s join alerts a on s.id = a.id where a.weight >= ? and s.timeStamp >= datetime('now', 'localtime', '-12 hour') group by strftime('%H', s.timeStamp)",
                (hmin[0], )).fetchall()
            chart_mediums = conn.cursor().execute(
                "select count(s.id), strftime('%H', s.timeStamp) from spicymango s join alerts a on s.id = a.id where a.weight between ? and ? and s.timeStamp >= datetime('now', 'localtime', '-12 hour') group by strftime('%H', s.timeStamp)",
                (med[0], med[1])).fetchall()
            chart_lows = conn.cursor().execute(
                "select count(s.id), strftime('%H', s.timeStamp) from spicymango s join alerts a on s.id = a.id where a.weight <= ? and s.timeStamp >= datetime('now', 'localtime', '-12 hour') group by strftime('%H', s.timeStamp)",
                (lmax[0], )).fetchall()
            recent_alls = conn.cursor().execute(
                "select a.weight, s.msg, s.timeStamp, s.id from spicymango s join alerts a on s.id=a.id order by timeStamp DESC limit 7"
            ).fetchall()
            recent_highs = conn.cursor().execute(
                "select s.msg, s.timeStamp, s.id from spicymango s join alerts a on s.id=a.id where a.weight >= ? order by timeStamp DESC limit 7",
                (hmin[0], )).fetchall()
            recent_mediums = conn.cursor().execute(
                "select s.msg, s.timeStamp, s.id from spicymango s join alerts a on s.id=a.id where a.weight between ? and ? order by timeStamp DESC limit 7",
                (med[0], med[1])).fetchall()
            recent_lows = conn.cursor().execute(
                "select s.msg, s.timeStamp, s.id from spicymango s join alerts a on s.id=a.id where a.weight <= ? order by timeStamp DESC limit 7",
                (lmax[0], )).fetchall()
            top_users = conn.cursor().execute(
                "select s.username, count(s.username) from spicymango s join alerts a on s.id = a.id group by username order by count(username) DESC LIMIT 5"
            ).fetchall()
            top_alerts = conn.cursor().execute(
                "select s.msg, a.weight, s.id from spicymango s join alerts a on s.id = a.id order by a.weight DESC LIMIT 5"
            ).fetchall()
            top_keywords = conn.cursor().execute(
                "select keyword, count from keywords order by count DESC LIMIT 5"
            ).fetchall()
            conn.close()

            i = 0
            last_12 = []
            while i < 13:
                d = datetime.datetime.now() - datetime.timedelta(hours=i)
                hr = d.strftime("%H")
                last_12.append(hr)
                i += 1

            last_12.reverse()
            c_hours = ""
            c_highs = ""
            c_mediums = ""
            c_lows = ""
            for hour in last_12:
                high_count = "0"
                medium_count = "0"
                low_count = "0"
                for chigh in chart_highs:
                    if hour == chigh[1]:
                        high_count = str(chigh[0])
                for cmedium in chart_mediums:
                    if hour == cmedium[1]:
                        medium_count = str(cmedium[0])
                for clow in chart_lows:
                    if hour == clow[1]:
                        low_count = str(clow[0])
                c_hours = c_hours + "<th>" + hour + ":00</th>"
                c_highs = c_highs + "<td>" + high_count + "</td>"
                c_mediums = c_mediums + "<td>" + medium_count + "</td>"
                c_lows = c_lows + "<td>" + low_count + "</td>"
            r_all = ""
            r_high = ""
            r_medium = ""
            r_low = ""
            for rall in recent_alls:
                if rall[0] >= hmin[0]:
                    priority = "high"
                    priority_label = "High"
                if med[0] <= rall[0] <= med[1]:
                    priority = "medium"
                    priority_label = "Medium"
                if rall[0] <= lmax[0]:
                    priority = "low"
                    priority_label = "Low"

                r_all = r_all + "<tr><td><span class='ticket {!s}'>{!s}</span></td><td class='full'><a id='{!s}' href='javascript:void(0)'>{!s}</a></td><td class='who'>{!s}</td></tr>".format(
                    priority, priority_label, rall[3], rall[1], rall[2])
            for rhigh in recent_highs:
                r_high = r_high + "<tr><td><span class='ticket high'>High</span></td><td class='full'><a id='{!s}' href='javascript:void(0)'>{!s}</a></td><td class='who'>{!s}</td></tr>".format(
                    rhigh[2], rhigh[0], rhigh[1])
            for rmedium in recent_mediums:
                r_medium = r_medium + "<tr><td><span class='ticket medium'>Medium</span></td><td class='full'><a id='{!s}' href='javascript:void(0)'>{!s}</a></td><td class='who'>{!s}</td></tr>".format(
                    rmedium[2], rmedium[0], rmedium[1])
            for rlow in recent_lows:
                r_low = r_low + "<tr><td><span class='ticket low'>Low</span></td><td class='full'><a id='{!s}' href='javascript:void(0)'>{!s}</a></td><td class='who'>{!s}</td></tr>".format(
                    rlow[2], rlow[0], rlow[1])

            return template('webview',
                            eventcount=events[0],
                            highs=high_events[0],
                            mediums=medium_events[0],
                            lows=low_events[0],
                            chart_hours=c_hours,
                            chart_highs=c_highs,
                            chart_mediums=c_mediums,
                            chart_lows=c_lows,
                            recent_all=r_all,
                            recent_highs=r_high,
                            recent_mediums=r_medium,
                            recent_lows=r_low,
                            topusers=top_users,
                            topalerts=top_alerts,
                            topkeywords=top_keywords)
        else:
            redirect('/login')
Exemplo n.º 8
0
 def set_pass():
     username = request.get_cookie("loggedin", secret='sm2345-45634')
     if username:
         return template('set-password')
     else:
         redirect('/login')
Exemplo n.º 9
0
 def eventpage():
     username = request.get_cookie("loggedin", secret='sm2345-45634')
     if username:
         return template('events')
     else:
         redirect('/login')
Exemplo n.º 10
0
	def mainview():
		username = request.get_cookie("loggedin", secret='sm2345-45634')
		if username:
			database = check_config("OUTPUT_SQLITE3_DB_PATH=")
			conn = sqlite3.connect(database)
			#Get Thresholds
			lmax = conn.cursor().execute("SELECT max from thresholds WHERE tname = 'low'").fetchone()
			med = conn.cursor().execute("SELECT min,max from thresholds WHERE tname = 'med'").fetchone()
			hmin = conn.cursor().execute("SELECT min from thresholds WHERE tname = 'high'").fetchone()

			events = conn.cursor().execute('select count(id) from spicymango').fetchone()
			high_events = conn.cursor().execute('select count(id) from alerts where weight >= ?', (hmin[0],)).fetchone()
			medium_events = conn.cursor().execute('select count(id) from alerts where weight between ? and ?', (med[0],med[1])).fetchone()
			low_events = conn.cursor().execute('select count(id) from alerts where weight <= ?', (lmax[0],)).fetchone()
			chart_highs = conn.cursor().execute("select count(s.id), strftime('%H', s.timeStamp) from spicymango s join alerts a on s.id = a.id where a.weight >= ? and s.timeStamp >= datetime('now', 'localtime', '-12 hour') group by strftime('%H', s.timeStamp)", (hmin[0],)).fetchall()
			chart_mediums = conn.cursor().execute("select count(s.id), strftime('%H', s.timeStamp) from spicymango s join alerts a on s.id = a.id where a.weight between ? and ? and s.timeStamp >= datetime('now', 'localtime', '-12 hour') group by strftime('%H', s.timeStamp)", (med[0],med[1])).fetchall()
			chart_lows = conn.cursor().execute("select count(s.id), strftime('%H', s.timeStamp) from spicymango s join alerts a on s.id = a.id where a.weight <= ? and s.timeStamp >= datetime('now', 'localtime', '-12 hour') group by strftime('%H', s.timeStamp)", (lmax[0],)).fetchall()
			recent_alls = conn.cursor().execute("select a.weight, s.msg, s.timeStamp, s.id from spicymango s join alerts a on s.id=a.id order by timeStamp DESC limit 7").fetchall()
			recent_highs = conn.cursor().execute("select s.msg, s.timeStamp, s.id from spicymango s join alerts a on s.id=a.id where a.weight >= ? order by timeStamp DESC limit 7", (hmin[0],)).fetchall()
			recent_mediums = conn.cursor().execute("select s.msg, s.timeStamp, s.id from spicymango s join alerts a on s.id=a.id where a.weight between ? and ? order by timeStamp DESC limit 7", (med[0],med[1])).fetchall()
			recent_lows = conn.cursor().execute("select s.msg, s.timeStamp, s.id from spicymango s join alerts a on s.id=a.id where a.weight <= ? order by timeStamp DESC limit 7", (lmax[0],)).fetchall()
			top_users = conn.cursor().execute("select s.username, count(s.username) from spicymango s join alerts a on s.id = a.id group by username order by count(username) DESC LIMIT 5").fetchall()
			top_alerts = conn.cursor().execute("select s.msg, a.weight, s.id from spicymango s join alerts a on s.id = a.id order by a.weight DESC LIMIT 5").fetchall()
			top_keywords = conn.cursor().execute("select keyword, count from keywords order by count DESC LIMIT 5").fetchall()
			conn.close()
			
			i = 0
			last_12 = []
			while i < 13:
				d = datetime.datetime.now() - datetime.timedelta(hours=i)
				hr = d.strftime("%H")
				last_12.append(hr)
				i += 1

			last_12.reverse()
			c_hours = ""
			c_highs = ""
			c_mediums = ""
			c_lows = ""
			for hour in last_12:
				high_count = "0"
				medium_count = "0"
				low_count = "0"
				for chigh in chart_highs:
					if hour == chigh[1]:
						high_count = str(chigh[0])
				for cmedium in chart_mediums:
					if hour == cmedium[1]:
						medium_count = str(cmedium[0])
				for clow in chart_lows:
					if hour == clow[1]:
						low_count = str(clow[0])
				c_hours = c_hours + "<th>"+hour+":00</th>"
				c_highs = c_highs + "<td>"+high_count+"</td>"
				c_mediums = c_mediums + "<td>"+medium_count+"</td>"
				c_lows = c_lows + "<td>"+low_count+"</td>"
			r_all = ""
			r_high = ""
			r_medium = ""
			r_low = ""
			for rall in recent_alls:
				if rall[0] >= hmin[0]:
					priority = "high"
					priority_label = "High"
				if med[0] <= rall[0] <= med[1]:
					priority = "medium"
					priority_label = "Medium"
				if rall[0] <= lmax[0]:
					priority = "low"
					priority_label = "Low"
					
				r_all = r_all + "<tr><td><span class='ticket {!s}'>{!s}</span></td><td class='full'><a id='{!s}' href='javascript:void(0)'>{!s}</a></td><td class='who'>{!s}</td></tr>".format(priority, priority_label, rall[3], rall[1], rall[2])
			for rhigh in recent_highs:
				r_high = r_high + "<tr><td><span class='ticket high'>High</span></td><td class='full'><a id='{!s}' href='javascript:void(0)'>{!s}</a></td><td class='who'>{!s}</td></tr>".format(rhigh[2],rhigh[0], rhigh[1])
			for rmedium in recent_mediums:
				r_medium = r_medium + "<tr><td><span class='ticket medium'>Medium</span></td><td class='full'><a id='{!s}' href='javascript:void(0)'>{!s}</a></td><td class='who'>{!s}</td></tr>".format(rmedium[2], rmedium[0], rmedium[1])
			for rlow in recent_lows:
				r_low = r_low + "<tr><td><span class='ticket low'>Low</span></td><td class='full'><a id='{!s}' href='javascript:void(0)'>{!s}</a></td><td class='who'>{!s}</td></tr>".format(rlow[2], rlow[0], rlow[1])
				
			return template('webview', eventcount=events[0], highs=high_events[0], mediums=medium_events[0], lows=low_events[0], chart_hours=c_hours, chart_highs=c_highs, chart_mediums=c_mediums, chart_lows=c_lows, recent_all=r_all, recent_highs=r_high, recent_mediums=r_medium, recent_lows=r_low, topusers=top_users, topalerts=top_alerts, topkeywords=top_keywords)
		else:
			redirect('/login')
Exemplo n.º 11
0
	def set_pass():
		username = request.get_cookie("loggedin", secret='sm2345-45634')
		if username:
			return template('set-password')
		else:
			redirect('/login')
Exemplo n.º 12
0
	def eventpage():
		username = request.get_cookie("loggedin", secret='sm2345-45634')
		if username:
			return template('events')
		else:
			redirect('/login')