How to display the webapp which is running in local host of a server in my laptop's browser - python-3.x

I have to say that, I am not a web developer and I don't know anything about how a web application works.
I've connected to a remote server via ssh, downloaded a project (Python, flask app) from github and run it there:
zwlayer#personalcomputer $ ssh myusername#ku.edu
myusername#ku.edu $ git clone https://github.com/.../project
myusername#ku.edu $ cd project
myusername#ku.edu $ env FLASK_APP=app.py FLASK_ENV=development env USE_CUDA=False flask run --host=0.0.0.0
Now, is it possible to get interact with that through my browser from my personalcomputer ?

You can use local port forwarding in SSH.
SSH to the server with command:
ssh -L 5000:127.0.0.1:5000 myusername#ku.edu
This will forward port 5000 on your host to port 5000 on the server
Run app with command:
flask run --host=127.0.0.1 --port=5000 (host and port options are used for the purpose of explicitness)
and you should be able to access the application by entering http://127.0.0.1:5000 in your browser.
Read more at https://www.booleanworld.com/guide-ssh-port-forwarding-tunnelling/

When starting a Flask development server using flask run, it starts listening on the loopback interface on port 5000 by default. By adding --host=0.0.0.0 you make the flask server listen on all network interfaces of the host. So, if you have full network access to the host, you should be able to point your browser to it. With the addresses given in your question, just enter http://ku.edu:5000 into the address bar of your browser to interact with your Flask web application.
However, this is not recommended, for security reasons! Since the server is listening on every network interfaces, any person with network access to the host computer can access the application. You're running the application with the Flask development server in development mode, which is not safe for production use.
Instead, I would suggest to use ssh port forwarding to access the flask development server, bound to the loopback interface of the remote host:
zwlayer#personalcomputer $ ssh -L 5000:localhost:5000 myusername#ku.edu
myusername#ku.edu $ git clone https://github.com/.../project
myusername#ku.edu $ cd project
myusername#ku.edu $ env FLASK_APP=app.py FLASK_ENV=development env USE_CUDA=False flask run
This way, ssh forwards all traffic directed to port 5000 of your local computer through the ssh tunnel to localhost:5000 at the remote host, i.e. to port 5000 of the remote host itself.
So, you can point your browser to http://localhost:5000, which is forwarded to the remote server's localhost:5000, which is where your flask server is listening. But—in contrast to the above solution—only local or ssh users at the remote host can access your application.

Related

How to run an FTP server locally that a docker container can connect to

I'm currently running vsftpd locally on port 21 and have a node program that pulls data from it and that also works great.
I have containerised the deployment of the program on my local machine and it deploys fine but complains it can't connect to the FTP server on port 21 which I realised was because that port wasn't open.
Now if I open that port with something like -p 21:21 then this is blocking the FTP server which is bound to 21. I don't understand how I can run a test FTP server and this container at the same time?
Is it possible?
If the "containerised program" is only the node app, then if you connect to the ftp server via localhost:21 it will fail because inside that container there is no ftp server running on port 21. If you want to use the ftp server that runs on your host os, you need to run the container with --net="host", then the node app should connect to the ftp server with 127.0.0.1:21.
Another approach would be creating another container for the ftp server and using docker dns system to communicate the containers.

Port forwarding on Spinnaker

I am doing a port forwarding to connect my local machine to Spinnaker.
Step1: -> Localhost to AWS instance
ssh -A -L 9000:localhost:9000 -L 8084:localhost:8084 -L 8087:localhost:8087 ec2-user#<aws-instance-ip>
Step2: -> Aws instance to Spinnaker cluster
ssh -L 9000:localhost:9000 -L 8084:localhost:8084 -L 8087:localhost:8087 ubuntu#10.100.10.5
This works fine when i do http://localhost:9000
However, instead of port forwarding from local machine I want to setup a tunnel from another aws instance (Eg: 55.55.55.55) and access via http://55.55.55.55:9000 . So that other team members can i directly access Spinnaker UI.
I have tried following the above steps from 55.55.55.55 host and then tried
http://55.55.55.55:9000 however it didnt work.
What should i change to make it resolve on 55.55.55.55 host?
Port forwarding is bound to the IP you give to ssh. If you give localhost (default), it will be accessible only on localhost (127.0.0.1). If you want to access it from outside, you need to give the 55.55.55.55 address instead.
You will also need a -g switch to ssh, which will allow remote hosts to connect to your locally forwarded ports.

How do I connect a somata client to a remote registry?

