Open Brun0oO opened 8 years ago
@Brun0oO You can use the globals()["_stash"].runtime.run(some_cmd, final_ins=your_stdin, final_outs=your_stdout, final_errs=your_stderr, persistent_lebel=1, add_to_history=True)
to call a command with a specific stdin
, stdout
and stderr
. However, this needs to be done for every command, so you will probably need some sort of loop and print the prompts by the script (or better, modify bin/source.py
to be able to open a shell to stdin
if called without args, so other scripts or the user can also use this as a shell. Then you would need to use the code above to redirect to the webshell).
Sorry for my bad english.
You're describing the SSH protocol.
Indeed, but i think a true ssh server should be more difficult to implement ...well, for me ;)
I saw a ssh client but not a ssh server in the Stash directory.
Brun0oO
I really want to make this now. It sounds like it shouldn't be hard, but since StaSh is really complicated itself, I don't exactly know where I would start.
All you would really need to do is write a simple socket
server and client program that would send the commands back and forth between devices. The only issue is actually getting the commands to be run dynamically from a program into the StaSh shell. Make sense?
After looking at the system
folder in StaSh's folder, I've noticed that if you want to make an SSH program, you'll have to re-write some of the files in order to call that SSH program like a module, that way it can execute commands directly to StaSh, but that is extremely difficult.
If you put the server program inside of stash/lib
, then stash/stash.py
will import it. I'm thinking that maybe if you did that, you could access stuff inside of the StaSh shell, including executing code dynamically?
Sorry for the excessive commenting, but once you make it load into the StaSh class by putting it in the lib folder, you can have it call StaSh.__call__
which will execute a StaSh command. Still figuring out how to do this.
For a ssh server, I think you would run in the bg, using &, from within stash. Then the server can call _stash to run commands. I think technically it is possible to run stash from a seperate module, launching it can be tricky.
Sent from my iPad
On Jul 12, 2017, at 5:44 PM, Sean Wilkerson notifications@github.com wrote:
After looking at the system folder in StaSh's folder, I've noticed that if you want to make an SSH program, you'll have to re-write some of the files in order to call that SSH program like a module, that way it can execute commands directly to StaSh, but that is extremely difficult.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.
I just made a basic version of this. I don't have an iOS device to test with today since my mom's gone, and I usually use her iPad to test these projects, so I'm flying blind here. But I think it's working fine by mind-compiling the programs...
# The server for "StaSSH" (cool name, I know)
import sys
import socket
def main(args):
HOSTNAME = args[0]
PORT = 4420 # Random, unpriviledged port.
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
sock.bind((HOSTNAME, PORT))
print("Server started at "+HOSTNAME+":"+str(PORT))
sock.listen(1)
conn, addr = sock.accept()
while True:
received = str(conn.recv(32768).decode("utf-8")) # A medium-large buffer in case of a large command.
_stash(received)
if __name__ == "__main__":
main(sys.argv[1:])
# The client program (you can run this on any device on the same WiFi network as you).
import sys
import socket
def main(args):
HOSTNAME = args[0]
PORT = 4420
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
sock.connect((HOSTNAME, PORT))
while True:
command = bytes(input("StaSSH>> ").encode("utf-8"))
sock.sendall(command)
if __name__ == "__main__":
main(sys.argv[1:])
Just move the server file into StaSh's bin as a command (I would recommend moving to ~/stash_extensions/bin/stassh.py
since that's the external bin path, and I love the name StaSSH. Once it's there, run it by doing stassh <local_ip_here>
where 192.168.x.x
). Once you find your IP, run the server command with the IP as an argument, it should say something like Server started at 192.168.1.140:4420
(the IP is going to be different, that's just an example).
Once you have that server started, just run the client program on any device that is connected to the same WiFi network that the server is running on. Make sure you pass in the same IP you used in the server program in the client program as an argument when you run it, so it knows which device to connect to.
Again, this is most likely going to be flawed since I haven't tested it, so please report back here if you have questions or errors.
Well, it has given me some new ideas.. I’m going to try a new approach... stay tunned :)
I made a little script here : https://github.com/Brun0oO/Pythonista/blob/master/rshell/rshell.py Copy it on your StaSH's bin as a command and call it using -l as argument. On your desktop, copy it in a directory, open a terminal in this directory and call it using the ip address of your iOS device and let the magic happen...
Notes:
Have fun !
@Brun0oO that's a pretty nifty system you made there.
Hi,
I would like to access to stash from my desktop through a kind of remote console located in a web browser. I managed to use websocket communications inside pythonista between an ios device (server side) and a desktop web browser (client side). I would like to intercept read and write operations inside stash in order to use my websocket communication. What is the best place to do it in the stash code ? Could you give some advices ?
Thanks, Brun0oO