public override void HandleRequest(string jsonString, AjaxBase ajax)
        {
            if (!User.IsAdminLoggedIn(ajax))
            {
                ajax.Unauthorized();
                return;
            }

            AdminErrorLogsGetRequest request = Utility.ParseJson<AdminErrorLogsGetRequest>(jsonString);
            AdminErrorLogsGetResponse response = new AdminErrorLogsGetResponse();
            response.numberOfLogs = Convert.ToInt32(Database.Select("errorlog", null, null, null, "COUNT(*)")[0]["COUNT(*)"]);
            List<ErrorLogJson> logs = new List<ErrorLogJson>();
            foreach (Dictionary<string, object> data in Database.Select("errorlog", null, "`time` DESC", (request.page * request.elementsPerPage) + "," + request.elementsPerPage))
            {
                ErrorLogJson log = new ErrorLogJson();
                log.id = Convert.ToInt32(data["id"]);
                log.time = Convert.ToInt32(data["time"]);
                log.type = Convert.ToString(data["type"]);
                log.source = Convert.ToString(data["source"]);
                log.message = Convert.ToString(data["message"]);
                log.stackTrace = Convert.ToString(data["stacktrace"]);
                logs.Add(log);
            }

            response.logs = logs.ToArray();
            ajax.ReturnJson(response);
        }
Ejemplo n.º 2
0
        public override void HandleRequest(string jsonString, AjaxBase ajax)
        {
            if (!User.IsAdminLoggedIn(ajax))
            {
                ajax.Unauthorized();
                return;
            }

            AdminUserAddRequest request = Utility.ParseJson<AdminUserAddRequest>(jsonString);
            Regex regex = new Regex("[^a-zA-Z0-9]");
            if (request.username == null || request.username == "" || regex.IsMatch(request.username) || request.username.Length > 30 || request.password == null || request.password.Length < 8 || request.password != request.password2)
            {
                ajax.BadRequest();
                return;
            }

            AdminUserAddResponse response = new AdminUserAddResponse();

            if (User.GetUser(request.username) != null)
            {
                response.status = 1;
            }
            else
            {
                response.status = 0;
                User.CreateNewUser(request.username, request.password, request.admin).Save();
            }

            ajax.ReturnJson(response);
        }
Ejemplo n.º 3
0
        public override void HandleRequest(string jsonString, AjaxBase ajax)
        {
            SearchModuleResponse response = new SearchModuleResponse();

            string mangaWhere = "`status`='0'";
            User user = User.GetCurrentUser(ajax);
            string collectionSelect = "FALSE";
            if (Settings.AllowGuest || user != null)
            {
                collectionSelect += " OR `cid` IN (SELECT `id` FROM `collection` WHERE `public`='1')";
            }

            if (user != null)
            {
                collectionSelect += " OR `cid` IN (SELECT `cid` FROM `collectionuser` WHERE `uid`=" + Database.Quote(user.Id.ToString()) + " AND `access`='1')";
                mangaWhere += " AND `cid` NOT IN (SELECT `cid` FROM `collectionuser` WHERE `uid`=" + Database.Quote(user.Id.ToString()) + " AND `access`='0')";
            }

            mangaWhere += " AND (" + collectionSelect + ")";

            string where = "`mid` IN (SELECT `id` FROM `manga` WHERE " + mangaWhere + ")";

            response.authors = Database.GetDistinctStringValues("meta", "author", where);
            response.series = Database.GetDistinctStringValues("meta", "series", where);
            response.publishers = Database.GetDistinctStringValues("meta", "publisher", where);

            ajax.ReturnJson(response);
        }
        public override void HandleRequest(string jsonString, AjaxBase ajax)
        {
            MangaListItemCoverRequest request = Utility.ParseJson<MangaListItemCoverRequest>(jsonString);
            Manga manga = Manga.GetById(request.id);

            if (manga == null || !manga.ParentCollection.Accessible(ajax))
            {
                ajax.BadRequest();
                return;
            }

            MangaImageResponse response = new MangaImageResponse();

            if (manga.Status == 0)
            {
                string cover = manga.GetCover();
                response.status = cover == null ? 1 : 0;
                response.url = cover;
            }
            else
            {
                response.status = 2;
            }

            ajax.ReturnJson(response);
        }
