Пример #1
0
        public void ProcessRequest(HttpContext context)
        {
            paramsContainer = new ParamsContainer(HttpContext.Current, nullTenantResponse: true);
            if (!paramsContainer.ApplicationID.HasValue)
            {
                return;
            }

            string responseText = string.Empty;

            switch (PublicMethods.parse_string(context.Request.Params["Type"], false, "Node").ToLower())
            {
            case "node":
                nodes_rss(PublicMethods.parse_guid(context.Request.Params["NodeTypeID"]),
                          HttpUtility.UrlDecode(PublicMethods.parse_string(context.Request.Params["Title"], false, string.Empty)),
                          HttpUtility.UrlDecode(PublicMethods.parse_string(context.Request.Params["Description"], false, string.Empty)),
                          PublicMethods.parse_int(context.Request.Params["Count"], 20),
                          PublicMethods.parse_long(context.Request.Params["LowerBoundary"]),
                          HttpUtility.UrlDecode(PublicMethods.parse_string(context.Request.Params["SearchText"], false, string.Empty)),
                          PublicMethods.parse_bool(context.Request.Params["IsDocument"]),
                          PublicMethods.parse_bool(context.Request.Params["IsKnowledge"]),
                          PublicMethods.parse_bool(context.Request.Params["Sitemap"]));
                return;

            case "question":
                questions_rss(HttpUtility.UrlDecode(PublicMethods.parse_string(context.Request.Params["Title"], false, string.Empty)),
                              HttpUtility.UrlDecode(PublicMethods.parse_string(context.Request.Params["Description"], false, string.Empty)),
                              PublicMethods.parse_int(context.Request.Params["Count"], 20));
                return;

            case "external":
                List <string> urlsArr = ListMaker.get_string_items(context.Request.Params["URLs"], '|').ToList();
                List <KeyValuePair <string, string> > urls = new List <KeyValuePair <string, string> >();
                foreach (string str in urlsArr)
                {
                    int index = str.IndexOf(',');
                    urls.Add(new KeyValuePair <string, string>(str.Substring(index + 1), Base64.decode(str.Substring(0, index)).ToLower()));
                }

                external(urls,
                         PublicMethods.parse_int(context.Request.Params["Count"], 20),
                         PublicMethods.parse_guid(context.Request.Params["StoreAsNodeTypeID"]), ref responseText);
                paramsContainer.return_response(ref responseText);
                return;

            case "sitemapindex":
                get_sitemap_index(PublicMethods.parse_int(context.Request.Params["Count"]));
                return;
            }

            paramsContainer.return_response(PublicConsts.BadRequestResponse);
        }
Пример #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            paramsContainer   = new ParamsContainer(HttpContext.Current);
            initialJson.Value = PublicMethods.toJSON(RouteList.get_data_server_side(paramsContainer, RouteName.node));

            try
            {
                Guid?nodeId = PublicMethods.parse_guid(Request.Params["ID"], alternatvieValue:
                                                       PublicMethods.parse_guid(Request.Params["NodeID"]));

                if (Request.Url.ToString().ToLower().Contains("_escaped_fragment_=") && nodeId.HasValue)
                {
                    ParamsContainer paramsContainer = new ParamsContainer(HttpContext.Current);

                    Modules.CoreNetwork.Node _nd = CNController.get_node(paramsContainer.Tenant.Id, nodeId.Value, true);

                    string htmlContent = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">" +
                                         "<html xmlns=\"http://www.w3.org/1999/xhtml\"><head><title>" + _nd.Name + " - " + RaaiVanSettings.SystemTitle(paramsContainer.Tenant.Id) + "</title></head><body>" +
                                         "<div>" + _nd.Name + "</div>" +
                                         "<div>" + ProviderUtil.list_to_string <string>(_nd.Tags, ' ') + "</div>" +
                                         "<div>" + PublicMethods.shuffle_text(PublicMethods.markup2plaintext(paramsContainer.Tenant.Id,
                                                                                                             _nd.Description, true)) + "</div>" +
                                         "<div>" + PublicMethods.markup2plaintext(paramsContainer.Tenant.Id,
                                                                                  Modules.Wiki.WikiController.get_wiki_content(paramsContainer.Tenant.Id, nodeId.Value), true) + "</div>" +
                                         "</body></html>";

                    paramsContainer.return_response(htmlContent);

                    return;
                }
            }
            catch { }
        }
Пример #3
0
        public void ProcessRequest(HttpContext context)
        {
            paramsContainer = new ParamsContainer(context, nullTenantResponse: true);
            if (!paramsContainer.ApplicationID.HasValue)
            {
                return;
            }

            string responseText = string.Empty;

            string command = PublicMethods.parse_string(context.Request.Params["Command"], false);

            switch (command)
            {
            case "GetReport":
                string reportName = PublicMethods.parse_string(context.Request.Params["ReportName"], false);

                ModuleIdentifier?moduleIdentifier = null;
                try { moduleIdentifier = (ModuleIdentifier)Enum.Parse(typeof(ModuleIdentifier), context.Request.Params["ModuleIdentifier"]); }
                catch { moduleIdentifier = null; }

                bool excel     = string.IsNullOrEmpty(context.Request.Params["Excel"]) ? false : context.Request.Params["Excel"].ToLower() == "true";
                bool rtl       = string.IsNullOrEmpty(context.Request.Params["RTL"]) ? false : context.Request.Params["RTL"].ToLower() == "true";
                bool isPersian = string.IsNullOrEmpty(context.Request.Params["Lang"]) ? false : context.Request.Params["Lang"].ToLower() == "fa";

                List <string> paramsList = ListMaker.get_string_items(context.Request.Params["ParamsOrder"], '|');

                List <ReportParameter> parameters = new List <ReportParameter>();

                parameters.Add(ReportUtilities.get_parameter("CurrentUserID", "Guid", paramsContainer.CurrentUserID.ToString()));

                for (int i = 0; i < paramsList.Count; ++i)
                {
                    string[] item       = paramsList[i].Split(':');
                    string   paramName  = item[0];
                    string   paramType  = item[1];
                    string   paramValue = context.Request.Params[paramName];

                    parameters.Add(ReportUtilities.get_parameter(paramName, paramType, paramValue));
                }

                Dictionary <string, string> dictionary = _get_dictionary("Dictionary");

                int pageNumber = string.IsNullOrEmpty(context.Request.Params["PageNumber"]) ? 1 : int.Parse(context.Request.Params["PageNumber"]);
                int pageSize   = string.IsNullOrEmpty(context.Request.Params["PageSize"]) ? 100 : int.Parse(context.Request.Params["PageSize"]);

                if (!string.IsNullOrEmpty(reportName) && moduleIdentifier.HasValue)
                {
                    get_report(moduleIdentifier.Value, reportName, excel, rtl, isPersian, ref dictionary,
                               pageNumber, pageSize, ref responseText, parameters,
                               PublicMethods.parse_string(context.Request.Params["PS"]));
                }
                _return_response(ref responseText);
                return;
            }

            paramsContainer.return_response(PublicConsts.BadRequestResponse);
        }
