Exemplo n.º 1
0
def run(url, env, start_response):
    start_response(b'200 OK', [(b'Content-Type', b'text/html')])
    
    result  = ""
    result += myu.get_insides("assets/header.html")
    result += "<form action='/answer.py'  method='post' enctype='multipart/form-data'>"
    result += "<div class='readable'>"
    
    try:
        conn = myu.get_conn()
        cu1  = conn.cursor()
        
        cu1.execute("SELECT TOP 1 * FROM questions_answers ORDER BY NEWID()")

        for row in cu1:
            quid    = myu.get_sqlval(row, 0)
            result += myu.get_sqlval(row, 1) + "<br><hr/>"
            #result += myu.get_sqlval(row, 4) + "<br>"
            
            catid = myu.get_sqlval(row, 2)
            truid = myu.get_sqlval(row, 3)
            #result += myu.get_sqlval(str(row), 3) + "<br>"
            #result += "<hr/>" + str(row) + "<br>"
        
            all_ans = []
            cu_answ = myu.get_conn().cursor()
            cu_anst = myu.get_conn().cursor()
            cu_answ.execute("SELECT TOP 3 * FROM answers WHERE id_category = " + catid + " AND NOT id = " + truid + " ORDER BY NEWID()")
            cu_anst.execute("SELECT * FROM answers WHERE id = " + truid)
            
            for row_ans in cu_anst:
                all_ans.append({"txt": myu.get_sqlval(row_ans, 1), "id": myu.get_sqlval(row_ans, 0)})
                
            for row_ans in cu_answ:
                all_ans.append({"txt": myu.get_sqlval(row_ans, 1), "id": myu.get_sqlval(row_ans, 0)})
                
            random.shuffle(all_ans)
            for ans in all_ans:
                result += "<input type='radio' id='" + str(ans["id"]) + "' name='ans_id' value='" + str(ans["id"]) + "'>"
                result += "<label for='" + str(ans["id"]) + "'>" + str(ans["txt"]) + "</label><br>"
                #result += "<br>" + str(ans["txt"])
                
            result += "<br>"
            result += "<input style='display: none;' id='answer' type='text' value='"+quid+"' name='que_id'>"
                
    except Exception as inst:
        result += "<br>ERROR-1: " + str(inst)
    
    result += "</div>"
    result += "<div class='centered'>"
    result += "<input id='answer' type='submit' value='Answer' name='submit'>"
    result += "</div>"
    result += "</form>"
    result += myu.get_insides("assets/bottom.html")
    
    return result
Exemplo n.º 2
0
def run(url, environ, start_response):
    #start_response(b'200 OK', [(b'Content-Type', b'text/html')])

    import cgi
    
    header_set = False
    
    msg   = "<div class='readable'>"
    fname = ""
        
    form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ, keep_blank_values=True)
    
    try:
        exists = False
        lg = form['logname'].file.read().translate(str.maketrans({"'":  r"''"}))
        pw = form['passwrd'].file.read().translate(str.maketrans({"'":  r"''"}))
        
        #msg += str(lg) + "<br>"
        #msg += str(pw) + "<br>"
        
        cu = myu.get_conn().cursor()
        
        cu.execute("SELECT id FROM usersdata WHERE name = '" + (lg) + "'")
        #cu.execute("SELECT * FROM usersdata WHERE id > 20")
        
        try:
            for ln in cu:
                exists = True
                break
        except Exception as inst:
            msg += "Error?<br>"
        
        #msg += lg + "<br>"
        #msg += pw + "<br>"
        
        if exists:
            msg += "Sorry, such user already exists. *weeps in corner*"
        else:
            cu.execute("INSERT INTO usersdata (name, pass_word) VALUES ('" + (lg) + "','" + (pw) + "')")
            cu.commit()
            
            header_set = myu.usr_login(lg, pw, start_response)
            msg += myu.gen_logmsg(header_set, lg)
        
    except Exception as inst:
        #msg += "<br>ERROR-1: " + str(inst)
        msg += "Error occured. A doggo died!" + "<br>ERROR-1: " + str(inst)
        
    msg += "</div>"
    #msg += "<div><a href='pages/login.html'><button>&#8592; Back</button></a></div>"
    try:
        msg  = myu.get_insides("assets/header.html") + msg
        msg += myu.get_insides("assets/bottom.html")
    except Exception as inst:
        msg += "<br>ERROR-2: " + str(inst)
        
    if not header_set:
        start_response(b'200 OK', [(b'Content-Type', b'text/html')])
        
    return msg