Ejemplo n.º 5
0
        public override void HandleRequest(string jsonString, AjaxBase ajax)
        {
            MangaReadRequest request = Utility.ParseJson<MangaReadRequest>(jsonString);
            MangaReadResponse response = new MangaReadResponse();

            Manga manga = Manga.GetById(request.id);
            Manga nextManga = Manga.GetById(request.nextId);

            if (manga == null || !manga.ParentCollection.Accessible(ajax))
            {
                response.id = -1;
            }
            else
            {
                response.id = manga.Id;
                response.pages = manga.NumberOfPages;
                response.ltr = manga.LeftToRight;
                manga.IncreaseViewCount();
            }

            if (nextManga == null || !nextManga.ParentCollection.Accessible(ajax))
            {
                response.nextId = -1;
            }
            else
            {
                response.nextId = nextManga.Id;
            }

            ajax.ReturnJson(response);
        }
        public override void HandleRequest(string jsonString, AjaxBase ajax)
        {
            User user = User.GetCurrentUser(ajax);
            if (user == null)
            {
                ajax.BadRequest();
                return;
            }

            ChangePasswordRequest request = Utility.ParseJson<ChangePasswordRequest>(jsonString);
            if (request.currentPassword == null || request.currentPassword == "" || request.newPassword == null || request.newPassword.Length < 8 || request.newPassword != request.newPassword2)
            {
                ajax.BadRequest();
                return;
            }

            ChangePasswordResponse response = new ChangePasswordResponse();

            if (!user.MatchPassword(request.currentPassword))
            {
                response.status = 1;
            }
            else
            {
                response.status = 0;
                user.SetPassword(request.newPassword);
                user.Save();
            }

            ajax.ReturnJson(response);
        }