Пример #4
0
        public void ProcessRequest(HttpContext context)
        {
            paramsContainer = new ParamsContainer(context, nullTenantResponse: true);
            if (!paramsContainer.ApplicationID.HasValue)
            {
                return;
            }

            string responseText = string.Empty;
            string command      = PublicMethods.parse_string(context.Request.Params["Command"], false);

            switch (command)
            {
            case "Search":
                List <SearchDocType> itemTypes = new List <SearchDocType>();

                SearchDocType tempDt = new SearchDocType();
                foreach (string str in ListMaker.get_string_items(context.Request.Params["ItemTypes"], '|'))
                {
                    if (Enum.TryParse <SearchDocType>(str, out tempDt))
                    {
                        itemTypes.Add(tempDt);
                    }
                }

                search(itemTypes,
                       PublicMethods.parse_string(context.Request.Params["SearchText"]),
                       PublicMethods.parse_int(context.Request.Params["LowerBoundary"]),
                       PublicMethods.parse_int(context.Request.Params["Count"]),
                       PublicMethods.parse_bool(context.Request.Params["Title"]),
                       PublicMethods.parse_bool(context.Request.Params["Description"]),
                       PublicMethods.parse_bool(context.Request.Params["Content"]),
                       PublicMethods.parse_bool(context.Request.Params["Tags"]),
                       PublicMethods.parse_bool(context.Request.Params["FileContent"]),
                       PublicMethods.parse_bool(context.Request.Params["ForceHasContent"]),
                       ListMaker.get_guid_items(context.Request.Params["TypeIDs"], '|'),
                       ListMaker.get_string_items(context.Request.Params["Types"], '|'),
                       PublicMethods.parse_bool(context.Request.Params["ShowExactItems"]),
                       PublicMethods.parse_bool(context.Request.Params["SuggestNodeTypes"]),
                       PublicMethods.parse_bool(context.Request.Params["Excel"]),
                       PublicMethods.parse_bool(context.Request.Params["FormDetails"]),
                       PublicMethods.fromJSON(PublicMethods.parse_string(context.Request.Params["ColumnNames"])),
                       ref responseText);
                _return_response(ref responseText);
                return;
            }

            paramsContainer.return_response(PublicConsts.BadRequestResponse);
        }
Пример #5
0
        public void ProcessRequest(HttpContext context)
        {
            paramsContainer = new ParamsContainer(context, nullTenantResponse: true);
            if (!paramsContainer.ApplicationID.HasValue)
            {
                return;
            }

            string responseText = string.Empty;
            string command      = string.IsNullOrEmpty(context.Request.Params["Command"]) ? string.Empty : context.Request.Params["Command"];

            switch (command)
            {
            /*
             * case "ImportData":
             *  string attachedFile = string.IsNullOrEmpty(context.Request.Params["AttachedFile"]) ? string.Empty :
             *      context.Request.Params["AttachedFile"];
             *
             *  string strGuidName = attachedFile.Split(',')[0];
             *  string folderAddress = DocumentUtilities.map_path(paramsContainer.Tenant.Id,
             *      FolderNames.TemporaryFiles);
             *
             *  handle_imported_file(folderAddress + "\\" + strGuidName, ref responseText);
             *  _return_response(ref responseText);
             *  return;
             */
            case "ImportData":
                List <DocFileInfo> files = DocumentUtilities.get_files_info(context.Request.Params["AttachedFile"]);

                if (files == null || files.Count != 1)
                {
                    responseText = "{\"ErrorText\":\"" + Messages.OperationFailed + "\"}";
                }
                else
                {
                    files[0].FolderName = FolderNames.TemporaryFiles;

                    handle_imported_file(files[0], ref responseText);
                }

                _return_response(ref responseText);
                return;
            }

            paramsContainer.return_response(PublicConsts.BadRequestResponse);
        }
Пример #6
0
        public void ProcessRequest(HttpContext context)
        {
            paramsContainer = new ParamsContainer(context, nullTenantResponse: true);
            if (!paramsContainer.ApplicationID.HasValue)
            {
                return;
            }

            string responseText = string.Empty;
            string command      = string.IsNullOrEmpty(context.Request.Params["Command"]) ? string.Empty : context.Request.Params["Command"];

            Guid userId = string.IsNullOrEmpty(context.Request.Params["UserID"]) ? Guid.Empty : Guid.Parse(context.Request.Params["UserID"]);

            Guid nodeId = string.IsNullOrEmpty(context.Request.Params["NodeID"]) ? Guid.Empty : Guid.Parse(context.Request.Params["NodeID"]);

            switch (command)
            {
            case "SearchExpertiseDomains":
                string searchText = string.IsNullOrEmpty(context.Request.Params["SearchText"]) ? string.Empty :
                                    Base64.decode(context.Request.Params["SearchText"]);
                int count = string.IsNullOrEmpty(context.Request.Params["Count"]) ? 20 : int.Parse(context.Request.Params["Count"]);
                search_expertise_domains(searchText, count, ref responseText);
                _return_response(ref responseText);
                return;

            case "GetExpertiseDomains":
                get_expertise_domains(userId == Guid.Empty && paramsContainer.CurrentUserID.HasValue ? paramsContainer.CurrentUserID.Value : userId, ref responseText);
                _return_response(ref responseText);
                return;

            case "IAmExpert":
                string expertiseDomain = string.IsNullOrEmpty(context.Request.Params["ExpertiseDomain"]) ? string.Empty :
                                         Base64.decode(context.Request.Params["ExpertiseDomain"]);
                i_am_expert(expertiseDomain, ref responseText);
                _return_response(ref responseText);
                return;

            case "IAmNotExpert":
                i_am_not_expert(nodeId, ref responseText);
                _return_response(ref responseText);
                return;
            }

            paramsContainer.return_response(PublicConsts.BadRequestResponse);
        }
