Пример #1
0
        public void Push(ApiCall call)
        {
            //must do the user validation here...
            Guid SiteId = call.GetGuidValue("SiteId");

            Guid Hash = call.GetGuidValue("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));
                }
            }

            if (SiteId != default(Guid))
            {
                var website = Kooboo.Data.GlobalDb.WebSites.Get(SiteId);
                var sitedb  = website.SiteDb();

                var converter = new IndexedDB.Serializer.Simple.SimpleConverter <SyncObject>();

                SyncObject sync = converter.FromBytes(call.Context.Request.PostData);

                SyncService.Receive(sitedb, sync);
            }
            else
            {
                throw new Exception(Data.Language.Hardcoded.GetValue("Website not found"));
            }
        }
Пример #2
0
        public Menu CreateSub(ApiCall call)
        {
            Guid ParentId = call.GetGuidValue("ParentId");
            Guid RootId   = call.GetGuidValue("RootId");

            if (ParentId != default(Guid) && RootId != default(Guid))
            {
                var root = call.WebSite.SiteDb().Menus.Get(RootId);
                if (root != null)
                {
                    var parentmenu = GetSubMenu(root, ParentId);
                    if (parentmenu != null)
                    {
                        string Name    = call.GetValue("Name");
                        string Url     = call.GetValue("Url");
                        var    Submenu = new Menu();
                        Submenu.ParentId = ParentId;
                        Submenu.Name     = Name;
                        Submenu.Values.Add(call.WebSite.DefaultCulture, Name);
                        Submenu.RootId = RootId;
                        Submenu.Url    = Url;
                        parentmenu.children.Insert(0, Submenu);
                        call.WebSite.SiteDb().Menus.AddOrUpdate(root, call.Context.User.Id);
                        return(Submenu);
                    }
                }
            }
            return(null);
        }
Пример #3
0
        public void Swap(ApiCall call)
        {
            Guid rootid = call.GetGuidValue("rootid");
            Guid ida    = call.GetGuidValue("ida");
            Guid idb    = call.GetGuidValue("idb");

            call.WebSite.SiteDb().Menus.Swap(rootid, ida, idb, call.Context.User.Id);
        }
Пример #4
0
        public List <ContentFieldViewModel> GetFields(ApiCall call)
        {
            Guid FolderId = call.GetGuidValue("FolderId");

            if (FolderId != default(Guid))
            {
                var contenttype = call.WebSite.SiteDb().ContentTypes.GetByFolder(FolderId);
                List <ContentFieldViewModel> result = new List <ContentFieldViewModel>();

                foreach (var item in contenttype.Properties)
                {
                    if (item.Editable)
                    {
                        ContentFieldViewModel model = new ContentFieldViewModel();
                        model.Name        = item.Name;
                        model.Validations = item.Validations;
                        model.ControlType = item.ControlType;
                        model.ToolTip     = item.Tooltip;
                        model.Order       = item.Order;
                        // model.Value = content.GetValue(item.Name);
                        model.IsMultilingual   = item.MultipleLanguage;
                        model.MultipleValue    = item.MultipleValue;
                        model.selectionOptions = item.selectionOptions;
                        result.Add(model);
                    }
                }
                return(result);
            }
            return(null);
        }
Пример #5
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);
            }
        }
Пример #6
0
        public List <BindingInfo> ListByDomain(ApiCall call)
        {
            Guid domainid = call.GetGuidValue("domainid");

            if (domainid != default(Guid))
            {
                var bindings = GlobalDb.Bindings.GetByDomain(domainid);
                List <BindingInfo> bindinginfos = new List <BindingInfo>();
                foreach (var item in bindings)
                {
                    BindingInfo info = new BindingInfo();
                    info.Id             = item.Id;
                    info.FullName       = item.FullName;
                    info.SubDomain      = item.SubDomain;
                    info.OrganizationId = item.OrganizationId;

                    if (item.Port > 0 && item.Port != 80)
                    {
                        info.Port = item.Port;
                    }

                    var site = Kooboo.Data.GlobalDb.WebSites.Get(item.WebSiteId);
                    info.SiteName  = site != null ? site.Name : "";
                    info.Device    = item.Device;
                    info.DomainId  = item.DomainId;
                    info.WebSiteId = item.WebSiteId;
                    bindinginfos.Add(info);
                }
                return(bindinginfos);
            }

            return(null);
        }
