Пример #1
0
        public static void Start()
        {
            if (!web_start)
            {
                Logger.Log.Warn("Beagle running with WebServices DISABLED\n");
                return;
            }

            try {
                IPHostEntry hostInfo = Dns.GetHostByName(Dns.GetHostName());
                //Fully qualified DNS name of host:
                hostname = hostInfo.HostName;
                Logger.Log.Info("This Computer Hostname: " + hostname);
            }
            catch (Exception ex)
            {
                Logger.Log.Error("Caught exception {0} in Dns.GetHostName: ", ex.Message);
                Logger.Log.Error("Resetting hostname to \"localhost\"");
                hostname = "localhost";
            }

            if (!web_global)
            {
                web_global = Conf.WebServices.AllowGlobalAccess;
            }

            //start web-access server first
            Logger.Log.Debug("Starting WebBackEnd");
            WebBackEnd.init();

            //Next start web-service server
            Logger.Log.Info("Starting WebServiceBackEnd");
            WebServiceBackEnd.init();

            Logger.Log.Debug("Global WebServicesAccess {0}", web_global ? "Enabled" : "Disabled");

            xsp_param[1] = web_port;
            xsp_param[3] = web_rootDir;

            //Check if web_rootDir_changed:
            if (String.Compare(web_rootDir, DEFAULT_XSP_ROOT, true) != 0)
            {
                //Assuming "/beagle" exists as an explicit sub-folder under user specified xsp root directory:
                xsp_param[5] = "/:" + web_rootDir + ",/beagle:" + web_rootDir + "/beagle";
            }

            try {
                // Mapping /beagle/local to ExternalStringsHack.Prefix
                if (Directory.Exists(ExternalStringsHack.Prefix))
                {
                    xsp_param[5] += ",/beagle/local:" + ExternalStringsHack.Prefix;
                }

                //Mapping /beagle/gnome to ExternalStringsHack.GnomePrefix
                if (Directory.Exists(ExternalStringsHack.GnomePrefix))
                {
                    xsp_param[5] += ",/beagle/gnome:" + ExternalStringsHack.GnomePrefix;
                }

                //Mapping /beagle/kde3 to ExternalStringsHack.KdePrefix
                if (Directory.Exists(ExternalStringsHack.KdePrefix))
                {
                    xsp_param[5] += ",/beagle/kde3:" + ExternalStringsHack.KdePrefix;
                }

                string imgDir = PathFinder.StorageDir + "/img";
                if (!Directory.Exists(imgDir))
                {
                    Process pr = new Process();
                    pr.StartInfo.UseShellExecute = true;
                    pr.StartInfo.FileName        = "mkdir";
                    pr.StartInfo.Arguments       = imgDir;

                    try {
                        pr.Start();
                        pr.WaitForExit();
                        pr.Close();
                        pr.Dispose();
                    }
                    catch (Exception e) {
                        Logger.Log.Warn("Error creating ~/.beagle/img folder");
                    }
                }
                xsp_param[5] += ",/beagle/img:" + imgDir;

                //if (!hostname.Equals("localhost")) {

                reserved_suffixes = new string[] { "beagle", "local", "gnome", "kde3" };
                BeagleHttpUriBase = "http://" + hostname + ":" + xsp_param[1] + "/beagle/";

                AccessFilter = new ExternalAccessFilter(BeagleHttpUriBase, reserved_suffixes);

                ArrayList matchers = AccessFilter.Matchers;
                foreach (SimpleMatcher sm in matchers)
                {
                    xsp_param[5] += ",/beagle/" + sm.Rewrite + ":" + sm.Match;
                }

                AccessFilter.Initialize();
                //}
            }
            catch (Exception e)
            {
                xsp_param[5] = DEFAULT_APP_MAPPINGS;
            }

            Logger.Log.Debug("Starting Internal Web Server");

            int retVal = 0;

            try {
                //Start beagled internal web server (BeagleXsp)
                retVal = Mono.ASPNET.Server.initXSP(xsp_param, out appServer);
            }
            catch (ArgumentException e) {
                //Retry with default application mappings:
                xsp_param[5] = DEFAULT_APP_MAPPINGS;
                retVal       = Mono.ASPNET.Server.initXSP(xsp_param, out appServer);
            }
            catch (System.Net.Sockets.SocketException) {
                Logger.Log.Error("Error starting Internal Web Server (retVal={0})", retVal);
                Logger.Log.Error("There is probably another beagled instance running.  "
                                 + "Use --replace to replace the running service");
            }

            if (retVal == 0)
            {
                Logger.Log.Debug("BeagleXSP Applications list: " + xsp_param[5]);
            }
        }