Пример #7
0
 protected void _return_response(ref string responseText)
 {
     paramsContainer.return_response(ref responseText);
 }
Пример #8
0
        public void ProcessRequest(HttpContext context)
        {
            paramsContainer = new ParamsContainer(context, nullTenantResponse: true);
            if (!paramsContainer.ApplicationID.HasValue)
            {
                return;
            }

            string responseText = string.Empty;
            string command      = PublicMethods.parse_string(context.Request.Params["Command"], false);

            switch (command)
            {
            case "CheckAuthority":
                check_authority(ListMaker.get_string_items(context.Request.Params["Permissions"], '|'), ref responseText);
                _return_response(ref responseText);
                return;

            case "CheckAccess":
            {
                PrivacyObjectType pType = PrivacyObjectType.None;
                if (!Enum.TryParse <PrivacyObjectType>(context.Request.Params["Type"], out pType))
                {
                    pType = PrivacyObjectType.None;
                }

                List <PermissionType> permissions = new List <PermissionType>();

                check_access(ListMaker.get_guid_items(context.Request.Params["ObjectIDs"], '|'),
                             pType,
                             ListMaker.get_enum_items <PermissionType>(context.Request.Params["Permissions"], '|')
                             .Where(p => p != PermissionType.None).ToList(),
                             ref responseText);
                _return_response(ref responseText);
            }
                return;

            case "SetAudience":
            {
                PrivacyObjectType objectType = PrivacyObjectType.None;
                if (!Enum.TryParse(context.Request.Params["ObjectType"], out objectType))
                {
                    objectType = PrivacyObjectType.None;
                }

                Dictionary <string, object> data =
                    PublicMethods.fromJSON(PublicMethods.parse_string(context.Request.Params["Data"]));

                List <Privacy> items = new List <Privacy>();

                foreach (string k in data.Keys)
                {
                    Guid objId = Guid.Empty;

                    if (!Guid.TryParse(k, out objId) || data[k].GetType() != typeof(Dictionary <string, object>))
                    {
                        continue;
                    }

                    Privacy p = Privacy.fromJson((Dictionary <string, object>)data[k]);

                    if (p != null)
                    {
                        p.ObjectID = objId;
                        items.Add(p);
                    }
                }

                set_audience(items, objectType, ref responseText);
                _return_response(ref responseText);
                return;
            }

            case "GetAudience":
            {
                PrivacyObjectType objectType = PrivacyObjectType.None;
                if (!Enum.TryParse(context.Request.Params["ObjectType"], out objectType))
                {
                    objectType = PrivacyObjectType.None;
                }

                get_audience(ListMaker.get_guid_items(context.Request.Params["ObjectIDs"], '|'),
                             objectType, ref responseText);
                _return_response(ref responseText);
                return;
            }

            case "AddConfidentialityLevel":
                add_confidentiality_level(PublicMethods.parse_int(context.Request.Params["LevelID"]),
                                          PublicMethods.parse_string(context.Request.Params["Title"]), ref responseText);
                _return_response(ref responseText);
                return;

            case "ModifyConfidentialityLevel":
                modify_confidentiality_level(PublicMethods.parse_guid(context.Request.Params["ConfidentialityID"]),
                                             PublicMethods.parse_int(context.Request.Params["LevelID"]),
                                             PublicMethods.parse_string(context.Request.Params["Title"]), ref responseText);
                _return_response(ref responseText);
                return;

            case "RemoveConfidentialityLevel":
                remove_confidentiality_level(PublicMethods.parse_guid(context.Request.Params["ConfidentialityID"]), ref responseText);
                _return_response(ref responseText);
                return;

            case "GetConfidentialityLevels":
                get_confidentiality_levels(ref responseText);
                _return_response(ref responseText);
                return;

            case "SetConfidentialityLevel":
                set_confidentiality_level(PublicMethods.parse_guid(context.Request.Params["ObjectID"]),
                                          PublicMethods.parse_guid(context.Request.Params["ConfidentialityID"]), ref responseText);
                _return_response(ref responseText);
                return;

            case "UnsetConfidentialityLevel":
                unset_confidentiality_level(PublicMethods.parse_guid(context.Request.Params["ObjectID"]), ref responseText);
                _return_response(ref responseText);
                return;

            case "GetConfidentialityLevel":
                get_confidentiality_level(PublicMethods.parse_guid(context.Request.Params["ObjectID"]), ref responseText);
                _return_response(ref responseText);
                return;

            case "GetConfidentialityLevelUsers":
                get_confidentiality_level_users(PublicMethods.parse_guid(context.Request.Params["ConfidentialityID"]),
                                                PublicMethods.parse_string(context.Request.Params["SearchText"]),
                                                PublicMethods.parse_int(context.Request.Params["Count"]),
                                                PublicMethods.parse_long(context.Request.Params["LowerBoundary"]),
                                                ref responseText);
                _return_response(ref responseText);
                return;
            }

            paramsContainer.return_response(PublicConsts.BadRequestResponse);
        }
