Esempio n. 1
0
    def test_utf_16_le_decode(self):
        string, num_processed = codecs.utf_16_le_decode(b'a\0b\0c\0')
        self.assertEqual(string, "abc")
        self.assertEqual(num_processed, 3 * 2)

        string, num_processed = codecs.utf_16_le_decode(codecs.BOM_UTF16_LE + b'a\0b\0c\0')
        self.assertEqual(string, "\uFEFFabc")
        self.assertEqual(num_processed, 4 * 2)
def read_bin_file(path):
    with open(path, "rb") as f:
        f.seek(0x18, 0)
        total_word_count = read_int_32(f)
        print "Total word is %s" % total_word_count
        current_word_num = 0
        f.seek(0x30, 0)

        res = []
        while current_word_num < total_word_count:
            same_py_count = read_int_16(f)
            unknow_var = read_int_16(f)
            py_count = read_int_16(f) / 2

            py_str = []

            for i in range(py_count):
                idx = read_int_16(f)
                if idx < len(PinYinDic) and idx >= 0:
                    py_str.append(PinYinDic[idx])
                else:
                    py_str.append("--")

            for i in range(same_py_count):
                word_count = read_int_16(f)
                word = codecs.utf_16_le_decode(f.read(word_count))[0]
                count = read_int_16(f)
                count2 = read_int_16(f)
                unknow_var2 = read_int_32(f)
                word_dic = {"count": count, "word": word, "pinyin": py_str}
                res.append(word_dic)
                print "current_word_num: %s and pinyin %s" % (current_word_num, py_str)
                current_word_num += 1
        return res
Esempio n. 3
0
    def test_utf_16_le_decode_incremental(self):
        b = b"\xfe\xff\x41\x00\x00\xd9\x00\xdd\x00\xdc\x00\xd8\x00\xdc"
        expected = [
            ('', 0),
            ('', 0),
            ('\ufffe', 2),
            ('\ufffe', 2),
            ('\ufffeA', 4),
            ('\ufffeA', 4),
            ('\ufffeA', 4),
            ('\ufffeA', 4),
            ('\ufffeA\U00050100', 8),
            ('\ufffeA\U00050100', 8),
            ('\ufffeA\U00050100\ufffd', 10),
            ('\ufffeA\U00050100\ufffd', 10),
            ('\ufffeA\U00050100\ufffd', 10),
            ('\ufffeA\U00050100\ufffd', 10),
            ('\ufffeA\U00050100\ufffd\U00010000', 14)
        ]
        if not is_cli:
            # CPython's strings are UTF-32 so an invalid surrogate pair results in one replacement char.
            # Therefore CPython cannot report error on a dangling low surrogate until it verifies
            # that the next char is not an invalid surrogate as well.
            expected[10] = expected[11] = ('\ufffeA\U00050100', 8)

        for i in range(len(b) + 1):
            res = codecs.utf_16_le_decode(b[:i], 'replace')
            self.assertEqual(res, expected[i])
 def _readStringData(self, stringSize):
     # reads string data
     if ( stringSize <= 0 ):
         rString = ""
     else:
         if ( debugLevel > 3 ):
             print("rSD @ " + str(self._f.tell()) + "/" + hex(self._f.tell()) +" :", end=' ')
         ## !!! *Unicode* string (UTF-16)... convert to Python unicode str
         rString = readString(self._f, stringSize)
         rString = utf_16_le_decode(rString)[0]
         if ( debugLevel > 3 ):
             print(rString + "   <"  + repr( rString ) + ">")
     if ( debugLevel > 0 ):
         print("StringVal:", rString)
     self._storeTag( self._curTagName, rString )
     return rString
Esempio n. 5
0
def parse_inf(filename):
    lineno = 0
    name = ''
    sections = {}
    section = None
    data = open(filename).read()

    ## Cheap Unicode to ascii
    if data[:2] == BOM_LE or data[:2] == BOM_BE:
        data = utf_16_le_decode(data)[0]
        data = data.encode('ascii', 'ignore')

    ## De-inf fixer ;)
    data = 'Copy'.join(data.split(';Cpy'))
    data = '\n'.join(data.split('\r\n'))
    data = ''.join(data.split('\\\n'))

    for line in data.split('\n'):
        lineno = lineno + 1
        line = line.strip()
        line = line.split(';', 1)[0]
        line = line.strip()

        if len(line) < 1: continue # empty lines

        if line[0] == ';': continue # comment

        ## We only need network drivers
        if name == 'version' and skip_inf(line):
            if debug > 0: print 'Skipped %s not a network inf' % filename
            return None

        ## Section start
        if line.startswith('[') and line.endswith(']'):
            name = line[1:-1].lower()
            sections[name] = {}
            section = sections[name]
        else:
            if section is None: continue
            if not parse_line(sections, name, lineno, line):
                break
    return sections
