Jump to content




Running a program sent from another computer?


  • You cannot reply to this topic
23 replies to this topic

#1 whatsfast

  • New Members
  • 35 posts

Posted 26 November 2012 - 04:44 AM

How would I do it that I receive a file from a main computer through rednet and then run it on my computer. How would I do that? I want do it as a safety precaution on my server. If there's another better way then tell me that too. Thanks!

#2 bjornir90

  • Members
  • 378 posts
  • LocationFrance

Posted 26 November 2012 - 05:02 AM

Look at the program I made it's buggy but the main thing is here.
It's on line 112 here :
http://pastebin.com/bEBmy1Zt

#3 Zudo

  • Members
  • 800 posts
  • LocationUK

Posted 26 November 2012 - 05:02 AM

Do you mean send the PROGRAM through rednet or run a local program on a rednet signal?

#4 Zudo

  • Members
  • 800 posts
  • LocationUK

Posted 26 November 2012 - 05:03 AM

To send a signal to run a local program do:
id, message, dist = rednet.receive()
shell.run(message)


#5 whatsfast

  • New Members
  • 35 posts

Posted 26 November 2012 - 05:17 AM

How would you send a program through rednet is my question.

#6 whatsfast

  • New Members
  • 35 posts

Posted 26 November 2012 - 09:57 AM

Above

#7 bjornir90

  • Members
  • 378 posts
  • LocationFrance

Posted 26 November 2012 - 10:05 AM

I already show you, the sample is after the (if msgType == "f" then), somewhere after the line 120.

View Postbjornir90, on 26 November 2012 - 05:02 AM, said:

Look at the program I made it's buggy but the main thing is here.
It's on line 112 here :
http://pastebin.com/bEBmy1Zt


#8 whatsfast

  • New Members
  • 35 posts

Posted 26 November 2012 - 10:16 AM

So when I do loadString(msg1) () it should load my string and start it or should I add like a shell.run() and a bunch of stuff?

line 124 btw

#9 whatsfast

  • New Members
  • 35 posts

Posted 26 November 2012 - 11:49 AM

I tried but it doesn't work. Can anyone else help me? It says im trying to call nil.

Code:
loadstring(message) ()

#10 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 26 November 2012 - 12:22 PM

First chunk is the sender, second chunk is the receiver:

local filePath = "fileName"
local fileHandle = io.open(filePath, "r")
if fileHandle then
    rednet.send(1, "file:"..filePath..";"..fileHandle:read("*a"))
    fileHandle:close()
end

id, message = rednet.receive()
local fileHandle = io.open(string.match(message, "file:(.-);"), "w")
if fileHandle then
    fileHandle:write(string.match(message, ";(.*)")
    fileHandle:close()
end


#11 whatsfast

  • New Members
  • 35 posts

Posted 26 November 2012 - 12:55 PM

Im trying to make it so that the program is being accessed from another computer not through a file. What you just did here will help me in the future for when I make a email system so it won't go to waste. But still my question isn't answered. How would I make it so that a string with the program is sent to another computer "the client" and then run on that one without any saving on the client side and they can't see anything. I want this because I have a server and I cant have people accessing my files and getting into my system. I got everything. The only problem I have is making a string run like a program and the code note being accessible. for that program.

#12 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 26 November 2012 - 01:08 PM

You're not going to actually be able to prevent them from getting a hold of the code if you're transmitting them to it in any way, but you can try this. Again, first is the sender, second is the receiver:

local filePath = "fileName"
local fileHandle = io.open(filePath, "r")
if fileHandle then
    rednet.send(1, fileHandle:read("*a"))
    fileHandle:close()
end

id, message = rednet.receive()
loadstring(message)()


#13 whatsfast

  • New Members
  • 35 posts

Posted 26 November 2012 - 01:33 PM

Where it asks for file path if it the computer folder or is the hard drive path. Or is it something completely different?

#14 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 26 November 2012 - 01:40 PM

The first line there? Set that to wherever the file you want the client to be sent to run is located. If it's not stored as a file, you just send the string that the code is in:

rednet.send(1, codeStringVariableHere)


#15 whatsfast

  • New Members
  • 35 posts

Posted 26 November 2012 - 01:45 PM

That brings me back to my first problem. Whenever I send the code. It goes through all fine until the line loadstring(message) ()
It give me the error client:15: attempted to call nil. This is whenever I try to send a string.

#16 whatsfast

  • New Members
  • 35 posts

Posted 26 November 2012 - 02:09 PM

Can anyone help?

#17 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 26 November 2012 - 02:17 PM

Is the string you're sending it a legitimate piece of code? If it can't load the string, it won't work. You could also try loadstring("function() "..message.." end")().

#18 ChunLing

  • Members
  • 2,027 posts

Posted 26 November 2012 - 02:19 PM

I like to use a simple function to do loadstring calls because they are a hassle otherwise.
local function ldstrng(luacd)
local tmpfnc,rslt = loadstring(luacd)
    if tmpfnc then _,rslt = pcall(tmpfnc) end
return rslt end


#19 whatsfast

  • New Members
  • 35 posts

Posted 26 November 2012 - 02:29 PM

Ok I did that and no errors but the program isnt starting.

<p> </p>
<div>local function ldstrng(message)</div>
<div> local tmpfnc,rslt = loadstring(message)</div>
<div> if tmpfnc then _,rslt = pcall(message) end</div>
<div>  return rslt end</div>


#20 ChunLing

  • Members
  • 2,027 posts

Posted 26 November 2012 - 02:44 PM

Use "print(ldstrng(message))" and you should get a display of exactly why the program doesn't run.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users