1 # Fedi API Block - An aggregator for fetching blocking data from fediverse nodes
2 # Copyright (C) 2023 Free Software Foundation
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU Affero General Public License as published
6 # by the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU Affero General Public License for more details.
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program. If not, see <https://www.gnu.org/licenses/>.
21 from fba import commands
22 from fba import database
24 from fba.helpers import locking
26 logging.basicConfig(level=logging.INFO)
27 logger = logging.getLogger(__name__)
33 logger.debug("CALLED!")
36 logger.debug("Initializing parser ...")
37 _PARSER = argparse.ArgumentParser(
38 description="Fetches block reasons from the fediverse",
39 epilog="Please note that some commands have optional arguments, you may want to try fba.py <command> --help to find them out.",
43 _PARSER.add_argument("--debug", action="store_const", dest="log_level", const=logging.DEBUG, help="Full debug output")
46 subparser_command = _PARSER.add_subparsers(
48 title="Commands to execute",
50 help="Command to perform",
53 ### Check instance ###
54 parser = subparser_command.add_parser(
56 help="Checks given instance if it exists and returns proper exit code"
58 parser.add_argument("--domain", required=True, help="Instance name (aka. domain) to check")
59 parser.set_defaults(command=commands.check_instance)
61 ### Fetch from bka.li ###
62 parser = subparser_command.add_parser(
64 help="Fetches domain names from bka.li API",
66 parser.set_defaults(command=commands.fetch_bkali)
68 ### Recheck instance's obfuscated peers ###
69 parser = subparser_command.add_parser(
70 "recheck_obfuscation",
71 help="Checks all instance's obfuscated peers if they can be de-obfuscated now.",
73 parser.add_argument("--domain", help="Instance name (aka. domain)")
74 parser.add_argument("--software", help="Name of software, e.g. 'lemmy'")
75 parser.add_argument("--all", action="store_true", help="Include also already existing instances, otherwise only new are checked")
76 parser.set_defaults(command=commands.recheck_obfuscation)
78 ### Fetch blocks from registered instances or given ###
79 parser = subparser_command.add_parser(
81 help="Fetches blocks from registered instances (run command fetch_instances first!).",
83 parser.add_argument("--domain", help="Instance name (aka. domain)")
84 parser.add_argument("--software", help="Name of software, e.g. 'lemmy'")
85 parser.set_defaults(command=commands.fetch_blocks)
87 ### Fetch blocks from chaos.social ###
88 parser = subparser_command.add_parser(
90 help="Fetches blocks from chaos.social's meta sub domain.",
92 parser.set_defaults(command=commands.fetch_cs)
94 ### Fetch blocks from todon.eu wiki ###
95 parser = subparser_command.add_parser(
97 help="Fetches blocks from todon.eu's wiki.",
99 parser.set_defaults(command=commands.fetch_todon_wiki)
101 ### Fetch blocks from a FBA-specific RSS feed ###
102 parser = subparser_command.add_parser(
104 help="Fetches domains from a FBA-specific RSS feed.",
106 parser.add_argument("--feed", required=True, help="RSS feed to fetch domains from (e.g. https://fba.ryoma.agency/rss?domain=foo.bar).")
107 parser.set_defaults(command=commands.fetch_fba_rss)
109 ### Fetch blocks from FBA's bot account ###
110 parser = subparser_command.add_parser(
112 help="Fetches ATOM feed with domains from FBA's bot account.",
114 parser.set_defaults(command=commands.fetch_fbabot_atom)
116 ### Fetch blocks from oliphant's GIT repository ###
117 parser = subparser_command.add_parser(
119 help="Fetches CSV files (block recommendations) for more possible instances to disover",
121 parser.add_argument("--domain", help="Instance name (aka. domain) to check")
122 parser.set_defaults(command=commands.fetch_oliphant)
124 ### Fetch instances from given initial instance ###
125 parser = subparser_command.add_parser(
127 help="Fetches instances (aka. \"domains\") from an initial instance. You may want to re-run this command several times (at least 3 with big instances) to have a decent amount of valid instances.",
129 parser.add_argument("--domain", required=True, help="Instance name (aka. domain) to fetch further instances from. Start with a large instance, e.g. mastodon.social .")
130 parser.add_argument("--single", action="store_true", help="Only fetch given instance.")
131 parser.set_defaults(command=commands.fetch_instances)
133 ### Fetch blocks from static text file(s) ###
134 parser = subparser_command.add_parser(
136 help="Fetches text/plain files as simple domain lists",
138 parser.set_defaults(command=commands.fetch_txt)
140 ### Fetch blocks from joinfediverse.wiki ###
141 parser = subparser_command.add_parser(
142 "fetch_joinfediverse",
143 help="Fetches FediBlock page from joinfediverse.wiki",
145 parser.set_defaults(command=commands.fetch_joinfediverse)
147 ### Fetch blocks from fediverse.observer ###
148 parser = subparser_command.add_parser(
150 help="Fetches blocks from fediverse.observer.",
152 parser.set_defaults(command=commands.fetch_observer)
153 parser.add_argument("--software", help="Name of software, e.g. 'lemmy'")
155 ### Fetch instances from fedipact.online ###
156 parser = subparser_command.add_parser(
158 help="Fetches blocks from fedipact.online.",
160 parser.set_defaults(command=commands.fetch_fedipact)
162 ### Fetch from pixelfed.org's API ###
163 parser = subparser_command.add_parser(
164 "fetch_pixelfed_api",
165 help="Fetches domain names from pixelfed.org's API",
167 parser.set_defaults(command=commands.fetch_pixelfed_api)
169 ### Check nodeinfo ###
170 parser = subparser_command.add_parser(
172 help="Checks if domain is part of nodeinfo.",
174 parser.set_defaults(command=commands.check_nodeinfo)
176 ### Fetch CSV from fedilist.com ###
177 parser = subparser_command.add_parser(
179 help="Fetches CSV from fedilist.com",
181 parser.set_defaults(command=commands.fetch_fedilist)
182 parser.add_argument("--software", help="Name of software, e.g. 'lemmy'")
183 parser.add_argument("--all", action="store_true", help="Include also already existing instances, otherwise only new are checked")
185 ### Update nodeinfo ###
186 parser = subparser_command.add_parser(
188 help="Updates nodeinfo for all instances",
190 parser.set_defaults(command=commands.update_nodeinfo)
191 parser.add_argument("--domain", help="Instance name (aka. domain)")
192 parser.add_argument("--software", help="Name of software, e.g. 'lemmy'")
194 logger.debug("EXIT!")
197 logger.debug("CALLED!")
198 args = _PARSER.parse_args()
200 if args.log_level is not None:
201 loggers = [logging.getLogger(name) for name in logging.root.manager.loggerDict]
202 for _logger in loggers:
203 _logger.setLevel(args.log_level)
205 logger.debug("args[%s]='%s'", type(args), args)
206 status = args.command(args)
208 logger.debug("status=%d - EXIT!", status)
212 logger.debug("Closing database connection ...")
213 database.connection.close()
215 logger.debug("Shutdown completed.")