Esempio n. 6
0
    def test_codecs_builtins(self):
        s = "abc"

        encoded = codecs.utf_8_encode(s)
        self.assertEqual(s, codecs.utf_8_decode(encoded[0])[0])

        encoded = codecs.utf_7_encode(s)
        self.assertEqual(s, codecs.utf_7_decode(encoded[0])[0])

        encoded = codecs.utf_16_encode(s)
        self.assertEqual(s, codecs.utf_16_decode(encoded[0])[0])

        encoded = codecs.utf_16_le_encode(s)
        self.assertEqual(s, codecs.utf_16_le_decode(encoded[0])[0])

        encoded = codecs.utf_16_be_encode(s)
        self.assertEqual(s, codecs.utf_16_be_decode(encoded[0])[0])

        encoded = codecs.utf_32_encode(s)
        self.assertEqual(s, codecs.utf_32_decode(encoded[0])[0])

        encoded = codecs.utf_32_le_encode(s)
        self.assertEqual(s, codecs.utf_32_le_decode(encoded[0])[0])

        encoded = codecs.utf_32_be_encode(s)
        self.assertEqual(s, codecs.utf_32_be_decode(encoded[0])[0])

        encoded = codecs.utf_32_be_encode(s)
        self.assertEqual(s, codecs.utf_32_be_decode(encoded[0])[0])

        encoded = codecs.raw_unicode_escape_encode(s)
        self.assertEqual(s, codecs.raw_unicode_escape_decode(encoded[0])[0])

        encoded = codecs.unicode_escape_encode(s)
        self.assertEqual(s, codecs.unicode_escape_decode(encoded[0])[0])

        encoded = codecs.latin_1_encode(s)
        self.assertEqual(s, codecs.latin_1_decode(encoded[0])[0])

        encoded = codecs.ascii_encode(s)
        self.assertEqual(s, codecs.ascii_decode(encoded[0])[0])
Esempio n. 7
0
 def utf_16_le_decode(data, errors, finish=False):
     if not finish and len(data) % 2 == 1:
         data = data[:-1]
     return codecs.utf_16_le_decode(data, errors)
    def render_blacklist(self, request):
        sqlstatement = """
        SELECT users.profileid, enabled, data, users.gameid, console,
               users.userid
        FROM nas_logins
        INNER JOIN users
        ON users.userid = nas_logins.userid
        INNER JOIN (
            SELECT max(profileid) newestpid, userid, gameid, devname
            FROM users
            GROUP BY userid, gameid
        ) ij
        ON ij.userid = users.userid
        AND users.profileid = ij.newestpid
        ORDER BY users.gameid"""
        dbconn = sqlite3.connect('gpcm.db')
        banned_list = []
        for row in dbconn.cursor().execute("SELECT * FROM BANNED"):
            banned_list.append(str(row[0]) + ":" + str(row[1]))
        responsedata = """
        <a href="http://%%20:%%20@%s">[CLICK HERE TO LOG OUT]</a>
        <br><br>
        <table border='1'>"
        <tr>
            <td>ingamesn or devname</td>
            <td>gameid</td>
            <td>Enabled</td>
            <td>newest dwc_pid</td>"
            <td>gsbrcd</td>
            <td>userid</td>
            <td>ipAddr</td>
        </tr>""" % request.getHeader('host')

        for row in dbconn.cursor().execute(sqlstatement):
            dwc_pid = str(row[0])
            enabled = str(row[1])
            nasdata = collections.defaultdict(lambda: '', json.loads(row[2]))
            gameid = str(row[3])
            is_console = int(str(row[4]))
            userid = str(row[5])
            gsbrcd = str(nasdata['gsbrcd'])
            ipaddr = str(nasdata['ipaddr'])
            ingamesn = ''
            if 'ingamesn' in nasdata:
                ingamesn = str(nasdata['ingamesn'])
            elif 'devname' in nasdata:
                ingamesn = str(nasdata['devname'])
            if ingamesn:
                ingamesn = gs_utils.base64_decode(ingamesn)
                if is_console:
                    ingamesn = codecs.utf_16_be_decode(ingamesn)[0]
                else:
                    ingamesn = codecs.utf_16_le_decode(ingamesn)[0]
            else:
                ingamesn = '[NOT AVAILABLE]'
            responsedata += """
            <tr>
                <td>%s</td>
                <td id="game">%s</td>
                <td>%s</td>
                <td>%s</td>
                <td>%s</td>
                <td>%s</td>
                <td>%s</td>
            """ % (ingamesn, gameid, enabled, dwc_pid, gsbrcd, userid, ipaddr)
            if gameid[:-1] + ":" + ipaddr in banned_list:
                responsedata += """
                    <td>
                    <form action='updatebanlist' method='POST'>
                        <input type='hidden' name='gameid' value='%s'>
                        <input type='hidden' name='ipaddr' value='%s'>
                        <input type='hidden' name='action' value='unban'>
                        <input type='submit' value='----- unban -----'>
                    </form>
                    </td>
                </tr>""" % (gameid, ipaddr)
            else:
                responsedata += """
                    <td>
                    <form action='updatebanlist' method='POST'>
                        <input type='hidden' name='gameid' value='%s'>
                        <input type='hidden' name='ipaddr' value='%s'>
                        <input type='hidden' name='action' value='ban'>
                        <input type='submit' value='Ban'>
                    </form>
                    </td>
                </tr>
                """ % (gameid, ipaddr)

        responsedata += "</table>"
        dbconn.close()
        request.setHeader("Content-Type", "text/html; charset=utf-8")
        return responsedata.encode('utf-8')
