Accept-or-Deny-access-to-listening-channel - WeOnlyDo Software example code



All

wodCrypt (12)
wodSSH (10)
wodSFTP (23)
wodSSHServer (1)
wodSSHTunnel (11)
wodSSHpackage
wodSFTPdll

wodSSH.NET (10)
wodSFTP.NET (24)
wodFtpDLX.NET (22)
wodWebServer.NET (10)

wodAppUpdate (13)
wodHttpDLX (8)
wodFtpDLX (22)
wodTelnetDLX
wodFTPServer (3)
wodWebServer (10)
wodVPN
wodXMPP (13)
All ** [Visual Basic] ** [C#] ** [VB.NET] **

Accept or Deny access to listening channel
VB code
Dim WithEvents wodSSHTunnel1 As wodTunnelCom
Private Sub Form_Load()
    Set wodSSHTunnel1 = New wodTunnelCom

    'Authenticate with SSH server using hostname, login, password.
    wodSSHTunnel1.HostName = "your_hostname"
    wodSSHTunnel1.Login = "your_login"
    wodSSHTunnel1.Password = "your_password"
    wodSSHTunnel1.Connect
End Sub

'UserConnecting Event fires when a user wants to connect to the listening channel.
Private Sub wodSSHTunnel1_UserConnecting(ByVal Chan As wodSSHTunnelCOMLib.IChannel, ByVal Hostname As String, ByVal Port As Long, Allow As Boolean)
    'Inside this Event you can allow or deny user from connecting to listening channel.
    'Using Hostname and Port variable you can allow certain users from certain Hostnames to access listening channel.
   
    'In this example we will allow only user from localhost to access listening channel.
    If Hostname = "127.0.0.1" Then
        Allow = True
    Else
        Allow = False
    End If
End Sub

'Connected Event fires when wodSSHTunnel connects to a remote server.
Private Sub wodSSHTunnel1_Connected()
    wodSSHTunnel1.Channels.Add LocalListen, "127.0.0.1", 80, "0.0.0.0", 80
    wodSSHTunnel1.Channels.StartAll 'Start channels
End Sub

'Disconnected Event fires when wodSSHTunnel disconnects from the server.
Private Sub wodSSHTunnel1_Disconnected(ByVal ErrorCode As Integer, ByVal ErrorText As String)
    If ErrorCode <> 0 Then
        MsgBox "DISCONNECTED: " & ErrorText 'Connection error is received here
    End If
End Sub
VB.NET code
Dim WithEvents wodSSHTunnel1 As wodSSHTunnelCOMLib.wodTunnelCom
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    wodSSHTunnel1 = New wodSSHTunnelCOMLib.wodTunnelCom

    'Authenticate with SSH server using hostname, login, password.
    wodSSHTunnel1.Hostname = "your_hostname"
    wodSSHTunnel1.Login = "your_login"
    wodSSHTunnel1.Password = "your_password"
    wodSSHTunnel1.Connect()
End Sub

'UserConnecting Event fires when a user wants to connect to the listening channel.
Private Sub wodSSHTunnel1_UserConnecting(ByVal Chan As wodSSHTunnelCOMLib.Channel, ByVal Hostname As String, ByVal Port As Integer, ByRef Allow As Boolean) Handles wodSSHTunnel1.UserConnecting
    'Inside this Event you can allow or deny user from connecting to listening channel.
    'Using Hostname and Port variable you can allow certain users from certain Hostnames to access listening channel.

    'In this example we will allow only user from localhost to access listening channel.
    If Hostname = "127.0.0.1" Then
        Allow = True
    Else
        Allow = False
    End If
End Sub

'Connected Event fires when wodSSHTunnel connects to a remote server.
Private Sub wodSSHTunnel1_Connected() Handles wodSSHTunnel1.Connected
    wodSSHTunnel1.Channels.Add(wodSSHTunnelCOMLib.ForwardTypesEnum.LocalListen, "127.0.0.1", 80, "0.0.0.0", 80)
    wodSSHTunnel1.Channels.StartAll() //Start channels
End Sub

'Disconnected Event fires when wodSSHTunnel disconnects from the server.
Private Sub wodSSHTunnel1_Disconnected(ByVal ErrorCode As Short, ByVal ErrorText As String) Handles wodSSHTunnel1.Disconnected
    If ErrorCode <> 0 Then
        MsgBox("DISCONNECTED: " & ErrorText) 'Connection error is received here
    End If
End Sub
C# code
wodSSHTunnelCOMLib.wodTunnelCom wodSSHTunnel1;
private void Form1_Load(System.Object sender, System.EventArgs e)
{
    wodSSHTunnel1 = new wodSSHTunnelCOMLib.wodTunnelCom();
    wodSSHTunnel1.Connected += new wodSSHTunnelCOMLib._IwodTunnelComEvents_ConnectedEventHandler(wodSSHTunnel1_Connected);
    wodSSHTunnel1.Disconnected += new wodSSHTunnelCOMLib._IwodTunnelComEvents_DisconnectedEventHandler(wodSSHTunnel1_Disconnected);
    wodSSHTunnel1.UserConnecting += new wodSSHTunnelCOMLib._IwodTunnelComEvents_UserConnectingEventHandler(wodSSHTunnel1_UserConnecting);

    //Authenticate with SSH server using hostname, login, password.
    wodSSHTunnel1.Hostname = "your_hostname";
    wodSSHTunnel1.Login = "your_login";
    wodSSHTunnel1.Password = "your_password";
    wodSSHTunnel1.Connect(wodSSHTunnel1.Hostname, wodSSHTunnel1.Port, wodSSHTunnel1.Protocol);
}

//UserConnecting Event fires when a user wants to connect to the listening channel.
void wodSSHTunnel1_UserConnecting(wodSSHTunnelCOMLib.Channel Chan, string Hostname, int Port, ref bool Allow)
{
    //Inside this Event you can allow or deny user from connecting to listening channel.
    //Using Hostname and Port variable you can allow certain users from certain Hostnames to access listening channel.

    //In this example we will allow only user from localhost to access listening channel.
    if (Hostname == "127.0.0.1")
    {
        Allow = true;
    }
    else
    {
        Allow = false;
    }
}

//Connected Event fires when wodSSHTunnel connects to a remote server.
private void wodSSHTunnel1_Connected()
{
    wodSSHTunnel1.Channels.Add(wodSSHTunnelCOMLib.ForwardTypesEnum.LocalListen, "127.0.0.1", 80, "0.0.0.0", 80);
    wodSSHTunnel1.Channels.StartAll(); //Start channels
}

//Disconnected Event fires when wodSSHTunnel disconnects from the server.
private void wodSSHTunnel1_Disconnected(short ErrorCode, string ErrorText)
{
    if (ErrorCode != 0)
    {
        MessageBox.Show("DISCONNECTED: " + ErrorText); //Connection error is received here
    }
}