|
@@ -822,3 +822,52 @@ def ffpb_remoteexec(bot, trigger):
|
|
|
target_alias,
|
|
|
err.output
|
|
|
))
|
|
|
+
|
|
|
+@willie.module.commands('forget-peer-sshhostkey')
|
|
|
+def ffpb_clearsshhostkey(bot, trigger):
|
|
|
+ """Forget given node's SSH host key"""
|
|
|
+
|
|
|
+ target_name = trigger.group(2) or ''
|
|
|
+ if len(target_name.strip()) == 0:
|
|
|
+ bot.say('Lasst uns einfach mal ' + trigger.nick + ' löschen!')
|
|
|
+ bot.say('Tipp: !forget-peer-sshhostkey <peer>')
|
|
|
+ return
|
|
|
+
|
|
|
+ # identify requested node or bail out
|
|
|
+ node = ffpb_findnode_from_botparam(bot, target_name,
|
|
|
+ ensure_recent_alfreddata=False)
|
|
|
+ if node is None:
|
|
|
+ return
|
|
|
+
|
|
|
+ # check ACL
|
|
|
+ if not playitsafe(bot, trigger, via_channel=True, node=node):
|
|
|
+ return
|
|
|
+
|
|
|
+ # derive target from node's MAC
|
|
|
+ node_mac = node.get('mac')
|
|
|
+ target = mac2ipv6(node_mac, 'fdca:ffee:ff12:132:')
|
|
|
+ target_alias = node["hostname"]
|
|
|
+
|
|
|
+ # assemble command
|
|
|
+ cmd = [
|
|
|
+ 'ssh-keygen',
|
|
|
+ '-f', '.ssh/known_hosts',
|
|
|
+ '-R',
|
|
|
+ target,
|
|
|
+ ]
|
|
|
+ try:
|
|
|
+ # call command
|
|
|
+ result = subprocess.check_output(
|
|
|
+ cmd,
|
|
|
+ stderr=subprocess.STDOUT,
|
|
|
+ shell=False,
|
|
|
+ )
|
|
|
+ bot.reply('Ich mache den Weg frei ... also den zu "' + target + '" per SSH zumindest.')
|
|
|
+
|
|
|
+ except subprocess.CalledProcessError as err:
|
|
|
+ bot.say('Fehler {0} bei remove-sshhostkey-of-peer({1}): {2}'.format(
|
|
|
+ err.returncode,
|
|
|
+ target_alias,
|
|
|
+ err.output
|
|
|
+ ))
|
|
|
+
|