Пример #9
0
        public void ProcessRequest(HttpContext context)
        {
            //Privacy Check: OK
            paramsContainer = new ParamsContainer(context, nullTenantResponse: true);
            if (!paramsContainer.ApplicationID.HasValue)
            {
                return;
            }

            string responseText = string.Empty;

            string command = PublicMethods.parse_string(context.Request.Params["Command"], false);

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

            Guid currentUserId = paramsContainer.CurrentUserID.HasValue ? paramsContainer.CurrentUserID.Value : Guid.Empty;

            Guid        fileId = string.IsNullOrEmpty(context.Request.Params["FileID"]) ? Guid.Empty : Guid.Parse(context.Request.Params["FileID"]);
            DocFileInfo file   = DocumentsController.get_file(paramsContainer.Tenant.Id, fileId);

            if (file == null)
            {
                paramsContainer.return_response(PublicConsts.BadRequestResponse);
                return;
            }

            bool isTemporary =
                PublicMethods.parse_string(HttpContext.Current.Request.Params["Category"], false).ToLower() == "temporary";

            bool hasAccess = isTemporary || PublicMethods.is_system_admin(paramsContainer.Tenant.Id, currentUserId);

            PrivacyObjectType pot = file.OwnerType == FileOwnerTypes.Node ? PrivacyObjectType.Node : PrivacyObjectType.None;

            hasAccess = hasAccess || PrivacyController.check_access(paramsContainer.Tenant.Id,
                                                                    paramsContainer.CurrentUserID, file.OwnerID.Value, pot, PermissionType.View);

            if (!hasAccess && currentUserId != Guid.Empty &&
                CNController.is_node(paramsContainer.Tenant.Id, file.OwnerID.Value))
            {
                bool isCreator = false, isContributor = false, isExpert = false, isMember = false, isAdminMember = false,
                     isServiceAdmin = false, isAreaAdmin = false, perCreatorLevel = false;

                CNController.get_user2node_status(paramsContainer.Tenant.Id, paramsContainer.CurrentUserID.Value,
                                                  file.OwnerID.Value, ref isCreator, ref isContributor, ref isExpert, ref isMember, ref isAdminMember,
                                                  ref isServiceAdmin, ref isAreaAdmin, ref perCreatorLevel);

                hasAccess = isServiceAdmin || isAreaAdmin || isCreator || isContributor || isExpert || isMember;
            }

            if (!hasAccess)
            {
                paramsContainer.return_response("{\"ErrorText\":\"" + Messages.AccessDenied.ToString() + "\"}");
            }

            if (isTemporary)
            {
                file.FolderName = FolderNames.TemporaryFiles;
            }
            else
            {
                file.refresh_folder_name();
            }

            if (!file.exists(paramsContainer.Tenant.Id))
            {
                _return_response(ref responseText);
            }

            DocFileInfo destFile = new DocFileInfo()
            {
                FileID = file.FileID, FolderName = FolderNames.PDFImages
            };

            switch (command)
            {
            case "Convert2Image":
                convert2image(file,
                              PublicMethods.parse_string(context.Request.Params["PS"]),
                              destFile,
                              PublicMethods.parse_bool(context.Request.Params["Repair"]), ref responseText);
                _return_response(ref responseText);
                return;

            case "GetPagesCount":
                get_pages_count(file,
                                PublicMethods.parse_string(context.Request.Params["PS"]),
                                destFile, ref responseText);
                _return_response(ref responseText);
                return;

            case "GetPage":
                get_page(PublicMethods.parse_int(context.Request.Params["Page"], 1), destFile);
                return;
            }

            paramsContainer.return_response(PublicConsts.BadRequestResponse);
        }
Пример #10
0
        public void ProcessRequest(HttpContext context)
        {
            paramsContainer = new ParamsContainer(context, nullTenantResponse: true);
            if (!paramsContainer.ApplicationID.HasValue)
            {
                return;
            }

            string responseText = string.Empty;
            string command      = PublicMethods.parse_string(context.Request.Params["Command"], false);

            switch (command)
            {
            case "GetRecentThreads":
                get_recent_threads(PublicMethods.parse_int(context.Request.Params["Count"]),
                                   PublicMethods.parse_int(context.Request.Params["LastID"]), ref responseText);
                _return_response(ref responseText);
                return;

            case "GetThreadUsers":
                get_thread_users(PublicMethods.parse_guid(context.Request.Params["ThreadID"]),
                                 PublicMethods.parse_int(context.Request.Params["Count"]),
                                 PublicMethods.parse_int(context.Request.Params["LastID"]), ref responseText);
                _return_response(ref responseText);
                return;

            case "GetMessages":
                get_messages(PublicMethods.parse_guid(context.Request.Params["ThreadID"]),
                             PublicMethods.parse_long(context.Request.Params["MinID"]),
                             PublicMethods.parse_int(context.Request.Params["Count"]), ref responseText);
                _return_response(ref responseText);
                return;

            case "GetForwardedMessages":
                get_forwarded_messages(PublicMethods.parse_guid(context.Request.Params["MessageID"]),
                                       PublicMethods.parse_int(context.Request.Params["Count"]),
                                       PublicMethods.parse_int(context.Request.Params["LastID"]), ref responseText);
                _return_response(ref responseText);
                return;

            case "GetMessageReceivers":
                get_message_receivers(PublicMethods.parse_guid(context.Request.Params["MessageID"]),
                                      PublicMethods.parse_int(context.Request.Params["Count"]),
                                      PublicMethods.parse_int(context.Request.Params["LastID"]), ref responseText);
                _return_response(ref responseText);
                return;

            case "SendMessage":
                send_message(PublicMethods.parse_guid(context.Request.Params["ForwardedFrom"]),
                             PublicMethods.parse_string(context.Request.Params["Title"]),
                             PublicMethods.parse_string(context.Request.Params["MessageText"]),
                             PublicMethods.parse_bool(context.Request.Params["IsGroup"]),
                             ListMaker.get_guid_items(context.Request.Params["ReceiverUserIDs"], '|'),
                             PublicMethods.parse_guid(context.Request.Params["ThreadID"]),
                             DocumentUtilities.get_files_info(context.Request.Params["AttachedFiles"]),
                             PublicMethods.parse_guid(context.Request.Params["GroupID"]),
                             PublicMethods.parse_string(context.Request.Params["Ref"], false),
                             ref responseText);
                _return_response(ref responseText);
                return;

            case "RemoveThread":
                remove_thread(PublicMethods.parse_guid(context.Request.Params["ThreadID"]), ref responseText);
                _return_response(ref responseText);
                return;

            case "RemoveMessage":
                remove_message(PublicMethods.parse_long(context.Request.Params["ID"]), ref responseText);
                _return_response(ref responseText);
                return;

            case "SetMessagesAsSeen":
                set_messages_as_seen(PublicMethods.parse_guid(context.Request.Params["ThreadID"]), ref responseText);
                _return_response(ref responseText);
                return;

            case "GetNotSeenMessagesCount":
                get_not_seen_messages_count(ref responseText);
                _return_response(ref responseText);
                return;
            }

            paramsContainer.return_response(PublicConsts.BadRequestResponse);
        }
