Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Maslakov committed Nov 5, 2015
1 parent a37fe41 commit c6c7a5b
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 10 deletions.
80 changes: 70 additions & 10 deletions OpenVpnManagement/Manager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net.Sockets;
using System.Net;

namespace OpenVpnManagement {
public class Manager {
Expand All @@ -12,42 +14,100 @@ enum Signal {
Usr1,
Usr2
}

private String ovpnFileName;
private String ovpnFileName; //todo
private String host;
private int port;
private int timeout;
public void Manager(String ovpnFileName) {
this.ovpnFileName = ovpnFileName;
}
private Socket socket;

public void Manager(String host, ) {
this.ovpnFileName = ovpnFileName;
public void Manager(String host = "localhost", int port = 1194, int timeout = 10) {
socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
try {
socket.Connect(host, port);
} catch (Exception ex) {
//todo
}
}

public String GetStatus() {
var a = this.SendCommand("status");
}

public String GetStats() {
var a = this.SendCommand("load-stats");
var a = this.SendCommand("load-stats"); //todo? doesn't exist?
}

public String GetVersion() {
return this.SendCommand("version");
}

public String GetPid() {
public String GetGetPid() {
return this.SendCommand("pid");
}

public String SendSignal(Signal sgn) {
return this.SendCommand(string.Format("SIG{}", sgn.ToString().ToUpper());
}

public String Mute() {
return this.SendCommand("pid");
}

public String GetEcho() {
return this.SendCommand("echo");
}

public String GetHelp() {
return this.SendCommand("help");
}

public String Kill() {

}

public String Net() {

}



public String GetState() {
return this.SendCommand("state");
}

public String GetState(int n) {
return this.SendCommand("state " + n.ToString());
}

public String GetStateAll() {
return this.SendCommand("state all");
}

public String SetStateOn() {
return this.SendCommand("state on");
}

public String SetStateOnAll() {
return this.SendCommand("state on all");
}

public String SetStateOff() {
return this.SendCommand("state off");
}

public String GetLog() {
return this.SendCommand("state off");
}


private String SendCommand(String cmd) {
byte[] buffer = Encoding.Default.GetBytes(cmd);
socket.Send(buffer, 0, buffer.Length, 0);
buffer = new byte[255];
int rec = socket.Receive(buffer, 0, buffer.Length, 0);

return rec.ToString();
}
}

}
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# OpenVpnManagement
A library in C# for communicating with OpenVPN Management Interface

0 comments on commit c6c7a5b

Please sign in to comment.