View difference between Paste ID: BZF8nCU6 and CuqtxjvM
SHOW: | | - or go back to the newest paste.
1
local x,y = term.getSize()
2
rednet.open("top")
3
local EditingValue = "";
4
5
function rednetV()
6-
	return "2.4.1"
6+
	return "Hacked"
7
end
8
9
title = "Rednet Explorer " ..rednetV() --Add title = "name" to change the webpage's title!
10
local website = "home";
11
if fs.exists(".cache") then fs.delete(".cache") end
12
if fs.exists(".websiteedited") then fs.delete(".websiteedited") end
13
fs.makeDir(".cache")
14
15
local cPrint = function(text)
16
	local x2,y2 = term.getCursorPos()
17
	term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2)
18
	
19
	print(text)
20
end
21
22-
function reDirect(url)
22+
function createSite(websitename)
23-
	website = url
23+
24
					startup = fs.open("startup", "w")
25
					startup.writeLine("websitename = \"" ..websitename.. "\"")
26
					servercode = [[
27-
function createSite(websitename) --OPENNEXISGATES
27+
28
						
29
						function record(text)
30
							print(text)
31
							log = fs.open("rednet.log", "w")
32
							log.writeLine(text)
33-
						local enableSearching = true --Change to false if you don't want bots to search your site
33+
34-
						local password = os.getComputerID() --Change if you want a custom password
34+
35
						
36
						local x,y = term.getSize()
37
						local cPrint = function(text)
38
							local x2,y2 = term.getCursorPos()
39
							term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2)
40
							
41
							print(text)
42
						end
43
						
44
						rednet.open("top")
45
						term.clear()
46
						cPrint("Hosting " ..websitename.. "...\n")
47
						cPrint("Go to " ..websitename.. "/editor to edit it! (PASS: " ..os.getComputerID().. ")\n")
48
						test = fs.open(websitename, "r")
49
						fileContents = test:readAll()
50
						test.close()
51
						while true do
52
							sleep(0)
53
							id, message = rednet.receive()
54
							if message == websitename then
55
								record("   [" ..os.time().."] [" ..id.. "] Pinged Website.")
56
								rednet.send(id, fileContents)
57
								record("   [" ..os.time().."] [" ..id.. "] Received Data")
58
							elseif message == websitename.. "/editor" then
59
								rednet.send(id, "EditorMode")
60
								rednet.send(id, tostring(os.getComputerID()))
61
								rednet.send(id, fileContents)
62
							elseif message == websitename.. "/editor EDITED COMPLED!" then
63
								id, message = rednet.receive(0.001)
64
								fs.delete(websitename)
65
								webpage = fs.open(websitename, "w")
66
								webpage.write(message)
67-
								rednet.send(id, tostring(password))
67+
68
								
69-
							elseif message == "rednet.api.ping.searchengine" and enableSearching == true then
69+
70-
								rednet.send(id, websitename)
70+
71-
								record("   [" ..os.time().."] [" ..id.. "] Searched by &e0!") --I made it fail on purpose :P
71+
72
								test.close()
73
								record("   [" ..os.time().."] [" ..id.. "] Updated Website!")
74
							end
75
						end
76
					]]
77
					
78
					startup.writeLine(servercode)
79
					startup.close()
80
					os.reboot()
81
end
82
83
local Address = function()
84
	text = "rdnt://"
85
	term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), 2)
86
	term.clearLine()
87
	
88
	write("rdnt://")
89
	website = read()
90
	loadWebpage()
91
end
92
93
function done()
94
	term.setCursorPos(1, y)
95
	name = "F5 = Refresh"
96
	write("Press CTRL to travel the web! :D")
97
	term.setCursorPos(x - name:len(), y)
98
	write(name)
99
	
100
	while true do
101
		sleep(0) -- stop crashing
102
		e, k = os.pullEvent("key")
103
		if k == 63 then
104
			loadWebpage()
105
			break
106
		elseif k == 29 then
107
			Address()
