示例#1
0
def edit_admin_entry(
    task_data,
    num,
    comment="",
    ival1=None,
    ival2="255.255.255.255",
    sval1="",
    total=False,
    sec=None,
    min=None,
    hour=None,
    day=None,
    month=None,
    year=None,
    noexpire=False,
):
    session = model.Session()
    table = model.admin
    sql = table.select().where(table.c.num == num)
    row = session.execute(sql).fetchone()

    if not row:
        raise WakaError("Entry was not created or was removed.")

    task_data.action = row.type + "_edit"

    if row.type in ("ipban", "whitelist"):
        if not noexpire:
            try:
                expiration = datetime(int(year), int(month), int(day), int(hour), int(min), int(sec))
            except:
                raise WakaError("Invalid date.")
            expiration = timegm(expiration.utctimetuple())
        else:
            expiration = 0
        ival1 = misc.dot_to_dec(ival1)
        ival2 = misc.dot_to_dec(ival2)
        task_data.contents.append(ival1 + " (" + ival2 + ")")
    else:
        expiration = 0
        task_data.contents.append(sval1)

    sql = (
        table.update()
        .where(table.c.num == num)
        .values(comment=comment, ival1=ival1, ival2=ival2, sval1=sval1, total=total, expiration=expiration)
    )
    row = session.execute(sql)

    return Template("edit_successful")
示例#2
0
def edit_admin_entry(task_data,
                     num,
                     comment='',
                     ival1=None,
                     ival2='255.255.255.255',
                     sval1='',
                     total=False,
                     sec=None,
                     min=None,
                     hour=None,
                     day=None,
                     month=None,
                     year=None,
                     noexpire=False):
    session = model.Session()
    table = model.admin
    sql = table.select().where(table.c.num == num)
    row = session.execute(sql).fetchone()

    if not row:
        raise WakaError('Entry was not created or was removed.')

    task_data.action = row.type + '_edit'

    if row.type in ('ipban', 'whitelist'):
        if not noexpire:
            try:
                expiration = datetime(int(year), int(month), int(day),
                                      int(hour), int(min), int(sec))
            except:
                raise WakaError('Invalid date.')
            expiration = timegm(expiration.utctimetuple())
        else:
            expiration = 0
        ival1 = misc.dot_to_dec(ival1)
        ival2 = misc.dot_to_dec(ival2)
        task_data.contents.append(ival1 + ' (' + ival2 + ')')
    else:
        expiration = 0
        task_data.contents.append(sval1)

    sql = table.update().where(table.c.num == num)\
               .values(comment=comment, ival1=ival1, ival2=ival2, sval1=sval1,
                       total=total, expiration=expiration)
    row = session.execute(sql)

    return Template('edit_successful')
示例#3
0
    def make_admin_post_search_panel(self, search, text, caller='internal'):
        board = self.board
        session = model.Session()
        table = board.table

        board.check_access(self.user)

        popup = caller != 'board'

        if search.find('IP Address') != -1:
            try:
                sql = table.select()\
                           .where(table.c.ip == misc.dot_to_dec(text))
            except ValueError:
                raise WakaError('Please enter a valid IP.')
            search_type = 'IP'
        elif search.find('Text String') != -1:
            sql = table.select().where(table.c.comment.like('%'+text+'%'))
            search_type = 'text string'
        elif search.find('Author') != -1:
            sql = table.select().where(or_(table.c.name.like('%'+text+'%'),
                table.c.trip.like('%'+text+'%')))
            search_type = 'author'
        else:
            sql = table.select().where(table.c.num == text)
            search_type = 'ID'

        if search_type != 'ID':
            page = model.Page(sql, self.page, self.perpage)
            rowcount = page.total_entries
            total_pages = page.total_pages
            posts = page.rows
            if not posts:
                raise WakaError("No posts found for %s %s" % (search_type, text))
        else:
            rowcount = total_pages = 1
            row = session.execute(sql).fetchone()
            if not row:
                raise WakaError("Post not found. (It may have just been"
                                " deleted.)")
            posts = [row]


        inputs = [
            {'name': 'board', 'value': board.name},
            {'name' : 'task', 'value' : 'searchposts'},
            {'name' : 'text', 'value' : text},
            {'name': 'caller', 'value': caller},
            {'name' : 'search', 'value': search}
        ]

        rooturl = misc.make_script_url(task='searchposts', board=board.name,
            caller=caller, search=search, text=text, _amp=True)

        Template.__init__(self, 'post_search', num=id,
                          posts=posts, search=search, text=text,
                          inputs=inputs, number_of_pages=total_pages,
                          rooturl=rooturl, rowcount=rowcount, popup=popup)
