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
0 commit comments