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. Please DO NOT overdose requests that are not limited by themselves. Typically parameters like --domain, --software and --force are unlimited. \"Unlimited\" here means that there is no \"is recently accessed?\" limitation.",
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.set_defaults(command=commands.check_instance)
59 parser.add_argument("--domain", required=True, help="Instance name (aka. domain) to check")
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.set_defaults(command=commands.recheck_obfuscation)
74 parser.add_argument("--domain", help="Instance name (aka. domain)")
75 parser.add_argument("--software", help="Name of software, e.g. 'lemmy'")
76 parser.add_argument("--force", action="store_true", help="Include also already existing instances, otherwise only new are checked")
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.set_defaults(command=commands.fetch_blocks)
84 parser.add_argument("--domain", help="Instance name (aka. domain)")
85 parser.add_argument("--software", help="Name of software, e.g. 'lemmy'")
86 parser.add_argument("--force", action="store_true", help="Forces update of data, no matter what.")
88 ### Fetch blocks from chaos.social ###
89 parser = subparser_command.add_parser(
91 help="Fetches blocks from chaos.social's meta sub domain.",
93 parser.set_defaults(command=commands.fetch_cs)
95 ### Fetch blocks from todon.eu wiki ###
96 parser = subparser_command.add_parser(
98 help="Fetches blocks from todon.eu's wiki.",
100 parser.set_defaults(command=commands.fetch_todon_wiki)
102 ### Fetch blocks from a FBA-specific RSS feed ###
103 parser = subparser_command.add_parser(
105 help="Fetches domains from a FBA-specific RSS feed.",
107 parser.set_defaults(command=commands.fetch_fba_rss)
108 parser.add_argument("--feed", required=True, help="RSS feed to fetch domains from (e.g. https://fba.ryoma.agency/rss?domain=foo.bar).")
110 ### Fetch blocks from FBA's bot account ###
111 parser = subparser_command.add_parser(
113 help="Fetches ATOM feed with domains from FBA's bot account.",
115 parser.set_defaults(command=commands.fetch_fbabot_atom)
116 parser.add_argument("--feed", required=True, help="RSS feed to fetch domains from (e.g. https://fba.ryoma.agency/rss?domain=foo.bar).")
118 ### Fetch blocks from oliphant's GIT repository ###
119 parser = subparser_command.add_parser(
121 help="Fetches CSV files (block recommendations) for more possible instances to disover",
123 parser.set_defaults(command=commands.fetch_oliphant)
124 parser.add_argument("--domain", help="Instance name (aka. domain) to check")
126 ### Fetch blocks from other CSV files
127 parser = subparser_command.add_parser(
129 help="Fetches CSV files (block recommendations) for more possible instances to disover",
131 parser.set_defaults(command=commands.fetch_csv)
132 parser.add_argument("--domain", help="Instance name (aka. domain) to check")
134 ### Fetch instances from given initial instance ###
135 parser = subparser_command.add_parser(
137 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.",
139 parser.set_defaults(command=commands.fetch_instances)
140 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 .")
141 parser.add_argument("--single", action="store_true", help="Only fetch given instance.")
143 ### Fetch blocks from static text file(s) ###
144 parser = subparser_command.add_parser(
146 help="Fetches text/plain files as simple domain lists",
148 parser.set_defaults(command=commands.fetch_txt)
150 ### Fetch blocks from joinfediverse.wiki ###
151 #parser = subparser_command.add_parser(
152 # "fetch_joinfediverse",
153 # help="Fetches FediBlock page from joinfediverse.wiki",
155 #parser.set_defaults(command=commands.fetch_joinfediverse)
157 ### Fetch instances JSON from instances.joinmobilizon.org
158 parser = subparser_command.add_parser(
159 "fetch_joinmobilizon",
160 help="Fetches instances from joinmobilizon",
162 parser.set_defaults(command=commands.fetch_joinmobilizon)
164 ### Fetch blocks from misskey.page ###
165 parser = subparser_command.add_parser(
167 help="Fetches instances.json from misskey.page",
169 parser.set_defaults(command=commands.fetch_joinmisskey)
171 ### Fetch blocks from fediverse.observer ###
172 parser = subparser_command.add_parser(
174 help="Fetches blocks from fediverse.observer.",
176 parser.set_defaults(command=commands.fetch_observer)
177 parser.add_argument("--software", help="Name of software, e.g. 'lemmy'")
179 ### Fetch instances from fedipact.online ###
180 parser = subparser_command.add_parser(
182 help="Fetches blocks from fedipact.online.",
184 parser.set_defaults(command=commands.fetch_fedipact)
186 ### Fetch from pixelfed.org's API ###
187 parser = subparser_command.add_parser(
188 "fetch_pixelfed_api",
189 help="Fetches domain names from pixelfed.org's API",
191 parser.set_defaults(command=commands.fetch_pixelfed_api)
193 ### Check nodeinfo ###
194 parser = subparser_command.add_parser(
196 help="Checks if domain is part of nodeinfo.",
198 parser.set_defaults(command=commands.check_nodeinfo)
200 ### Fetch CSV from fedilist.com ###
201 parser = subparser_command.add_parser(
203 help="Fetches CSV from fedilist.com",
205 parser.set_defaults(command=commands.fetch_fedilist)
206 parser.add_argument("--software", help="Name of software, e.g. 'lemmy'")
207 parser.add_argument("--force", action="store_true", help="Include also already existing instances, otherwise only new are checked")
209 ### Update nodeinfo ###
210 parser = subparser_command.add_parser(
212 help="Updates nodeinfo for all instances",
214 parser.set_defaults(command=commands.update_nodeinfo)
215 parser.add_argument("--domain", help="Instance name (aka. domain)")
216 parser.add_argument("--software", help="Name of software, e.g. 'lemmy'")
217 parser.add_argument("--mode", help="Name of detection mode, e.g. 'auto_discovery'")
218 parser.add_argument("--force", action="store_true", help="Forces update of data, no matter what.")
219 parser.add_argument("--no-software", action="store_true", help="Checks only entries with no software type detected.")
220 parser.add_argument("--no-auto", action="store_true", help="Checks only entries with other than AUTO_DISCOVERY as detection mode.")
222 ### Fetch instances from instances.social ###
223 parser = subparser_command.add_parser(
224 "fetch_instances_social",
225 help="Fetch instances from instances.social, you need an API key to access the API. Please consider donating to them when you want to more frequent use their API!",
227 parser.set_defaults(command=commands.fetch_instances_social)
229 ### Convert international domain names to punycode domains ###
230 parser = subparser_command.add_parser(
232 help="Convertes UTF-8 encoded international domain names into punycode (IDNA) domain names.",
234 parser.set_defaults(command=commands.convert_idna)
236 ### Fetch instances from ActivityPub relays ###
237 parser = subparser_command.add_parser(
239 help="Fetches instances from ActivityPub relays",
241 parser.set_defaults(command=commands.fetch_relays)
242 parser.add_argument("--domain", help="Instance name (aka. 'relay')")
243 parser.add_argument("--software", help="Name of software, e.g. 'lemmy'")
244 parser.add_argument("--force", action="store_true", help="Forces update of data, no matter what.")
246 ### Remove invalid domains ###
247 parser = subparser_command.add_parser(
249 help="Removes invalid domains.",
251 parser.set_defaults(command=commands.remove_invalid)
253 logger.debug("EXIT!")
256 logger.debug("CALLED!")
257 args = _PARSER.parse_args()
259 if args.log_level is not None:
260 loggers = [logging.getLogger(name) for name in logging.root.manager.loggerDict]
261 for _logger in loggers:
262 _logger.setLevel(args.log_level)
264 logger.debug("args[%s]='%s'", type(args), args)
265 status = args.command(args)
267 logger.debug("status=%d - EXIT!", status)
271 logger.debug("Closing database connection ...")
272 database.connection.close()
274 logger.debug("Shutdown completed.")