60 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			60 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
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);
 | 
						|
    }
 | 
						|
    /// <summary>
 | 
						|
    /// Returns a list ("unknown";"connected";"disconnected","name")
 | 
						|
    /// </summary>
 | 
						|
    /// <param name="names"></param>
 | 
						|
    /// <returns></returns>
 | 
						|
    public Dictionary<String, String> getStatus(List<string> vpns) {
 | 
						|
      this.addLog("ServiceSetter.setStatus", "", LogLevel.Debug);
 | 
						|
      this.addLog("ServiceSetter.setStatus", "Status von allen Services", LogLevel.Info);
 | 
						|
      Dictionary<String, String> ret = new Dictionary<String, String>();
 | 
						|
      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;
 | 
						|
    }
 | 
						|
    /// <summary>
 | 
						|
    /// Return a Status of one VPN
 | 
						|
    /// </summary>
 | 
						|
    /// <param name="config">Configfile</param>
 | 
						|
    /// <returns>Statusustring</returns>
 | 
						|
    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);
 | 
						|
    }
 | 
						|
  }
 | 
						|
}
 |