示例#4
0
 def _log_action(self):
     interboard.trim_activity()
     session = model.Session()
     table = model.activity
     ip = misc.dot_to_dec(self.user.login_data.addr)
     for content in self.contents:
         sql = table.insert().values(username=self.user.username,
                                     ip=ip,
                                     action=self.action,
                                     info=content,
                                     date=self.date,
                                     timestamp=self.timestamp,
                                     admin_id=self.admin_id)
         session.execute(sql)
示例#5
0
 def _log_action(self):
     interboard.trim_activity()
     session = model.Session()
     table = model.activity
     ip = misc.dot_to_dec(self.user.login_data.addr)
     for content in self.contents:
         sql = table.insert().values(username=self.user.username,
                                     ip=ip,
                                     action=self.action,
                                     info=content,
                                     date=self.date,
                                     timestamp=self.timestamp,
                                     admin_id=self.admin_id)
         session.execute(sql)
示例#6
0
def edit_admin_entry(task_data, num, comment='', ival1=None,
                     ival2='255.255.255.255', sval1='', total=False,
                     sec=None, min=None, hour=None, day=None, month=None,
                     year=None, noexpire=False):
    session = model.Session()
    table = model.admin
    sql = table.select().where(table.c.num == num)
    row = session.execute(sql).fetchone()

    if not row:
        raise WakaError('Entry was not created or was removed.')

    task_data.action = row.type + '_edit'

    if row.type in ('ipban', 'whitelist'):
        if not noexpire:
            try:
                expiration = datetime(int(year), int(month), int(day),
                                      int(hour), int(min), int(sec))
            except:
                raise WakaError('Invalid date.')
            expiration = timegm(expiration.utctimetuple())
        else:
            expiration = 0
        ival1 = misc.dot_to_dec(ival1)
        ival2 = misc.dot_to_dec(ival2)
        task_data.contents.append(ival1 + ' (' + ival2 + ')')
    else:
        expiration = 0
        task_data.contents.append(sval1)

    sql = table.update().where(table.c.num == num)\
               .values(comment=comment, ival1=ival1, ival2=ival2, sval1=sval1,
                       total=total, expiration=expiration)
    row = session.execute(sql)

    return Template('edit_successful')
示例#7
0
    def make_admin_post_search_panel(self, search, text, caller="internal"):
        board = self.board
        session = model.Session()
        table = board.table

        self.user.check_access(board.name)

        popup = caller != "board"

        if search.find("IP Address") != -1:
            try:
                sql = table.select().where(table.c.ip == misc.dot_to_dec(text))
            except ValueError:
                raise WakaError("Please enter a valid IP.")
            search_type = "IP"
        elif search.find("Text String") != -1:
            sql = table.select().where(table.c.comment.like("%" + text + "%"))
            search_type = "text string"
        elif search.find("Author") != -1:
            sql = table.select().where(or_(table.c.name.like("%" + text + "%"), table.c.trip.like("%" + text + "%")))
            search_type = "author"
        else:
            sql = table.select().where(table.c.num == text)
            search_type = "ID"

        if search_type != "ID":
            page = model.Page(sql, self.page, self.perpage)
            rowcount = page.total_entries
            total_pages = page.total_pages
            posts = page.rows
            if not posts:
                raise WakaError("No posts found for %s %s" % (search_type, text))
        else:
            rowcount = total_pages = 1
            row = session.execute(sql).fetchone()
            if not row:
                raise WakaError("Post not found. (It may have just been" " deleted.)")
            posts = [row]

        inputs = [
            {"name": "board", "value": board.name},
            {"name": "task", "value": "searchposts"},
            {"name": "text", "value": text},
            {"name": "caller", "value": caller},
            {"name": "search", "value": search},
        ]

        rooturl = misc.make_script_url(
            task="searchposts", board=board.name, caller=caller, search=search, text=text, _amp=True
        )

        Template.__init__(
            self,
            "post_search",
            num=id,
            posts=posts,
            search=search,
            text=text,
            inputs=inputs,
            number_of_pages=total_pages,
            rooturl=rooturl,
            rowcount=rowcount,
            popup=popup,
        )