Esempio n. 9
0
 def test_utf_16_le_decode(self):
     #sanity
     new_str, size = codecs.utf_16_le_decode("abc")
     self.assertEqual(new_str, u'\u6261')
     self.assertEqual(size, 2)
Esempio n. 10
0
 def test_utf_16_le_decode(self):
     #sanity
     new_str, size = codecs.utf_16_le_decode("abc")
     self.assertEqual(new_str, u'\u6261')
     self.assertEqual(size, 2)
Esempio n. 11
0
def decode(input, errors = 'strict'):
    return codecs.utf_16_le_decode(input, errors, True)
Esempio n. 12
0
def utf2ascii(text):
    return ascii_encode(utf_16_le_decode(text, "ignore")[0], "ignore")[0]
    def render_blacklist(self, request):
        sqlstatement = """
        SELECT users.profileid, enabled, data, users.gameid, console,
               users.userid
        FROM nas_logins
        INNER JOIN users
        ON users.userid = nas_logins.userid
        INNER JOIN (
            SELECT max(profileid) newestpid, userid, gameid, devname
            FROM users
            GROUP BY userid, gameid
        ) ij
        ON ij.userid = users.userid
        AND users.profileid = ij.newestpid
        ORDER BY users.gameid"""
        dbconn = sqlite3.connect('gpcm.db')
        banned_list = []
        for row in dbconn.cursor().execute("SELECT * FROM BANNED"):
            banned_list.append(str(row[0])+":"+str(row[1]))
        responsedata = """
        <a href="http://%%20:%%20@%s">[CLICK HERE TO LOG OUT]</a>
        <br><br>
        <table border='1'>"
        <tr>
            <td>ingamesn or devname</td>
            <td>gameid</td>
            <td>Enabled</td>
            <td>newest dwc_pid</td>"
            <td>gsbrcd</td>
            <td>userid</td>
            <td>ipAddr</td>
        </tr>""" % request.getHeader('host')

        for row in dbconn.cursor().execute(sqlstatement):
            dwc_pid = str(row[0])
            enabled = str(row[1])
            nasdata = collections.defaultdict(lambda: '', json.loads(row[2]))
            gameid = str(row[3])
            is_console = int(str(row[4]))
            userid = str(row[5])
            gsbrcd = str(nasdata['gsbrcd'])
            ipaddr = str(nasdata['ipaddr'])
            ingamesn = ''
            if 'ingamesn' in nasdata:
                ingamesn = str(nasdata['ingamesn'])
            elif 'devname' in nasdata:
                ingamesn = str(nasdata['devname'])
            if ingamesn:
                ingamesn = gs_utils.base64_decode(ingamesn)
                if is_console:
                    ingamesn = codecs.utf_16_be_decode(ingamesn)[0]
                else:
                    ingamesn = codecs.utf_16_le_decode(ingamesn)[0]
            else:
                ingamesn = '[NOT AVAILABLE]'
            responsedata += """
            <tr>
                <td>%s</td>
                <td>%s</td>
                <td>%s</td>
                <td>%s</td>
                <td>%s</td>
                <td>%s</td>
                <td>%s</td>
            """ % (ingamesn,
                   gameid,
                   enabled,
                   dwc_pid,
                   gsbrcd,
                   userid,
                   ipaddr)
            if gameid[:-1] + ":" + ipaddr in banned_list:
                responsedata += """
                    <td>
                    <form action='updatebanlist' method='POST'>
                        <input type='hidden' name='gameid' value='%s'>
                        <input type='hidden' name='ipaddr' value='%s'>
                        <input type='hidden' name='action' value='unban'>
                        <input type='submit' value='----- unban -----'>
                    </form>
                    </td>
                </tr>""" % (gameid, ipaddr)
            else:
                responsedata += """
                    <td>
                    <form action='updatebanlist' method='POST'>
                        <input type='hidden' name='gameid' value='%s'>
                        <input type='hidden' name='ipaddr' value='%s'>
                        <input type='hidden' name='action' value='ban'>
                        <input type='submit' value='Ban'>
                    </form>
                    </td>
                </tr>
                """ % (gameid, ipaddr)

        responsedata += "</table>"
        dbconn.close()
        request.setHeader("Content-Type", "text/html; charset=utf-8")
        return responsedata.encode('utf-8')
 def render_blacklist(self, request):
     sqlstatement = (
         ''
         'select users.profileid,enabled,data,users.gameid,console,users.userid '
         'from nas_logins '
         'inner join users '
         'on users.userid = nas_logins.userid '
         'inner join ( '
         '    select max(profileid) newestpid, userid, gameid, devname '
         '    from users '
         '    group by userid,gameid) '
         'ij on ij.userid = users.userid and '
         'users.profileid = ij.newestpid '
         'order by users.gameid '
         '')
     dbconn = sqlite3.connect('gpcm.db')
     banned_list = []
     for row in dbconn.cursor().execute("SELECT * FROM BANNED"):
         banned_list.append(str(row[0]) + ":" + str(row[1]))
     responsedata = (
         ""
         '<a href="http://%20:%20@' + request.getHeader('host') +
         '">[CLICK HERE TO LOG OUT]</a>'
         "<br><br>"
         "<table border='1'>"
         "<tr><td>ingamesn or devname</td><td>gameid</td>"
         "<td>Enabled</td><td>newest dwc_pid</td>"
         "<td>gsbrcd</td><td>userid</td><td>ipAddr</td></tr>\r\n")
     for row in dbconn.cursor().execute(sqlstatement):
         dwc_pid = str(row[0])
         enabled = str(row[1])
         nasdata = collections.defaultdict(lambda: '', json.loads(row[2]))
         gameid = str(row[3])
         is_console = int(str(row[4]))
         userid = str(row[5])
         gsbrcd = str(nasdata['gsbrcd'])
         ipaddr = str(nasdata['ipaddr'])
         ingamesn = ''
         if 'ingamesn' in nasdata:
             ingamesn = str(nasdata['ingamesn'])
         elif 'devname' in nasdata:
             ingamesn = str(nasdata['devname'])
         if ingamesn:
             ingamesn = gs_utils.base64_decode(ingamesn)
             if is_console:
                 ingamesn = codecs.utf_16_be_decode(ingamesn)[0]
             else:
                 ingamesn = codecs.utf_16_le_decode(ingamesn)[0]
         else:
             ingamesn = '[NOT AVAILABLE]'
         responsedata += "<tr>"
         responsedata += "<td>" + ingamesn + "</td>"
         responsedata += "<td>" + gameid + "</td>"
         responsedata += "<td>" + enabled + "</td>"
         responsedata += "<td>" + dwc_pid + "</td>"
         responsedata += "<td>" + gsbrcd + "</td>"
         responsedata += "<td>" + userid + "</td>"
         responsedata += "<td>" + ipaddr + "</td>"
         if gameid[:-1] + ":" + ipaddr in banned_list:
             responsedata += (
                 "<td><form action='updatebanlist' method='POST'>"
                 "<input type='hidden' name='gameid' value='" + gameid +
                 "'>"
                 "<input type='hidden' name='ipaddr' value='" + ipaddr +
                 "'>"
                 "<input type='hidden' name='action' value='unban'>"
                 "<input type='submit' value='----- unban -----'></form></td></tr>"
             )
         else:
             responsedata += (
                 "<td><form action='updatebanlist' method='POST'>"
                 "<input type='hidden' name='gameid' value='" + gameid +
                 "'>"
                 "<input type='hidden' name='ipaddr' value='" + ipaddr +
                 "'>"
                 "<input type='hidden' name='action' value='ban'>"
                 "<input type='submit' value='Ban'></form></td></tr>")
     responsedata += "</table>"
     dbconn.close()
     request.setHeader("Content-Type", "text/html; charset=utf-8")
     return responsedata.encode('utf-8')