Пример #2
0
		public static void Start()
		{			
			if (! web_start) {
				Logger.Log.Warn("Beagle running with WebServices DISABLED\n");
				return;
			}
				
			try {
				IPHostEntry hostInfo = Dns.GetHostByName(Dns.GetHostName());
				//Fully qualified DNS name of host:
				hostname = hostInfo.HostName;
				Logger.Log.Info("This Computer Hostname: " + hostname);
			}
			catch (Exception ex) 
			{
				Logger.Log.Error("Caught exception {0} in Dns.GetHostName: ", ex.Message);
				Logger.Log.Error("Resetting hostname to \"localhost\"");
				hostname = "localhost";
			}
			
			if (! web_global)
				web_global = Conf.WebServices.AllowGlobalAccess;
			
			//start web-access server first
			Logger.Log.Debug ("Starting WebBackEnd");
			WebBackEnd.init ();

			//Next start web-service server
			Logger.Log.Info ("Starting WebServiceBackEnd");
			WebServiceBackEnd.init ();

			Logger.Log.Debug ("Global WebServicesAccess {0}", web_global ? "Enabled" : "Disabled");

			xsp_param[1] = web_port;
			xsp_param[3] = web_rootDir;
			
			//Check if web_rootDir_changed:
			if (String.Compare(web_rootDir, DEFAULT_XSP_ROOT, true) != 0)
				//Assuming "/beagle" exists as an explicit sub-folder under user specified xsp root directory:
				xsp_param[5] = "/:" + web_rootDir + ",/beagle:" + web_rootDir + "/beagle";
			
			try {
					// Mapping /beagle/local to ExternalStringsHack.Prefix	
				if (Directory.Exists(ExternalStringsHack.Prefix))
				xsp_param[5] += ",/beagle/local:" + ExternalStringsHack.Prefix;
							
					//Mapping /beagle/gnome to ExternalStringsHack.GnomePrefix
				if (Directory.Exists(ExternalStringsHack.GnomePrefix))
				xsp_param[5] += ",/beagle/gnome:" + ExternalStringsHack.GnomePrefix;
												
					//Mapping /beagle/kde3 to ExternalStringsHack.KdePrefix
				if (Directory.Exists(ExternalStringsHack.KdePrefix))
				xsp_param[5] += ",/beagle/kde3:" + ExternalStringsHack.KdePrefix;

				string imgDir = PathFinder.StorageDir + "/img";
				if (!Directory.Exists(imgDir))
				{
					Process pr = new Process ();
					pr.StartInfo.UseShellExecute = true; 
					pr.StartInfo.FileName = "mkdir"; 
					pr.StartInfo.Arguments = imgDir;

					try {		
						pr.Start ();
						pr.WaitForExit(); 	  				
	  					pr.Close();
	  					pr.Dispose();				
					} 
					catch (Exception e) { 
						Logger.Log.Warn("Error creating ~/.beagle/img folder"); 
					} 				
				}
				xsp_param[5] += ",/beagle/img:" + imgDir;
				
				//if (!hostname.Equals("localhost")) {

					reserved_suffixes = new string[] {"beagle", "local", "gnome", "kde3"};
					BeagleHttpUriBase = "http://" + hostname + ":" + xsp_param[1] + "/beagle/";
				
					AccessFilter = new ExternalAccessFilter(BeagleHttpUriBase, reserved_suffixes);
				
					ArrayList matchers = AccessFilter.Matchers;				
					foreach (SimpleMatcher sm in matchers) 					
						xsp_param[5] += ",/beagle/" + sm.Rewrite +":" + sm.Match;					
							
					AccessFilter.Initialize();
				//}
			}
			catch (Exception e)
			{
				xsp_param[5] = DEFAULT_APP_MAPPINGS;
			}					
				
			Logger.Log.Debug ("Starting Internal Web Server");

			int retVal = 0;
			try {
				//Start beagled internal web server (BeagleXsp)
				retVal = Mono.ASPNET.Server.initXSP(xsp_param, out appServer);
			}
			catch (ArgumentException e) {
				//Retry with default application mappings:
				xsp_param[5] = DEFAULT_APP_MAPPINGS;
				retVal = Mono.ASPNET.Server.initXSP(xsp_param, out appServer);		
			}
			catch (System.Net.Sockets.SocketException) {
					Logger.Log.Error ("Error starting Internal Web Server (retVal={0})", retVal);
					Logger.Log.Error("There is probably another beagled instance running.  "
							  + "Use --replace to replace the running service");			
			}

			if (retVal == 0) 
				Logger.Log.Debug("BeagleXSP Applications list: " + xsp_param[5]);
		}