Simple WebUI With Flask and Python

Simple WebUI With Flask and Python



hey guys corrosive here today we're playing with Python and flask pycharm is the actual editor that I'm using today mi REE and essentially what flask is is a simple fairly easy to use web framework for creating websites you could compare it to Django I don't have enough experience in Django or even flask honestly to make a distinction on which is better but for my purposes this seems to be working pretty well the idea here is that I can use this to create a simple web page to remotely administrate tasks for example I have Linux deploy on my phone and Metasploit within the Linux deploy image and it would be nice if I had a simple web interface that I could just tap and have it execute certain commands or start certain applications for me so I can do things a little bit easier than trying to tap a bunch of things into the terminal you know on a touchscreen interface that's not fun so I thought this would be another route to try it's pretty simple you basically just make a folder called templates put all of your HTML files in there and then in here I just have a few post methods in a couple of forms it's just a real simple template the server Python file here is just going to import sub process that's going to let me execute commands here on windows there's other ways to do it depending on the operating system we're also importing of course flask the request function and the template rendering function basically what we're saying here we're going to start up the application the main like root of the folder where your index goes is going to be defined here and all it's going to do is it's going to run the index function which is going to return render template function index.html basically just saying when the server starts and someone connects direct them to index.html template more or less so it's going to render that template and then these are different commands that I'm passing through so you see we have you know slash echo calc and test and they are all post methods for the most part you'll see here under echo echo is something I use from a template doesn't really need to be echo anymore what this will actually do is it's almost like a shell not advanced by any means all this is set up to do is that when a request comes in we're going to take command and assign it the value of whatever was in the text form of my index so if we go over here here's my text input name here and whenever we enter text it's going to take that assign it to the value of echo pull it back over here excuse me it's going to use echo but it's going to assign it to the value of text and then once it comes through here it's going to run our sub process call and then enter the value of command so essentially I could run the server come over here up not there come over here let me come in so here's our echo line if I type in notepad and enter it opens up notepad on my machine because the server is running locally now for calc and this other button what I did is this one here it's going to use a post method but it's not looking for anything but a button press so if I select calc it launches calc you'll notice the server's still running in the background as soon as I close the calculator this will stop loading and my code tells it to simply return to our index and render the template and that's all it's going to do now with the last one you won't be able to close calc it is really just playing around seeing what I can do is that I've only been playing with it for a few minutes all it is is a simple loop and that's it so if I run calc it's going to execute and you'll see the server's still running it's actually waiting for that command to finish I'm not back rounding the task until I close calculator it's not going to continue the loop but with the way this is if I close it it's going to loop and it's going to open Kalpa gehen and it's going to keep doing this and doing it and doing it and doing it the only way you're going to close this I mean you can open up you know calc and process and cop comes right back it doesn't matter you need to either close the page or shut down your server so for kill the server you'll see calc has died and of course if we go to Chrome you know site cannot be reached we can't do anything with it as far as the IP address now I think I ever touched on the topic we are using port I think five thousand is the salt we were using here yeah that's the default I know that you can change it though I haven't bothered to try I have four on debug you know I almost wouldn't be surprised like I just type in port equal to 8080 and try to run it I don't know if it's going to work nope but maybe it wants it as a string don't see why would but you never know I'll try it ya know so I don't know how to change the port but just kind of quick video to kind of let you see what I've been playing with maybe give you some ideas of your own you know go play around with this stuff there's a lot of fun things you can do my first real project but this is probably trying to integrate with bootstrap themes and then I can have my own like development blog that I can update as I'm learning another thing this is bootstrap here they've got a really cool dashboard same that I'd like to integrate and there goes my phone which suggests to me that I've been talking too long so we're going to close that down let me know what you guys think you're interested in this sort of stuff might be more than happy to talk about it in the future you know I want to keep learning it so let me know and I will put a link in the description with the source to this just keep in mind if I make changes to this it will update the source but maybe I'll create a new repo so that it doesn't change from what you see in the video here all right thanks again guys have a good one

Related Posts

Intro to Web Development - 1 - Introduction

5 Replies to “Simple WebUI With Flask and Python”

  1. Good quick sample – thanks. And I hope this is obvious to most viewers already, but it's not a good idea to allow input from a web form to be executed as a host command.

Leave a Reply

Your email address will not be published. Required fields are marked *