Exemplo n.º 3
0
def is_logged(env, url):
    logged = True

    if (".py" in url or ".html" in url
            or url == "") and (url != "login.py") and (url != "register.py"):
        logged = False
        uid = myu.get_cookie(env, 'id')
        psw = myu.get_cookie(env, 'passwd')

        cu = myu.get_conn().cursor()
        cu.execute("SELECT id FROM usersdata WHERE id = '" + (uid) +
                   "' AND pass_word = '" + (psw) + "'")
        logged = False
        for row in cu:
            logged = True
            break

    return logged
        print_and_execute("INSERT INTO unified SELECT * FROM {0}".format(table), cur)




if __name__ == '__main__':
    if len(sys.argv) != 2:
        print "Usage: python create_reduced_log.py [operation]. Operations:"
        print "--initialize: Create the reduced_log db and 'users' and 'servers' tables, initially empty"
        print "--reduce: take all tables from general_log and create equivalent reduced tables in the reduced_log db by the rules in config.json"
        print "--create_unified: Create the unified table in the reduced_log db"
        print "--unify: add new tables (already redyced) into the unified table"
        print "ONLY SPECIFY ONE OPTION"
        sys.exit(1)

    db = get_conn(dbname = 'general_log')
    cur = db.cursor()
        
    if sys.argv[-1] == '--initialize':
        print "Creating reduced_log db"
        create_schema(cur)
    elif sys.argv[-1] == '--reduce':
        print "Reducing the general_log and storing in reduced_log"

        cur.execute("SHOW TABLES")
        gen_log_tables = set(x for x, in cur.fetchall())

        cur.execute("USE reduced_log")
        cur.execute("SHOW TABLES")
        red_log_tables = set(x for x, in cur.fetchall())
        
Exemplo n.º 5
0
def run(url, env, start_response):
    start_response(b'200 OK', [(b'Content-Type', b'text/html')])

    uid = myu.get_cookie(env, 'id')
    psw = myu.get_cookie(env, 'passwd')

    cu = myu.get_conn().cursor()
    cu.execute("SELECT name,e,series FROM usersdata WHERE id = '" + (uid) +
               "' AND pass_word = '" + (psw) + "'")

    msg = myu.get_insides("assets/header.html")
    msg += "<div class='readable'>"

    if cu.rowcount != 0:
        row = cu.fetchone()
        nm = myu.get_sqlval(row, 0)
        sc = myu.get_sqlval(row, 1)
        st = myu.get_sqlval(row, 2)

        msg += "<b>You are: </b>" + nm + "<br>"
        msg += "<b>Score: </b>" + sc + "<br>"
        msg += "<b>Strike: </b>" + st + "<br>"

        cu.execute("SELECT COUNT(id) FROM usersdata WHERE e > " + sc)
        plc = 0
        if cu.rowcount != 0:
            cnt = cu.fetchone()
            plc = int(myu.get_sqlval(cnt, 0))

        msg += "<b>Your place: </b>" + str(plc + 1) + "<br>"

    try:
        cu.execute(
            "SELECT TOP 10 name,e,series FROM usersdata ORDER BY e DESC")

        msg += "<br>"
        msg += "<table>"
        msg += "<tr class='header'>"
        msg += "<th class='header'>Name</th>"
        msg += "<th class='header'>Score</th>"
        msg += "<th class='header'>Strike</th>"
        msg += "</tr>"
        for row in cu:
            msg += "<tr>"

            msg += "<th>"
            msg += myu.get_sqlval(row, 0)
            msg += "</th>"

            msg += "<th>"
            msg += myu.get_sqlval(row, 1)
            msg += "</th>"

            msg += "<th>"
            msg += myu.get_sqlval(row, 2)
            msg += "</th>"

            msg += "</tr>"

        msg += "</table>"
    except Exception as inst:
        msg += "<br>ERROR: " + str(inst)

    msg += "</div>"
    msg += myu.get_insides("assets/bottom.html")

    return msg
