Ejemplo n.º 1
0
        public IActionResult Post([FromForm] MultipartFormData <Product> data)
        {
            var json  = data.Json ?? throw new NullReferenceException(nameof(data));
            var image = data.File;

            return(Ok());
        }
Ejemplo n.º 2
0
 public override void OnBeforeURLRequest(BeforeURLRequestParams parameters)
 {
     if ("POST" == parameters.Method)
     {
         PostData            post        = parameters.PostData;
         PostDataContentType contentType = post.ContentType;
         if (contentType == PostDataContentType.FORM_URL_ENCODED)
         {
             FormData postData = (FormData)post;
             postData.SetPair("key1", "value1", "value2");
             postData.SetPair("key2", "value2");
         }
         else if (contentType == PostDataContentType.MULTIPART_FORM_DATA)
         {
             MultipartFormData postData = (MultipartFormData)post;
             postData.SetPair("key1", "value1", "value2");
             postData.SetPair("key2", "value2");
             postData.SetFilePair("file3", "C:\\Test.zip");
         }
         else if (contentType == PostDataContentType.PLAIN_TEXT)
         {
             RawData postData = (RawData)post;
             postData.Data = "raw data";
         }
         else if (contentType == PostDataContentType.BYTES)
         {
             BytesData data = (BytesData)post;
             data.Data = Encoding.UTF8.GetBytes("My data");
         }
         parameters.PostData = post;
     }
 }
Ejemplo n.º 3
0
        private void extractDuplicateFilteringForDeployment(MultipartFormData payload, DeploymentBuilder deploymentBuilder)
        {
            bool enableDuplicateFiltering = false;
            bool deployChangedOnly        = false;

            MultipartFormData.FormPart deploymentEnableDuplicateFiltering = payload.getNamedPart(ENABLE_DUPLICATE_FILTERING);
            if (deploymentEnableDuplicateFiltering != null)
            {
                enableDuplicateFiltering = bool.Parse(deploymentEnableDuplicateFiltering.TextContent);
            }

            MultipartFormData.FormPart deploymentDeployChangedOnly = payload.getNamedPart(DEPLOY_CHANGED_ONLY);
            if (deploymentDeployChangedOnly != null)
            {
                deployChangedOnly = bool.Parse(deploymentDeployChangedOnly.TextContent);
            }

            // deployChangedOnly overrides the enableDuplicateFiltering setting
            if (deployChangedOnly)
            {
                deploymentBuilder.enableDuplicateFiltering(true);
            }
            else if (enableDuplicateFiltering)
            {
                deploymentBuilder.enableDuplicateFiltering(false);
            }
        }
        public void Sample_GetMultipartFormDataBytes()
        {
            // param
            var param_id   = new { key = "id", value = 123456 };
            var param_name = new { key = "name", value = "Mr-hai" };

            // data
            var data_file = new { key = "file", filename = "my.jpg", data = new byte[2] {
                                      10, 11
                                  } };

            using (var formData = new MultipartFormData()
                                  .AddParameter(param_id.key, param_id.value.ToString())
                                  .AddParameter(param_name.key, param_name.value)
                                  .AddFileObject(data_file.key, data_file.filename, data_file.data)
                                  .End())
            {
                // Get multipart/form-data as bytes
                var bytes = formData.GetDataBytes();

                // Get the multipart/form-data as Stream
                var stream = formData.GetDataStream();

                // Get the Boundary
                var boundary = formData.Boundary;
            }
        }