I'm using somata as my microservices platform for the web apps I'm building. I have successfully set up multiple clients on one machine with the somata registry running on the same machine. Now I want to have a client on one machine connect to a registry on another machine. How do I connect a client to a remote registry?
The simplest way is to use the environment variables SOMATA_REGISTRY_HOST (default "127.0.0.1") and SOMATA_REGISTRY_PORT (default 8420) when running your script:
SOMATA_REGISTRY_HOST=55.44.33.21 node test.js
The somata Client constructor also lets you connect to specific registries with the options registry_host and registry_port:
var client = new somata.Client({
registry_host: '55.44.33.21',
registry_port: 5858
})
Note: To allow connections from remote hosts, somata-registry will have to be run with its binding port as "0.0.0.0" instead of the default "127.0.0.1", which can be accomplished with the -h flag or SOMATA_REGISTRY_BIND_HOST environment variable when starting the registry. The -p flag and SOMATA_REGISTRY_BIND_PORT are also available for listening on a custom port.
somata-registry -h 0.0.0.0
or
SOMATA_REGISTRY_BIND_HOST=0.0.0.0 somata-registry
And of course you'll need access to the host and port from the remote machine.

SCP File from local to Heroku Server

I'd like to copy my config.yml file from my local django app directory to my heroku server, but I'm not sure how to get the user#host.com format for heroku.
I've tried running 'heroku run bash'
scp /home/user/app/config.yml
I'm not sure how I can get it in the
scp user#myhost.com:/home/user/dir1/file.txt user#myhost.com:/home/user/dir2'
format
As #tamas7 said it's firewalled, but your local machine is probably also firewalled. So unless you have a private server with SSH accessible from the Internet, you won't be able to scp.
I'm personally using transfer.sh free and open source service.
Upload your config.yml to it:
$ curl --upload-file ./config.yml https://transfer.sh/
https://transfer.sh/66nb8/config.yml
Then download it back from wherever you want:
$ wget https://transfer.sh/66nb8/config.yml
According to http://www.evans.io/posts/heroku-survival-guide/ incoming connections are firewalled off. In this case you need to approach your local machine from the Heroku server.
heroku run bash
scp user#mylocalmachine:/home/user/dir/file.txt .
This is a bit late to answer this question, but I use services like localtunnel - https://localtunnel.github.io/www/ to copy files from local machine to heroku.
First, run a python HTTP server in the directory where the file is located.
cd /path/to/file
python3 -m http.server
This starts a server in port 8000. Configure localtunnel to connect to that port.
lt -s mylocal -p 8000
Now from your heroku machine, you can fetch the file via curl.
curl -XGET http://mylocal.localtunnel.me/myfile.txt > myfile.txt
You could also use a service like https://ngrok.com/ to open up a TCP tunnel into your local machine.
You will need to enable Remote Login as in simlmx answer.
On your local machine open the TCP tunnel just like this:
$ ngrok tcp 22
And then, on the Heroku console, just use SCP with the PORT and HOST that Ngrok provided.
$ scp -P [PORT] username#[HOST]:~/path/to/file.ext .
If you need to download your entire repo, for example to recover an app that you no longer have locally, use heroku git:clone -a myapp. Docs.
Expanding on tamas7's answer:
You can connect to your computer from the heroku server.
If your computer is behind a router, you'll also need to forward the connection to your computer.
1. You computer must accept ssh connections
On my mac it was as simple as enabling it in the Preferences / Sharing panel.
2. Your router needs to forward the connection to your computer.
Go to your router's settings page in your browser (typically 192.168.0.1 but varies depending on the router). Find the port forwarding section and forward some port to your computer on port 22.
This is how it looked on my tp-link:
Here I am making sure that port 22000 is forwarded to my computer (192.168.0.110) on port 22.
3. Find your external IP
Simply google "what is my IP".
4. Scp your file from heroku
heroku run bash
scp -P 22000 your_user#your_external_IP:/path/to/your/file .
5. Undo everything!
Once you're done it's probably good practice to disable the port forwarding and remote login.

Accessing application in browser over SSH proxy on localhost.

I have SSH access to a web server that is hosting an application on port 8080. I have a SSH session setup and a proxy configured on Chrome to redirect requests to SSH tunnel. I basically configured it using these instructions: http://drewsymo.com/2013/11/ssh-tunnel-in-30-seconds-mac-osx-linux/
I can confirm using Whats My IP that my IP is that of the SSH session and that is working correctly.
But I cannot figure out how to access the local application on the web server that I am SSHed into. When I try localhost:8080 the SSH session gives me an error "channel X: open failed: connect failed: Connection refused"
Any idea what is going on?
You can just create a port-specific tunnel:
ssh -L18080:localhost:8080 username#theothermachine
and then go to localhost:18080 on your local machine. The tunnel will forward your request to port 8080 of the localhost on the other end (and of course, localhost on the other end is the other machine itself). If that doesn't work for some reason, then replace localhost by 127.0.0.1 in the ssh command.

Resources