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 instances from given initial instance ###
127 parser = subparser_command.add_parser(
129 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.",
131 parser.set_defaults(command=commands.fetch_instances)
132 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 .")
133 parser.add_argument("--single", action="store_true", help="Only fetch given instance.")
135 ### Fetch blocks from static text file(s) ###
136 parser = subparser_command.add_parser(
138 help="Fetches text/plain files as simple domain lists",
140 parser.set_defaults(command=commands.fetch_txt)
142 ### Fetch blocks from joinfediverse.wiki ###
143 parser = subparser_command.add_parser(
144 "fetch_joinfediverse",
145 help="Fetches FediBlock page from joinfediverse.wiki",
147 parser.set_defaults(command=commands.fetch_joinfediverse)
149 ### Fetch instances JSON from instances.joinmobilizon.org
150 parser = subparser_command.add_parser(
151 "fetch_joinmobilizon",
152 help="Fetches instances from joinmobilizon",
154 parser.set_defaults(command=commands.fetch_joinmobilizon)
156 ### Fetch blocks from misskey.page ###
157 parser = subparser_command.add_parser(
159 help="Fetches instances.json from misskey.page",
161 parser.set_defaults(command=commands.fetch_joinmisskey)
163 ### Fetch blocks from fediverse.observer ###
164 parser = subparser_command.add_parser(
166 help="Fetches blocks from fediverse.observer.",
168 parser.set_defaults(command=commands.fetch_observer)
169 parser.add_argument("--software", help="Name of software, e.g. 'lemmy'")
171 ### Fetch instances from fedipact.online ###
172 parser = subparser_command.add_parser(
174 help="Fetches blocks from fedipact.online.",
176 parser.set_defaults(command=commands.fetch_fedipact)
178 ### Fetch from pixelfed.org's API ###
179 parser = subparser_command.add_parser(
180 "fetch_pixelfed_api",
181 help="Fetches domain names from pixelfed.org's API",
183 parser.set_defaults(command=commands.fetch_pixelfed_api)
185 ### Check nodeinfo ###
186 parser = subparser_command.add_parser(
188 help="Checks if domain is part of nodeinfo.",
190 parser.set_defaults(command=commands.check_nodeinfo)
192 ### Fetch CSV from fedilist.com ###
193 parser = subparser_command.add_parser(
195 help="Fetches CSV from fedilist.com",
197 parser.set_defaults(command=commands.fetch_fedilist)
198 parser.add_argument("--software", help="Name of software, e.g. 'lemmy'")
199 parser.add_argument("--force", action="store_true", help="Include also already existing instances, otherwise only new are checked")
201 ### Update nodeinfo ###
202 parser = subparser_command.add_parser(
204 help="Updates nodeinfo for all instances",
206 parser.set_defaults(command=commands.update_nodeinfo)
207 parser.add_argument("--domain", help="Instance name (aka. domain)")
208 parser.add_argument("--software", help="Name of software, e.g. 'lemmy'")
209 parser.add_argument("--force", action="store_true", help="Forces update of data, no matter what.")
211 ### Fetch instances from instances.social ###
212 parser = subparser_command.add_parser(
213 "fetch_instances_social",
214 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!",
216 parser.set_defaults(command=commands.fetch_instances_social)
218 ### Convert international domain names to punycode domains ###
219 parser = subparser_command.add_parser(
221 help="Convertes UTF-8 encoded international domain names into punycode (IDNA) domain names.",
223 parser.set_defaults(command=commands.convert_idna)
225 ### Fetch instances from ActivityPub relays ###
226 parser = subparser_command.add_parser(
228 help="Fetches instances from ActivityPub relays",
230 parser.set_defaults(command=commands.fetch_relays)
231 parser.add_argument("--domain", help="Instance name (aka. 'relay')")
232 parser.add_argument("--force", action="store_true", help="Forces update of data, no matter what.")
234 logger.debug("EXIT!")
237 logger.debug("CALLED!")
238 args = _PARSER.parse_args()
240 if args.log_level is not None:
241 loggers = [logging.getLogger(name) for name in logging.root.manager.loggerDict]
242 for _logger in loggers:
243 _logger.setLevel(args.log_level)
245 logger.debug("args[%s]='%s'", type(args), args)
246 status = args.command(args)
248 logger.debug("status=%d - EXIT!", status)
252 logger.debug("Closing database connection ...")
253 database.connection.close()
255 logger.debug("Shutdown completed.")