Пример #11
0
        public void ProcessRequest(HttpContext context)
        {
            //Privacy Check: OK
            paramsContainer = new ParamsContainer(context, nullTenantResponse: false);

            Guid fileId = string.IsNullOrEmpty(context.Request.Params["FileID"]) ?
                          Guid.Empty : Guid.Parse(context.Request.Params["FileID"]);

            if (fileId == Guid.Empty && !Guid.TryParse(context.Request.Params["ATTFID"], out fileId))
            {
                fileId = Guid.Empty;
            }

            string category = PublicMethods.parse_string(context.Request.Params["Category"], false);

            bool   isTemporary = category.ToLower() == FolderNames.TemporaryFiles.ToString().ToLower();
            bool?  addFooter   = PublicMethods.parse_bool(context.Request.Params["Meta"]);
            Guid?  coverId     = PublicMethods.parse_guid(context.Request.Params["CoverID"]);
            string pdfPassword = PublicMethods.parse_string(context.Request.Params["PS"]);

            List <FolderNames> freeFolders = new[] {
                FolderNames.ProfileImages,
                FolderNames.HighQualityProfileImage,
                FolderNames.CoverPhoto,
                FolderNames.HighQualityCoverPhoto,
                FolderNames.Icons,
                FolderNames.HighQualityIcon,
                FolderNames.ApplicationIcons,
                FolderNames.HighQualityApplicationIcon,
                FolderNames.Pictures
            }.ToList();

            bool isFreeFolder = !string.IsNullOrEmpty(category) && freeFolders.Any(f => f.ToString().ToLower() == category.ToLower());

            if (isFreeFolder)
            {
                FolderNames fn = freeFolders.Where(u => u.ToString().ToLower() == category.ToLower()).FirstOrDefault();

                DocFileInfo pic =
                    new DocFileInfo()
                {
                    FileID = fileId, Extension = "jpg", FileName = fileId.ToString(), FolderName = fn
                };

                send_file(pic, false);
            }

            if (!paramsContainer.ApplicationID.HasValue)
            {
                paramsContainer.return_response(PublicConsts.NullTenantResponse);
                return;
            }

            if (isTemporary)
            {
                string ext = PublicMethods.parse_string(context.Request.Params["Extension"]);

                DocFileInfo temp = new DocFileInfo()
                {
                    FileID     = fileId,
                    Extension  = ext,
                    FileName   = fileId.ToString(),
                    FolderName = FolderNames.TemporaryFiles
                };

                send_file(temp, false);
            }
            else
            {
                DocFileInfo AttachFile = DocumentsController.get_file(paramsContainer.Tenant.Id, fileId);

                if (AttachFile == null)
                {
                    paramsContainer.return_response("{\"ErrorText\":\"" + Messages.AccessDenied + "\"}");
                    return;
                }

                PrivacyObjectType pot = AttachFile.OwnerType == FileOwnerTypes.Node ?
                                        PrivacyObjectType.Node : PrivacyObjectType.None;

                DocFileInfo ownerNode = !AttachFile.FileID.HasValue ? null :
                                        DocumentsController.get_file_owner_node(paramsContainer.Tenant.Id, AttachFile.FileID.Value);
                if (ownerNode != null)
                {
                    AttachFile.OwnerNodeID   = ownerNode.OwnerNodeID;
                    AttachFile.OwnerNodeName = ownerNode.OwnerNodeName;
                    AttachFile.OwnerNodeType = ownerNode.OwnerNodeType;
                }

                bool accessDenied =
                    !PrivacyController.check_access(paramsContainer.Tenant.Id,
                                                    paramsContainer.CurrentUserID, AttachFile.OwnerID.Value, pot, PermissionType.View) &&
                    !(
                        paramsContainer.CurrentUserID.HasValue &&
                        new CNAPI()
                {
                    paramsContainer = this.paramsContainer
                }
                        ._is_admin(paramsContainer.Tenant.Id, AttachFile.OwnerID.Value,
                                   paramsContainer.CurrentUserID.Value, CNAPI.AdminLevel.Creator, false)
                        );

                if (accessDenied)
                {
                    //Save Log
                    try
                    {
                        LogController.save_log(paramsContainer.Tenant.Id, new Log()
                        {
                            UserID           = paramsContainer.CurrentUserID,
                            HostAddress      = PublicMethods.get_client_ip(HttpContext.Current),
                            HostName         = PublicMethods.get_client_host_name(HttpContext.Current),
                            Action           = Modules.Log.Action.Download_AccessDenied,
                            SubjectID        = fileId,
                            Info             = "{\"Error\":\"" + Base64.encode(Messages.AccessDenied.ToString()) + "\"}",
                            ModuleIdentifier = ModuleIdentifier.DCT
                        });
                    }
                    catch { }
                    //end of Save Log

                    paramsContainer.return_response("{\"ErrorText\":\"" + Messages.AccessDenied + "\"}");

                    return;
                }

                AttachFile.refresh_folder_name();

                string ext = AttachFile == null || string.IsNullOrEmpty(AttachFile.Extension) ? string.Empty :
                             AttachFile.Extension.ToLower();
                bool isImage = ext == "jpg" || ext == "jpeg" || ext == "png" || ext == "gif" || ext == "bmp";

                if (string.IsNullOrEmpty(AttachFile.Extension) || AttachFile.Extension.ToLower() != "pdf")
                {
                    coverId = null;
                }

                bool   dl          = !isImage || PublicMethods.parse_bool(context.Request.Params["dl"], defaultValue: true) == true;
                string contentType = !dl && isImage?PublicMethods.get_mime_type_by_extension(ext) : null;

                send_file(AttachFile, !isImage, addPDFCover: true,
                          addPDFFooter: addFooter.HasValue && addFooter.Value,
                          coverId: coverId,
                          pdfPassword: pdfPassword,
                          contentType: contentType,
                          isAttachment: dl);
            }
        }
