Skip to content

Commit 53dc125

Browse files
authored
Revert "V2 version of the server"
1 parent b723b93 commit 53dc125

6 files changed

+440
-366
lines changed

MaenUpdater.lua

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ local filesystem = require("filesystem")
33
local computer = require("computer")
44

55
shell.setWorkingDirectory("/home/myaenetwork/")
6-
shell.execute("rm *.lua")
6+
shell.execute("rm web.lua")
7+
shell.execute("rm account.lua")
78

89
print("Updating")
910
shell.execute("wget https://raw.githubusercontent.com/PoroCoco/myaenetwork/main/account.lua")
1011
shell.execute("wget https://raw.githubusercontent.com/PoroCoco/myaenetwork/main/web.lua")
12+
shell.execute("wget https://raw.githubusercontent.com/PoroCoco/myaenetwork/main/accountAux.lua")
13+
shell.execute("wget https://raw.githubusercontent.com/PoroCoco/myaenetwork/main/webAux.lua")
1114
shell.execute("wget https://raw.githubusercontent.com/PoroCoco/myaenetwork/main/MaenUpdater.lua")
12-
shell.execute("wget https://raw.githubusercontent.com/rxi/json.lua/master/json.lua")
13-
1415
shell.setWorkingDirectory("/home/")
1516
print("Rebooting")
1617
computer.shutdown(true)

account.lua

+13-97
Original file line numberDiff line numberDiff line change
@@ -1,107 +1,23 @@
1+
local computer = require("computer")
12
local component = require("component")
23
local internet = require("internet")
34
local filesystem = require("filesystem")
45
local shell = require("shell")
5-
local data = component.data
66

7-
local urlAccount = "http://myaenetwork.ovh/accountCreation"
8-
local webIdPath = "/home/myaenetwork/webIdentification.txt"
9-
local workDirectory = "/home/myaenetwork/"
10-
local newDirectory = "/home/myaenetwork"
117

12-
13-
14-
function isConfigCorrect(rid, rusername,rpassword) --checks if each line of the identification file as the right data
15-
if rid == nil or rusername == nil or rpassword == nil then
16-
return false
17-
end
18-
if rid == "" or rusername == "" or rpassword == "" then
19-
return false
20-
else
21-
return true
22-
end
23-
end
24-
25-
function createAccount()
26-
print("Let's configure your account")
27-
print("The account is linked to the computer, you will use the account username and password to connect on the web page")
28-
print("Choose your account username")
29-
local id = math.floor(math.random(1000000))
30-
local username = io.read()
31-
while username == "" or string.match(username, ";") do
32-
print("Your username cannot be empty or contain ';'")
33-
print("Choose your account username.")
34-
username = io.read()
35-
end
36-
print("Your username is ".. username)
37-
print()
38-
print("Choose your account password.")
39-
print("DO NOT USE A SENSITIVE PASSWORD, THEY ARE NOT ENCRYPTED")
40-
print("I RECOMMAND YOU TO USE A PIN/SMALL PASSWORD")
41-
local password = io.read()
42-
while password == "" or string.match(password, ";") do
43-
print("Your password cannot be empty or contain ';'")
44-
print("Choose your account password.")
45-
password = io.read()
46-
end
47-
if accountToServer(id,username,password) then
48-
print("Account creation accepted by the server")
49-
else
50-
print("Account creation denied by the server")
51-
print("Server might be offline or account already registered")
52-
print("Please try the account creation one more time WITH A DIFFERENT USERNAME. Otherwise contact PoroCoco#4636 on Discord")
53-
return
54-
end
55-
local f = io.open(webIdPath,"w") -- writes the infos into the identification file
56-
f:write("id = "..tostring(id), "\n")
57-
f:write("username = "..username, "\n")
58-
f:write("password = "..password)
59-
f:close()
60-
print("Configuration is done !")
61-
end
62-
63-
function accountToServer(id, username, password)
64-
local accountData = tostring(id)..";"..username..";"..password
65-
shell.setWorkingDirectory("/home/") -- if the server is down, internet.request will give an error so before trying it's going back to the basic dir
66-
if internet.request(urlAccount, data.encode64(accountData))() == "Account accepted" then
67-
shell.setWorkingDirectory(workDirectory)
68-
return true
69-
else
70-
shell.setWorkingDirectory(workDirectory)
71-
return false
8+
function architectureCheck()
9+
if computer.getArchitecture() ~= "Lua 5.3" then
10+
print("Your computer isn't running on the requiered architecture")
11+
print("The computer will change from Lua 5.2 to Lua 5.3. Please restart the program after the reboot :)")
12+
for i=1,5 do
13+
print(6-i)
14+
os.sleep(1)
15+
end
16+
computer.setArchitecture("Lua 5.3")
17+
computer.shutdown(true)
7218
end
7319
end
7420