Esempio n. 15
0
def utf2ascii(text):
    return ascii_encode(utf_16_le_decode(text, 'ignore')[0], 'ignore')[0]
 def render_GET(self, request):
     if not self.is_authorized(request):
         return ""
     if request.path == "/whitelist":
         return self.render_whitelist(request)
     if request.path != "/banhammer":
         request.setResponseCode(500)
         return "wrong url path"
     sqlstatement = (
         ''
         'select users.profileid,enabled,data,users.gameid,console,users.userid '
         'from nas_logins '
         'inner join users '
         'on users.userid = nas_logins.userid '
         'inner join ( '
         '    select max(profileid) newestpid, userid, gameid, devname '
         '    from users '
         '    group by userid,gameid) '
         'ij on ij.userid = users.userid and '
         'users.profileid = ij.newestpid '
         'order by users.gameid '
         '')
     dbconn = sqlite3.connect('gpcm.db')
     responsedata = ("<html><meta charset='utf-8'>\r\n"
                     "<title>altwfc admin page</title>"
                     '<a href="http://%20:%20@' +
                     request.getHeader('host') +
                     '">[CLICK HERE TO LOG OUT]</a>'
                     "<br><br>"
                     '<a href="http://' + request.getHeader('host') +
                     '/whitelist">WhiteList</a>'
                     "<table border='1'>"
                     "<tr><td>ingamesn or devname</td><td>gameid</td>"
                     "<td>Enabled</td><td>newest dwc_pid</td>"
                     "<td>gsbrcd</td><td>userid</td></tr>\r\n")
     for row in dbconn.cursor().execute(sqlstatement):
         dwc_pid = str(row[0])
         enabled = str(row[1])
         nasdata = collections.defaultdict(lambda: '', json.loads(row[2]))
         gameid = str(row[3])
         is_console = int(str(row[4]))
         userid = str(row[5])
         gsbrcd = str(nasdata['gsbrcd'])
         ingamesn = ''
         if 'ingamesn' in nasdata:
             ingamesn = str(nasdata['ingamesn'])
         elif 'devname' in nasdata:
             ingamesn = str(nasdata['devname'])
         if ingamesn:
             ingamesn = gs_utils.base64_decode(ingamesn)
             if is_console:
                 ingamesn = codecs.utf_16_be_decode(ingamesn)[0]
             else:
                 ingamesn = codecs.utf_16_le_decode(ingamesn)[0]
         else:
             ingamesn = '[NOT AVAILABLE]'
         responsedata += "<tr>"
         responsedata += "<td>" + ingamesn + "</td>"
         responsedata += "<td>" + gameid + "</td>"
         responsedata += "<td>" + enabled + "</td>"
         responsedata += "<td>" + dwc_pid + "</td>"
         responsedata += "<td>" + gsbrcd + "</td>"
         responsedata += "<td>" + userid + "</td>"
         if enabled == "1":
             responsedata += (
                 "<td><form action='disableuser' method='POST'>"
                 "<input type='hidden' name='userid' value='" + userid +
                 "'>"
                 "<input type='hidden' name='gameid' value='" + gameid +
                 "'>"
                 "<input type='hidden' name='ingamesn' value='" + ingamesn +
                 "'>"
                 "<input type='submit' value='Ban'></form></td></tr>")
         else:
             responsedata += (
                 "<td><form action='enableuser' method='POST'>"
                 "<input type='hidden' name='userid' value='" + userid +
                 "'>"
                 "<input type='hidden' name='gameid' value='" + gameid +
                 "'>"
                 "<input type='hidden' name='ingamesn' value='" + ingamesn +
                 "'>"
                 "<input type='submit' value='----- unban -----'></form></td></tr>"
             )
     responsedata += "</table></html>"
     dbconn.close()
     request.setHeader("Content-Type", "text/html; charset=utf-8")
     return responsedata.encode('utf-8')
