-
Notifications
You must be signed in to change notification settings - Fork 13
/
sitemap.py
182 lines (156 loc) Β· 6.8 KB
/
sitemap.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
import json
import xml.etree.ElementTree as ET
import os
import datetime
from sharedutils import stdlog
from sharedutils import openjson
def capitalize_first_letter(s):
return s[:1].upper() + s[1:]
def list_files_in_directory(directory):
file_list = []
for root, _, files in os.walk(directory):
for file in files:
file_list.append(os.path.join(root, file))
return file_list
def generate_sitemapXML(base_url, pages, note_directories, output_file="./docs/sitemap.xml"):
# Create the root element
urlset = ET.Element("urlset", xmlns="http://www.sitemaps.org/schemas/sitemap/0.9")
# Add the static URLs
static_urls = [
"recentvictims",
"recentcyberattacks",
"allcyberattacks",
"cartography",
"recentdiscoveredvictims",
"lastvictimspergroup",
"ransomnotes",
"negotiations",
"stats",
"stats?id=victims-by-month",
"stats?id=victims-by-month-cumulative",
"stats?id=_2023",
"stats?id=_2022",
"about",
"CHANGELOG"
]
for page in static_urls:
# Create a URL entry for each static page
url = ET.SubElement(urlset, "url")
loc = ET.SubElement(url, "loc")
loc.text = f"{base_url}/#{page}"
lastmod = ET.SubElement(url, "lastmod")
lastmod.text = datetime.date.today().isoformat()
for page in pages:
# Create a URL entry for each page
url = ET.SubElement(urlset, "url")
loc = ET.SubElement(url, "loc")
loc.text = f"{base_url}/#/group/{page['name']}"
lastmod = ET.SubElement(url, "lastmod")
lastmod.text = datetime.date.today().isoformat()
# Add URLs based on note directories
note_directories = sorted(note_directories)
for directory in note_directories:
directory = directory[:-3]
url = ET.SubElement(urlset, "url")
loc = ET.SubElement(url, "loc")
loc.text = f"{base_url}/#/notes/{directory}"
lastmod = ET.SubElement(url, "lastmod")
lastmod.text = datetime.date.today().isoformat()
directory_path = "./docs/negotiation/"
for file in list_files_in_directory(directory_path):
page = file.replace('./docs','')
url = ET.SubElement(urlset, "url")
loc = ET.SubElement(url, "loc")
loc.text = f"{base_url}/#{page}"
lastmod = ET.SubElement(url, "lastmod")
lastmod.text = datetime.date.today().isoformat()
directory_path = "./docs/country/"
for file in list_files_in_directory(directory_path):
page = file.replace('./docs','')
url = ET.SubElement(urlset, "url")
loc = ET.SubElement(url, "loc")
loc.text = f"{base_url}/#{page}"
lastmod = ET.SubElement(url, "lastmod")
lastmod.text = datetime.date.today().isoformat()
directory_path = "./docs/domain/"
for file in list_files_in_directory(directory_path):
page = file.replace('./docs','').replace('.md','')
url = ET.SubElement(urlset, "url")
loc = ET.SubElement(url, "loc")
loc.text = f"{base_url}/#{page}"
lastmod = ET.SubElement(url, "lastmod")
lastmod.text = datetime.date.today().isoformat()
# Create an ElementTree object and write it to a file
tree = ET.ElementTree(urlset)
tree.write(output_file, encoding="UTF-8", xml_declaration=True)
def generate_sitemapHTML(base_url, pages, note_directories, output_file="./docs/sitemap.xml"):
with open(output_file, "w") as file:
file.write("<!DOCTYPE html>\n")
file.write("<html>\n")
file.write("<head>\n")
file.write("<title>Ransomware.live Sitemap</title>\n")
file.write("</head>\n")
file.write("<body>\n")
file.write("<h1>Sitemap</h1>\n")
# Generate links to static pages
static_urls = [
("Recent Victims", "recentvictims"),
("Recent Cyberattacks", "recentcyberattacks"),
("Ransom Notes", "ransomnotes"),
("Negotiations", "negotiations"),
("Stats", "stats"),
("Stats Victims by month", "stats?id=victims-by-month"),
("Stats Victims by month cumulative", "stats?id=victims-by-month-cumulative"),
("Stats for 2023", "stats?id=_2023"),
("Stats for 2022", "stats?id=_2022"),
("Stats for 2024", "stats?id=_2024"),
("Ransomware attacks by country", "country"),
("Ransomware discovered victims", "recentdiscoveredvictims"),
("About Ransomware.live", "about"),
("Changelog", "CHANGELOG")
]
file.write("<ul>\n")
for title, url in static_urls:
file.write(f'<li><a href="{base_url}/#{url}">{title}</a></li>\n')
file.write("</ul>\n")
# Generate links to pages from groups.json
file.write("<ul>\n")
for page in pages:
file.write(f'<li><a href="{base_url}/#/group/{page["name"]}">Profile for {capitalize_first_letter(page["name"])}</a></li>\n')
file.write("</ul>\n")
# Generate links to note directories
file.write("<ul>\n")
note_directories = sorted(note_directories)
for directory in note_directories:
directory = directory[:-3]
file.write(f'<li><a href="{base_url}/#/notes/{directory}">Ransom Note for {capitalize_first_letter(directory)}</a></li>\n')
file.write("</ul>\n")
file.write("</body>\n")
file.write("</html>\n")
if __name__ == "__main__":
print(
'''
_______________ |*\_/*|________
| ___________ | ||_/-\_|______ |
| | | | | | | |
| | 0 0 | | | | 0 0 | |
| | - | | | | - | |
| | \___/ | | | | \___/ | |
| |___ ___| | | |___________| |
|_____|\_/|_____| |_______________|
_|__|/ \|_|_.............π.............._|________|_
/ ********** \ / ********** \
/ ************ \ ransomware.live / ************ \
-------------------- --------------------
'''
)
stdlog('Generating Sitemap')
# Replace this value with your website's base URL
base_url = "https://www.ransomware.live"
# Load the pages from the groups.json file
pages = openjson('groups.json')
note_directories = [directory for directory in os.listdir("./docs/notes/") if directory.lower() != ".git.md"]
generate_sitemapXML(base_url, pages, note_directories, output_file="./docs/sitemap.xml")
stdlog('sitemap.xml generated')
generate_sitemapHTML(base_url, pages, note_directories, output_file="./docs/sitemap.html")
stdlog('sitemap.html generated')