MCPcopy Create free account
hub / github.com/PierreGode/Ragnar / generate_actions_json

Method generate_actions_json

shared.py:1419–1465  ·  view source on GitHub ↗

Generate the actions JSON file, it will be used to store the actions configuration.

(self)

Source from the content-addressed store, hash-verified

1417 mac_points = self.gamification_data.setdefault("mac_points", {})
1418 new_mac_count = 0
1419 points_awarded = 0
1420
1421 for mac in normalized:
1422 if mac in mac_points:
1423 continue
1424 mac_points[mac] = {
1425 "points": self.points_per_mac,
1426 "first_seen": datetime.utcnow().isoformat() + "Z"
1427 }
1428 new_mac_count += 1
1429 points_awarded += self.points_per_mac
1430
1431 if points_awarded:
1432 previous_points = self.gamification_data.get("total_points", 0)
1433 self.gamification_data["total_points"] = int(previous_points) + points_awarded
1434 prev_level = self.levelnbr
1435 self._update_gamification_state()
1436 self.save_gamification_data()
1437 logger.info(
1438 f"Awarded {points_awarded} points for {new_mac_count} new MAC address(es). "
1439 f"Level {prev_level} -> {self.levelnbr}"
1440 )
1441
1442 return new_mac_count, points_awarded
1443
1444 def delete_webconsolelog(self):
1445 """Delete the web console log file."""
1446 try:
1447 if os.path.exists(self.webconsolelog):
1448 os.remove(self.webconsolelog)
1449 logger.info(f"Deleted web console log file at {self.webconsolelog}")
1450 #recreate the file
1451
1452 else:
1453 logger.info(f"Web console log file not found at {self.webconsolelog} ...")
1454
1455 except OSError as e:
1456 logger.error(f"OS error occurred while deleting web console log file: {e}")
1457 except Exception as e:
1458 logger.error(f"Unexpected error occurred while deleting web console log file: {e}")
1459
1460 def create_livestatusfile(self):
1461 """Create the live status file, it will be used to store the current status of the scan."""
1462 try:
1463 if not os.path.exists(self.livestatusfile):
1464 with open(self.livestatusfile, 'w', newline='') as csvfile:
1465 csvwriter = csv.writer(csvfile)
1466 csvwriter.writerow(['Total Open Ports', 'Alive Hosts Count', 'All Known Hosts Count', 'Vulnerabilities Count'])
1467 csvwriter.writerow([0, 0, 0, 0])
1468 logger.info(f"Created live status file at {self.livestatusfile}")

Callers 3

setup_environmentMethod · 0.95
initialize_csvMethod · 0.80

Calls 4

debugMethod · 0.80
appendMethod · 0.80
errorMethod · 0.80
dumpMethod · 0.80

Tested by

no test coverage detected