예제 #1
0
        public static SunfishService GetServiceForPath(ref string path)
        {
            if (string.IsNullOrEmpty(path) || path == "/" || path.StartsWith("/$sunfish"))
            {
                return(sroot);
            }
            string         candidateRelativePath = "";
            SunfishService candidate             = null;

            foreach (SunfishService s in srvs)
            {
                string plb = s.Configuration.Location;
                if (!plb.EndsWith("/"))
                {
                    plb = plb + "/";
                }
                if ((path == s.Configuration.Location || path.StartsWith(plb)) &&
                    (candidate == null || (candidate.Configuration.Location.Length < s.Configuration.Location.Length)))
                {
                    candidate             = s;
                    candidateRelativePath = path.Substring(s.Configuration.Location.Length);
                }
            }
            if (candidate != null)
            {
                path = candidateRelativePath;
            }
            return(candidate);
        }
예제 #2
0
 static void Load()
 {
     try
     {
         if (!File.Exists(DEFAULT_CONF_FILE))
         {
             return;
         }
         conf = new SunfishConfiguration();
         conf = JsonNet.Deserialize <SunfishConfiguration>(File.ReadAllText(DEFAULT_CONF_FILE));
         if (conf.Services == null)
         {
             conf.Services = new List <SunfishServiceConfiguration>();
         }
         sroot.ShowMenu = conf.SunfishRoot;
         foreach (SunfishServiceConfiguration ssc in conf.Services)
         {
             srvs.Add(SunfishService.Instance(ssc));
         }
         if (conf.Active)
         {
             //Bypass set active check
             conf.Active = false;
             SetActive(true);
         }
     }
     catch { }
 }
예제 #3
0
 private void EditConfiguration(SunfishServiceConfiguration ssc, SunfishService oldService)
 {
     if (FServiceConf.Execute(ssc))
     {
         try
         {
             if (oldService == null)
             {
                 lbPaths.Items.Add(Sunfish.AddService(ssc));
             }
             else
             {
                 SunfishService s   = Sunfish.ReplaceService(oldService, ssc);
                 int            idx = lbPaths.Items.IndexOf(oldService);
                 if (idx < 0)
                 {
                     lbPaths.Items.Add(s);
                 }
                 else
                 {
                     lbPaths.Items[idx] = s;
                 }
             }
         }
         catch (Exception ex)
         {
             ex.Show();
         }
     }
 }
예제 #4
0
        public static SunfishService AddService(SunfishServiceConfiguration ssc)
        {
            SunfishService s;

            srvs.Add(s = SunfishService.Instance(ssc));
            conf.Services.Add(ssc);
            return(s);
        }
예제 #5
0
        private void clbPaths_DoubleClick(object sender, EventArgs e)
        {
            SunfishService s = (SunfishService)lbPaths.SelectedItem;

            if (s == null)
            {
                return;
            }
            EditConfiguration(s.Configuration, s);
        }