75-
if not component.isAvailable("data") then
76-
print("Please insert a data card into the computer")
77-
end
78-
21+
architectureCheck()
7922

80-
if component.isAvailable("internet") then
81-
filesystem.makeDirectory(newDirectory)
82-
shell.setWorkingDirectory(workDirectory)
83-
if filesystem.exists(webIdPath) then --tries to read the identification file, if it cannot start an account creation
84-
local f = io.open(webIdPath,"r")
85-
local rid = f:read('*l')
86-
local rusername = f:read('*l')
87-
local rpassword = f:read('*l')
88-
if isConfigCorrect(rid,rusername,rpassword) then
89-
print("Computer is already configured")
90-
print("Your account "..rusername)
91-
print("Show account password ? Yes/No")
92-
if io.read() == "Yes" then
93-
print("Your account "..rpassword)
94-
end
95-
else
96-
print("config file isn't correct. Remaking one")
97-
createAccount()
98-
end
99-
f:close()
100-
shell.setWorkingDirectory("/home/")
101-
else
102-
createAccount()
103-
shell.setWorkingDirectory("/home/")
104-
end
105-
else
106-
print("Please insert the Internet Card into the computer")
107-
end
23+
os.execute("myaenetwork/accountAux.lua")

accountAux.lua

+116
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
local component = require("component")
2+
local internet = require("internet")
3+
local filesystem = require("filesystem")
4+
local shell = require("shell")
5+
6+
local urlAccount = "http://myaenetwork.ovh/accountCreation"
7+
local webIdPath = "/home/myaenetwork/webIdentification.txt"
8+
local workDirectory = "/home/myaenetwork/"
9+
local newDirectory = "/home/myaenetwork"
10+
11+
local bs = { [0] =
12+
'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P',
13+
'Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f',
14+
'g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v',
15+
'w','x','y','z','0','1','2','3','4','5','6','7','8','9','+','/',
16+
}
17+
18+
function encode(s)
19+
local byte, rep = string.byte, string.rep
20+
local pad = 2 - ((#s-1) % 3)
21+
s = (s..rep('\0', pad)):gsub("...", function(cs)
22+
local a, b, c = byte(cs, 1, 3)
23+
return bs[a>>2] .. bs[(a&3)<<4|b>>4] .. bs[(b&15)<<2|c>>6] .. bs[c&63]
24+
end)
25+
return s:sub(1, #s-pad) .. rep('=', pad)
26+
end
27+
28+
function isConfigCorrect(rid, rusername,rpassword) --checks if each line of the identification file as the right data
29+
if rid == nil or rusername == nil or rpassword == nil then
30+
return false
31+
end
32+
if rid == "" or rusername == "" or rpassword == "" then
33+
return false
34+
else
35+
return true
36+
end
37+
end
38+
39+
function createAccount()
40+
print("Let's configure your account")
41+
print("The account is linked to the computer, you will use the account username and password to connect on the web page")
42+
print("Choose your account username")
43+
local id = math.floor(math.random(1000000))
44+
local username = io.read()
45+
while username == "" or string.match(username, ";") do
46+
print("Your username cannot be empty or contain ';'")
47+
print("Choose your account username.")
48+
username = io.read()
49+
end
50+
print("Your username is ".. username)
51+
print()
52+
print("Choose your account password.")
53+
print("DO NOT USE A SENSITIVE PASSWORD, THEY ARE NOT ENCRYPTED")
54+
print("I RECOMMAND YOU TO USE A PIN/SMALL PASSWORD")
55+
local password = io.read()
56+
while password == "" or string.match(password, ";") do
57+
print("Your password cannot be empty or contain ';'")
58+
print("Choose your account password.")
59+
password = io.read()
60+
end
61+
if accountToServer(id,username,password) then
62+
print("Account creation accepted by the server")
63+
else
64+
print("Account creation denied by the server")
65+
print("Server might be offline or account already registered")
66+
print("Please try the account creation one more time WITH A DIFFERENT USERNAME. Otherwise contact PoroCoco#4636 on Discord")
67+
return
68+
end
69+
local f = io.open(webIdPath,"w") -- writes the infos into the identification file
70+
f:write("id = "..tostring(id), "\n")
71+
f:write("username = "..username, "\n")
72+
f:write("password = "..password)
73+
f:close()
74+
print("Configuration is done !")
75+
end
76+
77+
function accountToServer(id, username, password)
78+
local accountData = tostring(id)..";"..username..";"..password
79+
shell.setWorkingDirectory("/home/") -- if the server is down, internet.request will give an error so before trying it's going back to the basic dir
80+
if internet.request(urlAccount, encode(accountData))() == "Account accepted" then
81+
shell.setWorkingDirectory(workDirectory)
82+
return true
83+
else
84+
shell.setWorkingDirectory(workDirectory)
85+
return false
86+
end
87+
end
88+
89+
if component.isAvailable("internet") then
90+
filesystem.makeDirectory(newDirectory)
91+
shell.setWorkingDirectory(workDirectory)
92+
if filesystem.exists(webIdPath) then --tries to read the identification file, if it cannot start an account creation
93+
local f = io.open(webIdPath,"r")
94+
local rid = f:read('*l')
95+
local rusername = f:read('*l')
96+
local rpassword = f:read('*l')
97+
if isConfigCorrect(rid,rusername,rpassword) then
98+
print("Computer is already configured")
99+
print("Your account "..rusername)
100+
print("Show account password ? Yes/No")
101+
if io.read() == "Yes" then
102+
print("Your account "..rpassword)
103+
end
104+
else
105+
print("config file isn't correct. Remaking one")
106+
createAccount()
107+
end
108+
f:close()
109+
shell.setWorkingDirectory("/home/")
110+
else
111+
createAccount()
112+
shell.setWorkingDirectory("/home/")
113+
end
114+
else
115+
print("Please insert the Internet Card into the computer")
116+
end

autoInstall.lua

+5-2
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,14 @@ if not filesystem.exists("/home/myaenetwork") then
1111
shell.execute("wget https://raw.githubusercontent.com/PoroCoco/myaenetwork/main/account.lua")
1212
shell.execute("wget https://raw.githubusercontent.com/PoroCoco/myaenetwork/main/web.lua")
1313
shell.execute("wget https://raw.githubusercontent.com/PoroCoco/myaenetwork/main/MaenUpdater.lua")
14-
shell.execute("wget https://raw.githubusercontent.com/rxi/json.lua/master/json.lua")
14+
shell.execute("wget https://raw.githubusercontent.com/PoroCoco/myaenetwork/main/accountAux.lua")
15+
shell.execute("wget https://raw.githubusercontent.com/PoroCoco/myaenetwork/main/webAux.lua")
1516
shell.setWorkingDirectory("/home/")
1617
filesystem.remove("home/autoInstall.lua")
1718
print("Done")
18-
19+
print("Switching computer architecture to Lua 5.3")
20+
os.sleep(2)
21+
computer.setArchitecture("Lua 5.3")
1922

2023
else
2124
print("Already installed")

0 commit comments

Comments
 (0)