Ejemplo n.º 7
0
        public override void HandleRequest(string jsonString, AjaxBase ajax)
        {
            LoginRequest request = Utility.ParseJson<LoginRequest>(jsonString);

            User user = null;
            if (request.username == null)
            {
                if (request.password == null)
                {
                    user = User.GetUser(SessionWrapper.GetUserName(ajax));
                }
            }
            else
            {
                user = User.GetUser(request.username, request.password);
            }

            LoginResponse response = new LoginResponse();

            if (user == null)
            {
                response.username = "";
                response.admin = false;
            }
            else
            {
                response.username = user.Username;
                response.admin = user.Admin;
            }

            SessionWrapper.SetUserName(ajax, response.username);

            ajax.ReturnJson(response);
        }
        public override void HandleRequest(string jsonString, AjaxBase ajax)
        {
            CheckMySqlSettingRequest request = Utility.ParseJson<CheckMySqlSettingRequest>(jsonString);

            MySqlConnection connection = null;
            bool pass = false;
            try
            {
                connection = Database.GetConnection(
                    request.server,
                    request.port,
                    request.username,
                    request.password,
                    request.database);

                new MySqlCommand(String.Format("SHOW FULL TABLES FROM `{0}`", MySqlHelper.EscapeString(request.database)), connection).ExecuteReader().Close();

                pass = true;
            }
            catch (Exception)
            {
            }

            if (connection != null)
            {
                connection.Close();
            }

            CheckMySqlSettingResponse response = new CheckMySqlSettingResponse();
            response.pass = pass;

            ajax.ReturnJson(response);
        }
        public override void HandleRequest(string jsonString, AjaxBase ajax)
        {
            if (!User.IsAdminLoggedIn(ajax))
            {
                ajax.Unauthorized();
                return;
            }

            AdminSettingsSetRequest request = Utility.ParseJson<AdminSettingsSetRequest>(jsonString);

            Settings.AllowGuest = request.guest;
            Settings.UseZip = request.zip;
            Settings.UseRar = request.rar;
            Settings.UsePdf = request.pdf;

            if (request.preprocessCount >= 0 && request.preprocessCount < 100)
            {
                Settings.MangaPagePreProcessCount = request.preprocessCount;
            }

            if (request.preprocessDelay >= 0 && request.preprocessDelay < 100000)
            {
                Settings.MangaPagePreProcessDelay = request.preprocessDelay;
            }

            if (request.cacheLimit >= 50 && request.cacheLimit < 100000)
            {
                Settings.MangaCacheSizeLimit = request.cacheLimit;
            }

            ajax.ReturnJson(new JsonResponse());
        }
        public override void HandleRequest(string jsonString, AjaxBase ajax)
        {
            if (!User.IsAdminLoggedIn(ajax))
            {
                ajax.Unauthorized();
                return;
            }

            AdminMangasGetRequest request = Utility.ParseJson<AdminMangasGetRequest>(jsonString);
            AdminMangasGetResponse response = new AdminMangasGetResponse();
            if (request.filter == null)
            {
                response.mangas = Manga.ToJsonArray(Manga.GetAllMangas());
            }
            else
            {
                Collection collection = null;
                if (!String.IsNullOrEmpty(request.filter.collection))
                {
                    if ((collection = Collection.GetByName(request.filter.collection)) == null)
                    {
                        ajax.BadRequest();
                        return;
                    }
                }

                response.mangas = Manga.ToJsonArray(Manga.GetMangasWithFilter(collection, request.filter.tag, request.filter.author, request.filter.type));
            }

            ajax.ReturnJson(response);
        }
        public override void HandleRequest(string jsonString, AjaxBase ajax)
        {
            if (!User.IsAdminLoggedIn(ajax))
            {
                ajax.Unauthorized();
                return;
            }

            AdminMangaMetaEditRequest request = Utility.ParseJson<AdminMangaMetaEditRequest>(jsonString);
            Manga manga = Manga.GetById(request.id);
            if (manga == null || request.meta == null)
            {
                ajax.BadRequest();
                return;
            }

            if (request.meta.author.Length > 100)
            {
                request.meta.author = request.meta.author.Substring(0, 100);
            }

            if (request.meta.title.Length > 100)
            {
                request.meta.title = request.meta.title.Substring(0, 100);
            }

            if (request.meta.series.Length > 100)
            {
                request.meta.series = request.meta.series.Substring(0, 100);
            }

            if (request.meta.publisher.Length > 100)
            {
                request.meta.publisher = request.meta.publisher.Substring(0, 100);
            }

            if (request.meta.volume < -1)
            {
                request.meta.volume = -1;
            }

            if (request.meta.volume > 999999999)
            {
                request.meta.volume = 999999999;
            }

            if (request.meta.year < -1)
            {
                request.meta.year = -1;
            }

            if (request.meta.year > 9999)
            {
                request.meta.year = 9999;
            }

            manga.UpdateMeta(request.meta);
            ajax.ReturnJson(new JsonResponse());
        }
        public override void HandleRequest(string jsonString, AjaxBase ajax)
        {
            PreInstallCheckResponse response = new PreInstallCheckResponse();
            response.installed = Config.IsInstalled;

            // assuming all these are good in asp.net version
            response.mySql = response.gd = response.zip = response.rar = response.pdfinfo = response.pdfdraw = true;

            ajax.ReturnJson(response);
        }
Ejemplo n.º 13
0
        public override void HandleRequest(string jsonString, AjaxBase ajax)
        {
            MangaListRequest request = Utility.ParseJson<MangaListRequest>(jsonString);
            MangaListResponse response = new MangaListResponse();
            response.items = Manga.ToListItemJsonArray(Manga.GetMangaList(ajax, request.filter));

            ThreadHelper.Run("ProcessAutoAddStage1");

            ajax.ReturnJson(response);
        }
        public override void HandleRequest(string jsonString, AjaxBase ajax)
        {
            if (!User.IsAdminLoggedIn(ajax))
            {
                ajax.Unauthorized();
                return;
            }

            AdminCollectionsGetResponse response = new AdminCollectionsGetResponse();
            response.collections = Collection.ToJsonArray(Collection.GetAllCollections());
            ajax.ReturnJson(response);
        }
