public void UpdateSubset(WebData webData, long subsetID = 0, string name = null)
        {
            MDBSubset subset;

            if (subsetID <= 0)
            {
                subset = new MDBSubset()
                {
                    ID = CaveSystemData.CalculateID(name), Name = name,
                };
                subset.ID = mdb.Subsets.Insert(subset);
            }
            else
            {
                subset = mdb.Subsets.TryGetStruct(subsetID);
                if (subset.ID == 0)
                {
                    throw new WebServerException(WebError.DatasetMissing, 0, "Subset does not exist!");
                }
                if (name != null)
                {
                    subset.Name = name;
                }
                mdb.Subsets.Replace(subset);
            }
            mdb.Save();
            GetSubsetList(webData);
            GetSubsetFilterList(webData, subset.ID);
        }
Esempio n. 2
0
        public void RemoveFromPlaylist(WebData webData, long playlistItemID)
        {
            var  userLevel = (MDBUserLevel)webData.Session.GetUser().AuthLevel;
            long ownerID   = CaveSystemData.CalculateID(webData.Request.SourceAddress);

            if (ownerID > 0)
            {
                ownerID = -ownerID;
            }

            Search search =
                Search.FieldEquals(nameof(MDBPlayListItem.ID), playlistItemID) &
                Search.FieldEquals(nameof(MDBPlayListItem.StreamID), MDBStreamType.JukeBob);

            lock (mdb.PlayListItems)
            {
                foreach (var item in mdb.PlayListItems.GetStructs(search))
                {
                    //admin mode or auto added subset title or added by myself
                    if (item.OwnerID >= 0 || item.OwnerID == ownerID || userLevel.HasFlag(MDBUserLevel.Admin))
                    {
                        mdb.PlayListItems.Delete(item.ID);
                    }
                    else
                    {
                        throw new WebServerException(WebError.MissingRights, 0, "You can only delete your own titles!");
                    }
                }
            }
        }
Esempio n. 3
0
        /// <summary>Checks the domain entries.</summary>
        /// <returns></returns>
        public List <Credentials> CheckDomainEntries()
        {
            foreach (DynDnsDomain dynDnsDomain in DynDnsDomains.GetStructs())
            {
                var  domainDns = DomainEntries.GetStructs(Search.FieldLike(nameof(DomainDns.NameAndTTL), dynDnsDomain.Username + "\t%"));
                bool ok        = domainDns.Any(d => d.DomainClass == "IN" && (d.DomainType == "A" || d.DomainType == "AAAA"));
                if (!ok)
                {
                    DynDnsDomains.Delete(dynDnsDomain.ID);
                    this.LogWarning("Deleted dyndns account for domain <yellow>{0}", dynDnsDomain.Username);
                }
            }

            List <Credentials> newUsers = new List <Credentials>();

            foreach (DomainDns domainDns in DomainEntries.GetStructs())
            {
                if (domainDns.DomainClass != "IN")
                {
                    continue;
                }
                if ((domainDns.DomainType != "A") && (domainDns.DomainType != "AAAA"))
                {
                    continue;
                }

                string[] parts = domainDns.Name.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries);
                if (parts.Length != 3)
                {
                    continue;
                }
                switch (parts[0])
                {
                case "wildcard":
                case "autoconfig": continue;
                }
                long id = CaveSystemData.CalculateID(domainDns.Name);
                if (!DynDnsDomains.Exist(id))
                {
                    Domain      domain      = Domains[domainDns.DomainID];
                    Admin       admin       = Admins[domain.AdminID];
                    Credentials credentials = new Credentials(id, admin.Email, domainDns);
                    DynDnsDomains.Replace(credentials.DynDnsDomain);
                    newUsers.Add(credentials);
                    this.LogInfo("Created new credentials for domain <cyan>{0}", domainDns.Name);
                }
            }
            return(newUsers);
        }
Esempio n. 4
0
        void Reload()
        {
            // only one reload at a time
            lock (this)
            {
                { // multi thread reload check
                    DateTime lastChanged = FileSystem.GetLastWriteTimeUtc(FileName);
                    if (lastChanged == LastChanged)
                    {
                        return;
                    }
                }

                Trace.TraceInformation("Reloading template {0}", FileName);

                // read config
                var config = IniReader.FromFile(FileName);
                {
                    LastChanged = FileSystem.GetLastWriteTimeUtc(FileName);
                    int v = config.ReadInt32("CaveWebTemplate", "Version");
                    if (v != 1)
                    {
                        throw new WebServerException(WebError.InternalServerError, 0, $"{FileName} invalid template version!");
                    }
                }

                // build function list
                {
                    var functions = new List <Func>();
                    foreach (string function in config.ReadSection("Functions", true))
                    {
                        var f = new Func
                        {
                            Name   = function,
                            Method = server.FindMethod(function),
                        };
                        if (f.Method == null)
                        {
                            throw new WebServerException(WebError.InternalServerError, 0, $"{FileName} invalid function call {function}!");
                        }

                        var list = new List <WebTemplateParameter>();
                        foreach (string parameter in config.ReadSection(function, true))
                        {
                            var i = Option.Parse(parameter);
                            if (i.Name.StartsWith("?"))
                            {
                                switch (i.Name)
                                {
                                case "?IfParametersPresent":
                                    foreach (string neededParam in i.Value.Split(','))
                                    {
                                        if (neededParam.Trim().Length == 0)
                                        {
                                            continue;
                                        }

                                        f.NeededParameters.Include(neededParam);
                                    }
                                    break;

                                default: throw new NotImplementedException($"Option {i} is not implemented!");
                                }
                                continue;
                            }
                            f.Parameters.Add(i.Name, i.Value);
                            list.Add(new WebTemplateParameter()
                            {
                                ID                  = CaveSystemData.CalculateID(function + i.Name),
                                FunctionName        = function,
                                ParameterAtFunction = i.Name,
                                ParameterAtTemplate = i.Value,
                            });
                        }
                        f.ParameterDescriptions = list.ToArray();
                        functions.Add(f);
                    }
                    this.functions = functions.ToArray();
                }

                // build content
                {
                    var content = new List <WebContentFile>();

                    // main file is always first content file
                    string master = config.ReadSetting("CaveWebTemplate", "Master");
                    if (master == null)
                    {
                        master = Path.GetFileNameWithoutExtension(FileName) + ".html";
                    }

                    string folder = Path.GetDirectoryName(FileName);
                    foreach (string contentFile in new string[] { master })
                    {
                        content.Add(new WebContentFile(server, folder, contentFile));
                    }
                    foreach (string contentFile in config.ReadSection("Content", true))
                    {
                        content.Add(new WebContentFile(server, folder, contentFile));
                    }

                    if (server.EnableStaticTemplates)
                    {
                        staticData = BuildStaticData(content.ToArray());
                    }
                    else
                    {
                        this.content = content.ToArray();
                    }
                }
            }
        }