Ejemplo n.º 5
0
        public virtual void setBinaryVariable(string variableKey, MultipartFormData payload)
        {
            MultipartFormData.FormPart dataPart       = payload.getNamedPart("data");
            MultipartFormData.FormPart objectTypePart = payload.getNamedPart("type");
            MultipartFormData.FormPart valueTypePart  = payload.getNamedPart("valueType");

            if (objectTypePart != null)
            {
                object @object = null;

                if (!string.ReferenceEquals(dataPart.ContentType, null) && dataPart.ContentType.ToLower().Contains(MediaType.APPLICATION_JSON))
                {
                    @object = deserializeJsonObject(objectTypePart.TextContent, dataPart.BinaryContent);
                }
                else
                {
                    throw new InvalidRequestException(Response.Status.BAD_REQUEST, "Unrecognized content type for serialized java type: " + dataPart.ContentType);
                }

                if (@object != null)
                {
                    setVariableEntity(variableKey, Variables.objectValue(@object).create());
                }
            }
            else
            {
                string valueTypeName = DEFAULT_BINARY_VALUE_TYPE;
                if (valueTypePart != null)
                {
                    if (string.ReferenceEquals(valueTypePart.TextContent, null))
                    {
                        throw new InvalidRequestException(Response.Status.BAD_REQUEST, "Form part with name 'valueType' must have a text/plain value");
                    }

                    valueTypeName = valueTypePart.TextContent;
                }

                VariableValueDto valueDto = VariableValueDto.fromFormPart(valueTypeName, dataPart);
                try
                {
                    TypedValue typedValue = valueDto.toTypedValue(engine, objectMapper);
                    setVariableEntity(variableKey, typedValue);
                }
                catch (AuthorizationException e)
                {
                    throw e;
                }
                catch (ProcessEngineException e)
                {
                    string errorMessage = string.Format("Cannot put {0} variable {1}: {2}", ResourceTypeName, variableKey, e.Message);
                    throw new RestException(Response.Status.INTERNAL_SERVER_ERROR, e, errorMessage);
                }
            }
        }
Ejemplo n.º 6
0
        private DeploymentBuilder extractDeploymentInformation(MultipartFormData payload)
        {
            DeploymentBuilder deploymentBuilder = ProcessEngine.RepositoryService.createDeployment();

            ISet <string> partNames = payload.PartNames;

            foreach (string name in partNames)
            {
                MultipartFormData.FormPart part = payload.getNamedPart(name);

                if (!RESERVED_KEYWORDS.Contains(name))
                {
                    string fileName = part.FileName;
                    if (!string.ReferenceEquals(fileName, null))
                    {
                        deploymentBuilder.addInputStream(part.FileName, new MemoryStream(part.BinaryContent));
                    }
                    else
                    {
                        throw new InvalidRequestException(Status.BAD_REQUEST, "No file name found in the deployment resource described by form parameter '" + fileName + "'.");
                    }
                }
            }

            MultipartFormData.FormPart deploymentName = payload.getNamedPart(DEPLOYMENT_NAME);
            if (deploymentName != null)
            {
                deploymentBuilder.name(deploymentName.TextContent);
            }

            MultipartFormData.FormPart deploymentSource = payload.getNamedPart(DEPLOYMENT_SOURCE);
            if (deploymentSource != null)
            {
                deploymentBuilder.source(deploymentSource.TextContent);
            }

            MultipartFormData.FormPart deploymentTenantId = payload.getNamedPart(TENANT_ID);
            if (deploymentTenantId != null)
            {
                deploymentBuilder.tenantId(deploymentTenantId.TextContent);
            }

            extractDuplicateFilteringForDeployment(payload, deploymentBuilder);
            return(deploymentBuilder);
        }