Пример #7
0
        public string UpdateLang(ApiCall call)
        {
            Guid   id      = call.ObjectId;
            string strroot = call.GetValue("RootId");
            Guid   RootId  = call.GetGuidValue("rootid");
            string values  = call.GetValue("Values");

            if (System.Guid.TryParse(strroot, out RootId))
            {
                var root = call.WebSite.SiteDb().Menus.Get(RootId);

                var sub = GetSubMenu(root, id);

                if (sub != null)
                {
                    var dict = Kooboo.Lib.Helper.JsonHelper.Deserialize <Dictionary <string, string> >(values);

                    sub.Values = dict;

                    call.WebSite.SiteDb().Menus.AddOrUpdate(root, call.Context.User.Id);

                    string defaultlangcode = call.WebSite.DefaultCulture;

                    if (dict.ContainsKey(defaultlangcode))
                    {
                        return(dict[defaultlangcode]);
                    }
                }
            }
            return(null);
        }
Пример #8
0
        public List <Binding> ListBySite(ApiCall call)
        {
            Guid siteid = call.GetGuidValue("SiteId");

            if (siteid != default(Guid))
            {
                return(GlobalDb.Bindings.GetByWebSite(siteid));
            }
            return(null);
        }
Пример #9
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);
                }
            }
        }
Пример #10
0
        protected SiteDb GetSiteDb(ApiCall call)
        {
            var siteDb = call.WebSite.SiteDb();

            if (siteDb == null)
            {
                Guid SiteId = call.GetGuidValue("SiteId");

                var website = Kooboo.Data.GlobalDb.WebSites.Get(SiteId);
                siteDb = website != null?website.SiteDb() : null;
            }
            return(siteDb);
        }
Пример #11
0
        public void Post(ApiCall call)
        {
            var siteid = call.GetGuidValue("SiteId");

            Data.Models.WebSite website = Data.GlobalDb.WebSites.Get(siteid);

            if (website == null)
            {
                website = call.WebSite;
            }
            var setting = call.Context.Request.Model as SyncSetting;

            if (website != null)
            {
                ///TODO: if remotesiteId == default(guid), call to create remote site id...
                // url... /_api/site/create, FullDomain, SiteName....

                if (!setting.RemoteServerUrl.ToLower().StartsWith("http"))
                {
                    setting.RemoteServerUrl = "http://" + setting.RemoteServerUrl;
                }

                if (setting.RemoteWebSiteId == default(Guid))
                {
                    string FullDomain = call.GetValue("FullDomain");
                    string SiteName   = call.GetValue("SiteName");

                    if (!string.IsNullOrEmpty(FullDomain) && !string.IsNullOrEmpty(SiteName))
                    {
                        string url = setting.RemoteServerUrl + "/_api/site/create";
                        Dictionary <string, string> para = new Dictionary <string, string>();
                        para.Add("FullDomain", FullDomain);
                        para.Add("SiteName", SiteName);

                        var newsite = Lib.Helper.HttpHelper.Get <WebSite>(url, para, call.Context.User.UserName, call.Context.User.PasswordHash.ToString());

                        if (newsite != null)
                        {
                            setting.RemoteSiteName  = newsite.Name;
                            setting.RemoteWebSiteId = newsite.Id;
                        }
                    }
                }
                if (setting.RemoteWebSiteId != default(Guid))
                {
                    website.SiteDb().SyncSettings.AddOrUpdate(setting, call.Context.User.Id);
                }
            }
        }
