This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
boudragon's profile picture

Boutech System Restore

Started by boudragon, 29 September 2013 - 09:43 PM
boudragon #1
Posted 29 September 2013 - 11:43 PM
After a long break of programming I decided to get back into it and finish what I started with my Login System. I ripped apart the Pastebin program to see just what made it work and discovered I could use a tiny snippet of it to pull files from my Pastebin account to restore an entire system worth of files. Please keep in mind that this is still a WIP and may have some bugs but as of right now it seems to get the job done. It currently points to some of my files including the Login System I linked above (fully functional), a system file (this file is a place holder for the Login System) and a startup file. Please DO NOT use this System Restore on a computer that you have any important files on! It WILL delete everything that is not read only on the system! Here is the full feature list:

FEATURES
  • After running the program it will verify that you want to continue to avoid accidental erasure of your files. Default option is set to "NO" for this purpose.
  • Program will format the system and remove all files and folders that are not read only protected.
  • The System Restore program will ignore the disk drive all together as the program itself must reside on a disk to function properly. (Have not tested if it works while on the system itself yet.)
  • After formatting the system it will add folders designated by the program.
  • Recovers files designated in the program directly from Pastebin.
  • Once completed the system will reboot and your system should be restored according to the files and folders designated.
OTHER COMMENTS
  • Ctrl-T is disallowed once the the process has begun to avoid damaging the system.
  • Easy to modify to suit your needs. Easy to manipulate functions at the beginning of the program allow you to add, modify or remove files or folders.
  • Clean GUI to make this program easy to use for any level of user.
PLANNED FEATURES
  • Integration into an overall OS where the system boots and does a system check. (memory, file structure etc.) If the check fails it will initiate a system restore sequence from disk to restore the system to it's previous state including any back-up files saved.
  • Clean up program and add any additional fail safes to prevent program crashes or failures in file downloading.
Spoiler

term.clear()
term.setCursorPos(1,1)
sid = 0
rep = 0
rep2 = 0
pbfile = 0
function mkdir()
  shell.run("mkdir /pending")
  shell.run("mkdir /users")
end
function sysrest()
  while rep2 <= 3 do
	if pbfile == 0 then
	  sCode = "tK3ikweu"
	  sFile = "login"
	elseif pbfile == 1 then
	  sCode = "daTg13eG"
	  sFile = "pb"
	elseif pbfile == 2 then
	  sCode = "tt4xZhjX"
	  sFile = "system"
	elseif pbfile == 3 then
	  sCode = "mciJr52F"
	  sFile = "startup"
	end
  local sPath = ("/".. sFile)
  local response = http.get("http://pastebin.com/raw.php?i="..textutils.urlEncode(sCode))
	if response then
	  local sResponse = response.readAll()
	  response.close()
	  local file = fs.open(sPath, "w")
	  file.write(sResponse)
	  file.close()
	  pbfile = pbfile+1
	  rep2 = rep2+1
	else
	rep2 = 4
	end
  end
end
function format()
  for _, f in pairs(fs.list("/")) do
	if not fs.isReadOnly(f) then
	  fs.delete(f)
	end
  end
end
function timer()
  sleep(0.2) write(".")
  sleep(0.2) write(".")
  sleep(0.2) write(".")
  sleep(0.3) write(" DONE!")
  sleep(0.3)
end
function clear()
  term.clear()
  term.setCursorPos(1,1)
end
function menu(id, text)
  if sid == id then
	write(">> ")
  else
	write("   ")
  end
  print(text)
end
while rep == 0 do
  clear()
  print("|=================================================|")
  print("|		   BouTech System Restore v1.3		   |")
  print("|=================================================|")
  term.setCursorPos(19,5)
  print(":: WARNING! ::")
  print(" This action will erase ALL data currently on this ")
  print("		  system and restore files for the		 ")
  print("			  BouTech Managment System			 ")
  print("")
  print("		   Continue with system restore?		   ")
  term.setCursorPos(16,11)
  menu(0, "NO")
  term.setCursorPos(29,11)
  menu(1, "YES")
  event, key = os.pullEvent("key")
  if key == 205 then
	if sid == 0 then
	  sid = 1
	elseif sid == 1 then
	  sid = 0
	end
  elseif key == 203 then
	if sid == 0 then
	  sid = 1
	elseif sid == 1 then
	  sid = 0
	end
  elseif key == 28 then
	if sid == 1 then
	  if not http then
		term.setCursorPos(1,14)
		print("|=================================================|")
		print("|   HTTP API must be enabled to restore system.   |")
		print("| Set enableAPI_http to true in ComputerCraft.cfg |")
		print("|			 System will now reboot.			 |")
		print("|=================================================|")
		sleep(3)
		return
	  end
	  clear()
	  os.pullEvent = os.pullEventRaw
	  print("|=================================================|")
	  print("|		   BouTech System Restore v1.3		   |")
	  print("|=================================================|")
	  term.setCursorPos(10,5)
	  print(":: SYSTEM RESTORE IN PROGRESS! ::")
	  sleep(0.5)
	  term.setCursorPos(17,7)
	  write("Formatting")
	  timer()
	  format()
	  term.setCursorPos(15,8)
	  write("Adding Folders")
	  timer()
	  mkdir()
	  term.setCursorPos(14,9)
	  write("Recovering Files")
	  timer()
	  sysrest()
	  term.setCursorPos(9,10)
	  write("Installing Files To System")
	  timer()
	  sleep(1)
	  term.setCursorPos(1,17)
	  write("|=================================================|")
	  write("|	Restore complete. System will now reboot.	|")
	  write("|=================================================|")
	  sleep(2)
	  rep = 1
	  clear()
	  os.reboot()
	elseif sid == 0 then
	  term.setCursorPos(1, 17)
	  print("|=================================================|")
	  print("|	Restore canceled. System will now reboot.	|")
	  print("|=================================================|")
	  sleep(2)
	  rep = 1
	  clear()
	  os.reboot()
	end
  end
