Exemple #1
0
def start_monitor(st_list_filepath,user_name,user_pwd):
    st_list = student_model.get_st_list(st_list_filepath)
    crawler = PAT_crawler(user_name, user_pwd, "")

    try:
        fp = open("media/monitor_result.txt","a+")
    except IOError:
        print "Error open result.txts error!"

    print "===start testing,see the result in console or result.txt ======================\n"
    ip2ids = {}
    while True:
        try:
            for i in range(len(st_list)):
                current_ip = crawler.get_ip_by_name(st_list[i].id)
                if current_ip == "":
                    #never logined
                    continue

                #login
                if ip2ids.has_key(current_ip) == False:
                    ip2ids[current_ip] = []
                if ip2ids[current_ip].count(st_list[i])==0:
                    ip2ids[current_ip].append(st_list[i])
                    if current_ip!="127.0.0.1" and len(ip2ids[current_ip]) > 1:
                        content = "\n%s:---------one ip with multiple id ---------\n" % time.strftime('%Y-%m-%d %H:%M',time.localtime(time.time()))
                        content = content + "ip:%s\n" % current_ip
                        content = content + "logined students:\n"+'\n'.join(str(tst) for tst in ip2ids[current_ip])
                        print content.decode('utf-8').encode(EncodeType)
                        fp.write(content)
                        fp.flush()

                llen = len(st_list[i].ips)
                if llen == 0:
                    st_list[i].ips.append(current_ip)
                else:
                    if st_list[i].last_ip != current_ip:
                        #different login ip detected
                        #print last ip and current ip
                        #print current ip has logined whos
                        #print this id has logined which ips
                        if st_list[i].ips.count(current_ip)==0:
                            st_list[i].ips.append( current_ip)
                        content = "\n%s:---------one id with multiple ip ---------\n" % time.strftime('%Y-%m-%d %H:%M',time.localtime(time.time()))
                        content = content + str(st_list[i])+":\n"
                        content = content + "logined ip:\n"+'\n'.join(st_list[i].ips)
                        content = content + '\ncurrent_ip:'+current_ip
                        print content.decode('utf-8').encode(EncodeType)
                        fp.write(content)
                        fp.flush()
                st_list[i].last_ip = current_ip
        except KeyboardInterrupt:
            print "exting..."
            fp.close()
            print "bye"
            raw_input("Press Enter to continue......")
            sys.exit()
Exemple #2
0
def main():

    st_dict = get_st_dict("tmp")
    tmp = get_name_pwd_from_console()
    crawler = PAT_crawler(tmp[0],tmp[1])

    while crawler.logined() == False:
        print "login error! try your account and password again!\n"
        tmp = get_name_pwd_from_console()
        crawler.login(tmp[0],tmp[1])

    st_dict = crawler.get_submissions(st_dict)
#    print st_dict
    #return
    keywords_set = [ ['cin','cout'],['class'],['operator','class'],['class','virtual'] ]

    #problems = [str(x+1001) for x in range(PROBLEM_NUM)]
    problems = [ string.ascii_uppercase[x] for x in range(PROBLEM_NUM)]
    tmp = {}
    for i in range(len(problems)):
       tmp[problems[i]] = keywords_set[i]


    keywords_set = tmp
    #print keywords_set
    for key in st_dict:
        for problem_id in problems:
            if problem_id in st_dict[key].submissions:
                st_dict[key].score = st_dict[key].score + st_dict[key].submissions[problem_id].score
                if crawler.code_filter(st_dict[key].submissions[problem_id].code_url,keywords_set[problem_id]) == True:
                    st_dict[key].submissions[problem_id].pass_filter = True
    #print st_dict

    write_txt(st_dict)
    write_xls(st_dict)
    save_codes(crawler,st_dict)
