Exemple #1
0
        public void DiskSyncUpdate(ApiCall call)
        {
            Data.Models.WebSite website = null;

            Guid SiteId = call.GetGuidValue("SiteId");

            website = Kooboo.Data.GlobalDb.WebSites.Get(SiteId);
            if (SiteId == default(Guid) || website == null)
            {
                return;
            }

            bool   enable = call.GetBoolValue("EnableDiskSync");
            string path   = call.GetValue("localpath");

            bool hasSamePath = Lib.Helper.StringHelper.IsSameValue(website.DiskSyncFolder, path);

            if (website.EnableDiskSync != enable || Lib.Helper.StringHelper.IsSameValue(website.DiskSyncFolder, path) == false)
            {
                website.EnableDiskSync = enable;
                website.DiskSyncFolder = path;
                GlobalDb.WebSites.AddOrUpdate(website);
            }

            if (enable)
            {
                // init disk..
                if (!hasSamePath)
                {
                }
                WebSiteService.InitDiskSync(website, true);
            }
        }
Exemple #2
0
        public JobViewModel GetEdit(ApiCall call)
        {
            var id = call.GetValue <long>("id");

            if (id > 0)
            {
                throw new Exception(Data.Language.Hardcoded.GetValue("Job can not edit, you may delete and create a new one"));

                var isrepeat = call.GetBoolValue("IsRepeat");

                if (isrepeat)
                {
                    var item = GlobalDb.RepeatingJob().Get(id);
                    if (item != null)
                    {
                        return(new JobViewModel(item));
                    }
                }
                else
                {
                    // var item = GlobalDb.ScheduleJob().
                }
            }

            return(new JobViewModel());
        }
Exemple #3
0
        public virtual void Post(ApiCall call)
        {
            string subdomain  = call.GetValue("subdomain");
            string RootDomain = call.GetValue("rootdomain");
            Guid   SiteId     = call.GetGuidValue("SiteId");
            int    port       = (int)call.GetLongValue("Port");

            if (string.IsNullOrEmpty(RootDomain))
            {
                return;
            }

            bool DefaultBinding = call.GetBoolValue("DefaultBinding");

            if (SiteId != default(Guid))
            {
                if (port <= 0)
                {
                    DefaultBinding = false;
                }


                if (!DefaultBinding)
                {
                    port = 0;
                }


                if (port > 0)
                {
                    if (!SystemStart.WebServers.ContainsKey(port) && Lib.Helper.NetworkHelper.IsPortInUse(port))
                    {
                        throw new Exception(Data.Language.Hardcoded.GetValue("port in use", call.Context) + ": " + port.ToString());
                    }
                }


                if (DefaultBinding && port > 0)
                {
                    GlobalDb.Bindings.AddOrUpdate(null, null, SiteId, call.Context.User.CurrentOrgId, DefaultBinding, port);
                }
                else
                {
                    var domain = GlobalDb.Domains.Get(RootDomain);
                    if (domain.OrganizationId != default(Guid) && AppSettings.IsOnlineServer && domain.OrganizationId != call.Context.User.CurrentOrgId)
                    {
                        throw new Exception(Data.Language.Hardcoded.GetValue("Domain does not owned by current user", call.Context));
                    }

                    GlobalDb.Bindings.AddOrUpdate(RootDomain, subdomain, SiteId, call.Context.User.CurrentOrgId, DefaultBinding, port);
                }
            }
        }
Exemple #4
0
        public void Zip(ApiCall call)
        {
            var isSpa = call.GetBoolValue("iSSpa");

            // TODO 根据这个为ImportExport.ImportZip确定是spa的导入

            if (call.Context.WebSite == null)
            {
                throw new Exception("site not found");
            }

            var SiteId = call.Context.WebSite.Id;

            // verify login.
            if (call.Context.User == null)
            {
                throw new Exception("Access denied");
            }
            else
            {
                var usersites = Kooboo.Sites.Service.WebSiteService.ListByUser(call.Context.User);

                var find = usersites.Find(o => o.Id == SiteId);
                if (find == null)
                {
                    throw new Exception("Access denied");
                }
            }

            // Guid Hash = call.GetValue<Guid>("hash");

            //if (Hash != default(Guid))
            //{
            //    var hashback = Kooboo.Lib.Security.Hash.ComputeGuid(call.Context.Request.PostData);

            //    if (hashback != Hash)
            //    {
            //        throw new Exception(Data.Language.Hardcoded.GetValue("Hash validation failed", call.Context));
            //    }
            //}

            var website = Kooboo.Data.GlobalDb.WebSites.Get(SiteId);
            var sitedb  = website.SiteDb();

            //  var zip = call.Context.Request.PostData;

            var files = Kooboo.Lib.NETMultiplePart.FormReader.ReadFile(call.Context.Request.PostData);

            if (files != null && files.Count > 0)
            {
                foreach (var f in files)
                {
                    var    bytes    = f.Bytes;
                    string filename = f.FileName;

                    string extension = System.IO.Path.GetExtension(filename);
                    if (!string.IsNullOrEmpty(extension))
                    {
                        extension = extension.ToLower();
                    }

                    if (extension == ".zip" || extension == ".rar")
                    {
                        MemoryStream memory = new MemoryStream(bytes);

                        Kooboo.Sites.Sync.ImportExport.ImportZip(memory, call.WebSite, call.Context.User.Id);
                    }
                }
            }
        }