Ejemplo n.º 7
0
        private void DeployZip(string zipFile)
        {
            var responseString = string.Empty;

            var req = new DigestHttpWebRequest(UserName, Password);

            req.Method = WebRequestMethods.Http.Post;

            var formData = new MultipartFormData();

            formData.Add("mysubmit", "Install");
            formData.AddFile("archive", zipFile, "application/x-zip-compressed");
            req.PostData    = formData.GetMultipartFormData();
            req.ContentType = formData.ContentType;


            Uri uri = new Uri(string.Format(URL, BoxIP));

            using (HttpWebResponse webResponse = req.GetResponse(uri))
                using (Stream responseStream = webResponse.GetResponseStream())
                {
                    if (responseStream != null)
                    {
                        using (StreamReader streamReader = new StreamReader(responseStream))
                        {
                            responseString = streamReader.ReadToEnd();

                            string          pattern = "<font color=\"red\">(.*?)<\\/font>";
                            MatchCollection matches = Regex.Matches(responseString, pattern);

                            foreach (Match m in matches)
                            {
                                if (m.Groups[1].Value.Contains("Install Success"))
                                {
                                    LogTaskMessage($"Deploy result: {m.Groups[1]}");
                                }
                                else
                                {
                                    Log.LogError($"Deploy result: {m.Groups[1]}");
                                }
                            }
                        }
                    }
                }
        }
        private static string GetImageUrl(string ip, string user, string pass)
        {
            var req = new DigestHttpWebRequest(user, pass);

            req.Method = WebRequestMethods.Http.Post;

            var formData = new MultipartFormData();

            formData.AddFile("archive", "", "application/octet-stream");
            formData.Add("passwd", "");
            formData.Add("mysubmit", "Screenshot");
            req.PostData    = formData.GetMultipartFormData();
            req.ContentType = formData.ContentType;

            Uri uri = new Uri(string.Format(URL, ip));

            using (HttpWebResponse webResponse = req.GetResponse(uri))
                using (Stream responseStream = webResponse.GetResponseStream())
                {
                    if (responseStream != null)
                    {
                        using (StreamReader streamReader = new StreamReader(responseStream))
                        {
                            var responseString = streamReader.ReadToEnd();

                            var             pattern = "<img src=\"(.*?)\">";
                            MatchCollection matches = Regex.Matches(responseString, pattern);

                            foreach (Match m in matches)
                            {
                                return(String.Format("http://{0}/{1}", ip, m.Groups[1]));
                            }
                        }
                    }
                }

            return(null);
        }
Ejemplo n.º 9
0
        private void DeployZip(string zipFile, string ip, ConfigModel options)
        {
            var responseString = string.Empty;

            var req = new DigestHttpWebRequest(options.User, options.Pass);

            req.Method = WebRequestMethods.Http.Post;

            var formData = new MultipartFormData();

            formData.Add("mysubmit", "Install");
            formData.AddFile("archive", zipFile, "application/x-zip-compressed");
            req.PostData    = formData.GetMultipartFormData();
            req.ContentType = formData.ContentType;


            Uri uri = new Uri(string.Format(URL, ip));

            using (HttpWebResponse webResponse = req.GetResponse(uri))
                using (Stream responseStream = webResponse.GetResponseStream())
                {
                    if (responseStream != null)
                    {
                        using (StreamReader streamReader = new StreamReader(responseStream))
                        {
                            responseString = streamReader.ReadToEnd();

                            string          pattern = "<font color=\"red\">(.*?)<\\/font>";
                            MatchCollection matches = Regex.Matches(responseString, pattern);

                            foreach (Match m in matches)
                            {
                                Console.WriteLine("Deploy result: {0}", m.Groups[1]);
                            }
                        }
                    }
                }
        }