Exemple #3
0
def main():
    # for sig in (SIGABRT, SIGILL, SIGINT, SIGSEGV, SIGTERM):
    # for sig in ( SIGINT, SIGTERM):
    # signal(sig, try_exit)
    signal(SIGTERM, try_exit)
    args = args_process()
    st_list = student_model.get_st_list("./media/norm2rand.txt")
    crawler = PAT_crawler(args.username, args.password, "")
    try:
        fp = open("./media/monitor_result.txt", "a+")
    except IOError:
        monitor_logger.error("Error open result.txts error!")
        print "Error open result.txts error!"

    print "===start testing,see the result in console or result.txt ======================\n"
    monitor_logger.info("start monitoring")
    ip2ids = {}
    try:
        while True:
            #            print "hello"
            # fp.write("hello~ now: "+time.strftime('%Y-%m-%d %H:%M',time.localtime(time.time()))+"<br>")
            # fp.flush()
            # time.sleep(1)
            # continue
            for i in range(len(st_list)):
                current_ip = crawler.get_ip_by_name(st_list[i].rand_id)
                if current_ip == "":
                    # never logined
                    continue
                # login
                if ip2ids.has_key(current_ip) == False:
                    ip2ids[current_ip] = []
                if ip2ids[current_ip].count(st_list[i]) == 0:
                    ip2ids[current_ip].append(st_list[i])
                    # if current_ip!="127.0.0.1" and len(ip2ids[current_ip]) > 1:
                    if len(ip2ids[current_ip]) > 1:
                        content = (
                            "<div class='panel panel-warning'> <div class='panel-heading'> <h4 class='panel-title'>"
                        )
                        content = content + "%s: one ip with multiple students" % time.strftime(
                            "%Y-%m-%d %H:%M", time.localtime(time.time())
                        )
                        content = content + " </h4> </div> <div class='panel-body'>"
                        content = content + "ip: %s<br>" % current_ip
                        content = content + "<br>".join(str(tst) for tst in ip2ids[current_ip])
                        content = content + " </div> </div> </div>"
                        fp.write(content)
                        fp.flush()
                llen = len(st_list[i].ips)
                if llen == 0:
                    st_list[i].ips.append(current_ip)
                else:
                    if st_list[i].last_ip != current_ip:
                        # different login ip detected
                        # print last ip and current ip
                        # print current ip has logined whos
                        # print this id has logined which ips
                        if st_list[i].ips.count(current_ip) == 0:
                            st_list[i].ips.append(current_ip)

                        content = (
                            "<div class='panel panel-danger'> <div class='panel-heading'> <h4 class='panel-title'>"
                        )
                        content = content + "%s: one stduent with multiple ip" % time.strftime(
                            "%Y-%m-%d %H:%M", time.localtime(time.time())
                        )
                        content = content + " </h4> </div> <div class='panel-body'>"
                        content = content + str(st_list[i]) + ":<br>"
                        content = content + "previous logined ip:<br>" + "<br>".join(st_list[i].ips)
                        content = content + "<br>current logined_ip:" + current_ip
                        content = content + " </div> </div> </div>"
                        fp.write(content)
                        fp.flush()
                st_list[i].last_ip = current_ip
            time.sleep(1)
    except Exception as e:
        print e
        monitor_logger.error(str(e))
    finally:
        fp.close()
        monitor_logger.info("stop monitoring")
        print "Good Bye!"
Exemple #4
0
def main():

    EncodeType = sys.getfilesystemencoding()
    args = args_process()
    st_list = student_model.get_st_list(args.student_list_file)

    tmp = get_name_pwd_from_console()
    crawler = PAT_crawler(tmp[0], tmp[1])

    while crawler.logined() == False:
        print "login error! try your account and password again!\n"
        tmp = get_name_pwd_from_console()
        crawler.login(tmp[0], tmp[1])
    try:
        fp = open("result.txt", "a+")
    except IOError:
        print "Error open result.txts error!"
        raw_input("Press Enter to continue......")
        sys.exit()
    print "===start testing,see the result in console or result.txt ======================\n"
    ip2ids = {}
    while True:
        try:
            for i in range(len(st_list)):
                current_ip = crawler.get_ip_by_name(st_list[i].id)
                if current_ip == "":
                    #never logined
                    continue

                #login
                if ip2ids.has_key(current_ip) == False:
                    ip2ids[current_ip] = []
                if ip2ids[current_ip].count(st_list[i]) == 0:
                    ip2ids[current_ip].append(st_list[i])
                    if current_ip != "127.0.0.1" and len(
                            ip2ids[current_ip]) > 1:
                        content = "\n%s:---------one ip with multiple id ---------\n" % time.strftime(
                            '%Y-%m-%d %H:%M', time.localtime(time.time()))
                        content = content + "ip:%s\n" % current_ip
                        content = content + "logined students:\n" + '\n'.join(
                            str(tst) for tst in ip2ids[current_ip])
                        print content.decode('utf-8').encode(EncodeType)
                        fp.write(content)
                        fp.flush()

                llen = len(st_list[i].ips)
                if llen == 0:
                    st_list[i].ips.append(current_ip)
                else:
                    if st_list[i].last_ip != current_ip:
                        #different login ip detected
                        #print last ip and current ip
                        #print current ip has logined whos
                        #print this id has logined which ips
                        if st_list[i].ips.count(current_ip) == 0:
                            st_list[i].ips.append(current_ip)
                        content = "\n%s:---------one id with multiple ip ---------\n" % time.strftime(
                            '%Y-%m-%d %H:%M', time.localtime(time.time()))
                        content = content + str(st_list[i]) + ":\n"
                        content = content + "logined ip:\n" + '\n'.join(
                            st_list[i].ips)
                        content = content + '\ncurrent_ip:' + current_ip
                        print content.decode('utf-8').encode(EncodeType)
                        fp.write(content)
                        fp.flush()
                st_list[i].last_ip = current_ip
        except KeyboardInterrupt:
            print "exting..."
            fp.close()
            print "bye"
            raw_input("Press Enter to continue......")
            sys.exit()