Пример #12
0
        protected void send_file(DocFileInfo file, bool logNeeded, bool addPDFCover = false, bool addPDFFooter = false,
                                 Guid?coverId = null, string pdfPassword = null, string contentType = null, bool isAttachment = true)
        {
            byte[] fileContent = file.toByteArray(paramsContainer.ApplicationID);

            if (fileContent.Length == 0)
            {
                send_empty_response();
                return;
            }

            //Save Log
            if (logNeeded && paramsContainer.CurrentUserID.HasValue)
            {
                LogController.save_log(paramsContainer.Tenant.Id, new Log()
                {
                    UserID           = paramsContainer.CurrentUserID,
                    Date             = DateTime.Now,
                    HostAddress      = PublicMethods.get_client_ip(HttpContext.Current),
                    HostName         = PublicMethods.get_client_host_name(HttpContext.Current),
                    Action           = Modules.Log.Action.Download,
                    SubjectID        = file.FileID,
                    Info             = file.toJson(paramsContainer.Tenant.Id),
                    ModuleIdentifier = ModuleIdentifier.DCT
                });
            }
            //end of Save Log

            if (file.Extension.ToLower() == "pdf")
            {
                addPDFCover = addPDFCover && file.OwnerNodeID.HasValue && coverId.HasValue &&
                              paramsContainer.ApplicationID.HasValue && paramsContainer.CurrentUserID.HasValue;

                if (addPDFFooter || addPDFCover)
                {
                    bool invalidPassword = false;

                    fileContent = PDFUtil.get_pdf_content(paramsContainer.Tenant.Id, fileContent, pdfPassword, ref invalidPassword);

                    if (invalidPassword)
                    {
                        string responseText = "{\"InvalidPassword\":" + true.ToString().ToLower() + "}";
                        paramsContainer.return_response(ref responseText);
                        return;
                    }
                }

                if (addPDFFooter)
                {
                    User currentUser = !paramsContainer.CurrentUserID.HasValue ? null :
                                       UsersController.get_user(paramsContainer.Tenant.Id, paramsContainer.CurrentUserID.Value);

                    if (currentUser == null)
                    {
                        currentUser = new User()
                        {
                            UserID    = Guid.NewGuid(),
                            UserName  = "******",
                            FirstName = "[anonymous]",
                            LastName  = "[anonymous]"
                        };
                    }

                    DownloadedFileMeta meta = new DownloadedFileMeta(PublicMethods.get_client_ip(HttpContext.Current),
                                                                     currentUser.UserName, currentUser.FirstName, currentUser.LastName, null);

                    fileContent = PDFTemplates.append_footer(fileContent, meta.toString());
                }

                if (addPDFCover)
                {
                    fileContent = Wiki2PDF.add_custom_cover(paramsContainer.Tenant.Id,
                                                            paramsContainer.CurrentUserID.Value, fileContent, coverId.Value, file.OwnerNodeID.Value);
                }

                if (!string.IsNullOrEmpty(pdfPassword))
                {
                    fileContent = PDFUtil.set_password(fileContent, pdfPassword);
                }
            }

            string retFileName = file.FileName + (string.IsNullOrEmpty(file.Extension) ? string.Empty : "." + file.Extension);

            paramsContainer.file_response(fileContent, retFileName, contentType: contentType, isAttachment: isAttachment);
        }
Пример #13
0
        public void ProcessRequest(HttpContext context)
        {
            paramsContainer = new ParamsContainer(context, nullTenantResponse: true);
            if (!paramsContainer.ApplicationID.HasValue)
            {
                return;
            }

            string command = string.IsNullOrEmpty(context.Request.Params["Command"]) ?
                             (string.IsNullOrEmpty(context.Request.Params["cmd"]) ? string.Empty : context.Request.Params["cmd"]) : context.Request.Params["Command"];
            string responseText = string.Empty;

            Guid mixedUserId = !string.IsNullOrEmpty(context.Request.Params["UserID"]) ? Guid.Parse(context.Request.Params["UserID"]) :
                               (paramsContainer.CurrentUserID.HasValue ? paramsContainer.CurrentUserID.Value : Guid.Empty);
            Guid eventId = !string.IsNullOrEmpty(context.Request.Params["EventID"]) ? Guid.Parse(context.Request.Params["EventID"]) :
                           (string.IsNullOrEmpty(context.Request.Params["CalenderID"]) ? Guid.Empty : Guid.Parse(context.Request.Params["CalenderID"]));

            switch (command)
            {
            case "NewEvent":
                register_event(PublicMethods.parse_string(context.Request.Params["Type"]),
                               PublicMethods.parse_string(context.Request.Params["Title"]),
                               PublicMethods.parse_string(context.Request.Params["Description"]),
                               PublicMethods.parse_date(context.Request.Params["BeginDate"]),
                               PublicMethods.parse_date(context.Request.Params["FinishDate"]),
                               ListMaker.get_guid_items(context.Request.Params["UserIDs"], '|'),
                               ListMaker.get_guid_items(context.Request.Params["GroupIDs"], '|'),
                               ListMaker.get_guid_items(context.Request.Params["NodeIDs"], '|'),
                               ref responseText);
                _return_response(responseText);
                return;

            case "GetEvent":
                get_event(eventId, ref responseText);
                _return_response(responseText);
                return;

            case "GetFinishedEventsCount":
                get_finished_events_count(ref responseText);
                _return_response(responseText);
                return;

            case "GetFinishedEvents":
                get_finished_events(ref responseText);
                _return_response(responseText);
                return;

            case "RemoveCalenderUser":
                remove_calender_user(eventId, mixedUserId, ref responseText);
                _return_response(responseText);
                return;

            case "ChangeCalenderUserStatus":
                string status = string.IsNullOrEmpty(context.Request.Params["Status"]) ? string.Empty : context.Request.Params["Status"];
                change_calender_user_status(eventId, mixedUserId, status, ref responseText);
                _return_response(responseText);
                return;
            }

            paramsContainer.return_response(PublicConsts.BadRequestResponse);
        }