예제 #6
0
        private void btSub_Click(object sender, EventArgs e)
        {
            SunfishService sh = (SunfishService)lbPaths.SelectedItem;

            if (sh == null)
            {
                return;
            }
            if (MessageBox.Show("Delete access " + sh.Configuration.Name + "? Can not be undone!", "Delete", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                Sunfish.DeleteService(sh);
                lbPaths.Items.Remove(sh);
            }
        }
예제 #7
0
        public static SunfishService ReplaceService(SunfishService sold, SunfishServiceConfiguration ssc)
        {
            SunfishService s = SunfishService.Instance(ssc);
            int            i = srvs.IndexOf(sold);

            if (i < 0)
            {
                srvs.Add(s);
            }
            else
            {
                srvs[i] = s;
            }
            i = conf.Services.IndexOf(ssc);
            if (i < 0)
            {
                conf.Services.Add(ssc);
            }
            return(s);
        }
예제 #8
0
        private void LoadScreen()
        {
            int height = Height;

            // Remove all
            pScreen.Controls.Clear();
            string type = cbType.SelectedItem == null ? null : cbType.SelectedItem.ToString();

            if (string.IsNullOrEmpty(type))
            {
                ClientSize    = new Size(ClientSize.Width, pScreen.Top + panelOffset);
                btAdv.Visible = false;
                return;
            }
            ConfigurationScreen cs = SunfishService.GetConfigurator(type).GetConfigurationScreen();

            btAdv.Visible = cs.Advanced != null;
            // Create new
            int y = 0;

            foreach (ConfigurationElement ce in cs.Elements)
            {
                if (ce is ConfigurationMessage)
                {
                    AddElementMessage((ConfigurationMessage)ce, pScreen, ref y);
                }
                else if (ce is ConfigurationString)
                {
                    AddElementString((ConfigurationString)ce, pScreen, ref y);
                }
                else if (ce is ConfigurationBool)
                {
                    AddElementBool((ConfigurationBool)ce, pScreen, ref y);
                }
            }
            ClientSize = new Size(ClientSize.Width, y + pScreen.Top + panelOffset + 5);
            if (Visible)
            {
                Top -= (Height - height) / 2;
            }
        }
예제 #9
0
        static void server_Process(HttpServer server, HttpCall call)
        {
            var            path = call.Request.Url.LocalPath;
            SunfishService s    = GetServiceForPath(ref path);

            if (string.IsNullOrWhiteSpace(path))
            {
                call.Redirect(call.Request.Url.LocalPath + "/");
            }
            else
            {
                if (s == null || !s.Enabled)
                {
                    ErrorService.Process404(call);
                }
                else
                {
                    s.Process(path, call);
                }
            }
            call.Close();
        }
예제 #10
0
        private void cmsItem_Opening(object sender, CancelEventArgs e)
        {
            SunfishService s = lbPaths.SelectedItem as SunfishService;

            editarToolStripMenuItem.Enabled = s != null;
            borrarToolStripMenuItem.Enabled = s != null;
            toolStripSeparator1.Visible     = s != null;
            while (cmsItem.Items.Count > 4)
            {
                cmsItem.Items.RemoveAt(cmsItem.Items.Count - 1);
            }
            if (s == null)
            {
                return;
            }
            foreach (IpInfo ip in ListInterfacesIPs())
            {
                ToolStripItem tsi = cmsItem.Items.Add("Copy url for " + ip.Address + " (" + ip.InterfaceName + ", " + ip.InterfaceType + ")");
                tsi.Tag    = "http://" + ip.Address + ":" + Sunfish.Port + "/" + s.Configuration.Location + "/";
                tsi.Click += tsi_Click;
            }
        }
예제 #11
0
        private void lbPaths_DrawItem(object sender, DrawItemEventArgs e)
        {
            e.DrawBackground();
            e.DrawFocusRectangle();
            if (e.Index < 0)
            {
                return;
            }
            SunfishService s = (SunfishService)lbPaths.Items[e.Index];
            Graphics       g = e.Graphics;
            int            y = e.Bounds.Top + 2;

            using (Brush itembrush = new SolidBrush(e.ForeColor))
            {
                g.DrawImage(s.Enabled ? Resources.foldericon : Resources.foldericond, 1, y, 24, 24);
                g.DrawString(s.Configuration.Name, lbPaths.Font, itembrush, 28, y);
                g.DrawString(s.Configuration.Location, smallfont, itembrushgray, 33, y + 12);
                //if (sh.AllowSubfolders)
                //    g.DrawImage(Resources.osubf, 16, y + 13);
                //if (sh.AllowUpload)
                //    g.DrawImage(Resources.ouplo, 3, y + 13);
            }
        }
예제 #12
0
 public static void DeleteService(SunfishService srv)
 {
     conf.Services.Remove(srv.Configuration);
 }
예제 #13
0
 private FServiceConf()
 {
     InitializeComponent();
     panelOffset = ClientSize.Height - pScreen.Top;
     cbType.Items.AddRange(SunfishService.GetTypes());
 }