Ejemplo n.º 15
0
        public override void HandleRequest(string jsonString, AjaxBase ajax)
        {
            if (!User.IsAdminLoggedIn(ajax))
            {
                ajax.Unauthorized();
                return;
            }

            AdminUsersGetResponse response = new AdminUsersGetResponse();
            response.users = User.ToJsonArray(User.GetAllUsers());
            ajax.ReturnJson(response);
        }
        public override void HandleRequest(string jsonString, AjaxBase ajax)
        {
            if (!User.IsAdminLoggedIn(ajax))
            {
                ajax.Unauthorized();
                return;
            }

            AdminMangaFilterResponse response = new AdminMangaFilterResponse();
            response.collections = Collection.GetAllCollectionNames();
            response.tags = Manga.GetAllTags();
            response.authors = MangaMeta.GetAuthors();
            ajax.ReturnJson(response);
        }
        public override void HandleRequest(string jsonString, AjaxBase ajax)
        {
            if (!User.IsAdminLoggedIn(ajax))
            {
                ajax.Unauthorized();
                return;
            }

            AdminMangaEditPathRequest request = Utility.ParseJson<AdminMangaEditPathRequest>(jsonString);
            Manga manga = Manga.GetById(request.id);

            if (manga == null)
            {
                ajax.BadRequest();
                return;
            }

            AdminMangaEditPathResponse response = new AdminMangaEditPathResponse();

            if (request.path == null || request.path == "")
            {
                response.path = manga.MangaPath;
                response.cid = manga.ParentCollectionId;
            }
            else
            {
                int mangaType;

                if ((request.path = Manga.CheckMangaPath(request.path)) == null || !Utility.IsValidStringForDatabase(request.path))
                {
                    response.status = 1;
                }
                else if (request.path.IndexOf(manga.ParentCollection.Path, StringComparison.InvariantCultureIgnoreCase) != 0)
                {
                    ajax.BadRequest();
                    return;
                }
                else if ((mangaType = Manga.CheckMangaType(request.path)) == -1)
                {
                    response.status = 3;
                }
                else
                {
                    response.status = 0;
                    manga.ChangePath(request.path, mangaType);
                }
            }

            ajax.ReturnJson(response);
        }
        public override void HandleRequest(string jsonString, AjaxBase ajax)
        {
            if (!User.IsAdminLoggedIn(ajax))
            {
                ajax.Unauthorized();
                return;
            }

            AdminCollectionEditNameRequest request = Utility.ParseJson<AdminCollectionEditNameRequest>(jsonString);
            Collection collection = Collection.GetById(request.id);

            if (collection == null)
            {
                ajax.BadRequest();
                return;
            }

            AdminCollectionEditNameResponse response = new AdminCollectionEditNameResponse();

            if (request.name == null || request.name == "")
            {
                response.name = collection.Name;
            }
            else
            {
                request.name = Utility.Remove4PlusBytesUtf8Chars(request.name);

                if (request.name.Length > 50)
                {
                    request.name = request.name.Substring(0, 50);
                }

                if (!Collection.CheckNewCollectionName(request.name))
                {
                    response.status = 1;
                }
                else
                {
                    response.status = 0;
                    collection.Name = request.name;
                    collection.MarkFolderCacheDirty();
                    collection.Save();
                }
            }

            ajax.ReturnJson(response);
        }
        public override void HandleRequest(string jsonString, AjaxBase ajax)
        {
            MangaDirectionRequest request = Utility.ParseJson<MangaDirectionRequest>(jsonString);

            Manga manga = Manga.GetById(request.id);

            if (manga == null || !manga.ParentCollection.Accessible(ajax))
            {
                ajax.BadRequest();
                return;
            }

            manga.LeftToRight = !manga.LeftToRight;
            manga.Save();

            ajax.ReturnJson(new JsonResponse());
        }
        public override void HandleRequest(string jsonString, AjaxBase ajax)
        {
            if (!User.IsAdminLoggedIn(ajax))
            {
                ajax.Unauthorized();
                return;
            }

            AdminSettingsGetResponse response = new AdminSettingsGetResponse();
            response.guest = Settings.AllowGuest;
            response.zip = Settings.UseZip;
            response.rar = Settings.UseRar;
            response.pdf = Settings.UsePdf;
            response.preprocessCount = Settings.MangaPagePreProcessCount;
            response.preprocessDelay = Settings.MangaPagePreProcessDelay;
            response.cacheLimit = Settings.MangaCacheSizeLimit;

            ajax.ReturnJson(response);
        }
        public override void HandleRequest(string jsonString, AjaxBase ajax)
        {
            if (!User.IsAdminLoggedIn(ajax))
            {
                ajax.Unauthorized();
                return;
            }

            AdminUsersSetAdminRequest request = Utility.ParseJson<AdminUsersSetAdminRequest>(jsonString);

            if (request.ids == null || request.ids.Length == 0)
            {
                ajax.BadRequest();
                return;
            }

            User.SetAdmin(request.ids, request.admin, User.GetCurrentUser(ajax));

            ajax.ReturnJson(new JsonResponse());
        }
        public override void HandleRequest(string jsonString, AjaxBase ajax)
        {
            if (!User.IsAdminLoggedIn(ajax))
            {
                ajax.Unauthorized();
                return;
            }

            AdminCollectionsSetPublicRequest request = Utility.ParseJson<AdminCollectionsSetPublicRequest>(jsonString);

            if (request.ids == null || request.ids.Length == 0)
            {
                ajax.BadRequest();
                return;
            }

            Collection.SetCollectionsPublic(request.ids, request.public_);

            ajax.ReturnJson(new JsonResponse());
        }
        public override void HandleRequest(string jsonString, AjaxBase ajax)
        {
            MangaListItemDetailsRequest request = Utility.ParseJson<MangaListItemDetailsRequest>(jsonString);
            Manga manga = Manga.GetById(request.id);

            if (manga == null || !manga.ParentCollection.Accessible(ajax))
            {
                ajax.BadRequest();
                return;
            }

            MangaListItemDetailsResponse response = new MangaListItemDetailsResponse();
            response.author = manga.Meta.Author;
            response.series = manga.Meta.Series;
            response.volume = manga.Meta.Volume;
            response.year = manga.Meta.Year;
            response.publisher = manga.Meta.Publisher;
            response.tags = manga.GetTags();
            ajax.ReturnJson(response);
        }
        public override void HandleRequest(string jsonString, AjaxBase ajax)
        {
            if (!User.IsAdminLoggedIn(ajax))
            {
                ajax.Unauthorized();
                return;
            }

            AdminMangasRefreshRequest request = Utility.ParseJson<AdminMangasRefreshRequest>(jsonString);

            if (request.ids == null || request.ids.Length == 0)
            {
                ajax.BadRequest();
                return;
            }

            Manga.RefreshMangasContent(request.ids);

            ajax.ReturnJson(new JsonResponse());
        }
        public override void HandleRequest(string jsonString, AjaxBase ajax)
        {
            if (!User.IsAdminLoggedIn(ajax))
            {
                ajax.Unauthorized();
                return;
            }

            AdminCollectionsUsersDeleteRequest request = Utility.ParseJson<AdminCollectionsUsersDeleteRequest>(jsonString);

            if (request.ids == null || request.ids.Length == 0 || (request.t != 0 && request.t != 1))
            {
                ajax.BadRequest();
                return;
            }

            CollectionUser.DeleteRelations(request.t, request.id, request.ids);

            ajax.ReturnJson(new JsonResponse());
        }