Пример #14
0
        public void ProcessRequest(HttpContext context)
        {
            paramsContainer = new ParamsContainer(context, nullTenantResponse: false);

            if (!paramsContainer.CurrentUserID.HasValue)
            {
                paramsContainer.return_response(PublicConsts.BadRequestResponse);
                return;
            }

            if (ProcessTenantIndependentRequest(context))
            {
                return;
            }

            if (!paramsContainer.ApplicationID.HasValue)
            {
                paramsContainer.return_response(PublicConsts.NullTenantResponse);
                return;
            }

            string responseText = string.Empty;

            string command = !string.IsNullOrEmpty(context.Request.Params["cmd"]) ? context.Request.Params["cmd"].ToLower() :
                             (string.IsNullOrEmpty(context.Request.Params["Command"]) ? "uploadfile" : context.Request.Params["Command"].ToLower());

            Guid userId = string.IsNullOrEmpty(context.Request.Params["UserID"]) ? PublicMethods.get_current_user_id() :
                          Guid.Parse(context.Request.Params["UserID"]);

            Guid ownerId = string.IsNullOrEmpty(context.Request.Params["OwnerID"]) ? Guid.Empty :
                           Guid.Parse(context.Request.Params["OwnerID"]);
            Guid fileId = string.IsNullOrEmpty(context.Request.Params["FileID"]) ? Guid.Empty :
                          Guid.Parse(context.Request.Params["FileID"]);
            string fileName = string.IsNullOrEmpty(context.Request.Params["FileName"]) ? string.Empty :
                              context.Request.Params["FileName"];

            FileOwnerTypes ownerType = FileOwnerTypes.None;

            if (!Enum.TryParse <FileOwnerTypes>(context.Request.Params["OwnerType"], out ownerType))
            {
                ownerType = FileOwnerTypes.None;
            }

            switch (command)
            {
            case "uploadfile":
            case "upload_file":
            {
                DocFileInfo file = new DocFileInfo()
                {
                    FileID    = fileId != Guid.Empty ? fileId : Guid.NewGuid(),
                    OwnerID   = ownerId,
                    OwnerType = ownerType
                };

                byte[] fileContent = new byte[0];

                _attach_file_command(paramsContainer.ApplicationID, file, ref responseText, ref fileContent);
                _return_response(ref responseText);
                return;
            }

            case "deletefile":
                responseText = remove_file(fileId, ref responseText) ? "yes" : "no";
                _return_response(ref responseText);
                return;

            case "removefile":
                remove_file(fileId, ref responseText);
                _return_response(ref responseText);
                return;

            case "uploadpicture":
            {
                int         maxWidth = 100, maxHeight = 100;
                FolderNames imageFolder = FolderNames.Pictures;

                Guid?pictureId = PublicMethods.parse_guid(context.Request.Params["PictureID"]);
                bool hasId     = pictureId.HasValue;
                if (!pictureId.HasValue)
                {
                    pictureId = Guid.NewGuid();
                }

                string imageType = string.IsNullOrEmpty(context.Request.Params["Type"]) ? "" :
                                   context.Request.Params["Type"].ToLower();

                string errorMessage = string.Empty;

                switch (imageType)
                {
                case "post":
                    maxWidth    = maxHeight = 640;
                    imageFolder = FolderNames.Pictures;
                    break;

                default:
                    _return_response(ref responseText);
                    return;
                }

                DocFileInfo uploaded = new DocFileInfo()
                {
                    FileID     = Guid.NewGuid(),
                    OwnerType  = ownerType,
                    FolderName = FolderNames.TemporaryFiles
                };

                if (ownerId != Guid.Empty)
                {
                    uploaded.OwnerID = ownerId;
                }

                byte[] fileContent = new byte[0];

                bool succeed = _attach_file_command(paramsContainer.ApplicationID,
                                                    uploaded, ref responseText, ref fileContent, dontStore: true);

                if (succeed)
                {
                    DocFileInfo destFile = new DocFileInfo()
                    {
                        FileID     = hasId ? pictureId : uploaded.FileID,
                        OwnerType  = ownerType,
                        Extension  = "jpg",
                        FolderName = hasId ? imageFolder : FolderNames.TemporaryFiles
                    };

                    if (ownerId != Guid.Empty)
                    {
                        destFile.OwnerID = ownerId;
                    }

                    byte[] destContent = new byte[0];

                    RVGraphics.make_thumbnail(paramsContainer.Tenant.Id, fileContent, destFile, ref destContent,
                                              maxWidth, maxHeight, 0, 0, ref errorMessage, "jpg");

                    if (string.IsNullOrEmpty(errorMessage))
                    {
                        responseText = responseText.Replace(uploaded.FileID.ToString(), destFile.FileID.ToString());
                    }
                }

                responseText = responseText.Replace("\"~[[MSG]]\"",
                                                    string.IsNullOrEmpty(errorMessage) ? "\"\"" : errorMessage);

                _return_response(ref responseText);
                return;
            }
            }

            paramsContainer.return_response(PublicConsts.BadRequestResponse);
        }
