craniumkid22

SmartPaste Firewolf Edition

Jan 7th, 2013
1,811
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 94.16 KB | None | 0 0
  1. --check Firewolf installation
  2. local fWolf = false
  3. if browserAgent then
  4.     if browserAgent:find("Firewolf") then
  5.         fWolf = true
  6.     end
  7. else
  8.     fWolf = false
  9. end
  10.  
  11. --check for HTTP API
  12. if not http then
  13.     print("Please enable the HTTP API within the ComputerCraft configuration.")
  14.     return
  15. end
  16.  
  17. local devKey = "3575e50cc6635311078014a550bc3f9f"
  18. local userKey = ""
  19. local username = "TEMP_USER"
  20. local password = "TEMP_PASSWORD"
  21. local logged = false
  22. local syntaxTab = {
  23.     menuNames = {
  24.         '4CS',                  '6502 ACME Cross Assembler','6502 Kick Assembler',      '6502 TASM/64TASS',
  25.         'ABAP',                 'ActionScript',             'ActionScript 3',           'Ada',
  26.         'ALGOL 68',             'Apache Log',               'AppleScript',              'APT Sources',
  27.         'ARM',                  'ASM (NASM)',               'ASP',                      'Asymptote',
  28.         'autoconf',             'Autohotkey',               'AutoIt',                   'Avisynth',
  29.         'Awk',                  'BASCOM AVR',               'Bash',                     'Basic4GL',
  30.         'BibTeX',               'Blitz Basic',              'BNF',                      'BOO',
  31.         'BrainFuck',            'C',                        'C for Macs',               'C Intermediate Language',
  32.         'C#',                   'C++',                      'C++ (with QT extensions)', 'C: Loadrunner',
  33.         'CAD DCL',              'CAD Lisp',                 'CFDG',                     'ChaiScript',
  34.         'Clojure',              'Clone C',                  'Clone C++',                'CMake',
  35.         'COBOL',                'CoffeeScript',             'ColdFusion',               'CSS',
  36.         'Cuesheet',             'D',                        'DCL',                      'DCPU-16',
  37.         'DCS',                  'Delphi',                   'Delphi Prism (Oxygene)',   'Diff',
  38.         'DIV',                  'DOS',                      'DOT',                      'E',
  39.         'ECMAScript',           'Eiffel',                   'Email',                    'EPC',
  40.         'Erlang',               'F#',                       'Falcon',                   'FO Language',
  41.         'Formula One',          'Fortran',                  'FreeBasic',                'FreeSWITCH',
  42.         'GAMBAS',               'Game Maker',               'GDB',                      'Genero',
  43.         'Genie',                'GetText',                  'Go',                       'Groovy',
  44.         'GwBasic',              'Haskell',                  'Haxe',                     'HicEst',
  45.         'HQ9 Plus',             'HTML',                     'HTML 5',                   'Icon',
  46.         'IDL',                  'INI file',                 'Inno Script',              'INTERCAL',
  47.         'IO',                   'J',                        'Java',                     'Java 5',
  48.         'JavaScript',           'jQuery',                   'KiXtart',                  'Latex',
  49.         'LDIF',                 'Liberty BASIC',            'Linden Scripting',         'Lisp',
  50.         'LLVM',                 'Loco Basic',               'Logtalk',                  'LOL Code',
  51.         'Lotus Formulas',       'Lotus Script',             'LScript',                  'Lua',
  52.         'M68000 Assembler',     'MagikSF',                  'Make',                     'MapBasic',
  53.         'MatLab',               'mIRC',                     'MIX Assembler',            'Modula 2',
  54.         'Modula 3',             'Motorola 68000 HiSoft Dev','MPASM',                    'MXML',
  55.         'MySQL',                'Nagios',                   'newLISP',                  'None',
  56.         'NullSoft Installer',   'Oberon 2',                 'Objeck Programming Langua','Objective C',
  57.         'OCalm Brief',          'OCaml',                    'Octave',                   'OpenBSD PACKET FILTER',
  58.         'OpenGL Shading',       'Openoffice BASIC',         'Oracle 11',                'Oracle 8',
  59.         'Oz',                   'ParaSail',                 'PARI/GP',                  'Pascal',
  60.         'PAWN',                 'PCRE',                     'Per',                      'Perl',
  61.         'Perl 6',               'PHP',                      'PHP Brief',                'Pic 16',
  62.         'Pike',                 'Pixel Bender',             'PL/SQL',                   'PostgreSQL',
  63.         'POV-Ray',              'Power Shell',              'PowerBuilder',             'ProFTPd',
  64.         'Progress',             'Prolog',                   'Properties',               'ProvideX',
  65.         'PureBasic',            'PyCon',                    'Python',                   'Python for S60',
  66.         'q/kdb+',               'QBasic',                   'R',                        'Rails',
  67.         'REBOL',                'REG',                      'Rexx',                     'Robots',
  68.         'RPM Spec',             'Ruby',                     'Ruby Gnuplot',             'SAS',
  69.         'Scala',                'Scheme',                   'Scilab',                   'SdlBasic',
  70.         'Smalltalk',            'Smarty',                   'SPARK',                    'SPARQL',
  71.         'SQL',                  'StoneScript',              'SystemVerilog',            'T-SQL',
  72.         'TCL',                  'Tera Term',                'thinBasic',                'TypoScript',
  73.         'Unicon',               'UnrealScript',             'UPC',                      'Urbi',
  74.         'Vala',                 'VB.NET',                   'Vedit',                    'VeriLog',
  75.         'VHDL',                 'VIM',                      'Visual Pro Log',           'VisualBasic',
  76.         'VisualFoxPro',         'WhiteSpace',               'WHOIS',                    'Winbatch',
  77.         'XBasic',               'XML',                      'Xorg Config',              'XPP',
  78.         'YAML',                 'Z80 Assembler',            'ZXBasic'
  79.         },
  80.     urlCodes = {
  81.         '4cs',                  '6502acme',                 '6502kickass',              '6502tasm',
  82.         'abap',                 'actionscript',             'actionscript3',            'ada',
  83.         'algol68',              'apache',                   'applescript',              'apt_sources',
  84.         'arm',                  'asm',                      'asp',                      'asymptote',
  85.         'autoconf',             'autohotkey',               'autoit',                   'avisynth',
  86.         'awk',                  'bascomavr',                'bash',                     'basic4gl',
  87.         'bibtex',               'blitzbasic',               'bnf',                      'boo',
  88.         'bf',                   'c',                        'c_mac',                    'cil',
  89.         'csharp',               'cpp',                      'cpp-qt',                   'c_loadrunner',
  90.         'caddcl',               'cadlisp',                  'cfdg',                     'chaiscript',
  91.         'clojure',              'klonec',                   'klonecpp',                 'cmake',
  92.         'cobol',                'coffeescript',             'cfm',                      'css',
  93.         'cuesheet',             'd',                        'dcl',                      'dcpu16',
  94.         'dcs',                  'delphi',                   'oxygene',                  'diff',
  95.         'div',                  'dos',                      'dot',                      'e',
  96.         'ecmascript',           'eiffel',                   'email',                    'epc',
  97.         'erlang',               'fsharp',                   'falcon',                   'fo',
  98.         'f1',                   'fortran',                  'freebasic',                'freeswitch',
  99.         'gambas',               'gml',                      'gdb',                      'genero',
  100.         'genie',                'gettext',                  'go',                       'groovy',
  101.         'gwbasic',              'haskell',                  'haxe',                     'hicest',
  102.         'hq9plus',              'html4strict',              'html5',                    'icon',
  103.         'idl',                  'ini',                      'inno',                     'intercal',
  104.         'io',                   'j',                        'java',                     'java5',
  105.         'javascript',           'jquery',                   'kixtart',                  'latex',
  106.         'ldif',                 'lb',                       'lsl2',                     'lisp',
  107.         'llvm',                 'locobasic',                'logtalk',                  'lolcode',
  108.         'lotusformulas',        'lotusscript',              'lscript',                  'lua',
  109.         'm68k',                 'magiksf',                  'make',                     'mapbasic',
  110.         'matlab',               'mirc',                     'mmix',                     'modula2',
  111.         'modula3',              '68000devpac',              'mpasm',                    'mxml',
  112.         'mysql',                'nagios',                   'newlisp',                  'text',
  113.         'nsis',                 'oberon2',                  'objeck',                   'objc',
  114.         'ocaml-brief',          'ocaml',                    'octave',                   'pf',
  115.         'glsl',                 'oobas',                    'oracle11',                 'oracle8',
  116.         'oz',                   'parasail',                 'parigp',                   'pascal',
  117.         'pawn',                 'pcre',                     'per',                      'perl',
  118.         'perl6',                'php',                      'php-brief',                'pic16',
  119.         'pike',                 'pixelbender',              'plsql',                    'postgresql',
  120.         'povray',               'powershell',               'powerbuilder',             'proftpd',
  121.         'progress',             'prolog',                   'properties',               'providex',
  122.         'purebasic',            'pycon',                    'python',                   'pys60',
  123.         'q',                    'qbasic',                   'rsplus',                   'rails',
  124.         'rebol',                'reg',                      'rexx',                     'robots',
  125.         'rpmspec',              'ruby',                     'gnuplot',                  'sas',
  126.         'scala',                'scheme',                   'scilab',                   'sdlbasic',
  127.         'smalltalk',            'smarty',                   'spark',                    'sparql',
  128.         'sql',                  'stonescript',              'systemverilog',            'tsql',
  129.         'tcl',                  'teraterm',                 'thinbasic',                'typoscript',
  130.         'unicon',               'uscript',                  'ups',                      'urbi',
  131.         'vala',                 'vbnet',                    'vedit',                    'verilog',
  132.         'vhdl',                 'vim',                      'visualprolog',             'vb',
  133.         'visualfoxpro',         'whitespace',               'whois',                    'winbatch',
  134.         'xbasic',               'xml',                      'xorg_conf',                'xpp',
  135.         'yaml',                 'z80',                      'zxbasic'--check for arguments
  136. local function usage()
  137.     print("Usage:")
  138.     print(shell.getRunningProgram().." <get> <pastebin code> <save file> [username]")
  139.     print(shell.getRunningProgram().." <put> <save file> [username]")
  140.     print("Required: < >")
  141.     print("Optional: [ ]")
  142. end
  143.  
  144. local tArgs = {...}
  145. if #tArgs >= 2 and #tArgs <= 4 then
  146.     if tArgs[1] == "get" then
  147.         print("Retrieving from url: http://pastebin.com/"..tArgs[2])
  148.         print("Saving to file: "..tArgs[3])
  149.         if #tArgs[2] > 8 or #tArgs[2] < 8 then
  150.             print("Invalid Pastebin code!")
  151.             return
  152.         else
  153.             print("Connecting to Pastebin...")
  154.             local site = http.get("http://pastebin.com/raw.php?i="..tArgs[2])
  155.             if not site then
  156.                 print("Unable to connect to Pastebin!")
  157.                 return
  158.             else
  159.                 print("Connected! Reading url contents...")
  160.                 local siteContent = site.readAll()
  161.                 if not fs.exists(tArgs[3]) then
  162.                     local file = fs.open(tArgs[3], "w")
  163.                     file.write(siteContent)
  164.                     file.close()
  165.                     print("Download complete! Saved as '"..tArgs[3].."'")
  166.                     return
  167.                 else
  168.                     print("File already exists!")
  169.                     return
  170.                 end
  171.             end
  172.         end
  173.     elseif tArgs[1] == "put" then
  174.         local badResponses = {
  175.             "Bad API request, IP blocked",
  176.             "Bad API request, api_paste_code was empty",
  177.             "Bad API request, maximum paste file size exceeded"
  178.             }
  179.         if not fs.exists(tArgs[2]) then
  180.             print("No file exists!")
  181.             return
  182.         else
  183.             if not tArgs[3] then
  184.                 print("Reading file...")
  185.                 local file = fs.open(tArgs[2], "r")
  186.                 local postText = file.readAll()
  187.                 file.close()
  188.                 local postName = tArgs[2]
  189.  
  190.                 local response = http.post(
  191.                     "http://pastebin.com/api/api_post.php",
  192.                     "api_option=paste&"..
  193.                     "api_dev_key="..devKey.."&"..
  194.                     "api_paste_format=lua&"..
  195.                     "api_paste_name="..textutils.urlEncode(postName).."&"..
  196.                     "api_paste_code="..textutils.urlEncode(postText)
  197.                     ).readAll()
  198.                 if response then
  199.                     for i = 1, #badResponses do
  200.                         if response == badResponses[i] then
  201.                             print(badResponses[i])
  202.                             return
  203.                         else
  204.                             print("Save successful! File stored at:\n"..response)
  205.                             return
  206.                         end
  207.                     end
  208.                 else
  209.                     print("Unable to connect to Pastebin! Please try again.")
  210.                 end
  211.             else
  212.                 print("Using private authentication. Password required!")
  213.                 write("Password: ")
  214.                 local password = read("*")
  215.                 local response = http.post(
  216.                     "http://pastebin.com/api/api_login.php",
  217.                     "api_dev_key="..devKey.."&"..
  218.                     "api_user_name="..textutils.urlEncode(tArgs[3]).."&"..
  219.                     "api_user_password="..textutils.urlEncode(password)
  220.                     ).readAll()
  221.  
  222.                 local badRequests = {
  223.                     "Bad API request, invalid login",
  224.                     "Bad API request, account not active"
  225.                     }
  226.                
  227.                 if response == badRequests[1] then
  228.                     print("Invalid login!")
  229.                     return
  230.                 elseif response == badRequests[2] then
  231.                     print("Inactive account!")
  232.                     return
  233.                 else
  234.                     local userKey = response
  235.                     print("Reading file...")
  236.                     local file = fs.open(tArgs[2], "r")
  237.                     local postText = file.readAll()
  238.                     file.close()
  239.                     local postName = tArgs[2]
  240.                     local response = http.post(
  241.                     "http://pastebin.com/api/api_post.php",
  242.                         "api_option=paste&"..
  243.                         "api_dev_key="..devKey.."&"..
  244.                         "api_user_key="..userKey.."&"..
  245.                         "api_paste_format=lua&"..
  246.                         "api_paste_private=0&"..
  247.                         "api_paste_name="..textutils.urlEncode(postName).."&"..
  248.                         "api_paste_code="..textutils.urlEncode(postText)
  249.                         ).readAll()
  250.  
  251.                     if response then
  252.                         for i = 1, #badResponses do
  253.                             if response == badResponses[i] then
  254.                                 print(badResponses[i])
  255.                                 return
  256.                             else
  257.                                 print("Save successful! File stored at:\n"..response)
  258.                                 return
  259.                             end
  260.                         end
  261.                     else
  262.                         print("Unable to connect to Pastebin! Please try again.")
  263.                     end
  264.                 end
  265.             end
  266.         end
  267.     else
  268.         usage()
  269.         return
  270.     end
  271. end
  272.  
  273. --Throw relevant errors
  274. local x,y = term.getSize()
  275. if turtle or not term.isColor() or x ~= 51 and y ~= 19 then
  276.     print("Please run this program from commandline prompts.")
  277.     usage()
  278.     return
  279. end
  280.  
  281. local function checkCode()
  282.     local kCode = {200, 200, 208, 208, 203, 205, 203, 205, 48, 30, 28}
  283.     local extraCode = {200, 200, 208, 208, 203, 205, 203, 205, "b", "a", 28}
  284.     local eventTab = {"key", "key", "key", "key", "key", "key", "key", "key", "char", "char", "key"}
  285.     local code = false
  286.     local index = 1
  287.     while true do
  288.         local events = {os.pullEvent()}
  289.         --[[for i = 1, #events do
  290.             term.setCursorPos(20, 5 + i)
  291.             write(events[i].." / "..i.. " / "..index)
  292.             sleep(1)
  293.         end]]
  294.         sleep(0)
  295.         if index == #kCode then
  296.             code = true
  297.             term.setCursorPos(7,2)
  298.             term.setBackgroundColor(colors.lightGray)
  299.             term.setTextColor(colors.red)
  300.             write("Code entry successful")
  301.             break
  302.         else
  303.             code = false
  304.         end
  305.         if events[1] == "char" then
  306.             if events[2] == kCode[index] or events[2] == extraCode[index] then
  307.                 index = index + 1
  308.             else
  309.                 code = false
  310.                 break
  311.             end
  312.         elseif events[1] == "key" then
  313.             if events[2] == kCode[index] or events[2] == extraCode[index] then
  314.                 index = index + 1
  315.             else
  316.                 code = false
  317.                 break
  318.             end
  319.         elseif events[1] ~= "key" and events[1] ~= "char" then
  320.             os.queueEvent(unpack(events))
  321.             break
  322.         end
  323.     end
  324.     return code
  325. end
  326.  
  327. local function unlock()
  328.     paintutils.drawImage(codec, 1, 3)
  329.     for i = 3, 10 do
  330.         term.setTextColor(colors.lightGray)
  331.         term.setBackgroundColor(colors.black)
  332.         term.setCursorPos(1, i)
  333.         write("|")
  334.         term.setCursorPos(12, i)
  335.         write("|")
  336.         term.setCursorPos(40, i)
  337.         write("|")
  338.         term.setCursorPos(51, i)
  339.         write("|")
  340.         term.setCursorPos(1, i)
  341.         write(i == 3 and "+"..string.rep("-", 10).."+"..string.rep("-", 27).."+"..string.rep("-", 10).."+" or i == 10 and "+"..string.rep("-", 10).."+"..string.rep("-", 27).."+"..string.rep("-", 10).."+" or "")
  342.     end
  343.     for i = 12, 18 do
  344.         term.setTextColor(colors.lightGray)
  345.         term.setBackgroundColor(colors.black)
  346.         term.setCursorPos(2, i)
  347.         write(i == 12 and "+"..string.rep("-", 47).."+" or i == 18 and "+"..string.rep("-", 47).."+" or "|")
  348.         term.setCursorPos(50, i)
  349.         write("|")
  350.     end
  351.     local talking = true
  352.     local function static()
  353.         while talking do
  354.             local staticColors = {
  355.                     colors.white,
  356.                     colors.gray,
  357.                     colors.black,
  358.                     colors.lightGray}
  359.             for i = 2, 11 do
  360.                 for k = 4, 9 do
  361.                     local cx, cy = term.getCursorPos()
  362.                     term.setCursorPos(i, k)
  363.                     term.setBackgroundColor(staticColors[math.random(1,4)])
  364.                     write(" ")
  365.                     term.setCursorPos(cx, cy)
  366.                     term.setBackgroundColor(colors.black)
  367.                 end
  368.             end
  369.             for i = 41, 50 do
  370.                 for k = 4, 9 do
  371.                     local cx, cy = term.getCursorPos()
  372.                     term.setCursorPos(i, k)
  373.                     term.setBackgroundColor(staticColors[math.random(1,4)])
  374.                     write(" ")
  375.                     term.setCursorPos(cx, cy)
  376.                     term.setBackgroundColor(colors.black)
  377.                 end
  378.             end
  379.             sleep(.01)
  380.         end
  381.     end
  382.     local function writeText()
  383.         local chatTab = {
  384.             {"Unknown voice 1: The user has found the",
  385.              "    backdoor. Shall I terminate the connection",
  386.              "    to the server?"},
  387.             {"Unknown voice 2: No. Their dilligence has paid",
  388.              "    off. Give them more tests. Scatter them",
  389.              "    throughout cyberspace. Let's see if they",
  390.              "    can find all of the clues."},
  391.             {"Unknown voice 1: Understood sir."}
  392.             }
  393.  
  394.         term.setBackgroundColor(colors.black)
  395.         term.setTextColor(colors.white)
  396.         for i = 1, #chatTab do
  397.             for k = 1, #chatTab[i] do
  398.                 term.setCursorPos(4, 12 + k)
  399.                 term.setBackgroundColor(colors.black)
  400.                 term.setTextColor(colors.white)
  401.                 textutils.slowWrite(chatTab[i][k], 10)
  402.             end
  403.             sleep(2)
  404.             for v = 13, 17 do
  405.                 paintutils.drawLine(3, v, 49, v, colors.black)
  406.             end
  407.         end
  408.         talking = false
  409.     end
  410.    
  411.     parallel.waitForAll(static, writeText)
  412.     sleep(1)
  413.     background()
  414. end
  415.  
  416. -- limit read function
  417. local function limitRead(limX, rChar)
  418.     local origX, origY = term.getCursorPos()
  419.     term.setBackgroundColor(colors.white)
  420.     term.setTextColor(colors.blue)
  421.     term.setCursorPos(origX, origY)
  422.     term.setCursorBlink(true)
  423.     local returnString = ""
  424.     while true do
  425.         local xPos, yPos = term.getCursorPos()
  426.         local events = {os.pullEvent()}
  427.         if events[1] == "char" then
  428.             returnString = returnString..events[2]
  429.             if not rChar then
  430.                 if not limX then
  431.                     term.setTextColor(colors.blue)
  432.                     write(events[2])
  433.                 else
  434.                     if string.len(returnString) >= limX then
  435.                         term.setTextColor(colors.blue)
  436.                         term.setCursorPos(origX, origY)
  437.                         write(string.sub(returnString, (string.len(returnString)-limX)+1))
  438.                     elseif string.len(returnString) < limX then
  439.                         term.setTextColor(colors.blue)
  440.                         write(events[2])
  441.                     end
  442.                 end
  443.             else
  444.                 if not limX then
  445.                     term.setTextColor(colors.blue)
  446.                     write(rChar)
  447.                 else
  448.                     if string.len(returnString) >= limX then
  449.                         term.setTextColor(colors.blue)
  450.                         term.setCursorPos(origX, origY)
  451.                         write(string.rep(rChar, limX))
  452.                     elseif string.len(returnString) < limX then
  453.                         term.setTextColor(colors.blue)
  454.                         write(rChar)
  455.                     end
  456.                 end
  457.             end
  458.         elseif events[1] == "key" and events[2] == 14 then --backspace
  459.             returnString = string.sub(returnString, 1, (string.len(returnString))-1)
  460.             term.setCursorPos(xPos-1,yPos)
  461.             term.setTextColor(colors.blue)
  462.             write(" ")
  463.             term.setCursorPos(origX, origY)
  464.             if string.len(returnString) >= limX then
  465.                 if not rChar then
  466.                     term.setTextColor(colors.blue)
  467.                     write(string.sub(returnString, (string.len(returnString)-limX)+1))
  468.                 else
  469.                     term.setTextColor(colors.blue)
  470.                     write(string.rep(rChar,limX))
  471.                 end
  472.             else
  473.                 if not rChar then
  474.                     term.setTextColor(colors.blue)
  475.                     write(returnString)
  476.                 else
  477.                     term.setTextColor(colors.blue)
  478.                     write(string.rep(rChar, string.len(returnString)))
  479.                 end
  480.             end
  481.         elseif events[1] == "key" and events[2] == 28 then --enter
  482.             break
  483.         elseif events[1] == "mouse_click" and events[2] == 1 then
  484.             if events[3] >= 15 and events[3] <= 19 and events[4] == 13 and login == true then --"login"
  485.                 break
  486.             elseif events[3] >= 30 and events[3] <= 35 and events[4] == 13 and login == true then --"cancel"
  487.                 returnString = "EXIT LOGIN"
  488.                 break
  489.             elseif events[3] >= 21 and events[3] <= 28 and events[4] == 11 and downloading == true then --download(not logged)
  490.                 os.queueEvent(unpack(events))
  491.                 break
  492.             elseif events[3] >= 1 and events[3] <= 5 and events[4] == 2 then
  493.                 returnString = login and "EXIT LOGIN" or ""
  494.                 os.queueEvent(unpack(events))
  495.                 break
  496.             elseif events[3] >= 21 and events[3] <= 24 and events[4] == 2 then
  497.                 returnString = login and "EXIT LOGIN" or ""
  498.                 os.queueEvent(unpack(events))
  499.                 break
  500.             elseif events[3] >= 28 and events[3] <= 31 and events[4] == 2 then
  501.                 returnString = login and "EXIT LOGIN" or ""
  502.                 os.queueEvent(unpack(events))
  503.                 break
  504.             elseif events[3] >= 34 and events[3] <= 42 and events[4] == 2 then
  505.                 returnString = login and "EXIT LOGIN" or ""
  506.                 os.queueEvent(unpack(events))
  507.                 break
  508.             elseif events[3] >= 45 and events[3] <= 49 and events[4] == 2 then
  509.                 returnString = login and "EXIT LOGIN" or ""
  510.                 os.queueEvent(unpack(events))
  511.                 break
  512.             elseif events[3] == x and events[4] == 1 then
  513.                 term.setBackgroundColor(colors.black)
  514.                 term.setTextColor(colors.white)
  515.                 term.clear()
  516.                 term.setCursorPos(1,1)
  517.                 print("Thank you for using SmartPaste!")
  518.                 os.queueEvent("terminate")
  519.                 returnString = "TERMINATE"
  520.                 break
  521.             end
  522.         end
  523.     end
  524.     term.setCursorBlink(false)
  525.     return returnString
  526. end
  527.  
  528. local function loginScript()
  529.     if not logged then
  530.         paintutils.drawLine(10,6,40,6, colors.blue)
  531.         term.setCursorPos(10, 6)
  532.         term.setTextColor(colors.white)
  533.         term.setBackgroundColor(colors.blue)
  534.         write("Please login")
  535.         for i = 1, 8 do
  536.             paintutils.drawLine(10, 6 + i, 40, 6 + i, colors.lightGray)
  537.         end
  538.         local loginObjects = {
  539.             {name = "Username:",
  540.             nameX = 11,
  541.             nameY = 9,
  542.             color = colors.black,
  543.             BGcolor = colors.lightGray},
  544.             {name = "Username:         ",
  545.             nameX = 21,
  546.             nameY = 9,
  547.             color = colors.white,
  548.             BGcolor = colors.white},
  549.             {name = "Password:",
  550.             nameX = 11,
  551.             nameY = 11,
  552.             color = colors.black,
  553.             BGcolor = colors.lightGray},
  554.             {name = "Password:         ",
  555.             nameX = 21,
  556.             nameY = 11,
  557.             color = colors.white,
  558.             BGcolor = colors.white},
  559.             {name = "Login",
  560.             nameX = 15,
  561.             nameY = 13,
  562.             color = colors.white,
  563.             BGcolor = colors.green},
  564.             {name = "Cancel",
  565.             nameX = 30,
  566.             nameY = 13,
  567.             color = colors.white,
  568.             BGcolor = colors.red}
  569.             }
  570.  
  571.         while true do
  572.             for i = 1, #loginObjects do
  573.                 term.setCursorPos(loginObjects[i].nameX, loginObjects[i].nameY)
  574.                 term.setTextColor(loginObjects[i].color)
  575.                 term.setBackgroundColor(loginObjects[i].BGcolor)
  576.                 write(loginObjects[i].name)
  577.             end
  578.  
  579.             term.setCursorPos(22, 9)
  580.             login = true
  581.             username = limitRead(16)
  582.             if username ~= "EXIT LOGIN" and username ~= "TERMINATE" then
  583.                 term.setCursorPos(22, 11)
  584.                 password = limitRead(16, "*")
  585.                 if password ~= "EXIT LOGIN" and username ~= "TERMINATE" then
  586.                     local response = http.post(
  587.                         "http://pastebin.com/api/api_login.php",
  588.                         "api_dev_key="..devKey.."&"..
  589.                         "api_user_name="..textutils.urlEncode(username).."&"..
  590.                         "api_user_password="..textutils.urlEncode(password)
  591.                         ).readAll()
  592.                
  593.                     local badRequests = {
  594.                         "Bad API request, invalid login",
  595.                         "Bad API request, account not active"
  596.                         }
  597.                     if response then
  598.                         if response == badRequests[1] then
  599.                             term.setCursorPos(11,7)
  600.                             term.setBackgroundColor(colors.lightGray)
  601.                             term.setTextColor(colors.red)
  602.                             write("Invalid login!")
  603.                         elseif response == badRequests[2] then
  604.                             term.setCursorPos(11,7)
  605.                             term.setBackgroundColor(colors.lightGray)
  606.                             term.setTextColor(colors.red)
  607.                             write("Inactive account!")
  608.                         else
  609.                             userKey = response
  610.                             logged = true
  611.                             background()
  612.                             break
  613.                         end
  614.                     end
  615.                 elseif password == "TERMINATE" then
  616.                     os.queueEvent("terminate")
  617.                     break
  618.                 elseif password == "EXIT LOGIN" then
  619.                     password = "TEMP_PASSWORD"
  620.                     background()
  621.                     break
  622.                 else
  623.                     userKey = ""
  624.                     logged = false
  625.                     background()
  626.                     break
  627.                 end
  628.             elseif username == "TERMINATE" then
  629.                 os.queueEvent("terminate")
  630.                 break
  631.             elseif username == "EXIT LOGIN" then
  632.                 username = "TEMP_USER"
  633.                 background()
  634.                 break
  635.             else
  636.                 userKey = ""
  637.                 logged = false
  638.                 background()
  639.                 break
  640.             end
  641.         end
  642.         login = false
  643.     else
  644.         logged = false
  645.         userKey = ""
  646.         background()
  647.     end
  648. end
  649.  
  650. local function helpScreen()
  651.     for i = 3, y do
  652.         paintutils.drawLine(1,i,x,i,colors.lightBlue)
  653.     end
  654.     for i = 6, y-3 do
  655.         paintutils.drawLine(28,i,x-1,i,colors.white)
  656.     end
  657.     term.setBackgroundColor(colors.lightBlue)
  658.     term.setTextColor(colors.black)
  659.     term.setCursorPos(15,4)
  660.     write("SmartPaste Help Section")
  661.     term.setCursorPos(45,2)
  662.     term.setBackgroundColor(colors.red)
  663.     term.setTextColor(colors.black)
  664.     write("Help")
  665.     term.setCursorPos(1,6)
  666.     term.setTextColor(colors.white)
  667.     term.setBackgroundColor(colors.lightBlue)
  668.     write([[    Please select from a
  669.     topic on the right.
  670.     Help information will
  671.     be displayed here.]])
  672.     local helpMenu = {
  673.         {topic = "How to login",
  674.         y = 7,
  675.         action = function()
  676.                 for i = 6, y do
  677.                     paintutils.drawLine(1,i,27,i,colors.lightBlue)
  678.                 end
  679.                 term.setCursorPos(8,6)
  680.                 term.setTextColor(colors.black)
  681.                 term.setBackgroundColor(colors.lightBlue)
  682.                 print("How to login")
  683.                 term.setTextColor(colors.white)
  684.                 write([[
  685.  Select the "Login" option
  686. at the top. You will enter
  687. your personal login for
  688. your pastebin account.
  689.  
  690.  Rest assured, your account
  691. information is not stored
  692. anywhere. We use a user
  693. key once we receive a
  694. successful login from
  695. Pastebin.]])
  696.             end},
  697.         {topic = "How to retrieve a post",
  698.         y = 8,
  699.         action = function()
  700.                 for i = 6, y do
  701.                     paintutils.drawLine(1,i,27,i,colors.lightBlue)
  702.                 end
  703.                 term.setCursorPos(3,6)
  704.                 term.setTextColor(colors.black)
  705.                 term.setBackgroundColor(colors.lightBlue)
  706.                 print("How to retrieve a post")
  707.                 term.setTextColor(colors.white)
  708.                 write([[
  709.  Select "Download" from the
  710. menu.
  711.  
  712. If you are logged in, you
  713. willbe able to view your
  714. own posts or download
  715. directly from a paste
  716. code.
  717.  
  718. Otherwise, you can just
  719. download directly using a
  720. paste code.]])
  721.             end},
  722.         {topic = "How to save a post",
  723.         y = 9,
  724.         action = function()
  725.                 for i = 6, y do
  726.                     paintutils.drawLine(1,i,27,i,colors.lightBlue)
  727.                 end
  728.                 term.setCursorPos(5,6)
  729.                 term.setTextColor(colors.black)
  730.                 term.setBackgroundColor(colors.lightBlue)
  731.                 print("How to save a post")
  732.                 term.setTextColor(colors.white)
  733.                 write([[
  734.  Select 'New' from the main
  735. menu at the top. From there
  736. you can scroll through the
  737. files you have on your
  738. computer/turtle. Use the
  739. Enter key to make your
  740. selection.
  741.  You have the option of
  742. changing the syntax
  743. of your paste, expiration,
  744. and if you are logged in,
  745. even the exposure.]])
  746.             end},
  747.         {topic = "What's new",
  748.         y = 10,
  749.         action = function()
  750.                 for i = 6, y do
  751.                     paintutils.drawLine(1,i,27,i,colors.lightBlue)
  752.                 end
  753.                 term.setCursorPos(9,6)
  754.                 term.setTextColor(colors.black)
  755.                 term.setBackgroundColor(colors.lightBlue)
  756.                 print("What's new")
  757.                 term.setTextColor(colors.white)
  758.                 write([[
  759. -You are now able to select
  760.  the syntax highlighting
  761.  that is posted to Pastebin
  762.  as well as changing the
  763.  paste expiry date. You can
  764.  also change how the post
  765.  is published, to public,
  766.  private, or unlisted.
  767. -Obvious graphic changes.
  768. -Automatic integration with
  769.  Firewolf.
  770. -A secret! Try to find it!!]])
  771.             end},
  772.         {topic = "Credits",
  773.         y = 11,
  774.         action = function()
  775.                 for i = 6, y do
  776.                     paintutils.drawLine(1,i,27,i,colors.lightBlue)
  777.                 end
  778.                 term.setCursorPos(12,6)
  779.                 term.setTextColor(colors.black)
  780.                 term.setBackgroundColor(colors.lightBlue)
  781.                 print("Credits")
  782.                 term.setTextColor(colors.white)
  783.                 write([[
  784. Code -- Cranium
  785. Design -- Cranium
  786. Logo -- Cranium
  787. Firewolf -- 1Lann and
  788.          Gravityscore
  789. Bug Fixing -- CC Forums
  790. Logo Idea -- RunasSudo
  791.     Special thanks to 1Lann
  792. and Gravityscore for giving
  793. me the idea to redo the
  794. whole thing, and making it
  795. so much better.]])
  796.             end},
  797.         {topic = "About",
  798.         y = 12,
  799.         action = function()
  800.                 for i = 6, y do
  801.                     paintutils.drawLine(1,i,27,i,colors.lightBlue)
  802.                 end
  803.                 term.setCursorPos(12,6)
  804.                 term.setTextColor(colors.black)
  805.                 term.setBackgroundColor(colors.lightBlue)
  806.                 print("About")
  807.                 term.setTextColor(colors.white)
  808.                 write([[
  809.       -Version 2.0-
  810.  Written for ComputerCraft
  811.        ver. 1.48+
  812.  This awesome program was
  813. written by Cranium, and use
  814. of this program is granted
  815. under these two conditions:
  816.  
  817.  Any modifications must
  818. be approved by the original
  819. author and credit cannot be
  820. claimed by the user.]])
  821.             end}
  822.         }
  823.     local help = true
  824.     while help do
  825.         for i = 1, 6 do
  826.             term.setCursorPos(29, 6 + i)
  827.             term.setTextColor(colors.blue)
  828.             term.setBackgroundColor(colors.white)
  829.             write(helpMenu[i].topic)
  830.         end
  831.         local events = {os.pullEvent()}
  832.         if events[1] == "mouse_click" and events[2] == 1 then
  833.             for i = 1, #helpMenu do
  834.                 if events[3] >= 29 and events[3] <= x-1 then
  835.                     if events[4] == helpMenu[i].y then
  836.                         helpMenu[i].action()
  837.                     end
  838.                 end
  839.             end
  840.             if events[4] == 2 then
  841.                 if events[3] >= 1 and events[3] <= 5 then
  842.                     os.queueEvent(unpack(events))
  843.                     break
  844.                 elseif events[3] >= 21 and events[3] <= 24 then
  845.                     os.queueEvent(unpack(events))
  846.                     break
  847.                 elseif events[3] >= 28 and events[3] <= 31 then
  848.                     os.queueEvent(unpack(events))
  849.                     break
  850.                 elseif events[3] >= 34 and events[3] <= 42 then
  851.                     os.queueEvent(unpack(events))
  852.                     break
  853.                 elseif events[3] >= 45 and events[3] <= 49 then
  854.                     os.queueEvent(unpack(events))
  855.                     break
  856.                 end
  857.             elseif events[4] == 1 and events[3] == x then
  858.                 os.queueEvent("terminate")
  859.                 break
  860.             end
  861.         end
  862.     end
  863. end
  864.  
  865. local function downloadPaste()
  866.     for i = 3, y do
  867.         paintutils.drawLine(1,i,x,i,colors.lightBlue)
  868.     end
  869.     if logged then
  870.         for i = 9, 12 do
  871.             paintutils.drawLine(10,i,40,i,colors.white)
  872.         end
  873.         term.setCursorPos(15,10)
  874.         term.setTextColor(colors.blue)
  875.         write("Retrieving posts for:")
  876.         local cX = (x/2)-(string.len(username)/2)
  877.         term.setCursorPos(cX,11)
  878.         term.setTextColor(colors.red)
  879.         write(username)
  880.  
  881.         local response = http.post(
  882.             "http://pastebin.com/api/api_post.php",
  883.             "api_option=list&"..
  884.             "api_dev_key="..devKey.."&"..
  885.             "api_user_key="..userKey
  886.             ).readAll()
  887.  
  888.         if not response then
  889.             for i = 6,10 do
  890.                 paintutils.drawLine(8,i,42,i,colors.lightGray)
  891.             end
  892.             paintutils.drawLine(9,8,41,8,colors.white)
  893.             term.setCursorPos(11,8)
  894.             term.setTextColor(colors.red)
  895.             write("Unable to connect to Pastebin!")
  896.         end
  897.  
  898.         for i = 3, y do
  899.             paintutils.drawLine(1,i,x,i,colors.lightBlue)
  900.         end
  901.  
  902.         local codeTable = {}
  903.         local titleTable = {}
  904.         local formatTable = {}
  905.         local privTable = {}
  906.         for code in string.gmatch(response, "<paste_key>(%w-)</paste_key>") do
  907.             table.insert(codeTable, code)
  908.         end
  909.         for title in string.gmatch(response, "<paste_title>(.-)</paste_title>") do
  910.             table.insert(titleTable, title)
  911.         end
  912.         for formatLong in string.gmatch(response, "<paste_format_long>(%w-)</paste_format_long>") do
  913.             table.insert(formatTable, formatLong)
  914.         end
  915.         for private in string.gmatch(response, "<paste_private>(%d-)</paste_private>") do
  916.             if private == "0" then
  917.                 table.insert(privTable, "Public")
  918.             elseif private == "1" then
  919.                 table.insert(privTable, "Unlisted")
  920.             elseif private == "2" then
  921.                 table.insert(privTable, "Private")
  922.             end
  923.         end
  924.  
  925.         if not codeTable[1] then
  926.             for i = 9, 12 do
  927.                 paintutils.drawLine(10,i,40,i,colors.white)
  928.             end
  929.             term.setCursorPos(18, 10)
  930.             term.setTextColor(colors.red)
  931.             write("No pastes found!")
  932.             sleep(1)
  933.             return
  934.         end
  935.  
  936.         term.setBackgroundColor(colors.lightBlue)
  937.         term.setCursorPos(2, 4)
  938.         term.setTextColor(colors.black)
  939.         write("Title")
  940.         term.setCursorPos(19, 4)
  941.         write("Syntax")
  942.         term.setCursorPos(30, 4)
  943.         write("Paste Type")
  944.         term.setCursorPos(2, 14)
  945.         term.setBackgroundColor(colors.lightBlue)
  946.         term.setTextColor(colors.black)
  947.         write("Selected Paste Info:")
  948.         for k = 15, y do
  949.             paintutils.drawLine(2,k,25,k,colors.lightGray)
  950.         end
  951.         term.setCursorPos(10, 18)
  952.         term.setBackgroundColor(colors.green)
  953.         write("Download")
  954.         for k = 15, y do
  955.             paintutils.drawLine(27,k,50,k,colors.lightGray)
  956.         end
  957.         term.setCursorPos(35, 18)
  958.         term.setBackgroundColor(colors.green)
  959.         write("Download")
  960.         term.setCursorPos(27, 14)
  961.         term.setBackgroundColor(colors.lightBlue)
  962.         write("Enter Pastebin Code:")
  963.         paintutils.drawLine(28,16,49,16,colors.white)
  964.  
  965.         local scroll = 1
  966.         while true do
  967.             local function drawList(titleTable, formatTable, scroll)
  968.                 if scroll <= 8 then
  969.                     for i = 1, 8 do
  970.                         if i > #titleTable then break end
  971.                         if titleTable[1] == nil then break end
  972.                         term.setBackgroundColor(colors.lightBlue)
  973.                         term.setCursorPos(1, 4 + i)
  974.                         term.setTextColor(colors.white)
  975.                         if string.len(titleTable[i]) >= 17 then
  976.                             write(" "..string.sub(titleTable[i], 1, 14).."...")
  977.                         else
  978.                             write(" "..titleTable[i])
  979.                         end
  980.                         local mX,mY = term.getCursorPos()
  981.                         for i = 1, 19 - mX do
  982.                             write(" ")
  983.                         end
  984.                         write(formatTable[i])
  985.                         local mX,mY = term.getCursorPos()
  986.                         for i = 1, 30 - mX do
  987.                             write(" ")
  988.                         end
  989.                         write(privTable[i])
  990.                         local mX,mY = term.getCursorPos()
  991.                         for i = 1, 50 - mX do
  992.                             write(" ")
  993.                         end
  994.                     end
  995.                     term.setCursorPos(1, 4 + scroll)
  996.                     term.setTextColor(colors.red)
  997.                     if string.len(titleTable[scroll]) >= 17 then
  998.                         write(">"..string.sub(titleTable[scroll], 1, 14).."...")
  999.                     else
  1000.                         write(">"..titleTable[scroll])
  1001.                     end
  1002.                     local mX,mY = term.getCursorPos()
  1003.                     for i = 1, 19 - mX do
  1004.                         write(" ")
  1005.                     end
  1006.                 else
  1007.                     for i = 1, 8 do
  1008.                         if i > #titleTable then break end
  1009.                         term.setBackgroundColor(colors.lightBlue)
  1010.                         term.setCursorPos(1, 4 + i)
  1011.                         term.setTextColor(colors.white)
  1012.                         if string.len(titleTable[scroll + (i - 8)]) >= 17 then
  1013.                             write(" "..string.sub(titleTable[scroll + (i - 8)], 1, 14).."...")
  1014.                         else
  1015.                             write(" "..titleTable[scroll + (i - 8)])
  1016.                         end
  1017.                         local mX,mY = term.getCursorPos()
  1018.                         for i = 1, 19 - mX do
  1019.                             write(" ")
  1020.                         end
  1021.                             write(formatTable[scroll + (i - 8)])
  1022.                         local mX,mY = term.getCursorPos()
  1023.                         for i = 1, 30 - mX do
  1024.                             write(" ")
  1025.                         end
  1026.                         write(privTable[scroll + (i - 8)])
  1027.                         local mX,mY = term.getCursorPos()
  1028.                         for i = 1, 50 - mX do
  1029.                             write(" ")
  1030.                         end
  1031.                     end
  1032.                     term.setCursorPos(1, 12)
  1033.                     term.setTextColor(colors.red)
  1034.                     if string.len(titleTable[scroll]) >= 17 then
  1035.                         write(">"..string.sub(titleTable[scroll], 1, 14).."...")
  1036.                     else
  1037.                         write(">"..titleTable[scroll])
  1038.                     end
  1039.                     local mX,mY = term.getCursorPos()
  1040.                     for i = 1, 19 - mX do
  1041.                         write(" ")
  1042.                     end
  1043.                 end
  1044.                 paintutils.drawLine(3, 16, 24, 16, colors.white)
  1045.                 term.setCursorPos(3, 16)
  1046.                 term.setTextColor(colors.blue)
  1047.                 if string.len(titleTable[scroll]) >= 19 then
  1048.                     write(string.sub(titleTable[scroll], 1, 19).."...")
  1049.                 else
  1050.                     write(titleTable[scroll])
  1051.                 end
  1052.             end
  1053.  
  1054.             drawList(titleTable, formatTable, scroll)
  1055.             local events = {os.pullEvent()}
  1056.             if events[1] == "mouse_scroll" then
  1057.                 if events[2] == 1 then
  1058.                     if scroll >= #titleTable then
  1059.                         scroll = #titleTable
  1060.                     elseif scroll >= 1 and scroll < #titleTable then
  1061.                         scroll = scroll + 1
  1062.                         drawList(titleTable, formatTable, scroll)
  1063.                     end
  1064.                 elseif events[2] == -1 then
  1065.                     if scroll <= 1 then
  1066.                         scroll = 1
  1067.                     elseif scroll >= 1 then
  1068.                         scroll = scroll - 1
  1069.                         drawList(titleTable, formatTable, scroll)
  1070.                     end
  1071.                 end
  1072.             elseif events[1] == "key" then
  1073.                 if events[2] == 208 then
  1074.                     if scroll >= #titleTable then
  1075.                         scroll = #titleTable
  1076.                     elseif scroll >= 1 and scroll < #titleTable then
  1077.                         scroll = scroll + 1
  1078.                         drawList(titleTable, formatTable, scroll)
  1079.                     end
  1080.                 elseif events[2] == 200 then
  1081.                     if scroll <= 1 then
  1082.                         scroll = 1
  1083.                     elseif scroll >= 1 then
  1084.                         scroll = scroll - 1
  1085.                         drawList(titleTable, formatTable, scroll)
  1086.                     end
  1087.                 end
  1088.             elseif events[1] == "char" then
  1089.                 for i = 1, #titleTable do
  1090.                     if string.lower(string.sub(titleTable[i], 1, 1)) == events[2] then
  1091.                         scroll = i
  1092.                         break
  1093.                     end
  1094.                     drawList(titleTable, formatTable, scroll)
  1095.                 end
  1096.             elseif events[1] == "mouse_click" and events[2] == 1 then
  1097.                 if events[3] >= 28 and events[3] <= 49 and events[4] == 16 then
  1098.                     paintutils.drawLine(28,16,49,16,colors.white)
  1099.                     term.setCursorPos(29,16)
  1100.                     DLcode = read()
  1101.                 elseif events[3] >= 35 and events[3] <= 42 and events[4] == 18 then
  1102.                     if DLcode ~= "" and DLcode ~= nil then
  1103.                         local DLcontent = http.get("http://pastebin.com/raw.php?i="..DLcode)
  1104.                         if not DLcontent then
  1105.                             for k = 6, 8 do
  1106.                                 paintutils.drawLine(10,k,40,k, colors.lightGray)
  1107.                             end
  1108.                             term.setCursorPos(11,7)
  1109.                             term.setTextColor(colors.red)
  1110.                             write("Unable to connect to Pastebin!")
  1111.                         else
  1112.                             newFile = DLcontent.readAll()
  1113.                         end
  1114.                         for k = 6, 9 do
  1115.                             paintutils.drawLine(10,k,40,k, colors.lightGray)
  1116.                         end
  1117.                         paintutils.drawLine(11,8,39,8,colors.white)
  1118.                         term.setCursorPos(11,6)
  1119.                         term.setBackgroundColor(colors.lightGray)
  1120.                         term.setTextColor(colors.black)
  1121.                         write("Please enter new filename:")
  1122.                         term.setCursorPos(12,8)
  1123.                         term.setTextColor(colors.blue)
  1124.                         term.setBackgroundColor(colors.white)
  1125.                         local fName = read()
  1126.                         if fName ~= "" and fName ~= nil then
  1127.                             if not fs.exists(fName) then
  1128.                                 local file = fs.open(fName, "w")
  1129.                                 file.write(newFile)
  1130.                                 file.close()
  1131.                                 for k = 6, 8 do
  1132.                                     paintutils.drawLine(10,k,40,k, colors.lightGray)
  1133.                                 end
  1134.                                 term.setCursorPos(11,7)
  1135.                                 term.setTextColor(colors.red)
  1136.                                 write("Download Successful!")
  1137.                                 sleep(1)
  1138.                                 DLcode = false
  1139.                                 for i = 5, 12 do
  1140.                                     paintutils.drawLine(1, i, 50, i, colors.lightBlue)
  1141.                                 end
  1142.                             else
  1143.                                 term.setCursorPos(11,7)
  1144.                                 term.setTextColor(colors.red)
  1145.                                 print("FILE EXISTS!")
  1146.                                 sleep(1)
  1147.                                 for i = 5, 12 do
  1148.                                     paintutils.drawLine(1, i, 50, i, colors.lightBlue)
  1149.                                 end
  1150.                             end
  1151.                         end
  1152.                     end
  1153.                 elseif events[3] >= 10 and events[3] <= 17 and events[4] == 18 then
  1154.                     local DLcontent = http.get("http://pastebin.com/raw.php?i="..codeTable[scroll])
  1155.                     if not DLcontent then
  1156.                         for k = 6, 8 do
  1157.                             paintutils.drawLine(10,k,40,k, colors.lightGray)
  1158.                         end
  1159.                         term.setCursorPos(11,7)
  1160.                         term.setTextColor(colors.red)
  1161.                         write("Unable to connect to Pastebin!")
  1162.                     else
  1163.                         newFile = DLcontent.readAll()
  1164.                     end
  1165.                     for k = 6, 9 do
  1166.                         paintutils.drawLine(10,k,40,k, colors.lightGray)
  1167.                     end
  1168.                     paintutils.drawLine(11,8,39,8,colors.white)
  1169.                     term.setCursorPos(11,6)
  1170.                     term.setBackgroundColor(colors.lightGray)
  1171.                     term.setTextColor(colors.black)
  1172.                     write("Please enter new filename:")
  1173.                     term.setCursorPos(12,8)
  1174.                     term.setTextColor(colors.blue)
  1175.                     term.setBackgroundColor(colors.white)
  1176.                     local fName = read()
  1177.                     if fName ~= "" and fName ~= nil then
  1178.                         if not fs.exists(fName) then
  1179.                             local file = fs.open(fName, "w")
  1180.                             file.write(newFile)
  1181.                             file.close()
  1182.                             for k = 6, 8 do
  1183.                                 paintutils.drawLine(10,k,40,k, colors.lightGray)
  1184.                             end
  1185.                             term.setCursorPos(11,7)
  1186.                             term.setTextColor(colors.red)
  1187.                             write("Download Successful!")
  1188.                             sleep(1)
  1189.                             DLcode = false
  1190.                             for i = 5, 12 do
  1191.                                 paintutils.drawLine(1, i, 50, i, colors.lightBlue)
  1192.                             end
  1193.                         else
  1194.                             term.setCursorPos(11,7)
  1195.                             term.setTextColor(colors.red)
  1196.                             print("FILE EXISTS!")
  1197.                             sleep(1)
  1198.                             for i = 5, 12 do
  1199.                                 paintutils.drawLine(1, i, 50, i, colors.lightBlue)
  1200.                             end
  1201.                         end
  1202.                     end
  1203.                 elseif events[4] == 2 then
  1204.                     if events[3] >= 1 and events[3] <= 5 then
  1205.                         os.queueEvent(unpack(events))
  1206.                         break
  1207.                     elseif events[3] >= 21 and events[3] <= 24 then
  1208.                         os.queueEvent(unpack(events))
  1209.                         break
  1210.                     elseif events[3] >= 28 and events[3] <= 31 then
  1211.                         os.queueEvent(unpack(events))
  1212.                         break
  1213.                     elseif events[3] >= 34 and events[3] <= 42 then
  1214.                         os.queueEvent(unpack(events))
  1215.                         break
  1216.                     elseif events[3] >= 45 and events[3] <= 49 then
  1217.                         os.queueEvent(unpack(events))
  1218.                         break
  1219.                     end
  1220.                 elseif events[3] == x and events[4] == 1 then
  1221.                     os.queueEvent("terminate")
  1222.                     break
  1223.                 end
  1224.             end
  1225.         end
  1226.     else
  1227.         for i = 7,11 do
  1228.             paintutils.drawLine(15,i,35,i,colors.lightGray)
  1229.         end
  1230.         term.setCursorPos(16,7)
  1231.         term.setTextColor(colors.black)
  1232.         write("Enter Pastebin Code")
  1233.         term.setBackgroundColor(colors.green)
  1234.         term.setCursorPos(21,11)
  1235.         write("Download")
  1236.         paintutils.drawLine(16,9,34,9,colors.white)
  1237.         term.setCursorPos(17,9)
  1238.         term.setTextColor(colors.blue)
  1239.         downloading = true
  1240.         local PBcode = limitRead(17)
  1241.         if PBcode ~= "" then
  1242.             while true do
  1243.                 local events = {os.pullEvent()}
  1244.                 if events[1] == "mouse_click" and events[2] == 1 then
  1245.                     if events[3] >= 21 and events[3] <= 28 and events[4] == 11 then
  1246.                         if PBcode ~= "TERMINATE" then
  1247.                             paintutils.drawLine(16,9,34,9,colors.white)
  1248.                             paintutils.drawLine(15,7,35,7,colors.lightGray)
  1249.                             term.setCursorPos(16,7)
  1250.                             term.setTextColor(colors.black)
  1251.                             write("Enter new Filename:")
  1252.                             term.setCursorPos(17,9)
  1253.                             local fName = limitRead(17)
  1254.                             if fName ~= "" then
  1255.                                 local site = http.get("http://pastebin.com/raw.php?i="..PBcode)
  1256.                                 if site then
  1257.                                     local pasteContent = site.readAll()
  1258.                                     local file = fs.open(fName, "w")
  1259.                                     file.write(pasteContent)
  1260.                                     file.close()
  1261.                                     background()
  1262.                                     break
  1263.                                 end
  1264.                             end
  1265.                         else
  1266.                             os.queueEvent("terminate")
  1267.                             break
  1268.                         end
  1269.                     elseif events[4] == 2 then
  1270.                         if events[3] >= 1 and events[3] <= 5 then
  1271.                             os.queueEvent(unpack(events))
  1272.                             break
  1273.                         elseif events[3] >= 21 and events[3] <= 24 then
  1274.                             os.queueEvent(unpack(events))
  1275.                             break
  1276.                         elseif events[3] >= 28 and events[3] <= 31 then
  1277.                             os.queueEvent(unpack(events))
  1278.                             break
  1279.                         elseif events[3] >= 34 and events[3] <= 42 then
  1280.                             os.queueEvent(unpack(events))
  1281.                             break
  1282.                         elseif events[3] >= 45 and events[3] <= 49 then
  1283.                             os.queueEvent(unpack(events))
  1284.                             break
  1285.                         end
  1286.                     elseif events[3] == x and events[4] == 1 then
  1287.                         os.queueEvent("terminate")
  1288.                         break
  1289.                     end
  1290.                 end
  1291.             end
  1292.         end
  1293.         downloading = false
  1294.     end
  1295. end
  1296.  
  1297. local function newPaste()
  1298.     local optsTab = {
  1299.         "Syntax highlighting:",
  1300.         "Paste expiration:",
  1301.         "Paste exposure:",
  1302.         "Show hidden files:"
  1303.         }
  1304.     local expiryTab = {
  1305.         "Never",
  1306.         "10 minutes",
  1307.         "1 hour",
  1308.         "1 day",
  1309.         "1 month"
  1310.         }
  1311.     local expTabList = {
  1312.         'N',
  1313.         '10M',
  1314.         '1H',
  1315.         '1D',
  1316.         '1M'
  1317.         }
  1318.     local exposureTab = {
  1319.         "Public",
  1320.         "Private",
  1321.         "Unlisted"
  1322.         }
  1323.     local scroll = 1
  1324.     local synOpt = 128
  1325.     local expOpt = 1
  1326.     local pubOpt = 1
  1327.     local dirTab = {""}
  1328.     local hidden = false
  1329.  
  1330.     for i = 3, y do
  1331.         paintutils.drawLine(1,i,x,i,colors.lightBlue)
  1332.     end
  1333.     term.setBackgroundColor(colors.lightBlue)
  1334.     term.setCursorPos(2, 4)
  1335.     term.setTextColor(colors.black)
  1336.     write("File")
  1337.     term.setCursorPos(19, 4)
  1338.     write("Type")
  1339.     term.setCursorPos(30, 4)
  1340.     write("File Size")
  1341.     for k = 14, y do
  1342.         paintutils.drawLine(2,k,50,k,colors.lightGray)
  1343.     end
  1344.     for i = 1, 4 do
  1345.         term.setTextColor(colors.black)
  1346.         term.setBackgroundColor(colors.lightGray)
  1347.         paintutils.drawLine(2, 14 + i, 50, 14 + i, colors.lightGray)
  1348.         term.setCursorPos(3, 14 + i)
  1349.         write(optsTab[i])
  1350.     end
  1351.    
  1352.     local function getFiles(dir, hidden)
  1353.         local rTab = {}
  1354.         for _, v in pairs(fs.list(dir)) do
  1355.             if hidden == true then
  1356.                 table.insert(rTab, v)
  1357.             else
  1358.                 if string.sub(v, 1, 1) ~= "." then
  1359.                     table.insert(rTab, v)
  1360.                 end
  1361.             end
  1362.         end
  1363.         return rTab
  1364.     end
  1365.  
  1366.     while true do
  1367.         local listTable = getFiles(table.concat(dirTab, "/"), hidden)
  1368.         local typeTable = {}
  1369.         local sizeTable = {}
  1370.  
  1371.         for i = 1, #listTable do
  1372.             if fs.isDir(table.concat(dirTab, "/").."/"..listTable[i]) then
  1373.                 table.insert(listTable, 1, listTable[i])
  1374.                 table.remove(listTable, i + 1)
  1375.                 table.insert(typeTable, 1, "Folder")
  1376.                 table.insert(sizeTable, 1, "")
  1377.             else
  1378.                 table.insert(typeTable, "File")
  1379.                 table.insert(sizeTable, fs.getSize(table.concat(dirTab, "/").."/"..listTable[i]).." Bytes")
  1380.             end
  1381.         end
  1382.         table.insert(listTable, 1, "Return")
  1383.         table.insert(typeTable, 1, "")
  1384.         table.insert(sizeTable, 1, "")
  1385.        
  1386.         -- list files on computer
  1387.         local function drawList(dirTab, listTable, scroll)
  1388.             if scroll <= 8 then
  1389.                 for i = 1, 8 do
  1390.                     if i > #listTable then break end
  1391.                     term.setBackgroundColor(colors.lightBlue)
  1392.                     term.setCursorPos(1, 4 + i)
  1393.                     if fs.isDir(table.concat(dirTab, "/").."/"..listTable[i]) then
  1394.                         term.setTextColor(colors.lime)
  1395.                     elseif listTable[i] == "Return" then
  1396.                         term.setTextColor(colors.green)
  1397.                     else
  1398.                         term.setTextColor(colors.white)
  1399.                     end
  1400.                     if string.len(listTable[i]) >= 17 then
  1401.                         write(" "..string.sub(listTable[i], 1, 14).."...")
  1402.                     else
  1403.                         write(" "..listTable[i])
  1404.                     end
  1405.                     local mX,mY = term.getCursorPos()
  1406.                     for i = 1, 19 - mX do
  1407.                         write(" ")
  1408.                     end
  1409.                     write(typeTable[i])
  1410.                     local mX,mY = term.getCursorPos()
  1411.                     for i = 1, 30 - mX do
  1412.                         write(" ")
  1413.                     end
  1414.                     write(sizeTable[i])
  1415.                     local mX,mY = term.getCursorPos()
  1416.                     for i = 1, 50 - mX do
  1417.                         write(" ")
  1418.                     end
  1419.                 end
  1420.                 term.setCursorPos(1, 4 + scroll)
  1421.                 term.setTextColor(colors.red)
  1422.                 if string.len(listTable[scroll]) >= 17 then
  1423.                     write(">"..string.sub(listTable[scroll], 1, 14).."...")
  1424.                 else
  1425.                     write(">"..listTable[scroll])
  1426.                 end
  1427.                 local mX,mY = term.getCursorPos()
  1428.                 for i = 1, 19 - mX do
  1429.                     write(" ")
  1430.                 end
  1431.             else
  1432.                 for i = 1, 8 do
  1433.                     if i > #listTable then break end
  1434.                     term.setBackgroundColor(colors.lightBlue)
  1435.                     term.setCursorPos(1, 4 + i)
  1436.                     if fs.isDir(table.concat(dirTab, "/").."/"..listTable[scroll + (i - 8)]) then
  1437.                         term.setTextColor(colors.lime)
  1438.                     elseif listTable[scroll + (i - 8)] == "Return" then
  1439.                         term.setTextColor(colors.green)
  1440.                     else
  1441.                         term.setTextColor(colors.white)
  1442.                     end
  1443.                     if string.len(listTable[scroll + (i - 8)]) >= 17 then
  1444.                         write(" "..string.sub(listTable[scroll + (i - 8)], 1, 14).."...")
  1445.                     else
  1446.                         write(" "..listTable[scroll + (i - 8)])
  1447.                     end
  1448.                     local mX,mY = term.getCursorPos()
  1449.                     for i = 1, 19 - mX do
  1450.                         write(" ")
  1451.                     end
  1452.                     write(typeTable[scroll + (i - 8)])
  1453.                     local mX,mY = term.getCursorPos()
  1454.                     for i = 1, 30 - mX do
  1455.                         write(" ")
  1456.                     end
  1457.                     write(sizeTable[scroll + (i - 8)])
  1458.                     local mX,mY = term.getCursorPos()
  1459.                     for i = 1, 50 - mX do
  1460.                         write(" ")
  1461.                     end
  1462.                 end
  1463.                 term.setCursorPos(1, 12)
  1464.                 term.setTextColor(colors.red)
  1465.                 if string.len(listTable[scroll]) >= 17 then
  1466.                     write(">"..string.sub(listTable[scroll], 1, 14).."...")
  1467.                 else
  1468.                     write(">"..listTable[scroll])
  1469.                 end
  1470.                 local mX,mY = term.getCursorPos()
  1471.                 for i = 1, 19 - mX do
  1472.                     write(" ")
  1473.                 end
  1474.             end
  1475.         end
  1476.     drawList(dirTab, listTable, scroll)
  1477.         for i = 1, 4 do
  1478.             term.setCursorPos(24, 14 + i)
  1479.             term.setTextColor(colors.white)
  1480.             term.setBackgroundColor(colors.lightGray)
  1481.             write(
  1482.                 i == 1 and syntaxTab.menuNames[synOpt] or
  1483.                 i == 2 and expiryTab[expOpt] or
  1484.                 i == 3 and exposureTab[pubOpt] or
  1485.                 i == 4 and hidden and "[X]" or
  1486.                 i == 4 and not hidden and "[ ]"
  1487.                 )
  1488.             local mX, mY = term.getCursorPos()
  1489.             for i = 1, 50 - mX do
  1490.                 write(" ")
  1491.             end
  1492.         end
  1493.  
  1494.         local function drawMiniMenu(menuType, menuTable)
  1495.             for i = 5, 12 do
  1496.                 paintutils.drawLine(10, i, 41, i, colors.blue)
  1497.                 paintutils.drawLine(11, i, 40, i, colors.white)
  1498.             end
  1499.             for i = 5, 12 do
  1500.                 term.setCursorPos(38,i)
  1501.                 term.setTextColor(i == 5 and colors.black or i == 12 and colors.black or colors.lightGray)
  1502.                 write(i == 5 and "/\\" or i == 12 and "\\/" or "||")
  1503.             end
  1504.             local menuNum = 0
  1505.             local scroll = menuType == "syntax" and 127 or 0
  1506.             while true do
  1507.                 local selected = menuType == "syntax" and menuTable[scroll + 1] or menuTable[scroll + 1]
  1508.                 if menuType == "syntax" then
  1509.                     menuNum = #menuTable
  1510.                     for i = 1, 6 do
  1511.                         paintutils.drawLine(12, i + 5, 36, i + 5, colors.white)
  1512.                         term.setCursorPos(12, i + 5)
  1513.                         if selected == menuTable[scroll + i] then
  1514.                             term.setBackgroundColor(colors.lightGray)
  1515.                         else
  1516.                             term.setBackgroundColor(colors.white)
  1517.                         end
  1518.                         term.setTextColor(colors.blue)
  1519.                         write(menuTable[scroll + i])
  1520.                     end
  1521.                 elseif menuType == "expiration" or menuType == "exposure" then
  1522.                     menuNum = #menuTable
  1523.                     for i = 1, menuNum do
  1524.                         term.setCursorPos(12, i + 5)
  1525.                         term.setBackgroundColor(colors.white)
  1526.                         term.setTextColor(colors.blue)
  1527.                         write(menuTable[i])
  1528.                     end
  1529.                     term.setCursorPos(12, scroll + 6)
  1530.                     term.setBackgroundColor(colors.lightGray)
  1531.                     write(menuTable[scroll + 1])
  1532.                 end
  1533.                 local events = {os.pullEvent()}
  1534.                 if events[1] == "mouse_scroll" and menuType == "syntax" then
  1535.                     if events[2] == 1 then
  1536.                         if scroll >= menuNum - 6 then
  1537.                             scroll = menuNum - 6
  1538.                         else
  1539.                             scroll = scroll + 1
  1540.                         end
  1541.                     elseif events[2] == -1 then
  1542.                         if scroll <= 0 then
  1543.                             scroll = 0
  1544.                         else
  1545.                             scroll = scroll - 1
  1546.                         end
  1547.                     end
  1548.                 elseif events[1] == "char" then
  1549.                     for i = 1, #syntaxTab.menuNames do
  1550.                         if string.lower(string.sub(syntaxTab.menuNames[i], 1, 1)) == events[2] then
  1551.                             scroll = i
  1552.                             break
  1553.                         end
  1554.                     end
  1555.                 elseif events[1] == "key" then
  1556.                     if events[2] == 208 then
  1557.                         scroll = scroll + 1
  1558.                     elseif events[2] == 200 then
  1559.                         scroll = scroll - 1
  1560.                     elseif events[2] == 28 then
  1561.                         for i = 1, #menuTable do
  1562.                             if selected == menuTable[i] then
  1563.                                 selectedNum = i
  1564.                                 break
  1565.                             end
  1566.                         end
  1567.                         for i = 5, 12 do
  1568.                             paintutils.drawLine(2, i, 50, i, colors.lightBlue)
  1569.                         end
  1570.                         return selectedNum
  1571.                     end
  1572.                 elseif events[1] == "mouse_click" and events[2] == 1 then
  1573.                     if events[3] >= 37 and events[3] >= 36 and menuType == "syntax" then
  1574.                         if events[4] == 5 then
  1575.                             scroll = scroll - 5
  1576.                             if scroll <= 5 then
  1577.                                 scroll = 0
  1578.                             end
  1579.                         elseif events[4] == 12 then
  1580.                             scroll = scroll + 5
  1581.                             if scroll >= menuNum - 6 then
  1582.                                 scroll = menuNum - 6
  1583.                             end
  1584.                         end
  1585.                     elseif events[3] >= 12 and events[3] <= 35 then
  1586.                         for i = 6, 11 do
  1587.                             if events[4] == i then
  1588.                                 selected = menuTable[scroll + (i - 5)]
  1589.                                 scroll = i - 6
  1590.                             end
  1591.                         end
  1592.                     end
  1593.                 end
  1594.                 if scroll >= menuNum then
  1595.                     scroll = menuNum - 1
  1596.                 elseif scroll < 0 then
  1597.                     scroll = 0
  1598.                 end
  1599.             end
  1600.         end
  1601.  
  1602.         local events = {os.pullEvent()}
  1603.         if events[1] == "mouse_scroll" then
  1604.             if events[2] == 1 then
  1605.                 if scroll >= #listTable then
  1606.                     scroll = #listTable
  1607.                 elseif scroll >= 1 and scroll < #listTable then
  1608.                     scroll = scroll + 1
  1609.                     drawList(dirTab, listTable, scroll)
  1610.                 end
  1611.             elseif events[2] == -1 then
  1612.                 if scroll <= 1 then
  1613.                     scroll = 1
  1614.                 elseif scroll >= 1 then
  1615.                     scroll = scroll - 1
  1616.                     drawList(dirTab, listTable, scroll)
  1617.                 end
  1618.             end
  1619.         elseif events[1] == "key" then
  1620.             if events[2] == 208 then
  1621.                 if scroll >= #listTable then
  1622.                     scroll = #listTable
  1623.                 elseif scroll >= 1 and scroll < #listTable then
  1624.                     scroll = scroll + 1
  1625.                     drawList(dirTab, listTable, scroll)
  1626.                 end
  1627.             elseif events[2] == 200 then
  1628.                 if scroll <= 1 then
  1629.                     scroll = 1
  1630.                 elseif scroll >= 1 then
  1631.                     scroll = scroll - 1
  1632.                     drawList(dirTab, listTable, scroll)
  1633.                 end
  1634.             elseif events[2] == 28 then
  1635.                 if scroll == 1 and dir ~= "/" then
  1636.                     table.remove(dirTab)
  1637.                     scroll = 1
  1638.                     for i = 5,13 do
  1639.                         paintutils.drawLine(1,i,x,i,colors.lightBlue)
  1640.                     end
  1641.                 else
  1642.                     if fs.isDir(table.concat(dirTab, "/").."/"..listTable[scroll]) then
  1643.                         table.insert(dirTab, listTable[scroll])
  1644.                         scroll = 1
  1645.                         for i = 5,13 do
  1646.                             paintutils.drawLine(1,i,x,i,colors.lightBlue)
  1647.                         end
  1648.                     else
  1649.                         local fileName = shell.resolve(table.concat(dirTab, "/").."/"..listTable[scroll])
  1650.                         local file = fs.open(fileName, "r")
  1651.                         local postText = file.readAll()
  1652.                         file.close()
  1653.                         for i = 7, 12 do
  1654.                             paintutils.drawLine(10, i, 41, i, colors.blue)
  1655.                             paintutils.drawLine(11, i, 40, i, colors.white)
  1656.                             paintutils.drawLine(12, i, 39, i, colors.lightGray)
  1657.                         end
  1658.                         paintutils.drawLine(13, 10, 38, 10, colors.white)
  1659.                         term.setCursorPos(21, 8)
  1660.                         term.setTextColor(colors.black)
  1661.                         term.setBackgroundColor(colors.lightGray)
  1662.                         write("Post name:")
  1663.                         term.setCursorPos(14,10)
  1664.                         term.setTextColor(colors.black)
  1665.                         term.setBackgroundColor(colors.lightGray)
  1666.                         local postName = limitRead(25)
  1667.                         if logged then
  1668.                             --add logged upload
  1669.                             local response = http.post(
  1670.                                 "http://pastebin.com/api/api_post.php",
  1671.                                 "api_option=paste&"..
  1672.                                 "api_dev_key="..devKey.."&"..
  1673.                                 "api_paste_format="..syntaxTab.urlCodes[synOpt].."&"..
  1674.                                 "api_user_key="..userKey.."&"..
  1675.                                 "api_paste_name="..textutils.urlEncode(postName).."&"..
  1676.                                 "api_paste_private="..(pubOpt - 1).."&"..
  1677.                                 "api_paste_expire_date="..expTabList[expOpt].."&"..
  1678.                                 "api_paste_code="..textutils.urlEncode(postText)
  1679.                                 )
  1680.                             if response then
  1681.                                 local pasteURL = response.readAll()
  1682.                                 for i = 7, 12 do
  1683.                                     paintutils.drawLine(10, i, 41, i, colors.blue)
  1684.                                     paintutils.drawLine(11, i, 40, i, colors.white)
  1685.                                     paintutils.drawLine(12, i, 39, i, colors.lightGray)
  1686.                                 end
  1687.                                 term.setCursorPos(17, 8)
  1688.                                 term.setTextColor(colors.black)
  1689.                                 term.setBackgroundColor(colors.lightGray)
  1690.                                 write("Paste saved at:")
  1691.                                 term.setCursorPos(12, 10)
  1692.                                 term.setTextColor(colors.lime)
  1693.                                 write(pasteURL)
  1694.                                 os.pullEvent()
  1695.                             end
  1696.                         else
  1697.                             --not logged upload
  1698.                             local response = http.post(
  1699.                                 "http://pastebin.com/api/api_post.php",
  1700.                                 "api_option=paste&"..
  1701.                                 "api_dev_key="..devKey.."&"..
  1702.                                 "api_paste_format="..syntaxTab.urlCodes[synOpt].."&"..
  1703.                                 "api_paste_name="..textutils.urlEncode(postName).."&"..
  1704.                                 "api_paste_expire_date="..expTabList[expOpt].."&"..
  1705.                                 "api_paste_code="..textutils.urlEncode(postText)
  1706.                                 )
  1707.                             if response then
  1708.                                 local pasteURL = response.readAll()
  1709.                                 for i = 7, 12 do
  1710.                                     paintutils.drawLine(10, i, 41, i, colors.blue)
  1711.                                     paintutils.drawLine(11, i, 40, i, colors.white)
  1712.                                     paintutils.drawLine(12, i, 39, i, colors.lightGray)
  1713.                                 end
  1714.                                 term.setCursorPos(17, 8)
  1715.                                 term.setTextColor(colors.black)
  1716.                                 term.setBackgroundColor(colors.lightGray)
  1717.                                 write("Paste saved at:")
  1718.                                 term.setCursorPos(12, 10)
  1719.                                 term.setTextColor(colors.lime)
  1720.                                 write(pasteURL)
  1721.                                 os.pullEvent()
  1722.                             end
  1723.                         end
  1724.                     end
  1725.                 end
  1726.             end
  1727.         elseif events[1] == "char" then
  1728.             for i = 1, #listTable do
  1729.                 if string.lower(string.sub(listTable[i], 1, 1)) == events[2] then
  1730.                     scroll = i
  1731.                     break
  1732.                 end
  1733.                 drawList(dirTab, listTable, scroll)
  1734.             end
  1735.         elseif events[1] == "mouse_click" and events[2] == 1 then
  1736.             if events[4] == 15 then
  1737.                 if events[3] >= 24 and events[3] <= 48 then
  1738.                     synOpt = drawMiniMenu("syntax", syntaxTab.menuNames)
  1739.                 end
  1740.             elseif events[4] == 16 then
  1741.                 if events[3] >= 24 and events[3] <= 48 then
  1742.                     expOpt = drawMiniMenu("expiration", expiryTab)
  1743.                 end
  1744.             elseif events[4] == 17 then
  1745.                 if events[3] >= 24 and events[3] <= 48 then
  1746.                     pubOpt = logged and drawMiniMenu("exposure", exposureTab) or 1
  1747.                 end
  1748.             elseif events[4] == 18 then
  1749.                 if events[3] >= 24 and events[3] <= 26 then
  1750.                     if hidden == true then
  1751.                         hidden = false
  1752.                     elseif hidden == false then
  1753.                         hidden = true
  1754.                     end
  1755.                 end
  1756.             elseif events[4] == 2 then
  1757.                 if events[3] >= 1 and events[3] <= 5 then
  1758.                     os.queueEvent(unpack(events))
  1759.                     break
  1760.                 elseif events[3] >= 21 and events[3] <= 24 then
  1761.                     os.queueEvent(unpack(events))
  1762.                     break
  1763.                 elseif events[3] >= 28 and events[3] <= 31 then
  1764.                     os.queueEvent(unpack(events))
  1765.                     break
  1766.                 elseif events[3] >= 34 and events[3] <= 42 then
  1767.                     os.queueEvent(unpack(events))
  1768.                     break
  1769.                 elseif events[3] >= 45 and events[3] <= 49 then
  1770.                     os.queueEvent(unpack(events))
  1771.                     break
  1772.                 end
  1773.             elseif events[4] == 1 and events[3] == x then
  1774.                 os.queueEvent("terminate")
  1775.                 break
  1776.             end
  1777.         end
  1778.     end
  1779. end
  1780.  
  1781. --button objects
  1782. buttons = {
  1783.     {name = not logged and "Login" or "Welcome!",
  1784.     action = function() loginScript() end,
  1785.     color = colors.black,
  1786.     BGcolor = colors.lightGray,
  1787.     x1 = 1,
  1788.     x2 = 5,
  1789.     y = 2},
  1790.     {name = fWolf and "Home" or "",
  1791.     action = fWolf and function()
  1792.                 term.clear = oldTerm
  1793.                 redirect("home")
  1794.             end or
  1795.             function()
  1796.                 if checkCode() then
  1797.                     unlock()
  1798.                 end
  1799.             end,
  1800.     color = colors.black,
  1801.     BGcolor = colors.lightGray,
  1802.     x1 = 21,
  1803.     x2 = 24,
  1804.     y = 2},
  1805.     {name = "New",
  1806.     action = function() newPaste() end,
  1807.     color = colors.black,
  1808.     BGcolor = colors.lightGray,
  1809.     x1 = 28,
  1810.     x2 = 31,
  1811.     y = 2},
  1812.     {name = "Download",
  1813.     action = function() downloadPaste() end,
  1814.     color = colors.black,
  1815.     BGcolor = colors.lightGray,
  1816.     x1 = 34,
  1817.     x2 = 42,
  1818.     y = 2},
  1819.     {name = "Help",
  1820.     action = function()
  1821.                 helpScreen()
  1822.             end,
  1823.     color = colors.black,
  1824.     BGcolor = colors.lightGray,
  1825.     x1 = 45,
  1826.     x2 = 49,
  1827.     y = 2},
  1828.     {name = "X",
  1829.     action = fWolf and function()
  1830.                 sleep(0)
  1831.             end or
  1832.             function()
  1833.                 os.queueEvent("terminate")
  1834.             end,
  1835.     color = colors.white,
  1836.     BGcolor = colors.red,
  1837.     x1 = 51,
  1838.     x2 = 51,
  1839.     y = 1}
  1840.     }
  1841.  
  1842. --gui functions
  1843. local logoTab = {
  1844. " __                      _   ",
  1845. "/ _\\_ __ ___   __ _ _ __| |_ ",
  1846. "\\ \\| '_ ' _ \\ / _' | '__| __|",
  1847. "_\\ \\ | | | | | (_| | |  | |_ ",
  1848. "\\__/_| |_| |_|\\__,_|_|   \\__|",
  1849. "   ___          _            ",
  1850. "  / _ \\__ _ ___| |_ ___      ",
  1851. " / /_)/ _' / __| __/ _ \\     ",
  1852. "/ ___/ (_| \\__ \\ ||  __/     ",
  1853. "\\/    \\__,_|___/\\__\\___|     "}
  1854.  
  1855. function background()
  1856.     term.setBackgroundColor(colors.black)
  1857.     term.setTextColor(colors.white)
  1858.     if fWolf then
  1859.         os.pullEvent, term = hideBar()
  1860.         term.clear()
  1861.     else
  1862.         term.clear()
  1863.     end
  1864.     term.setCursorPos(1,1)
  1865.     if fWolf then hideBar() end
  1866.     term.setTextColor(colors.white)
  1867.     term.setBackgroundColor(colors.blue)
  1868.     write(logged and "SmartPaste - "..username or "SmartPaste")
  1869.     repeat
  1870.         local tX, tY = term.getCursorPos()
  1871.         write(" ")
  1872.     until tX == x - 1
  1873.     term.setCursorPos(1,2)
  1874.     term.setBackgroundColor(colors.lightGray)
  1875.     write(string.rep(" ", x))
  1876.     for i = 1, #buttons do
  1877.         term.setCursorPos(buttons[i].x1, buttons[i].y)
  1878.         term.setBackgroundColor(buttons[i].BGcolor)
  1879.         term.setTextColor(buttons[i].color)
  1880.         write(buttons[i].name)
  1881.         term.setBackgroundColor(colors.black)
  1882.     end
  1883.     if fWolf then
  1884.         term.setCursorPos(25,17)
  1885.         term.setTextColor(colors.white)
  1886.         write("Firewolf Edition")
  1887.     end
  1888.     if logged then
  1889.         term.setCursorPos(1,2)
  1890.         term.setBackgroundColor(colors.lightGray)
  1891.         term.setTextColor(colors.black)
  1892.         write("Logout")
  1893.     end
  1894.     paintutils.drawImage(logo, 3, 3)
  1895.     for i = 1, #logoTab do
  1896.         term.setCursorPos(22, i + 5)
  1897.         term.setTextColor(fWolf and colors.orange or colors.blue)
  1898.         term.setBackgroundColor(colors.black)
  1899.         write(logoTab[i])
  1900.     end
  1901. end
  1902.  
  1903. -- Main menu navigation system
  1904. background()
  1905. while true do
  1906.     local events = {os.pullEventRaw()}
  1907.     if events[1] == "mouse_click" and events[2] == 1 and events[4] <= 2 and events[4] >= 1 then
  1908.         background()
  1909.         for i = 1, #buttons do
  1910.             if events[4] == buttons[i].y then
  1911.                 if events[3] >= buttons[i].x1 and events[3] <= buttons[i].x2 then
  1912.                     term.setCursorPos(buttons[i].x1, buttons[i].y)
  1913.                     term.setBackgroundColor(colors.red)
  1914.                     term.setTextColor(buttons[i].color)
  1915.                     write(buttons[i].name)
  1916.                     term.setBackgroundColor(colors.black)
  1917.                     term.setTextColor(colors.white)
  1918.                     buttons[i].action()
  1919.                 end
  1920.             end
  1921.         end
  1922.     elseif events[1] == "terminate" then
  1923.         term.setBackgroundColor(colors.black)
  1924.         term.setTextColor(colors.white)
  1925.         if fWolf then
  1926.             os.pullEvent, term = showBar()
  1927.             term.clear()
  1928.         else
  1929.             term.clear()
  1930.         end
  1931.         term.setCursorPos(1,1)
  1932.         print("Thank you for using SmartPaste!")
  1933.         return
  1934.     end
  1935. end
Advertisement
Add Comment
Please, Sign In to add comment