Ejemplo n.º 10
0
        private void Update(string html, bool hidden1 = false, bool hidden2 = false, bool hidden3 = false)
        {
            if (!hidden1 && !hidden2 && !hidden3)
            {
                return;
            }
            HtmlParser    par = new HtmlParser();
            IHtmlDocument document;

            document = par.Parse(html);
            var form = document.QuerySelector("[id='updateArtForm']");

            if (form == null)
            {
                Console.WriteLine("> not found form update");
                return;
            }

            var nodes = form.QuerySelectorAll("input,textarea");
            MultipartFormData formdata = new MultipartFormData();

            foreach (var node in nodes)
            {
                string name  = node.GetAttribute("name");
                string value = "";
                //if (name == "ltoRelaunch"|| name== "LimitedTime")
                //    continue;
                if (name == "Description" || name == "Keywords")
                {
                    value = node.TextContent;
                }
                else
                {
                    value = node.GetAttribute("value");
                }
                if (name.Contains("amount"))
                {
                    value = value.Remove(value.Length - 2);
                }
                formdata.Add(new FormElement(name, value));
            }
            formdata.RemoveElements("ltoRelaunch");
            formdata.RemoveElements("LimitedTime");
            if (hidden1)
            {
                formdata.SetValue("ExcludeFromSearch", "1");
            }
            else
            {
                formdata.RemoveElements("ExcludeFromSearch");
            }
            if (hidden2)
            {
                formdata.SetValue("DoNotAllowGoogle", "1");
            }
            else
            {
                formdata.RemoveElements("DoNotAllowGoogle");
            }
            if (hidden3)
            {
                formdata.SetValue("isBlackout", "2");
            }
            else
            {
                formdata.RemoveElements("isBlackout");
            }
            formdata.Add(new FormElement("submit", ""));

            string res = http.Request("POST", "https://manager.hostingrocket.com/my-art-edit.cfm", new string[]
            {
                "Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryffQeAkANeAVRVjmj"
            }, formdata.GetData("----WebKitFormBoundaryffQeAkANeAVRVjmj"));
            //File.WriteAllText("res_update.html", res);
            //File.WriteAllBytes("post.txt", formdata.GetData("----WebKitFormBoundaryffQeAkANeAVRVjmj"));
        }
Ejemplo n.º 11
0
        public virtual AttachmentDto addAttachment(UriInfo uriInfo, MultipartFormData payload)
        {
            ensureHistoryEnabled(Status.FORBIDDEN);
            ensureTaskExists(Status.BAD_REQUEST);

            MultipartFormData.FormPart attachmentNamePart        = payload.getNamedPart("attachment-name");
            MultipartFormData.FormPart attachmentTypePart        = payload.getNamedPart("attachment-type");
            MultipartFormData.FormPart attachmentDescriptionPart = payload.getNamedPart("attachment-description");
            MultipartFormData.FormPart contentPart = payload.getNamedPart("content");
            MultipartFormData.FormPart urlPart     = payload.getNamedPart("url");

            if (urlPart == null && contentPart == null)
            {
                throw new InvalidRequestException(Status.BAD_REQUEST, "No content or url to remote content exists to create the task attachment.");
            }

            string attachmentName        = null;
            string attachmentDescription = null;
            string attachmentType        = null;

            if (attachmentNamePart != null)
            {
                attachmentName = attachmentNamePart.TextContent;
            }
            if (attachmentDescriptionPart != null)
            {
                attachmentDescription = attachmentDescriptionPart.TextContent;
            }
            if (attachmentTypePart != null)
            {
                attachmentType = attachmentTypePart.TextContent;
            }

            Attachment attachment = null;

            try
            {
                if (contentPart != null)
                {
                    MemoryStream byteArrayInputStream = new MemoryStream(contentPart.BinaryContent);
                    attachment = engine.TaskService.createAttachment(attachmentType, taskId, null, attachmentName, attachmentDescription, byteArrayInputStream);
                }
                else if (urlPart != null)
                {
                    attachment = engine.TaskService.createAttachment(attachmentType, taskId, null, attachmentName, attachmentDescription, urlPart.TextContent);
                }
            }
            catch (ProcessEngineException e)
            {
                throw new InvalidRequestException(Status.BAD_REQUEST, e, "Task id is null");
            }

            URI uri = uriInfo.BaseUriBuilder.path(rootResourcePath).path(org.camunda.bpm.engine.rest.TaskRestService_Fields.PATH).path(taskId + "/attachment/" + attachment.Id).build();

            AttachmentDto attachmentDto = AttachmentDto.fromAttachment(attachment);

            // GET /
            attachmentDto.addReflexiveLink(uri, HttpMethod.GET, "self");

            return(attachmentDto);
        }