Ejemplo n.º 26
0
        public override void HandleRequest(string jsonString, AjaxBase ajax)
        {
            MangaPageRequest request = Utility.ParseJson<MangaPageRequest>(jsonString);
            Manga manga = Manga.GetById(request.id);

            if (manga == null || request.page < 0 || request.page >= manga.NumberOfPages || (request.width <= 0 && request.height <= 0))
            {
                ajax.BadRequest();
                return;
            }

            if (!manga.ParentCollection.Accessible(ajax))
            {
                ajax.Unauthorized();
                return;
            }

            MangaImageResponse response = new MangaImageResponse();

            if (manga.Status == 0)
            {
                if (request.page < 0 || request.page >= manga.NumberOfPages)
                {
                    ajax.BadRequest();
                    return;
                }

                string page = manga.GetPage(request.page, request.width, request.height, request.part);
                response.status = page == null ? 1 : 0;
                response.url = page;
                response.dimensions = request.dimensions && request.part == 0 && page != null ? manga.GetDimensions(request.page) : null;

                ThreadHelper.Run(request.part == 0 ? "MangaPreprocessFiles" : "MangaPreprocessParts", request.id, request.page, request.width, request.height);
            }
            else
            {
                response.status = 2;
            }

            ajax.ReturnJson(response);
        }
        public override void HandleRequest(string jsonString, AjaxBase ajax)
        {
            if (!User.IsAdminLoggedIn(ajax))
            {
                ajax.Unauthorized();
                return;
            }

            AdminCollectionUserAddRequest request = Utility.ParseJson<AdminCollectionUserAddRequest>(jsonString);
            Collection collection = Collection.GetByName(request.collectionName);
            User user = User.GetUser(request.username);

            if (collection == null || user == null || CollectionUser.Get(collection, user) != null)
            {
                ajax.BadRequest();
                return;
            }

            CollectionUser.CreateNew(collection, user, request.access).Save();
            ajax.ReturnJson(new JsonResponse());
        }