Пример #15
0
        public bool ProcessTenantIndependentRequest(HttpContext context)
        {
            if (!RaaiVanSettings.SAASBasedMultiTenancy && !paramsContainer.ApplicationID.HasValue)
            {
                paramsContainer.return_response(PublicConsts.NullTenantResponse);
                return(true);
            }

            string responseText = string.Empty;

            string command = !string.IsNullOrEmpty(context.Request.Params["cmd"]) ? context.Request.Params["cmd"].ToLower() :
                             (string.IsNullOrEmpty(context.Request.Params["Command"]) ? "uploadfile" : context.Request.Params["Command"].ToLower());

            Guid userId = string.IsNullOrEmpty(context.Request.Params["UserID"]) ? PublicMethods.get_current_user_id() :
                          Guid.Parse(context.Request.Params["UserID"]);

            Guid ownerId = string.IsNullOrEmpty(context.Request.Params["OwnerID"]) ? Guid.Empty :
                           Guid.Parse(context.Request.Params["OwnerID"]);

            FileOwnerTypes ownerType = FileOwnerTypes.None;

            if (!Enum.TryParse <FileOwnerTypes>(context.Request.Params["OwnerType"], out ownerType))
            {
                ownerType = FileOwnerTypes.None;
            }

            Guid?applicationId = paramsContainer.ApplicationID;

            switch (command)
            {
            case "uploadicon":
            {
                Guid iconId = string.IsNullOrEmpty(context.Request.Params["IconID"]) ? Guid.Empty :
                              Guid.Parse(context.Request.Params["IconID"]);

                IconType iconType = IconType.None;
                if (!Enum.TryParse <IconType>(context.Request.Params["Type"], true, out iconType))
                {
                    iconType = IconType.None;
                }

                if (iconType == IconType.ApplicationIcon || (RaaiVanSettings.SAASBasedMultiTenancy &&
                                                             (iconType == IconType.ProfileImage || iconType == IconType.CoverPhoto)))
                {
                    applicationId = null;
                }
                else if (!applicationId.HasValue)
                {
                    responseText = PublicConsts.NullTenantResponse;
                    break;
                }

                DocFileInfo uploaded = new DocFileInfo()
                {
                    FileID     = iconId,
                    OwnerID    = ownerId,
                    OwnerType  = ownerType,
                    FolderName = FolderNames.TemporaryFiles
                };

                byte[] fileContent = new byte[0];

                bool succeed = _attach_file_command(applicationId, uploaded, ref responseText, ref fileContent, dontStore: true);

                if (!succeed || fileContent == null || fileContent.Length == 0)
                {
                    break;
                }

                if (iconType == IconType.ProfileImage && iconId == Guid.Empty)
                {
                    iconId = userId;
                }

                string errorMessage = string.Empty;

                IconMeta meta = null;

                succeed = RVGraphics.create_icon(applicationId, iconId, iconType, fileContent, ref errorMessage, ref meta);

                if (succeed && meta != null)
                {
                    responseText = responseText.Replace("\"~[[MSG]]\"", meta.toJson(applicationId));
                }
                else
                {
                    responseText = responseText.Replace("\"~[[MSG]]\"", errorMessage);
                }

                try
                {
                    string tempRes = string.Empty;
                    if (succeed)
                    {
                        remove_file(uploaded, ref tempRes);
                    }
                }
                catch { }

                break;
            }

            case "deleteicon":
            {
                Guid iconId = string.IsNullOrEmpty(context.Request.Params["IconID"]) ? Guid.Empty :
                              Guid.Parse(context.Request.Params["IconID"]);

                IconType iconType = IconType.None;
                if (!Enum.TryParse <IconType>(context.Request.Params["Type"], true, out iconType))
                {
                    iconType = IconType.None;
                }

                if (iconType == IconType.ApplicationIcon || (RaaiVanSettings.SAASBasedMultiTenancy &&
                                                             (iconType == IconType.ProfileImage || iconType == IconType.CoverPhoto)))
                {
                    applicationId = null;
                }
                else if (!applicationId.HasValue)
                {
                    responseText = PublicConsts.NullTenantResponse;
                    break;
                }

                if (iconType == IconType.ProfileImage && iconId == Guid.Empty)
                {
                    iconId = userId;
                }

                FolderNames folderName            = FolderNames.ProfileImages;
                FolderNames highQualityFolderName = FolderNames.HighQualityProfileImage;

                string defaultIconUrl = string.Empty;

                bool isValid = DocumentUtilities.get_icon_parameters(applicationId, iconType,
                                                                     ref folderName, ref highQualityFolderName, ref defaultIconUrl);

                if (!isValid)
                {
                    responseText = PublicConsts.NullTenantResponse;
                    break;
                }

                new DocFileInfo()
                {
                    FileID     = iconId,
                    Extension  = "jpg",
                    OwnerID    = ownerId,
                    OwnerType  = ownerType,
                    FolderName = folderName
                }.delete(paramsContainer.ApplicationID);

                new DocFileInfo()
                {
                    FileID     = iconId,
                    Extension  = "jpg",
                    OwnerID    = ownerId,
                    OwnerType  = ownerType,
                    FolderName = highQualityFolderName
                }.delete(paramsContainer.ApplicationID);

                responseText = "{\"Succeed\":\"" + Messages.OperationCompletedSuccessfully + "\"" +
                               ",\"DefaultIconURL\":\"" + defaultIconUrl + "\"}";

                break;
            }

            case "cropicon":
            {
                Guid iconId = string.IsNullOrEmpty(context.Request.Params["IconID"]) ? Guid.Empty :
                              Guid.Parse(context.Request.Params["IconID"]);

                IconType iconType = IconType.None;
                if (!Enum.TryParse <IconType>(context.Request.Params["Type"], true, out iconType))
                {
                    iconType = IconType.None;
                }

                if (iconType == IconType.ApplicationIcon || (RaaiVanSettings.SAASBasedMultiTenancy &&
                                                             (iconType == IconType.ProfileImage || iconType == IconType.CoverPhoto)))
                {
                    applicationId = null;
                }
                else if (!applicationId.HasValue)
                {
                    responseText = PublicConsts.NullTenantResponse;
                    break;
                }

                int         iconWidth = 100, iconHeight = 100;
                FolderNames imageFolder            = FolderNames.ProfileImages,
                            highQualityImageFolder = FolderNames.HighQualityProfileImage;

                if (iconType == IconType.ProfileImage && iconId == Guid.Empty)
                {
                    iconId = userId;
                }

                bool isValid = DocumentUtilities.get_icon_parameters(applicationId, iconType,
                                                                     ref iconWidth, ref iconHeight, ref imageFolder, ref highQualityImageFolder);

                if (!isValid)
                {
                    break;
                }

                DocFileInfo highQualityFile =
                    new DocFileInfo()
                {
                    FileID = iconId, Extension = "jpg", FolderName = highQualityImageFolder
                };

                DocFileInfo file = new DocFileInfo()
                {
                    FileID = iconId, Extension = "jpg", FolderName = imageFolder
                };

                int x     = string.IsNullOrEmpty(context.Request.Params["X"]) ? -1 : int.Parse(context.Request.Params["X"]);
                int y     = string.IsNullOrEmpty(context.Request.Params["Y"]) ? -1 : int.Parse(context.Request.Params["Y"]);
                int width = string.IsNullOrEmpty(context.Request.Params["Width"]) ? -1 :
                            (int)double.Parse(context.Request.Params["Width"]);
                int height = string.IsNullOrEmpty(context.Request.Params["Height"]) ? -1 :
                             (int)double.Parse(context.Request.Params["Height"]);

                IconMeta meta = null;

                RVGraphics.extract_thumbnail(applicationId, highQualityFile, highQualityFile.toByteArray(applicationId), file,
                                             x, y, width, height, iconWidth, iconHeight, ref responseText, ref meta);

                break;
            }
            }

            if (!string.IsNullOrEmpty(responseText))
            {
                paramsContainer.return_response(ref responseText);
            }

            return(!string.IsNullOrEmpty(responseText));
        }