· 10 months ago · Feb 25, 2025, 02:05 PM
1
2
3-----------------PASTEBINs--------------------------
4installer = "PTGLduYm"
5
6player_module = "rWp0GXDW"
7redstone_module = "KkCYWkSU"
8fluid_module = "x7K3zUAC"
9energy_module = "RxLuZWHp"
10
11hash_api = "FLQ68J88"
12startup = "KnmEN37h"
13---------------------------------------------
14term.clear()
15local token = ''
16local module_name = ''
17local username = ''
18local type = ''
19local updating = false
20
21function draw_text_term(x, y, text, text_color, bg_color)
22 term.setTextColor(text_color)
23 term.setBackgroundColor(bg_color)
24 term.setCursorPos(x,y)
25 write(text)
26end
27
28function draw_line_term(x, y, length, color)
29 term.setBackgroundColor(color)
30 term.setCursorPos(x,y)
31 term.write(string.rep(" ", length))
32end
33
34function bars()
35 draw_line_term(1, 1, 51, colors.lime)
36 draw_line_term(1, 19, 51, colors.lime)
37 draw_text_term(12, 1, 'CraftNanny Module Installer', colors.gray, colors.lime)
38 draw_text_term(17, 19, 'mrjohndowe.com/craftnanny', colors.gray, colors.lime)
39end
40
41-- saves current token variable to local text file
42function save_config()
43 sw = fs.open("config.txt", "w")
44 sw.writeLine(token)
45 sw.writeLine(module_name)
46 sw.writeLine(username)
47 sw.writeLine(type)
48 sw.close()
49end
50
51function load_config()
52 sr = fs.open("config.txt", "r")
53 token = sr.readLine()
54 module_name = sr.readLine()
55 username = sr.readLine()
56 type = sr.readLine()
57 sr.close()
58end
59
60function launch_module()
61 shell.run("CN_module")
62end
63
64function install_module()
65 if type == '1' then
66 pastebin = player_module
67 else if type == '2' then
68 pastebin = energy_module
69 else if type == '3' then
70 pastebin = fluid_module
71 else if type == '4' then
72 pastebin = redstone_module
73 end
74 end
75 end
76 end
77
78 term.clear()
79 bars()
80 draw_text_term(1, 3, 'successfully logged in', colors.lime, colors.black)
81 sleep(0.5)
82 draw_text_term(1, 4, 'installing...', colors.white, colors.black)
83 sleep(0.5)
84
85 draw_text_term(1, 5, 'removing old versions', colors.white, colors.black)
86 if fs.exists("CN_module") then
87 fs.delete("CN_module")
88 end
89 sleep(0.5)
90
91 draw_text_term(1, 6, 'fetch from pastebin', colors.white, colors.black)
92 term.setCursorPos(1,7)
93 term.setTextColor(colors.white)
94 shell.run("pastebin get "..pastebin.." CN_module")
95 sleep(0.5)
96
97 draw_text_term(1, 9, 'create startup file', colors.white, colors.black)
98 term.setCursorPos(1,10)
99 term.setTextColor(colors.white)
100 if fs.exists("startup") then
101 fs.delete("startup")
102 end
103 shell.run("pastebin get "..startup.." startup")
104 sleep(1)
105
106 draw_text_term(1, 13, 'Setup Complete', colors.lime, colors.black)
107
108 draw_text_term(1, 14, 'press enter to continue', colors.lightGray, colors.black)
109
110 if updating then
111
112 else
113 input = read()
114 end
115
116 launch_module()
117end
118
119function hash(password)
120 shell.run("pastebin get "..hash_api.." sha1_api")
121 os.loadAPI('sha1_api')
122 response = http.post(
123 "http://mrjohndowe.com/craftnanny/code/salt.php",
124 "user="..user)
125 salt = response.readAll()
126 hash = sha1_api.sha1(salt..password)
127 return hash
128end
129
130function login()
131 term.clear()
132 bars()
133 draw_text_term(1, 3, 'Register module to your CraftNanny account.', colors.lime, colors.black)
134 draw_text_term(1, 4, 'Create an account at www.mrjohndowe.com/craftnanny', colors.lightGray, colors.black)
135
136 draw_text_term(1, 6, 'Username: ', colors.lime, colors.black)
137 term.setTextColor(colors.white)
138 user = read()
139 draw_text_term(1, 7, 'Password: ', colors.lime, colors.black)
140 term.setTextColor(colors.white)
141 pass = read("*")
142
143 password = hash(pass)
144
145 response = http.post(
146 "http://mrjohndowe.com/craftnanny/code/signin.php",
147 "user="..user.."&pass="..password.."&id="..os.getComputerID().."&name="..module_name.."&module_type="..type)
148 token = response.readAll()
149
150 if token == 'error' then
151 draw_text_term(1, 8, 'login failed', colors.red, colors.black)
152 sleep(2)
153 login()
154 else
155 username = user
156 save_config()
157 install_module()
158 end
159end
160
161function name()
162 term.clear()
163 bars()
164
165 draw_text_term(1, 3, 'Give this module a unique name:', colors.lime, colors.black)
166 term.setCursorPos(2,4)
167 term.setTextColor(colors.white)
168 module_name = read()
169 os.setComputerLabel(string.gsub(module_name, "%s+", ""))
170 login()
171end
172
173function player_tracker()
174
175 -- code to check that openperipheral sensor is present. give relavent error
176
177 type = '1'
178 name()
179end
180
181function choose_module(input)
182 if input == '1' then
183 player_tracker()
184 elseif input == '2' then
185 type = '2'
186 name()
187 elseif input == '3' then
188 type = '3'
189 name()
190 elseif input == '4' then
191 type = '4'
192 name()
193 elseif input == '5' then
194
195 end
196
197end
198
199function install_select()
200 term.clear()
201 bars()
202 draw_text_term(15, 3, 'Welcome to CraftNanny!', colors.lime, colors.black)
203 draw_text_term(1, 5, 'What module would you like to install?', colors.white, colors.black)
204
205 draw_text_term(2, 7, '1. Player Tracking', colors.white, colors.black)
206 draw_text_term(2, 8, '2. Energy Monitor', colors.white, colors.black)
207 draw_text_term(2, 9, '3. Fluid Monitor', colors.white, colors.black)
208 draw_text_term(2, 10, '4. Redstone Controls', colors.white, colors.black)
209 draw_text_term(2, 11, '5. Rednet Controls', colors.white, colors.black)
210 draw_text_term(1, 13, 'Enter number:', colors.white, colors.black)
211 term.setCursorPos(1,14)
212 term.setTextColor(colors.white)
213 input = read()
214
215 choose_module(input)
216end
217
218function start()
219 term.clear()
220 if fs.exists("config.txt") then
221 load_config()
222 updating = true
223 install_module()
224 else
225 install_select()
226 end
227end
228
229start()