Exemplo n.º 1
0
def display():
    """ duisplay the banner """
    print(color("    ┌──────────────────────────────────────────┐", fg="#b61042"))
    print(
        color("    │       ", fg="#b61042")
        + color(f"π-hole 5 list tool  v{__version__}", "#FFF")
        + color("         │", fg="#b61042")
    )
    print(color("    └──────────────────────────────────────────┘", fg="#b61042"))
    utils.info("    https://github.com/jessedp/pihole5-list-tool\n")
def remove(cur):
    """ remove lists we added """

    utils.info("""
    This will try to remove blocklists added by this tool. Removal is done
    based on the comment for each list. If you've never changed any comments
    or used other tools, this is 100% safe.
""")

    if prompts.confirm("Are you sure?", "n"):
        cur.execute(
            "DELETE FROM domainlist WHERE comment LIKE '%AndeepND |%' OR comment LIKE '%[ph5lt]'"
        )
        return True

    return False
Exemplo n.º 3
0
def block_header(cur):
    """ block portion of header """

    block_data = [
        [
            "Total     :",
            get(cur, "total_adlist_enabled") + "/" + get(cur, "total_adlist"),
        ],
        [
            "Our Lists :",
            get(cur, "our_adlist_enabled") + "/" + get(cur, "our_adlist")
        ],
        [
            "Others    :",
            get(cur, "other_adlist_enabled") + "/" + get(cur, "other_adlist"),
        ],
    ]
    block_table = AsciiTable(block_data)

    block_table.inner_heading_row_border = False
    block_table.outer_border = False
    block_table.inner_row_border = False
    block_table.inner_column_border = False

    rows = adlist_top3_by_comment(cur)
    t3_block_data = []
    for row in rows:
        t3_block_data.append([row[0], row[1]])

    t3_block_table = AsciiTable(t3_block_data)

    t3_block_table.inner_heading_row_border = False
    t3_block_table.outer_border = False
    t3_block_table.inner_row_border = False
    t3_block_table.inner_column_border = False

    table_data = [
        ["Ad/Blocklist Stats", "Top 3 by Comment"],
        [block_table.table, t3_block_table.table],
        [],
    ]

    table = SingleTable(table_data)
    table.padding_left = 2
    table.outer_border = False

    utils.info(table.table)
def reset(cur):
    """ reset block lists to pihole install default """
    utils.info("\nThis will replace ALL blocklists with these defaults:")

    for url in DEFAULT_LISTS:
        utils.info("    - " + url)
    print()

    if prompts.confirm("Are you sure?", "n"):
        cur.execute("DELETE FROM adlist")
        for url in DEFAULT_LISTS:
            vals = (url, "Pi-hole defaults")
            cur.execute(
                "INSERT OR IGNORE INTO adlist (address, comment) VALUES (?,?)",
                vals)
        return True

    return False
Exemplo n.º 5
0
def update_gravity(use_docker):
    """ various ways of updating the gravity db """

    if prompts.confirm("Update Gravity for immediate effect?"):
        print()
        if use_docker:
            os.system('docker exec pihole bash "/usr/local/bin/pihole" "-g"')
        else:
            os.system("pihole -g")
    else:
        print()
        if use_docker:
            utils.info(
                "Update Gravity through the web interface or by running:\n\t"
                + '# docker exec pihole bash "/usr/local/bin/pihole" "-g"'
            )

        else:
            utils.info(
                "Update Gravity through the web interface or by running:\n\t# pihole -g"
            )
Exemplo n.º 6
0
def main():
    """main method"""
    conn = None
    try:
        utils.clear()
        banner.display()

        use_docker = False
        docker = utils.find_docker()

        if docker[0] is True:
            utils.success(f"+ Found Running Docker config: {docker[1]}")
            use_docker = prompts.confirm("Use Docker-ized config?", "n")
            if use_docker:
                db_file = docker[1]

        if not use_docker:
            print()
            db_file = prompts.ask_db()

        # ask_db validates the db, pass this connection round for easy access & "global" mgmt
        conn = sqlite3.connect(db_file)
        cur = conn.cursor()

        default = constants.BLOCKLIST
        option = ""
        any_save = False
        while option != constants.EXIT:
            stats.stat_bar(cur)
            option = prompts.main_menu(default)
            save = False

            if option == constants.BLOCKLIST:
                save = blocklists.manage_blocklists(cur)

            if option == constants.ALLOWLIST:
                save = allowlists.manage_allowlists(cur)

            if option == constants.STATS:
                stats.header(cur)

            if save:
                any_save = True
                default = constants.EXIT
                conn.commit()
                if option == constants.ALLOWLIST:
                    stats.allow_header(cur)

                if option == constants.BLOCKLIST:
                    stats.block_header(cur)

                if prompts.confirm("Are you finished?"):
                    break

        conn.close()
        if any_save:
            update_gravity(use_docker)

        utils.info("\n\tBye!\n")

    except (KeyboardInterrupt, KeyError):
        if conn:
            conn.close()
        sys.exit(0)