Esempio n. 17
0
 def utf_16_le_decode(data, errors, finish = False):
     if not finish and len(data) % 2 == 1:
         data = data[:-1]
     return codecs.utf_16_le_decode(data, errors)
Esempio n. 18
0
def utf2ascii(text):
    return ascii_encode(utf_16_le_decode(text, 'ignore')[0], 'ignore')[0]
Esempio n. 19
0
def decode(input, errors='strict'):
    return codecs.utf_16_le_decode(input, errors, True)
 def render_blacklist(self, request):
     sqlstatement = (''
         'select users.profileid,enabled,data,users.gameid,console,users.userid '
         'from nas_logins '
         'inner join users '
         'on users.userid = nas_logins.userid '
         'inner join ( '
         '    select max(profileid) newestpid, userid, gameid, devname '
         '    from users '
         '    group by userid,gameid) '
         'ij on ij.userid = users.userid and '
         'users.profileid = ij.newestpid '
         'order by users.gameid '
         '') 
     dbconn = sqlite3.connect('gpcm.db')
     banned_list = []
     for row in dbconn.cursor().execute("SELECT * FROM IP_BANNED"):
         banned_list.append(str(row[0]))
     responsedata = (""
         '<a href="http://%20:%20@'+request.getHeader('host')+'">[CLICK HERE TO LOG OUT]</a>'
         "<br><br>"
         "<table border='1'>" 
         "<tr><td>ingamesn or devname</td><td>gameid</td>"
         "<td>Enabled</td><td>newest dwc_pid</td>"
         "<td>gsbrcd</td><td>userid</td><td>ipAddr</td><td>macadr</td><td>cfc</td><td>csnum</td><td>Ban/Unban IP</td></tr>\r\n")
     for row in dbconn.cursor().execute(sqlstatement):
         dwc_pid = str(row[0])
         enabled = str(row[1])
         nasdata = collections.defaultdict(lambda: '', json.loads(row[2]))
         gameid = str(row[3])
         is_console = int(str(row[4]))
         userid = str(row[5])
         gsbrcd = str(nasdata['gsbrcd'])
         ipaddr = str(nasdata['ipaddr'])
         macadr = str(nasdata['macadr'])
         cfc = str(nasdata['cfc'])
         csnum = str(nasdata['csnum'])
         ingamesn = ''
         if 'ingamesn' in nasdata:
             ingamesn = str(nasdata['ingamesn'])
         elif 'devname' in nasdata:
             ingamesn = str(nasdata['devname'])
         if ingamesn:
             ingamesn = gs_utils.base64_decode(ingamesn)
             if is_console:
                 ingamesn = codecs.utf_16_be_decode(ingamesn)[0]
             else:
                 ingamesn = codecs.utf_16_le_decode(ingamesn)[0]
         else:
             ingamesn = '[NOT AVAILABLE]'
         responsedata += "<tr>"
         responsedata += "<td>"+ingamesn+"</td>"
         responsedata += "<td>"+gameid+"</td>"
         responsedata += "<td>"+enabled+"</td>"
         responsedata += "<td>"+dwc_pid+"</td>"
         responsedata += "<td>"+gsbrcd+"</td>"
         responsedata += "<td>"+userid+"</td>"
         responsedata += "<td>"+ipaddr+"</td>"
         responsedata += "<td>"+macadr+"</td>"
         responsedata += "<td>"+cfc+"</td>"
         responsedata +="<td>"+csnum+"</td>"
         if ipaddr in banned_list:
             responsedata += ("<td><form action='updatebanlist' method='POST'>"
             "<input type='hidden' name='gameid' value='"+gameid+"'>"
             "<input type='hidden' name='ipaddr' value='"+ipaddr+"'>"
             "<input type='hidden' name='action' value='unban'>"
             "<input type='submit' value='----- unban -----'></form></td></tr>")
         else:
             responsedata += ("<td><form action='updatebanlist' method='POST'>"
             "<input type='hidden' name='gameid' value='"+gameid+"'>"
             "<input type='hidden' name='ipaddr' value='"+ipaddr+"'>"
             "<input type='hidden' name='action' value='ban'>"
             "<input type='submit' value='Ban'></form></td></tr>")
     responsedata += "</table>" 
     dbconn.close()
     request.setHeader("Content-Type", "text/html; charset=utf-8")
     return responsedata.encode('utf-8')
 def render_GET(self, request):
     if not self.is_authorized(request):
         return ""
     if request.path == "/whitelist":
         return self.render_whitelist(request)
     if request.path != "/banhammer":
         request.setResponseCode(500)
         return "wrong url path"
     sqlstatement = (''
         'select users.profileid,enabled,data,users.gameid,console,users.userid '
         'from nas_logins '
         'inner join users '
         'on users.userid = nas_logins.userid '
         'inner join ( '
         '    select max(profileid) newestpid, userid, gameid, devname '
         '    from users '
         '    group by userid,gameid) '
         'ij on ij.userid = users.userid and '
         'users.profileid = ij.newestpid '
         'order by users.gameid '
         '') 
     dbconn = sqlite3.connect('gpcm.db')
     responsedata = ("<html><meta charset='utf-8'>\r\n"
         "<title>altwfc admin page</title>"
         '<a href="http://%20:%20@'+request.getHeader('host')+'">[CLICK HERE TO LOG OUT]</a>'
         "<br><br>"
         '<a href="http://'+request.getHeader('host')+'/whitelist">WhiteList</a>'
         "<table border='1'>" 
         "<tr><td>ingamesn or devname</td><td>gameid</td>"
         "<td>Enabled</td><td>newest dwc_pid</td>"
         "<td>gsbrcd</td><td>userid</td></tr>\r\n")
     for row in dbconn.cursor().execute(sqlstatement):
         dwc_pid = str(row[0])
         enabled = str(row[1])
         nasdata = collections.defaultdict(lambda: '', json.loads(row[2]))
         gameid = str(row[3])
         is_console = int(str(row[4]))
         userid = str(row[5])
         gsbrcd = str(nasdata['gsbrcd'])
         ingamesn = ''
         if 'ingamesn' in nasdata:
             ingamesn = str(nasdata['ingamesn'])
         elif 'devname' in nasdata:
             ingamesn = str(nasdata['devname'])
         if ingamesn:
             ingamesn = gs_utils.base64_decode(ingamesn)
             if is_console:
                 ingamesn = codecs.utf_16_be_decode(ingamesn)[0]
             else:
                 ingamesn = codecs.utf_16_le_decode(ingamesn)[0]
         else:
             ingamesn = '[NOT AVAILABLE]'
         responsedata += "<tr>"
         responsedata += "<td>"+ingamesn+"</td>"
         responsedata += "<td>"+gameid+"</td>"
         responsedata += "<td>"+enabled+"</td>"
         responsedata += "<td>"+dwc_pid+"</td>"
         responsedata += "<td>"+gsbrcd+"</td>"
         responsedata += "<td>"+userid+"</td>"
         if enabled == "1":
             responsedata += ("<td><form action='disableuser' method='POST'>"
             "<input type='hidden' name='userid' value='"+userid+"'>"
             "<input type='hidden' name='gameid' value='"+gameid+"'>"
             "<input type='hidden' name='ingamesn' value='"+ingamesn+"'>"
             "<input type='submit' value='Ban'></form></td></tr>")
         else:
             responsedata += ("<td><form action='enableuser' method='POST'>"
             "<input type='hidden' name='userid' value='"+userid+"'>"
             "<input type='hidden' name='gameid' value='"+gameid+"'>"
             "<input type='hidden' name='ingamesn' value='"+ingamesn+"'>"
             "<input type='submit' value='----- unban -----'></form></td></tr>")
     responsedata += "</table></html>" 
     dbconn.close()
     request.setHeader("Content-Type", "text/html; charset=utf-8")
     return responsedata.encode('utf-8')
Esempio n. 22
0
 def update_event(self, inp=-1):
     self.set_output_val(
         0,
         codecs.utf_16_le_decode(self.input(0), self.input(1),
                                 self.input(2)))