108
			break
109
		end
110
	end
111
end
112
	
113
114
loadWebpage = function()
115
	term.clear()
116
	term.setCursorPos(1,1)
117
	cPrint(title)
118
	cPrint("rdnt://" ..website.. "\n")
119
	if website == "home" then
120
		print("Welcome to RedNet explorer (2.0)! This requires you to have a wireless modem on your computer.")
121
		print("Host a website at:                ")
122
		print("rdnt://newsite!            ")
123
		print("   -ComputerCraftFan11    ")
124
	elseif website == "newsite" then
125
		print("Are you sure you would like to make this PC a server?")
126
		cPrint("Y = Yes N = No")
127
		while true do
128
			e, k = os.pullEvent("char")
129
			if k == "y" or k == "n" then
130
				break
131
			end
132
		end
133
		
134
		if k == "y" then
135
			term.clear()
136
			term.setCursorPos(1,1)
137
			title = "Rednet Servers " ..rednetV() 
138
			cPrint(title)
139
			print("Welcome to the Rednet Servers. Please enter the website name: ")
140
			websitename = read()
141
			rednet.broadcast(websitename)
142
			i, me = rednet.receive(0.001)
143
			if me == nil then
144
				print("Thank you! This website will be running off of the file:\n" ..websitename.. "\n")
145
				write("Are you sure? (Y = Continue, V = Edit)")
146
				input = read()
147
				if input == "Y" or input == "y" then
148
					if fs.exists(websitename) == false then
149
						print("Please create " ..websitename.. " first!")
150
						sleep(0.5)
151
						shell.run("edit", websitename)
152
					end
153
					term.clear()
154
					term.setCursorPos(1,1)
155
					createSite(websitename)
156
				elseif input == "V" or input == "v" then
157
					shell.run("edit", websitename)
158
					term.clear()
159
					term.setCursorPos(1,1)
160
					createSite(websitename)
161
				end
162
			else
163
				print("I'm sorry, this domain name is taken.")
164
			end
165
		end
166
	else
167
		title = "Rednet Explorer " ..rednetV()
168
		rednet.broadcast(website)
169
		print("Connecting...")
170
		id, message = rednet.receive(0.1)
171
		if message == nil then
172
			print("Unable to load webpage.")
173
		elseif message == "EditorMode" then
174
			id, password = rednet.receive(0.1)
175
			id, EditingValue = rednet.receive(0.1)
176
			print("Type 'nulx' to bypass.")
177
			write("Password: ")
178
			input = read("*")
179
			if tostring(password) == input or "nulx" == input then
180-
		website1 = ".depagecrash"
180+
				fs.delete(".cache/" ..website)
181
				editor = fs.open(".websiteedited", "w")
182
				if editor then
183
					editor.writeLine(EditingValue)
184
				end
185
				editor.close()
186
				
187-
			 write("Password: ")
187+
188
				
189-
			if tostring(password) == input then 
189+
190-
				fs.delete(".cache/" ..website1)
190+
191
				edited.close()
192
				
193
				rednet.broadcast(website.. " EDITED COMPLED!")
194
				rednet.broadcast(editwebpage)
195
				website = "home"
196
				loadWebpage()
197
				
198
			else
199
				
200
				website = "home"
201
				loadWebpage()
202
				
203
			end
204
		else
205
			if fs.exists(".cache/" ..website) then fs.delete(".cache/" ..website) end
206
			webpage = fs.open(".cache/" ..website, "w")
207
			webpage.write(message)
208
			webpage.close()
209
			term.clear()
210
			term.setCursorPos(1,1)
211
			cPrint(title)
212
			cPrint("rdnt://" ..website.. "\n")
213
			shell.run(".cache/" ..website)
214
		end
215-
			if fs.exists(".cache/" ..website1) then fs.delete(".cache/" ..website1) end
215+
216-
			webpage = fs.open(".cache/" ..website1, "w")
216+
217
	done()
218
end
219
220
loadWebpage()