Пример #12
0
        public bool Delete(ApiCall call)
        {
            Guid SiteId = call.GetGuidValue("SiteId");

            if (SiteId == default(Guid) && call.ObjectId != default(Guid))
            {
                SiteId = call.ObjectId;
            }

            if (SiteId != default(Guid))
            {
                WebSiteService.Delete(SiteId, call.Context.User);
                return(true);
            }
            return(false);
        }
Пример #13
0
        public List <ItemVersionViewModel> Versions(ApiCall call)
        {
            Guid KeyHash       = call.GetGuidValue("KeyHash");
            int  StoreNameHash = call.GetIntValue("StoreNameHash");

            if (KeyHash == default(Guid) || StoreNameHash == 0)
            {
                return(null);
            }
            var logs = call.WebSite.SiteDb().Log.Store.Where(o => o.KeyHash == KeyHash && o.StoreNameHash == StoreNameHash).SelectAll();

            List <ItemVersionViewModel> list = new List <ItemVersionViewModel>();

            foreach (var item in logs.OrderByDescending(o => o.Id))
            {
                list.Add(new ItemVersionViewModel()
                {
                    LastModified = item.UpdateTime, Id = item.Id, UserName = Data.GlobalDb.Users.GetUserName(item.UserId)
                });
            }

            return(list);
        }
Пример #14
0
        public Dictionary <string, string> GetLang(ApiCall call)
        {
            Guid   id      = call.ObjectId;
            string strroot = call.GetValue("RootId");
            Guid   RootId  = call.GetGuidValue("rootid");

            Dictionary <string, string> Values = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);

            if (System.Guid.TryParse(strroot, out RootId))
            {
                var root = call.WebSite.SiteDb().Menus.Get(RootId);

                var sub = GetSubMenu(root, id);

                if (sub != null)
                {
                    foreach (var item in call.WebSite.Culture.Keys.ToList())
                    {
                        string itemvalue = string.Empty;
                        if (sub.Values != null && sub.Values.ContainsKey(item))
                        {
                            itemvalue = sub.Values[item];
                        }

                        Values[item] = itemvalue;
                    }

                    var defaultvalue = Values[call.WebSite.DefaultCulture];
                    if (string.IsNullOrEmpty(defaultvalue) && !string.IsNullOrEmpty(sub.Name))
                    {
                        Values[call.WebSite.DefaultCulture] = sub.Name;
                    }
                }
            }
            return(Values);
        }
Пример #15
0
        private PagedListViewModel <SyncLogItemViewModel> GetLogItem(ApiCall call, bool initem)
        {
            var sitedb = call.WebSite.SiteDb();

            int pagesize = ApiHelper.GetPageSize(call);
            int pagenr   = ApiHelper.GetPageNr(call);

            PagedListViewModel <SyncLogItemViewModel> model = new PagedListViewModel <SyncLogItemViewModel>();

            model.PageNr   = pagenr;
            model.PageSize = pagesize;

            List <SyncLogItemViewModel> result = new List <SyncLogItemViewModel>();

            Guid settingid = call.GetGuidValue("SyncSettingId");

            var items = sitedb.Synchronization.Query.Where(o => o.SyncSettingId == settingid && o.In == initem).SelectAll().OrderByDescending(o => o.LastModifyTick);

            model.TotalCount = items.Count();
            model.TotalPages = ApiHelper.GetPageCount(model.TotalCount, model.PageSize);

            foreach (var item in items.Skip(model.PageNr * model.PageSize - model.PageSize).Take(model.PageSize))
            {
                var repo = sitedb.GetRepository(item.StoreName);

                if (repo != null)
                {
                    var log = sitedb.Log.Get(item.Version);
                    if (log != null)
                    {
                        var siteobject = repo.GetByLog(log);

                        SyncLogItemViewModel logitem = new SyncLogItemViewModel();
                        var info = ObjectService.GetObjectInfo(sitedb, siteobject as ISiteObject);
                        logitem.Name         = info.Name;
                        logitem.Size         = Lib.Utilities.CalculateUtility.GetSizeString(info.Size);
                        logitem.ObjectType   = repo.StoreName;
                        logitem.LastModified = log.UpdateTime;
                        logitem.LogId        = log.Id;

                        if (log.EditType == IndexedDB.EditType.Add)
                        {
                            logitem.ChangeType = ChangeType.Add;
                        }
                        else if (log.EditType == IndexedDB.EditType.Update)
                        {
                            logitem.ChangeType = ChangeType.Update;
                        }
                        else
                        {
                            logitem.ChangeType = ChangeType.Delete;
                        }

                        result.Add(logitem);
                    }
                }
            }

            model.List = result;
            return(model);
        }