Exemplo n.º 6
0
    def __init__(self):
        Application.__init__(self, title = "Log Analysis Tool")
        print >>sys.stderr, "app init'd"

        self.window = Window(size = (1200, 750), title = "Log Analysis Tool")
        print >>sys.stderr, "made window"

        # Create db cursor
        db = get_conn(dbname = 'reduced_log')
        self.cur = db.cursor()
        print >>sys.stderr, "made db cursor"

        self.current_table_suffix = None
        
        # Load the dummy image for now
        self.image = GraphView(size = (640, 460), position = (10, 10))
        self.graph_panel = Frame()
        self.graph_panel.add(self.image)
        print >>sys.stderr, "loaded dummy image"

        # Declare other image lists
        self.full_ = None
        self.peruser_alltime_ = None
        self.peruser_divided_total_ = None
        self.peruser_divided_ = None

        # Create the display selection radio
        self.display_select_radiogroup = RadioGroup(action = 
                                                    self.change_images)
        height, startx = 495, 20
        sp = 10
        r1 = RadioButton("All users",
                         group = self.display_select_radiogroup,
                         value = 'all_users')
        r2 = RadioButton("Per user, query type",
                         group = self.display_select_radiogroup,
                         value = 'peruser_querytype')
        r3 = RadioButton("Per user, time",
                         group = self.display_select_radiogroup,
                         value = 'peruser_time')
        r4 = RadioButton("Per user, query type and time",
                         group = self.display_select_radiogroup,
                         value = 'peruser_querytype_time')
        
        self.graph_panel.place(r1, top = self.image + 10, left = sp)
        self.graph_panel.place(r2, top = self.image + 10, left = r1 + sp)
        self.graph_panel.place(r3, top = self.image + 10, left = r2 + sp)
        self.graph_panel.place(r4, top = self.image + 10, left = r3 + sp)
        self.window.place(self.graph_panel, top=0, left=0)
        self.display_select_radiogroup.value = 'all_users'
        
        # Create the top queries textbox
        self.topqueries = TopqueryPanel(size = (500, 460),
                                        extent = (500, 1000))
        self.topqueries.panels = [[TopqueryLabel("This is a placeholder until you select a filter",
                                                ["This is where", "the values", "will go"])]]
        self.window.place(self.topqueries, top=10, left=680)

        topqueries_next_button = Button("Next", action = self.topqueries.next)
        topqueries_prev_button = Button("Prev", action = self.topqueries.prev)
        self.window.place(topqueries_next_button, left = 930, top = top - 50)
        self.window.place(topqueries_prev_button, left = 830, top = top - 50)
        print >>sys.stderr, "made top queries text box"

        # Declare the filter and last updated filter pointers
        self.fil = None
        self.last_used_fil = None
        
        #
        # *************************
        # FILTER PANEL
        # *************************
        #

        # **CREATE DATE PANEL**
        field_width = 140
        self.date_panel = Frame()
        self.begin_date_field = TextField(size = (field_width, 30),
                                          position = (0, 5),
                                          text = DEFAULT_BEGIN_DATE_TEXT)
        self.end_date_field = TextField(size = (field_width, 30),
                                        position = (0, 35),
                                        text = DEFAULT_END_DATE_TEXT)
        self.date_panel.size = (field_width, 0)

        # Time division radios
        self.time_division_radiogroup = RadioGroup()
        left, right = 5, 70
        row1, rowspace = 95, 25

        group_by_label = Label("Group by:",
                               position = (5, 70))
        hour = RadioButton("Hour",
                           position = (left, row1),
                           group = self.time_division_radiogroup,
                           value = 'hour')
        day = RadioButton("Day",
                          position = (right, row1),
                          group = self.time_division_radiogroup,
                          value = 'day')
        week = RadioButton('Week',
                           position = (left, row1 + rowspace),
                           group = self.time_division_radiogroup,
                           value = 'week',
                           enabled = False) #TODO: implement 'week' in the gnuplot function
        month = RadioButton("Month",
                            position = (right, row1 + rowspace),
                            group = self.time_division_radiogroup,
                            value = 'month')
        year = RadioButton("Year", 
                           position = (left, row1 + 2*rowspace),
                           group = self.time_division_radiogroup,
                           value = 'year')
        self.time_division_radiogroup.value = 'day'
        self.last_grouped_by = None

        # Add all to date panel
        self.date_panel.add([self.begin_date_field, self.end_date_field])
        self.date_panel.add([group_by_label, hour, day, week, month, year])
        self.window.place(self.date_panel, top=top, left=10)
        print >>sys.stderr, "made date panel"

        # **CREATE QUERY TYPE FILTER CHECKBOXES**
        x_pos = 0
        y_pos = 0
        y_spacing = 20
        self.query_type_checkboxes = {}
        for qtype in querytypes:
            # underscores don't display properly, need an extra space after
            self.query_type_checkboxes[qtype] = CheckBox(qtype.replace('_', '_ '),
                                                         position = (x_pos,
                                                                     y_pos),
                                                         value = True)
            y_pos += y_spacing


        # Add the query type checkboxes and buttons to a Frame
        self.query_type_panel = Frame()
        maxw = 0
        for cbox in self.query_type_checkboxes.values():
            self.query_type_panel.add(cbox)
            maxw = max(cbox.size[0], maxw)
        self.query_type_panel.size = (maxw, 0)

        # Create all/none/invert buttons for query types
        buttonsize = (55, 25)
        self.query_type_panel.add(Button("All",
                                         action = (self.select_all,
                                                   'query_type'),
                                         size = buttonsize,
                                         position = (20, y_pos)))
        y_pos += 25
        self.query_type_panel.add(Button("None",
                                         action = (self.deselect_all,
                                                   'query_type'),
                                         size = buttonsize,
                                         position = (20, y_pos)))
        y_pos += 25
        self.query_type_panel.add(Button("Invert",
                                         action = (self.invert_all,
                                                   'query_type'),
                                         size = buttonsize,
                                         position = (20, y_pos)))

        # Add query_type_panel to the window
        self.window.place(self.query_type_panel, top = top,
                          left=self.date_panel + horiz_sp)
        print >>sys.stderr, "made query type cboxes"


        # **CREATE USER AND SERVER CHECKBOX LISTS**
        self.user_panel = None
        self.server_panel = None
        self.create_checkbox_lists(initial=True)

        self.cur.execute("SELECT user, userid FROM users")
        self.userids = dict(self.cur.fetchall())
        self.cur.execute("SELECT server, serverid FROM servers")
        self.serverids = dict(self.cur.fetchall())

        print >>sys.stderr, "made user, server cboxes"


        # **CREATE QUERY SEARCH STRING PANEL**
        num_search_strings = 5
        spacing = 30
        field_width = 250
        self.search_string_panel = Frame()
        self.search_string_panel.size = (field_width, 0)
        self.search_string_fields = [TextField(size = (field_width, 30),
                                               position = (0, spacing * i),
                                               text = "Query Search String {0}".format(i + 1))
                                     for i in range(num_search_strings)]
        self.search_string_panel.add(self.search_string_fields)

        self.any_all_radiogroup = RadioGroup()
        any_string_radio = RadioButton("Any",
                                       position = (40, 10 + spacing * \
                                                   num_search_strings),
                                       group = self.any_all_radiogroup,
                                       value = 'any')
        all_strings_radio = RadioButton("All",
                                        position = (130, 10 + spacing * \
                                                    num_search_strings),
                                        group = self.any_all_radiogroup,
                                        value = 'all')
        no_string_radio = RadioButton("None",
                                      position = (40, 30 + spacing * \
                                                  num_search_strings),
                                      group = self.any_all_radiogroup,
                                      value = 'none')
        not_all_string_radio = RadioButton("Not All",
                                           position = (130, 30 + spacing * \
                                                       num_search_strings),
                                           group = self.any_all_radiogroup,
                                           value = 'not all')
        self.any_all_radiogroup.value = 'any'
        self.search_string_panel.add(any_string_radio)
        self.search_string_panel.add(all_strings_radio)
        self.search_string_panel.add(no_string_radio)
        self.search_string_panel.add(not_all_string_radio)
        self.window.place(self.search_string_panel, top = top,
                          left = self.server_panel + 10)
        print >>sys.stderr, "made search string panel"


        # SELECT ALL/NONE, INVERT USERS
        # TODO: create user, server panels? atm only the cboxes are in
        # a ScrollableView
        buttonsize = (55, 25)
        invertbuttonsize = (60, 25)
        userstart = 295
        serverstart = 565
        self.window.place(Button("All",
                                 action = (self.select_all,
                                           'user'),
                                 size = buttonsize),
                          top = top + 155, left = userstart)
        self.window.place(Button("None",
                                 action = (self.deselect_all,
                                           'user'),
                                 size = buttonsize),
                          top = top + 155, left = userstart + 55 + 5)
        self.window.place(Button("Invert",
                                 action = (self.invert_all,
                                           'user'),
                                 size = invertbuttonsize),
                          top = top + 155, left = userstart + 55 + 5 + 55 + 5)
    
        # user search string textbox
        # TODO: the action is always one keystroke behind the text field.
        # This is a PyGUI 'bug',but it may only happen on windows (not sure
        # how the X server works).
        # See http://mail.python.org/pipermail/pygui/2010-November/000102.html
        self.user_search_string = ResponsiveTextField(emptyaction = None,
                                                      action = (self.select_all_matching,
                                                                'user'),
                                                      size = (180, 30),
                                                      text = DEFAULT_USER_SEARCH_STRING)
        self.window.place(self.user_search_string,
                          top = top + 155 + 25 + 5,
                          left = userstart)

        # SELECT ALL/NONE, INVERT SERVERS
        self.window.place(Button("All",
                                 action = (self.select_all,
                                           'server'),
                                 size = buttonsize),
                          top = top + 155, left = serverstart)
        self.window.place(Button("None",
                                 action = (self.deselect_all,
                                           'server'),
                                 size = buttonsize),
                          top = top + 155, left = serverstart + 55 + 5)
        self.window.place(Button("Invert",
                                 action = (self.invert_all,
                                           'server'),
                                 size = invertbuttonsize),
                          top = top + 155,
                          left = serverstart + 55 + 5 + 55 + 5)

        # server search string textbox
        self.server_search_string = ResponsiveTextField(emptyaction = None,
                                                        action = (self.select_all_matching,
                                                                  'server'),
                                                        size = (180, 30),
                                                        text = DEFAULT_SERVER_SEARCH_STRING)
        self.window.place(self.server_search_string,
                          top = top + 155 + 25 + 5, left=serverstart)

        self.window.show()


        # **CREATE BUTTONS**
        self.negate = CheckBox("Negate Filter", position=(0, 0), value=False)
        self.refresh_button = Button("Refresh",
                                     position = (0, 25),
                                     action=self.refresh)
        self.update_button = Button("Update",
                                    position = (0, 60),
                                    action = self.update)
    
        # Add buttons to a panel
        self.button_panel = Frame()
        self.button_panel.add([self.negate,
                               self.refresh_button,
                               self.update_button])
        self.window.place(self.button_panel, top = top,
                          left=self.search_string_panel + horiz_sp)
        print >>sys.stderr, "made button panel"