using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BlubbFish.Utils;
namespace NetMonitorUtils {
public class OpenVpnSetter : OwnObject {
private ServiceControl serviceController;
private InIReader vpnini;
public OpenVpnSetter(string vpnfile, string configfile) {
this.addLog("NetworkSetter", "vpnfile: " + vpnfile + "; configfile: " + configfile + ";", LogLevel.Debug);
this.vpnini = InIReader.getInstance(vpnfile);
this.serviceController = ServiceControl.getInstance(configfile);
}
public bool setStart(string name) {
this.addLog("ServiceSetter.setStart", "", LogLevel.Debug);
this.addLog("ServiceSetter.setStart", "Starte Service", LogLevel.Info);
return this.serviceController.VpnSetStart(name);
}
public bool setStop(string name) {
this.addLog("ServiceSetter.setStop", "", LogLevel.Debug);
this.addLog("ServiceSetter.setStop", "Stoppe Service", LogLevel.Info);
return this.serviceController.VpnSetStop(name);
}
///
/// Returns a list ("unknown";"connected";"disconnected","name")
///
///
///
public Dictionary getStatus(List vpns) {
this.addLog("ServiceSetter.setStatus", "", LogLevel.Debug);
this.addLog("ServiceSetter.setStatus", "Status von allen Services", LogLevel.Info);
Dictionary ret = new Dictionary();
foreach(string vpn in vpns) {
String data = this.serviceController.VpnGetStatus(vpn);
if(data == "unknown") {
ret.Add(vpn, "unknown");
} else if(data.StartsWith("[connected")) {
ret.Add(vpn, "connected");
} else {
ret.Add(vpn, "disconnected");
}
}
return ret;
}
///
/// Return a Status of one VPN
///
/// Configfile
/// Statusustring
public string getStatus(string config) {
this.addLog("ServiceSetter.getStatus", "", LogLevel.Debug);
this.addLog("ServiceSetter.getStatus", "Status vom Service", LogLevel.Info);
return this.serviceController.VpnGetStatus(config);
}
}
}