示例#8
0
def add_admin_entry(task_data,
                    option,
                    comment,
                    ip='',
                    mask='255.255.255.255',
                    sval1='',
                    total='',
                    expiration=0,
                    caller=''):
    session = model.Session()
    table = model.admin

    ival1 = ival2 = 0

    if not comment:
        raise WakaError(strings.COMMENT_A_MUST)
    if option in ('ipban', 'whitelist'):
        if not ip:
            raise WakaError('IP address required.')
        if not mask:
            mask = '255.255.255.255'
        # Convert to decimal.
        (ival1, ival2) = (misc.dot_to_dec(ip), misc.dot_to_dec(mask))
        sql = table.select().where(table.c.type == option)
        query = session.execute(sql)

        for row in query:
            try:
                if int(row.ival1) & int(row.ival2) == ival1 & ival2:
                    raise WakaError('IP address and mask match ban #%d.' % \
                                    (row.num))
            except ValueError:
                raise WakaError("Entry #%s on ban table is inconsistent. "
                                "This shouldn't happen." % row.num)
        # Add info to task data.
        content = ip + (' (' + mask + ')' if mask else '')

        if total == 'yes':
            add_htaccess_entry(ip)
            content += ' (no browse)'

        content += ' "' + comment + '"'
        task_data.contents.append(content)
    else:
        if not sval1:
            raise WakaError(strings.STRINGFIELDMISSING)
        sql = table.select().where(
            and_(table.c.sval1 == sval1, table.c.type == option))
        row = session.execute(sql).fetchone()

        if row:
            raise WakaError('Duplicate String in ban #%d.' % (row.num))
        # Add ifno to task data.
        task_data.contents.append(sval1)

    comment = str_format.clean_string(\
        str_format.decode_string(comment, config.CHARSET))
    expiration = int(expiration) if expiration else 0
    if expiration:
        expiration = expiration + time.time()

    sql = table.insert().values(type=option,
                                comment=comment,
                                ival1=int(ival1),
                                ival2=int(ival2),
                                sval1=sval1,
                                total=total,
                                expiration=expiration)
    result = session.execute(sql)

    task_data.admin_id = result.inserted_primary_key[0]

    # Add specific action name to task data.
    task_data.action = option

    board = local.environ['waka.board']
    forward_url = misc.make_script_url(task='bans', board=board.name)

    if caller == 'window':
        return Template('edit_successful')
    return util.make_http_forward(forward_url, config.ALTERNATE_REDIRECT)