Ejemplo n.º 12
0
        public async Task <ICollection <IAnalysisResult> > Analyse(ICollection <IDetectionResultItem> items)
        {
            var result = new List <IAnalysisResult>();

            try
            {
                //name="action"
                //auswerten

                //name="langselect"
                //english

                //name="logfile"
                //

                //name="debuging"
                //0 //default
                //1

                //name="communitycheck"
                //1 //default
                //0

                //name="Submit"
                //Analyze

                var data = string.Join("\r\n", items.Select(s => s.LegacyString.Trim()));

                var postParameters = new Dictionary <string, string>()
                {
                    { "action", "auswerten" },
                    { "langselect", "english" },
                    { "logfile", data },
                    { "debuging", "0" },
                    { "communitycheck", "1" },
                    { "Submit", "Analyze" },
                };

                var cachedItems =
                    items.Select(
                        f =>
                        new
                {
                    Match = f /*.LegacyString*/,
                    Name  = f.LegacyString.Trim()
                            .Split(220)
                }).Distinct().ToList();

                var responseMessage = await MultipartFormData.Post(
                    "http://www.hijackthis.de/#anl",
                    "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.117 Safari/537.36",
                    postParameters);

                var match = Regex.Match(responseMessage, REG_EX_PATTERN,
                                        RegexOptions.Singleline | RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace |
                                        RegexOptions.CultureInvariant);

                if (match.Success)
                {
                    var i = 0;
                    foreach (var capture in match.Groups["entry"].Captures)
                    {
                        var name = WebUtility.HtmlDecode(((Capture)capture).Value.Trim());

                        if (!result.Any(f => f.Match.LegacyString.Trim()
                                        .Split(220).Equals(name)))
                        {
                            foreach (var resultItem in cachedItems.Where(
                                         f =>
                                         f.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase))
                                     .Select(item => new AnalysisResult {
                                Match = item.Match
                            }))
                            {
                                switch (match.Groups["kind"].Captures[i].Value.ToLower())
                                {
                                case "safe.":
                                    resultItem.Result = AnalyseResultType.Safe;
                                    break;

                                case "nasty":
                                    resultItem.Result = AnalyseResultType.Critical;
                                    break;

                                //case "":
                                //  resultItem.Type = AnalyseResultType.Caution;
                                //  break;
                                default: //unknown
                                    resultItem.Result = AnalyseResultType.Unknown;
                                    break;
                                }

                                resultItem.Text = match.Groups["information"].Captures[i].Value.Trim();

                                result.Add(resultItem);
                            }
                        }
                        i++;
                    }
                }
            }
            catch (Exception ex)
            {
                //MessageBox.Show(ex.Message);
                throw;
            }

            return(result);
        }
Ejemplo n.º 13
0
        public virtual DeploymentWithDefinitionsDto createDeployment(UriInfo uriInfo, MultipartFormData payload)
        {
            DeploymentBuilder deploymentBuilder = extractDeploymentInformation(payload);

            if (deploymentBuilder.ResourceNames.Count > 0)
            {
                DeploymentWithDefinitions deployment = deploymentBuilder.deployWithResult();

                DeploymentWithDefinitionsDto deploymentDto = DeploymentWithDefinitionsDto.fromDeployment(deployment);


                URI uri = uriInfo.BaseUriBuilder.path(relativeRootResourcePath).path(org.camunda.bpm.engine.rest.DeploymentRestService_Fields.PATH).path(deployment.Id).build();

                // GET
                deploymentDto.addReflexiveLink(uri, HttpMethod.GET, "self");

                return(deploymentDto);
            }
            else
            {
                throw new InvalidRequestException(Status.BAD_REQUEST, "No deployment resources contained in the form upload.");
            }
        }