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);
        }
        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;
            }

            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);
        }
        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);
        }
        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());
        }
Пример #7
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;
            }

            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;
            }

            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;
            }

            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());
        }
        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;
            }

            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());
        }
        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;
            }

            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;
            }

            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);
        }
        public override void HandleRequest(string jsonString, AjaxBase ajax)
        {
            if (!User.IsAdminLoggedIn(ajax))
            {
                ajax.Unauthorized();
                return;
            }

            AdminCollectionsUsersGetRequest request = Utility.ParseJson<AdminCollectionsUsersGetRequest>(jsonString);
            AdminCollectionsUsersGetResponse response = new AdminCollectionsUsersGetResponse();

            if (request.t == 0)
            {
                Collection collection = Collection.GetById(request.id);
                if (collection == null)
                {
                    ajax.BadRequest();
                    return;
                }

                response.name = collection.Name;
                response.data = CollectionUser.ToJsonArray(CollectionUser.GetByCollection(collection));

                List<string> newNames = new List<string>();
                List<string> exNames = new List<string>();
                foreach (CollectionUserJson cu in response.data)
                {
                    exNames.Add(cu.username);
                }

                foreach (User user in User.GetAllUsers())
                {
                    if (!exNames.Contains(user.Username))
                    {
                        newNames.Add(user.Username);
                    }
                }

                response.names = newNames.ToArray();
            }
            else if (request.t == 1)
            {
                User user = User.GetById(request.id);
                if (user == null)
                {
                    ajax.BadRequest();
                    return;
                }

                response.name = user.Username;
                response.data = CollectionUser.ToJsonArray(CollectionUser.GetByUser(user));

                List<string> newNames = new List<string>();
                List<string> exNames = new List<string>();
                foreach (CollectionUserJson cu in response.data)
                {
                    exNames.Add(cu.collectionName);
                }

                foreach (Collection collection in Collection.GetAllCollections())
                {
                    if (!exNames.Contains(collection.Name))
                    {
                        newNames.Add(collection.Name);
                    }
                }

                response.names = newNames.ToArray();
            }
            else
            {
                ajax.BadRequest();
                return;
            }

            ajax.ReturnJson(response);
        }