end

PASTEBIN
  • Pastebin get 8sbPWVgA or go to Pastebin.
Please feel free to comment or make suggestions!

No screenshots yet as I do not feel they are necessary but if you feel you need some post here and request some.
MKlegoman357 #2
Posted 30 September 2013 - 02:19 AM
Ok… :mellow:/>

Localize variables and functions:

local me = "Hi"

local function you ()
  print(me)
end

———————————————————–


shell.run("mkdir /pending")

Use shell.run() ONLY when you want to run an external program. Use fs.makeDir() to create a folder/directory.

———————————————————–

Your GUI is hardcoded. It means that it is compatible with only one screen size. You should make it to be compatible with all screen sizes.

———————————————————–

This message is spelled wrong:


write("Installing Files To System")
timer()
sleep(1)

--//Should be this:
write("Waiting for 1 second for no reason... I mean more than 2 seconds")
timer()
sleep(1)

Actually, shorten sleep times because this process takes less than a second and you make it to look like it takes a lot of time.

———————————————————–

You don't need to clear the screen or reset your variables if you are going to reboot the computer:


term.setCursorPos(1, 17)
print("|=================================================|")
print("|	  Restore canceled. System will now reboot.	   |")
print("|=================================================|")
sleep(2)
rep = 1
clear()
os.reboot()

———————————————————–

I hope I didn't miss anything :D/>!
boudragon #3
Posted 30 September 2013 - 08:03 AM
Anything that takes time is strictly for effect… you want it shorter you can shorten it. I hard coded the GUI because this is being tied into a series of other programs for my purposes. Also because I generally don't use any other size or an attached monitor but It is easy to adjust to your liking should you need it larger or smaller. I have the functions there for easy manipulation of adding files and folders. The only one that isn't critical is the format() function but I figured why not since I am learning more about functions.

The only valid argument that I see is instead of using shell.run to use fs.makeDIR() and even then they both do the same thing. The program runs fine and nothing seems to break so what's the difference?

So take it easy on me Nit-Pick Mcgee! :)/> Besides… only my 3rd program ;)/>

PS - Thank you for the formatting feature BTW MKlegoman357 ;)/>
boudragon #4
Posted 30 September 2013 - 08:12 AM
??? I'm sorry what are you talking about TechBlaster? What Parallel.WairForAny are you talking about?
Wojbie #5
Posted 30 September 2013 - 08:12 AM
The only valid argument that I see is instead of using shell.run to use fs.makeDIR() and even then they both do the same thing. The program runs fine and nothing seems to break so what's the difference?

Simple - Someone could make program named mkdir in / that would be run instead of standard mkdir program - allowing someone's code to be run inside of your program - and it allow someone to simply take over whole system.

With fs.makeDIR() you know you are making folder. With shell.run you run something - with no 100% insurance it will do its job.

While i realize you are deleting all files from computer with format() before its still security flaw that could be used to bring whole system down.
boudragon #6
Posted 30 September 2013 - 08:16 AM
Ahhh see now THAT makes sense. Thank you for the explanation. I can fix that easy enough. But like you just said with this program it is deleting files and prevents CTRL-T from being used during the process so for this the point is almost moot… but either way a good catch thank you!
MKlegoman357 #7
Posted 30 September 2013 - 02:00 PM
??? I'm sorry what are you talking about TechBlaster? What Parallel.WairForAny are you talking about?
It allows 2 programs to run at once.


This and a virus running means disaster.

What?
boudragon #8
Posted 30 September 2013 - 11:13 PM
I said the same thing MKlegoman357… :-p
svdragster #9
Posted 02 October 2013 - 11:30 AM
Why is the computer rebooting when the program finishes?
boudragon #10
Posted 02 October 2013 - 12:08 PM
Because one of the files restored is a startup file which tells the computer to run the system login :)/> Sure I could just tell it to close out and open up the login program but what fun would that be? :-p
svdragster #11
Posted 02 October 2013 - 12:12 PM
Well, if you want to make it compatible with any Os, you should just close the program instead of rebooting :P/>
boudragon #12
Posted 02 October 2013 - 12:15 PM
Its not meant to be compatible with another OS… its meant to be part of MY OS :)/> Besides you can plug it in regardless… the files it recovers can easily be changed in the coding to be YOUR files instead of mine…