Ejemplo n.º 28
0
        public override void HandleRequest(string jsonString, AjaxBase ajax)
        {
            if (!User.IsAdminLoggedIn(ajax))
            {
                ajax.Unauthorized();
                return;
            }

            AdminMangaAddRequest request = Utility.ParseJson<AdminMangaAddRequest>(jsonString);
            Collection collection = Collection.GetById(request.cid);

            if (request.path == null || request.path == "" || collection == null)
            {
                ajax.BadRequest();
                return;
            }

            AdminMangaAddResponse response = new AdminMangaAddResponse();

            if ((request.path = Manga.CheckMangaPath(request.path)) == null || !Utility.IsValidStringForDatabase(request.path))
            {
                response.status = 1;
            }
            else if (request.path.IndexOf(collection.Path, StringComparison.InvariantCultureIgnoreCase) != 0)
            {
                response.status = 2;
            }
            else if (Manga.CheckMangaType(request.path) == -1)
            {
                response.status = 3;
            }
            else
            {
                response.status = 0;
                Manga.CreateNewManga(collection, request.path).Save();
                collection.MarkFolderCacheDirty();
            }

            ajax.ReturnJson(response);
        }
        public override void HandleRequest(string jsonString, AjaxBase ajax)
        {
            if (!User.IsAdminLoggedIn(ajax))
            {
                ajax.Unauthorized();
                return;
            }

            AdminCollectionAddRequest request = Utility.ParseJson<AdminCollectionAddRequest>(jsonString);

            if (request.name == null || request.name == "" || request.path == null || request.path == "")
            {
                ajax.BadRequest();
                return;
            }

            AdminCollectionAddResponse response = new AdminCollectionAddResponse();
            request.name = Utility.Remove4PlusBytesUtf8Chars(request.name);

            if (request.name.Length > 50)
            {
                request.name = request.name.Substring(0, 50);
            }

            if (!Collection.CheckNewCollectionName(request.name))
            {
                response.status = 1;
            }
            else if ((request.path = Collection.CheckNewCollectionPath(request.path)) == null || !Utility.IsValidStringForDatabase(request.path))
            {
                response.status = 2;
            }
            else
            {
                response.status = 0;
                Collection.CreateNewCollection(request.name, request.path, request.public_, request.autoadd).Save();
            }

            ajax.ReturnJson(response);
        }
        public override void HandleRequest(string jsonString, AjaxBase ajax)
        {
            if (!User.IsAdminLoggedIn(ajax))
            {
                ajax.Unauthorized();
                return;
            }

            AdminMangaMetaGetRequest request = Utility.ParseJson<AdminMangaMetaGetRequest>(jsonString);
            Manga manga = Manga.GetById(request.id);
            if (manga == null)
            {
                ajax.BadRequest();
                return;
            }

            AdminMangaMetaGetResponse response = new AdminMangaMetaGetResponse();
            response.meta = manga.GetMetaJson();
            response.authors = MangaMeta.GetAuthors();
            response.series = MangaMeta.GetSeries();
            response.publishers = MangaMeta.GetPublishers();
            ajax.ReturnJson(response);
        }