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.set_defaults(command=commands.recheck_obfuscation)
77 ### Fetch blocks from registered instances or given ###
78 parser = subparser_command.add_parser(
80 help="Fetches blocks from registered instances (run command fetch_instances first!).",
82 parser.add_argument("--domain", help="Instance name (aka. domain)")
83 parser.add_argument("--software", help="Name of software, e.g. 'lemmy'")
84 parser.set_defaults(command=commands.fetch_blocks)
86 ### Fetch blocks from chaos.social ###
87 parser = subparser_command.add_parser(
89 help="Fetches blocks from chaos.social's meta sub domain.",
91 parser.set_defaults(command=commands.fetch_cs)
93 ### Fetch blocks from todon.eu wiki ###
94 parser = subparser_command.add_parser(
96 help="Fetches blocks from todon.eu's wiki.",
98 parser.set_defaults(command=commands.fetch_todon_wiki)
100 ### Fetch blocks from a FBA-specific RSS feed ###
101 parser = subparser_command.add_parser(
103 help="Fetches domains from a FBA-specific RSS feed.",
105 parser.add_argument("--feed", required=True, help="RSS feed to fetch domains from (e.g. https://fba.ryoma.agency/rss?domain=foo.bar).")
106 parser.set_defaults(command=commands.fetch_fba_rss)
108 ### Fetch blocks from FBA's bot account ###
109 parser = subparser_command.add_parser(
111 help="Fetches ATOM feed with domains from FBA's bot account.",
113 parser.set_defaults(command=commands.fetch_fbabot_atom)
115 ### Fetch blocks from oliphant's GIT repository ###
116 parser = subparser_command.add_parser(
118 help="Fetches CSV files (block recommendations) for more possible instances to disover",
120 parser.add_argument("--domain", help="Instance name (aka. domain) to check")
121 parser.set_defaults(command=commands.fetch_oliphant)
123 ### Fetch instances from given initial instance ###
124 parser = subparser_command.add_parser(
126 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.",
128 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 .")
129 parser.add_argument("--single", action="store_true", help="Only fetch given instance.")
130 parser.set_defaults(command=commands.fetch_instances)
132 ### Fetch blocks from static text file(s) ###
133 parser = subparser_command.add_parser(
135 help="Fetches text/plain files as simple domain lists",
137 parser.set_defaults(command=commands.fetch_txt)
139 ### Fetch blocks from joinfediverse.wiki ###
140 parser = subparser_command.add_parser(
141 "fetch_joinfediverse",
142 help="Fetches FediBlock page from joinfediverse.wiki",
144 parser.set_defaults(command=commands.fetch_joinfediverse)
146 ### Fetch blocks from fediverse.observer ###
147 parser = subparser_command.add_parser(
149 help="Fetches blocks from fediverse.observer.",
151 parser.set_defaults(command=commands.fetch_observer)
152 parser.add_argument("--software", help="Name of software, e.g. 'lemmy'")
154 ### Fetch instances from fedipact.online ###
155 parser = subparser_command.add_parser(
157 help="Fetches blocks from fedipact.online.",
159 parser.set_defaults(command=commands.fetch_fedipact)
161 ### Fetch from pixelfed.org's API ###
162 parser = subparser_command.add_parser(
163 "fetch_pixelfed_api",
164 help="Fetches domain names from pixelfed.org's API",
166 parser.set_defaults(command=commands.fetch_pixelfed_api)
168 ### Check nodeinfo ###
169 parser = subparser_command.add_parser(
171 help="Checks if domain is part of nodeinfo.",
173 parser.set_defaults(command=commands.check_nodeinfo)
175 logger.debug("EXIT!")
178 logger.debug("CALLED!")
179 args = _PARSER.parse_args()
181 if args.log_level is not None:
182 loggers = [logging.getLogger(name) for name in logging.root.manager.loggerDict]
183 for _logger in loggers:
184 _logger.setLevel(args.log_level)
186 logger.debug("args[%s]='%s'", type(args), args)
187 status = args.command(args)
189 logger.debug("status=%d - EXIT!", status)
193 logger.debug("Closing database connection ...")
194 database.connection.close()
196 logger.debug("Shutdown completed.")