Skip to content

Commit

Permalink
Feature: Use environment variables to provide username/password for m…
Browse files Browse the repository at this point in the history
…acchina.io REMOTE]
  • Loading branch information
obiltschnig committed Sep 26, 2023
1 parent 6bbe4ab commit 9762cc4
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 9 deletions.
3 changes: 3 additions & 0 deletions WebTunnel/WebTunnelClient/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ remote-client https://8ba57423-ec1a-4f31-992f-a66c240cbfa0.remote.macchina.io /r
`remote-client` will prompt for your macchina.io REMOTE username and password.
When no longer needed, the tunnel can be terminated by typing `CTRL-C`.

The macchina.io REMOTE username and password can also be supplied via environment
variables `REMOTE_USERNAME` and `REMOTE_PASSWORD`.

You can now start your SSH client and connect it to port 2222 on your local machine
in order to open an SSH session to your device:

Expand Down
5 changes: 4 additions & 1 deletion WebTunnel/WebTunnelClient/src/WebTunnelClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "Poco/Util/IntValidator.h"
#include "Poco/NumberParser.h"
#include "Poco/Process.h"
#include "Poco/Environment.h"
#include <iostream>
#if defined(POCO_OS_FAMILY_WINDOWS)
#include <windows.h>
Expand Down Expand Up @@ -95,7 +96,9 @@ class WebTunnelClient: public Poco::Util::ServerApplication
_helpRequested(false),
_localPort(0),
_remotePort(0),
_bindAddress("localhost"s)
_bindAddress("localhost"s),
_username(Poco::Environment::get("REMOTE_USERNAME"s, ""s)),
_password(Poco::Environment::get("REMOTE_PASSWORD"s, ""s))
{
}

Expand Down
3 changes: 3 additions & 0 deletions WebTunnel/WebTunnelRDP/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ remote-rdp https://8ba57423-ec1a-4f31-992f-a66c240cbfa0.remote.macchina.io
`remote-rdp` will prompt for your macchina.io REMOTE username and password and
then launch the Remote Desktop client with correct parameters for host and port number.

The macchina.io REMOTE username and password can also be supplied via environment
variables `REMOTE_USERNAME` and `REMOTE_PASSWORD`.

The following RDP clients are used:

- `mstsc.exe` on Windows
Expand Down
9 changes: 5 additions & 4 deletions WebTunnel/WebTunnelRDP/src/WebTunnelRDP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "Poco/TemporaryFile.h"
#include "Poco/FileStream.h"
#include "Poco/Process.h"
#include "Poco/Environment.h"
#include "Poco/Format.h"
#include "Poco/String.h"
#include <iostream>
Expand Down Expand Up @@ -367,7 +368,7 @@ class WebTunnelRDP: public Poco::Util::Application
rdpExecutable = "open";
const std::string rdpPath(Poco::TemporaryFile::tempName() + ".rdp");
Poco::FileOutputStream rdpFile(rdpPath);
rdpFile
rdpFile
<< "full address:s:localhost:" << forwarder.localPort() << "\n"
<< "autoreconnection enabled:i:1\n"
<< "disable menu anims:i:1\n"
Expand All @@ -392,7 +393,7 @@ class WebTunnelRDP: public Poco::Util::Application
if (_remoteUsername.empty())
{
std::cout << "Windows Username: " << std::flush;
std::getline(std::cin, _remoteUsername);
std::getline(std::cin, _remoteUsername);
}
rdpArgs.push_back("/u:"s + _remoteUsername);
#else
Expand All @@ -419,8 +420,8 @@ class WebTunnelRDP: public Poco::Util::Application
bool _fullScreen = false;
Poco::UInt16 _localPort = 0;
Poco::UInt16 _remotePort = 3389;
std::string _username;
std::string _password;
std::string _username = Poco::Environment::get("REMOTE_USERNAME"s, ""s);
std::string _password = Poco::Environment::get("REMOTE_PASSWORD"s, ""s);
std::string _remoteUsername;
SSLInitializer _sslInitializer;
};
Expand Down
3 changes: 3 additions & 0 deletions WebTunnel/WebTunnelSCP/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ remote-scp file.txt pi@8ba57423-ec1a-4f31-992f-a66c240cbfa0.remote.macchina.io:
the tunnel connection and then launch the `scp` client program with correct parameters
for host, port number and remote user name.

The macchina.io REMOTE username and password can also be supplied via environment
variables `REMOTE_USERNAME` and `REMOTE_PASSWORD`.

