[Pkg-mono-svn-commits] rev 316 - mono-nethostmanager/src
Pablo Fischer
pabl0-guest@quantz.debian.org
Sun, 22 Feb 2004 18:12:21 +0100
Author: pabl0-guest
Date: 2004-02-22 18:12:20 +0100 (Sun, 22 Feb 2004)
New Revision: 316
Modified:
mono-nethostmanager/src/Manager.cs
Log:
Modified: mono-nethostmanager/src/Manager.cs
===================================================================
--- mono-nethostmanager/src/Manager.cs 2004-02-22 16:16:37 UTC (rev 315)
+++ mono-nethostmanager/src/Manager.cs 2004-02-22 17:12:20 UTC (rev 316)
@@ -13,6 +13,7 @@
private static string config_file;
private static string host_path;
private static string host_alias;
+ private static string action;
///<summary>
///Verifies if the config file exists (the one that receives from the cmd line)
@@ -92,34 +93,77 @@
///Detects the option that is given from the command line
///</summary>
private static void WhatIsIt(string option) {
- if(option.StartsWith("--config-file")) {
+
+ //We don't need this if we are just going to print or repair
+ if(action == "repair" || action == "print") {
//Get the file name, after the '=' char
- config_file = option.Split('=')[1];
- //Does the file exists?
- if(!ExistsConfig()) {
- Console.WriteLine("[FNE] The filename does not exists");
+ //Does the option has a value?
+ try {
+ config_file = option.Split('=')[1];
+ }catch(System.IndexOutOfRangeException ex) {
+ Console.WriteLine("No values for {0}", option.Split('=')[0]);
+ System.Environment.Exit(0);
+ }
+ //If the file does not exists and the action depends of the file
+ if(!ExistsConfig() && action != "repair") {
+ Console.WriteLine("[FNE] The filename does not exists {0}", config_file);
+ System.Environment.Exit(0);
}
if(!IsConfigValid()) {
- Console.WriteLine("[FNV] The file format is not valid");
- }
+ Console.WriteLine("[FNV] The file format is not valid {0}", config_file);
+ System.Environment.Exit(0);
+ }
}
- if(option.StartsWith("--path")) {
- host_path = option.Split('=')[1];
- if(!System.IO.Directory.Exists(host_path)) {
- Console.WriteLine("[DNE] The Path Directory does not exists");
+ else {
+ switch(option.Split('=')[0]) {
+ case "--config-file":
+ //Get the file name, after the '=' char
+ //Does the option has a value?
+ try {
+ config_file = option.Split('=')[1];
+ }catch(System.IndexOutOfRangeException ex) {
+ Console.WriteLine("No values for {0}", option.Split('=')[0]);
+ System.Environment.Exit(0);
+ }
+ //If the file does not exists and the action depends of the file
+ if(!ExistsConfig()) {
+ Console.WriteLine("[FNE] The filename does not exists {0}", config_file);
+ System.Environment.Exit(0);
+ }
+ if(!IsConfigValid()) {
+ Console.WriteLine("[FNV] The file format is not valid {0}", config_file);
+ System.Environment.Exit(0);
+ }
+ break;
+ case "--path":
+ //Get the full path of the web files
+ //Does the option has a value?
+ try {
+ host_path = option.Split('=')[1];
+ }catch(System.IndexOutOfRangeException ex) {
+ Console.WriteLine("No values for {0}", option.Split('=')[0]);
+ System.Environment.Exit(0);
+ }
+ if(!System.IO.Directory.Exists(host_path)) {
+ Console.WriteLine("[DNE] The Path Directory does not exists");
+ System.Environment.Exit(0);
+ }
+ break;
+ case "--alias":
+ try {
+ host_alias = option.Split('=')[1];
+ }catch(System.IndexOutOfRangeException ex) {
+ Console.WriteLine("No values for {0}", option.Split('=')[0]);
+ System.Environment.Exit(0);
}
- }
- if(option.StartsWith("--alias")) {
- host_alias = option.Split('=')[1];
//Remove the /
- host_alias.Replace("/", "");
+ host_alias.Replace("/", "");
+ break;
+ default:
+ Console.WriteLine("[ONR] {0} Option not Recognized", option.Split('=')[0]);
+ System.Environment.Exit(0);
+ break;
}
- if(option.StartsWith("del") || option.StartsWith("del") || option.StartsWith("up")) {
- //Ok..
- }
- else {
- Console.WriteLine("[ONR] Option not Recognized");
- }
}
@@ -128,25 +172,76 @@
///The main
///</summary>
public static void Main(string[] args) {
- if(args.Length == 0) {
+ if(args.Length == 0 || args.Length < 4) {
Console.WriteLine("VirtualHost Manager");
Console.WriteLine("Use: netvirtualhost action options \n");
Console.WriteLine("Actions:");
Console.WriteLine(" add Add a VirtualHost");
Console.WriteLine(" del Delete a VirtualHost");
Console.WriteLine(" up Update the information of the host");
+ Console.WriteLine(" print Prints the file to screen in the xsp format (/alias:path)");
+ Console.WriteLine(" repair Creates a new VirtualHost file");
Console.WriteLine("Options:");
Console.WriteLine(" --config-file=<file> The full path where the config file is");
Console.WriteLine(" --alias=<alias> The alias that you want for the host");
Console.WriteLine(" --path=<path> The path where your web files are");
Console.WriteLine("\nFor example:");
Console.WriteLine(" netvirtualhost add --config-file=/etc/xsp/files.conf --alias=/examples --path=/usr/share/foo/bar\n");
+ System.Environment.Exit(0);
+
}
+ //Ok, read the command line args
else {
- foreach(string option in args) {
- WhatIsIt(option);
+ action = args[0];
+ //Which action?
+ if(action != "add" || action != "del" ||
+ action != "up" || action != "repair" ||
+ action != "print") {
+ Console.WriteLine("[ANR] {0} Action not Recognized", action);
+ System.Environment.Exit(0);
}
+ for(int i=1; i<args.Length; i++) {
+ WhatIsIt(args[i]);
+ }
}
+
+ //Now, what we need to do?
+ switch(action) {
+ case "add":
+ hosts = new VirtualHosts();
+ LoadConfigInfo();
+ //We already have a host with this path/alias?
+ if(hosts.GetHostPosition(host_alias, host_path) == -1) {
+ hosts.AddHost(new Host(host_path, host_alias));
+ Save();
+ }
+ else {
+ Console.WriteLine("[VHE] The VirtualHost already exists");
+ System.Environment.Exit(0);
+ }
+ break;
+ case "del":
+ hosts = new VirtualHosts();
+ LoadConfigInfo();
+ //We have this host?
+ //Save the value cause we will need it later..
+ int position = hosts.GetHostPosition(host_alias, host_path);
+ if(position != -1) {
+ hosts.RemoveHost(position);
+ Save();
+ }
+ else {
+ Console.WriteLine("[VHN] The VirtualHost does not exists");
+ System.Environment.Exit(0);
+ }
+ break;
+ case "up":
+
+
+
+
+
+ }
}
}