示例#9
0
    def make_admin_post_search_panel(self, search, text, caller='internal'):
        board = self.board
        session = model.Session()
        table = board.table

        board.check_access(self.user)

        popup = caller != 'board'

        if search.find('IP Address') != -1:
            try:
                sql = table.select()\
                           .where(table.c.ip == misc.dot_to_dec(text))
            except ValueError:
                raise WakaError('Please enter a valid IP.')
            search_type = 'IP'
        elif search.find('Text String') != -1:
            sql = table.select().where(table.c.comment.like('%' + text + '%'))
            search_type = 'text string'
        elif search.find('Author') != -1:
            sql = table.select().where(
                or_(table.c.name.like('%' + text + '%'),
                    table.c.trip.like('%' + text + '%')))
            search_type = 'author'
        else:
            sql = table.select().where(table.c.num == text)
            search_type = 'ID'

        if search_type != 'ID':
            page = model.Page(sql, self.page, self.perpage)
            rowcount = page.total_entries
            total_pages = page.total_pages
            posts = page.rows
            if not posts:
                raise WakaError("No posts found for %s %s" %
                                (search_type, text))
        else:
            rowcount = total_pages = 1
            row = session.execute(sql).fetchone()
            if not row:
                raise WakaError("Post not found. (It may have just been"
                                " deleted.)")
            posts = [row]

        inputs = [{
            'name': 'board',
            'value': board.name
        }, {
            'name': 'task',
            'value': 'searchposts'
        }, {
            'name': 'text',
            'value': text
        }, {
            'name': 'caller',
            'value': caller
        }, {
            'name': 'search',
            'value': search
        }]

        rooturl = misc.make_script_url(task='searchposts',
                                       board=board.name,
                                       caller=caller,
                                       search=search,
                                       text=text,
                                       _amp=True)

        Template.__init__(self,
                          'post_search',
                          num=id,
                          posts=posts,
                          search=search,
                          text=text,
                          inputs=inputs,
                          number_of_pages=total_pages,
                          rooturl=rooturl,
                          rowcount=rowcount,
                          popup=popup)
示例#10
0
def add_admin_entry(task_data, option, comment, ip='', mask='255.255.255.255',
                    sval1='', total='', expiration=0,
                    caller=''):
    session = model.Session()
    table = model.admin

    ival1 = ival2 = 0

    if not comment:
        raise WakaError(strings.COMMENT_A_MUST)
    if option in ('ipban', 'whitelist'):
        if not ip:
            raise WakaError('IP address required.')
        if not mask:
            mask = '255.255.255.255'
        # Convert to decimal.
        (ival1, ival2) = (misc.dot_to_dec(ip), misc.dot_to_dec(mask))
        sql = table.select().where(table.c.type == option)
        query = session.execute(sql)

        for row in query:
            try:
                if int(row.ival1) & int(row.ival2) == ival1 & ival2:
                    raise WakaError('IP address and mask match ban #%d.' % \
                                    (row.num))
            except ValueError:
                raise WakaError("Entry #%s on ban table is inconsistent. "
                    "This shouldn't happen." % row.num)
        # Add info to task data.
        content = ip + (' (' + mask + ')' if mask else '')

        if total == 'yes':
            add_htaccess_entry(ip)
            content += ' (no browse)'

        content += ' "' + comment + '"'
        task_data.contents.append(content)
    else:
        if not sval1:
            raise WakaError(strings.STRINGFIELDMISSING)
        sql = table.select().where(and_(table.c.sval1 == sval1,
                                        table.c.type == option))
        row = session.execute(sql).fetchone()

        if row:
            raise WakaError('Duplicate String in ban #%d.' % (row.num))
        # Add ifno to task data.
        task_data.contents.append(sval1)

    comment = str_format.clean_string(\
        str_format.decode_string(comment, config.CHARSET))
    expiration = int(expiration) if expiration else 0
    if expiration:
        expiration = expiration + time.time()

    sql = table.insert().values(type=option, comment=comment, ival1=int(ival1),
                                ival2=int(ival2), sval1=sval1, total=total,
                                expiration=expiration)
    result = session.execute(sql)

    task_data.admin_id = result.inserted_primary_key[0]

    # Add specific action name to task data.
    task_data.action = option

    board = local.environ['waka.board']
    forward_url = misc.make_script_url(task='bans', board=board.name)

    if caller == 'window':
        return Template('edit_successful')
    return util.make_http_forward(forward_url, config.ALTERNATE_REDIRECT)