### Passing Options to the SCP Client

`remote-scp` can pass command-line options to the SCP client. SCP command-line arguments
Expand Down
4 changes: 3 additions & 1 deletion WebTunnel/WebTunnelSCP/src/WebTunnelSCP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ class WebTunnelSCP: public Poco::Util::Application
WebTunnelSCP():
_helpRequested(false),
_localPort(0),
_remotePort(22)
_remotePort(22),
_username(Poco::Environment::get("REMOTE_USERNAME"s, ""s)),
_password(Poco::Environment::get("REMOTE_PASSWORD"s, ""s))
{
#if defined(POCO_OS_FAMILY_WINDOWS)
_scpClient = findExecutable("scp.exe"s);
Expand Down
3 changes: 3 additions & 0 deletions WebTunnel/WebTunnelSFTP/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ or `/sftp-client` command-line argument), an error message is printed and
then launch the SFTP client with correct parameters for host, port number and
remote user name.

The macchina.io REMOTE username and password can also be supplied via environment
variables `REMOTE_USERNAME` and `REMOTE_PASSWORD`.

### Passing Options to the SFTP Client

`remote-sftp` can pass command-line options to the SFTP client. SFTP command-line arguments
Expand Down
4 changes: 3 additions & 1 deletion WebTunnel/WebTunnelSFTP/src/WebTunnelSFTP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ class WebTunnelSFTP: public Poco::Util::Application
WebTunnelSFTP():
_helpRequested(false),
_localPort(0),
_remotePort(22)
_remotePort(22),
_username(Poco::Environment::get("REMOTE_USERNAME"s, ""s)),
_password(Poco::Environment::get("REMOTE_PASSWORD"s, ""s))
{
#if defined(POCO_OS_FAMILY_WINDOWS)
_sftpClient = findExecutable("sftp.exe"s);
Expand Down
3 changes: 3 additions & 0 deletions WebTunnel/WebTunnelSSH/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ or `/ssh-client` command-line argument), an error message is printed and
then launch the SSH client with correct parameters for host, port number and
remote SSH login name.

The macchina.io REMOTE username and password can also be supplied via environment
variables `REMOTE_USERNAME` and `REMOTE_PASSWORD`.

### Disabling Host Fingerprint Checking and Authenticity Warning

When connecting via SSH to a remote host with `remote-ssh`, the `ssh` client will
Expand Down
4 changes: 3 additions & 1 deletion WebTunnel/WebTunnelSSH/src/WebTunnelSSH.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ class WebTunnelSSH: public Poco::Util::Application
WebTunnelSSH():
_helpRequested(false),
_localPort(0),
_remotePort(22)
_remotePort(22),
_username(Poco::Environment::get("REMOTE_USERNAME"s, ""s)),
_password(Poco::Environment::get("REMOTE_PASSWORD"s, ""s))
{
#if defined(POCO_OS_FAMILY_WINDOWS)
_sshClient = findExecutable("ssh.exe"s);
Expand Down
3 changes: 3 additions & 0 deletions WebTunnel/WebTunnelVNC/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ remote-vnc https://8ba57423-ec1a-4f31-992f-a66c240cbfa0.remote.macchina.io
then launch the VNC client with correct parameters for host, port number and
remote user name.

The macchina.io REMOTE username and password can also be supplied via environment
variables `REMOTE_USERNAME` and `REMOTE_PASSWORD`.

On macOS, `remote-vnc` will launch the built-in macOS Screen Sharing client.
On other platforms, `remote-vnc` will attempt to launch an executable
named `vncviewer`, which must be in the executable search path.
Expand Down
5 changes: 4 additions & 1 deletion WebTunnel/WebTunnelVNC/src/WebTunnelVNC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "Poco/NumberParser.h"
#include "Poco/NumberFormatter.h"
#include "Poco/Process.h"
#include "Poco/Environment.h"
#include "Poco/Format.h"
#include "Poco/String.h"
#include <iostream>
Expand Down Expand Up @@ -70,7 +71,9 @@ class WebTunnelVNC: public Poco::Util::Application
WebTunnelVNC():
_helpRequested(false),
_localPort(0),
_remotePort(5900)
_remotePort(5900),
_username(Poco::Environment::get("REMOTE_USERNAME"s, ""s)),
_password(Poco::Environment::get("REMOTE_PASSWORD"s, ""s))
{
}

Expand Down

0 comments on commit 9762cc4

Please sign in to comment.