My goal is fairly simple, I have written a python 3 script that runs on an ubuntu server at my workplace. Currently I (and other users) have to SSH into this ubuntu box anytime we want to run the script, which with a growing number of users is getting messy - from a convenience and security standpoint. So my boss would like me to create a nice webpage-based GUI to access this script and some other similar scripts I have written.
This seems like a straight forward thing, but the difficulty is in the details - the script is used for viewing and editing records so it has a lot of back-and-forth communication with the user (using input()) as well as screen clears and code like the following:
sys.stdout.write("\033[F") #back to previous line
sys.stdout.write("\033[K") #clear line
...to keep things clean and within one terminal.
If absolutely needed of course I could modify the script to accept inputs in a different format and output in a more html-friendly method without line and screen clears, but this would be rather tedious to redo for the whole script. SO - my question is what would be the best way to achieve what I'm after with minimal modifications to my written code? Ideally the webpage would just have a container holding a terminal-like graphic that handles all the input and output of the selected script as if it was running through a full fat terminal.
Things I've already looked into include basic python web frameworks such as CGI or mod_wsgi, or a python package like flask, but - correct me if I'm wrong - it seems there isn't a nice way to handle constant inputs within scripts with these let alone the terminal-oriented clearing I do for clearing lines and screens.
I also looked into ways to just host a full terminal on the webpage, and security concerns aside, this seems like the closest solution - using something like ajaxterm (which seems rather outdated now?) or wetty. My main concern with this is it isn't any easier than just using SSH at that point. Unless I could modify the terminal to auto-login and start a specific script automagically with the push of a button on the webpage, this would just be a glorified web-rendition of putty.
Any suggestions on how you would achieve this?
Related
There is a game I play that I want to automate some tasks in.
Not hacking just consistently print screening and execute fake keyboard outputs.
So I wrote some python code and packaged it into a .exe with pyinstaller so I can also share it with others.
The problem is, I know that the game autobans for using known macro softwares like macro recorder, AutoHotKey etc...
The game runs on windows with admin privileges, so I know it can probably gets a list of my running processes..
My question is, how can I protect myself?
There is no real way to protect yourself against a program that can see all processes, without turning it into something like a rootkit. However, there is a good chance your program won't be flagged, since you made it yourself and I doubt python itself is flagged. It depends on what game in particular you are referring to.
I have a python script that runs for a few hours. There is some probability of it failing or hanging. Therefore, I would like to find a way to monitor this script's progress while away from the computer it runs on. I have been looking into multiple options, but none of them are robust and straightforward enough.
If someone has some ideas, I'd love to hear them.
Here are some options I considered:
The computer running python is connected to my dropbox account. Therefore, I could write an HTML file to my dropbox. This would work on other computers. I could open the HTML file on another computer and refresh the page to get the latest version. However, this would not work on my phone. It would also not push any updates (not necessary, but that would be a great feature).
I looked into building an online dashboard that would visualize data. The idea would be to update the data as the script runs, thereby getting the script's latest state. I looked into plotly and anvil. However, I could not find a way of programmatically updating the data online.
As a very simple quick fix you could make a log file and have it update it at intervals. Pretty straightforward.
I have something in my clipboard, and I'd like to run a python script that invokes CTRL+V as if it was pressed on the keyboard, and pastes the clipboard's content to the current focused window (say chrome). Any idea how to do that?
You have an X-Y problem.
What you want to accomplish is programmatically take data from one program (where you hit cntrl-V) and place it into another arbitrary program (chrome).
There are two ways to do that:
First
You can either set the programs up to have a data exchange mechanism such as a system pipe, or a network connection. This requires some API for data exchange to be already included in the program or access to the source so you might add one. There are very specific channels for cross program data exchange and you wont do well to try to circumvent them. Program A cant just say
get_program_b().get_text_box().add(clip_board);
That would be a violation of Process Isolaton and an OS like windows is written expressly to make it impossible. Some programs are designed to take input from other programs.
popen.open('mysql -e "ISNERT INTO table (a) VALUES ('4')")
Chrome is not one of those programs, chrome avoids allowing programs from doing this because it would be a target for programs to do things like, get the saved password or credit card data out of chrome. Or use save password to login to someone account and buy things in someone elses name.
Second
You could try to spoof user input and input the data exactly like a user would so chrome wont know the difference. But spoofing a user is hard to do and intentionally so because it prevents malicious scripts from taking control of a computer and doing bad things. The makers of windows are accutely aware that spoofing input is a method to circumvent allowed data exchange channels. So the makers of windows made it hard to do. You need to have access to a lot of system assets that most programs wont be given. At a minimum a program has to run as admin on windows to accomplish this, then there are libs that will let you do it. Even then Im willing to bet there are easier way to get the job done. On a machine where you have access to anything and everything it is possible. If you don't have admin access, it should be downright impossible without knowing some unpatched exploit in the system.
Therefore
What you are trying to do goes against what the computer was designed to let you do. If we had more information on what you want to accomplish maybe some of the wonderful people here could help. Getting to the end result you want shouldnt be that hard. But you way of doing it is like trying to run across the ocean, when you just need a boat. As it is my answer is -- dont do it, that's not how windows was designed to work.
I've found a Python telnet file, which works fine (at binary tides) but I'm hoping to (learn to) implement control over the input area such that I have shell like history and editing of the input line, uninterrupted by the feed from the telnet server I'm logged into.
I've seen some posts on this, would I be right to think that I need to learn threading so that I can simultaneously watch the server, the input line and handle the division of the console area, to do this? Similar to the discussion of threads/sockets here (SO separate threads for sockets..) except that is for Java and I'm trying to study Python.
Or perhaps SO TKinter is what I should put in my study list..?
EDIT: I should mention that I hope to move to GUI presentation eventually for my small projects but for this one I'm happy to use the console...I figured it might be a smaller step (learning curve).
I wrote a python script that reads in text from a file and writes a text file of definitions. I want to somehow integrate my program with a webpage for the whole world to see.
I want to be able to retrieve input text from one text box, have the python script process it, then display the output in the other text box.
I have done quite a bit of research thus far but I am still unsure of the best way to go about doing this. I tried using google's app engine but encountered too many problems, for example the app engine runtime environment uses python 2.5.2, I wrote my program using 3.1.2. Other than that I just felt that I was beginning to waste my time trying to port my program over.
I'm starting to think that javascript is the way to go or maybe pyjamas. I was also wondering if it would be possible to just have the python program constantly running on the server and to perform a system call.
I posses very little knowledge when it comes to web development. I appreciate any advice.
You could use the cgi module and create a CGI script, if your server supports it.
It's a much bigger question, involving:
Where are you going to host the site,
How slow is the script (can it execute in a few seconds or not),
Does it need access data from files or a database,
How complex is it,
etc.
I would suggest you read about Django:
http://docs.djangoproject.com/en/1.2/
That is probably the easiest way to set up a simple web site, but is also very powerful if you want to do something more in the future (related to this project or not).
However, since your script is Python 3 only, you don't have too many options, see this question:
https://stackoverflow.com/questions/373945/what-web-development-frameworks-support-python-3
I suppose, if not too hard, it is worth thinking about converting it to Python 2.7.
If that is an option, then you might very well go down to Python 2.5 and use Google App Engine. It gives you many things for free and you really don't need to worry about many things that you would if you were to set up your server. It includes a modified (better to say, shrunk down) version of Django 1.1. When you say you are wasting your time porting from 3.x to 2.5, I guess you were not counting the time that you will waste setting all other things up.