Пример #20
0
        public override void HandleRequest(string jsonString, AjaxBase ajax)
        {
            InstallRequest request = Utility.ParseJson<InstallRequest>(jsonString);

            // Check Admin user name and password
            Regex regex = new Regex("[^a-zA-Z0-9]");
            if (String.IsNullOrEmpty(request.admin) || regex.IsMatch(request.admin) || request.admin.Length > 30 || request.password == null || request.password.Length < 8 || request.password != request.password2)
            {
                ajax.BadRequest();
                return;
            }

            // Save MySQL setting, 7z, pdfinfo and mudraw to web.config
            Configuration configuration = WebConfigurationManager.OpenWebConfiguration("~");
            AppSettingsSection section = configuration.AppSettings;
            foreach (string key in new string[] { "MangaWebInstalled", "MangaWebMySQLServer", "MangaWebMySQLPort", "MangaWebMySQLUser", "MangaWebMySQLPassword", "MangaWebMySQLDatabase", "MangaWeb7zDll", "MangaWebPdfinfo", "MangaWebMudraw" })
            {
                if (section.Settings.AllKeys.Contains(key))
                {
                    section.Settings.Remove(key);
                }
            }

            section.Settings.Add("MangaWebInstalled", true.ToString());

            section.Settings.Add("MangaWebMySQLServer", request.mysqlServer);
            section.Settings.Add("MangaWebMySQLPort", request.mysqlPort.ToString());
            section.Settings.Add("MangaWebMySQLUser", request.mysqlUser);
            section.Settings.Add("MangaWebMySQLPassword", request.mysqlPassword);
            section.Settings.Add("MangaWebMySQLDatabase", request.mysqlDatabase);

            section.Settings.Add("MangaWeb7zDll", request.sevenZipPath);

            configuration.Save();
            NameValueCollection settings = new NameValueCollection();
            foreach (string key in section.Settings.AllKeys)
            {
                settings[key] = section.Settings[key].Value;
            }

            ConfigurationManager.RefreshSection("appSettings");
            Config.Refresh(settings);

            // Import install.sql to MySQL
            using (StreamReader sqlFile = new StreamReader(Path.Combine(AjaxBase.DirectoryPath, "install.sql"))) Database.ExecuteSql(sqlFile.ReadToEnd());

            // Create Administrator
            User.CreateNewUser(request.admin, request.password, true).Save();

            // Save zip, rar, pdf to Settings table
            Settings.UseZip = request.zip;
            Settings.UseRar = request.rar;
            Settings.UsePdf = request.pdf;
            Settings.AllowGuest = true;
            Settings.LastAutoAddProcessTime = 0;
            Settings.MangaPagePreProcessCount = 5;
            Settings.MangaPagePreProcessDelay = 300;
            Settings.MangaCacheSizeLimit = 200;

            // Delete Install files
            string[] filesToDelete =
            {
                "install.html",
                "install.sql",
                "InstallAjax.aspx",
                @"bin\afung.MangaWeb3.Server.Install.*",
                @"js\afung.MangaWeb3.Client.Install.*",
                @"template\install.html",
            };

            StringBuilder argumentBuilder = new StringBuilder();
            argumentBuilder.Append("/C ping 1.1.1.1 -n 1 -w 3000 > Nul");
            foreach (string fileToDelete in filesToDelete)
            {
                argumentBuilder.AppendFormat(" & del \"{0}\\{1}\"", AjaxBase.DirectoryPath, fileToDelete);
            }

            string argument = argumentBuilder.ToString();
            ThreadStart runDeleteFilesCmd = delegate()
            {
                string output;
                int exitCode;
                ProcessLauncher.Run("cmd.exe", argument, out output, out exitCode);
            };

            new Thread(runDeleteFilesCmd).Start();

            InstallResponse response = new InstallResponse();
            response.installsuccessful = true;

            ajax.ReturnJson(response);
        }
Пример #21
0
        public override void HandleRequest(string jsonString, AjaxBase ajax)
        {
            if (!User.IsAdminLoggedIn(ajax))
            {
                ajax.Unauthorized();
                return;
            }

            AdminFinderRequest request = Utility.ParseJson<AdminFinderRequest>(jsonString);
            AdminFinderResponse response = new AdminFinderResponse();
            Collection collection = null;
            string[][] finderData;

            if (request.cid != -1)
            {
                collection = Collection.GetById(request.cid);
                if (collection == null)
                {
                    ajax.BadRequest();
                    return;
                }

                finderData = new string[][] { new string[] { collection.Name, collection.Path } };
            }
            else
            {
                List<string[]> diskData = new List<string[]>();
                string[] discs = Environment.GetLogicalDrives();
                for (int i = 0; i < discs.Length; i++)
                {
                    string driveLetter = discs[i].Replace(":\\", "");
                    using (System.Management.ManagementObject diskObj = new System.Management.ManagementObject("win32_logicaldisk.deviceid=\"" + driveLetter + ":\""))
                    {
                        if (diskObj["DriveType"].ToString() == "3") // Local Disk
                        {
                            diskData.Add(new string[] { driveLetter + ":", driveLetter + ":\\" });
                        }
                    }
                }

                finderData = diskData.ToArray();
            }

            Random r = new Random();
            StringBuilder tokenBuilder = new StringBuilder();
            for (int i = 0; i < 32; i++)
            {
                int n = r.Next(36);
                if (n < 10)
                {
                    tokenBuilder.Append(n);
                }
                else
                {
                    tokenBuilder.Append(Convert.ToChar(55 + n));
                }
            }

            response.token = tokenBuilder.ToString();

            SessionWrapper.SetFinderData(ajax, response.token, finderData);

            ajax.ReturnJson(response);
        }