Пример #16
0
        private PagedListViewModel <SyncLogItemViewModel> GetLogItem(ApiCall call, bool initem)
        {
            var sitedb = call.WebSite.SiteDb();

            int pagesize = ApiHelper.GetPageSize(call);
            int pagenr   = ApiHelper.GetPageNr(call);

            PagedListViewModel <SyncLogItemViewModel> model = new PagedListViewModel <SyncLogItemViewModel>();

            model.PageNr   = pagenr;
            model.PageSize = pagesize;

            List <SyncLogItemViewModel> result = new List <SyncLogItemViewModel>();

            Guid settingid = call.GetGuidValue("SyncSettingId");

            var items = sitedb.Synchronization.Query.Where(o => o.SyncSettingId == settingid && o.In == initem).SelectAll().OrderByDescending(o => o.LastModifyTick);

            model.TotalCount = items.Count();
            model.TotalPages = ApiHelper.GetPageCount(model.TotalCount, model.PageSize);

            foreach (var item in items.Skip(model.PageNr * model.PageSize - model.PageSize).Take(model.PageSize))
            {
                var log = sitedb.Log.Get(item.Version);
                if (log != null)
                {
                    ChangeType changetype;
                    if (log.EditType == IndexedDB.EditType.Add)
                    {
                        changetype = ChangeType.Add;
                    }
                    else if (log.EditType == IndexedDB.EditType.Update)
                    {
                        changetype = ChangeType.Update;
                    }
                    else
                    {
                        changetype = ChangeType.Delete;
                    }

                    if (log.IsTable)
                    {
                        var kdb   = Kooboo.Data.DB.GetKDatabase(sitedb.WebSite);
                        var table = Data.DB.GetTable(kdb, log.TableName);

                        if (table != null)
                        {
                            var logdata = table.GetLogData(log);

                            string size = null;
                            if (logdata != null)
                            {
                                var json = Lib.Helper.JsonHelper.Serialize(logdata);
                                size = CalculateUtility.GetSizeString(json.Length);
                            }

                            var name = Kooboo.Sites.Service.LogService.GetTableDisplayName(sitedb, log, call.Context, logdata);

                            SyncLogItemViewModel logitem = new SyncLogItemViewModel();
                            logitem.Name = name;

                            logitem.ObjectType   = Data.Language.Hardcoded.GetValue("Table", call.Context);
                            logitem.LastModified = log.UpdateTime;
                            logitem.LogId        = log.Id;
                            logitem.ChangeType   = changetype;

                            result.Add(logitem);
                        }
                    }

                    else
                    {
                        var repo = sitedb.GetRepository(item.StoreName);

                        if (repo != null)
                        {
                            var siteobject = repo.GetByLog(log);

                            SyncLogItemViewModel logitem = new SyncLogItemViewModel();
                            var info = ObjectService.GetObjectInfo(sitedb, siteobject as ISiteObject);
                            logitem.Name         = info.Name;
                            logitem.Size         = Lib.Utilities.CalculateUtility.GetSizeString(info.Size);
                            logitem.ObjectType   = repo.StoreName;
                            logitem.LastModified = log.UpdateTime;
                            logitem.LogId        = log.Id;
                            logitem.ChangeType   = changetype;

                            result.Add(logitem);
                        }
                    }
                }
            }
            model.List = result;
            return(model);
        }