HTTP Post Rails 4 Issue - rest

Thank you in advance for any and all help.
I've been having a ridiculous issue with trying to get my rails 4 app to take in data from an email parsing API that sends an XML response to a specified url within my application. For whatever reason I can't seem to find, the data is not getting into my application via the HTTP Post from the API.
When I test out using requestb.in and Advanced Rest Client everything works great, however when I try to send the data to my app, no dice. I'm currently sending to my dev branch via Pow.cx so it has a specific url to send to. I've been testing using google's Advanced Rest Client and requestb.in and using requestbin I've had no problem getting the data to show up on Advanced Rest Client, however it will not get into my App. Any help will be super appreciated. Thank you!!
My Routes:
get 'worldmate/receive', to: 'worldmate#receive'
post 'worldmate/receive', to: 'worldmate#receive'
In My Controller:
require 'nokogiri'
require 'net/http'
require 'open-uri'
require 'json'
class WorldmateController < ActionController::Base
def receive
#request = request
#xml = #request.body
#string = #request.body.read
#size = #request.body.size
end
My erb:
<p> Request: <%= #string %> <p>
<br>
<p> Less Detailed Request: <%= #xml %> </p>
<br>
<p> Size: <%= #size %> </p>
I have no idea why my app isn't taking this data in. When I send a post request using Advanced Rest Client it works totally fine. Any and all help is SUPER appreciated. Many thanks.

My guess is that you have configured your email parsing service to POST the data to a URL which is only accessible from your local system, for instance a pow.cx style ".dev" URL.
The reason this works using your test utility is I'm assuming the test client is also on your local machine and therefore your local server is addressable from there.
The way I've worked around this is using tunneling. Ngrok is a nice, low-config tool for tunneling, but there are many solutions out there to make your local dev environment accessible from the web for testing purposes.

Related

Notification Templating with WebHooks default payload (Appveyor)

So currently I am in the process of setting up notifications, and what I had wanted to send in my message portion was the url for the artifact zip file that was created.
I took a look at the default payload (https://www.appveyor.com/docs/notifications/#webhook-payload-default) and was able to send {{jobs}} which gave me in the email this:
System.Collections.Generic.List`1[Appveyor.Models.BuildJobNotificationTemplateData]
I figured I could traverse this in my messaging template. However, when I tried to do that it kept erroring out with different methods that I’ve tried.
Some of them include :
{{jobs[0].artifacts[0].url}}
{{jobs.artifacts.url}}
{{eventData.jobs.artifacts.url}}
{{eventData.jobs[0].artifacts[0].url}}
Etc…
What would the proper syntax be to grab the first artifacts url using the templating engine?
This syntax will work (see mustache template to understand the syntax)
<p>Artifacts:</p>
<ul>
{{#jobs}}
{{#artifacts}}
<li>{{url}}</li>
{{/artifacts}}
{{/jobs}}
</ul>
But unfortunately it will return temporary Azure blob storage URL, which will expire in 60 minutes. Please watch https://github.com/appveyor/ci/issues/1646. For now to get permanent URL please use this workaround

Send variable to 3rd party online form

In golang, is there a way to pipe a variable to part of a web form?
For example, sending "123 Random St." to the Street address part of https://www.dominos.com/en/pages/order/#/locations/search/ and so on? I found pizza_party*, but the GUI used is no longer available, I have also found pizzadash**, but this uses a credit card where I want to use cash. I even found a list of golang ones, but the links that they use doesn't work anymore.***
Therefore, my goal is so: order a pizza in golang through the dominos website API!
NOTE: Please suggest a package or function with example!
NOTE: I do not want to make a web scraper/data getter.
NOTE: Your answer must work on at least one box of my linked website.
NOTE: I want to fill out links similar to the provided link from the linux command line.
*https://github.com/coryarcangel/Pizza-Party-0.1.b
**https://github.com/bhberson/pizzadash
***https://golanglibs.com/top?q=pizza
This is how you post any form values onto an online form. Provided you know the POST endpoint of the service.
func main():
resp, err := http.PostForm(targetPostUrlHere,
url.Values{"Service_Type": {"Delivery"},
"Address_Type_Select": {"House"},
"Street": {"123 E 24th St"},
"Address_Line_2": {"4D"},
"City": {"New York"},
"Region": {"NY"},
"Postal_Code": {"10027"}})
}
**Note: The field keys and values are guesstimates. You must inspect the actual key names expected in the form.
In your case, https://www.dominos.com/en/pages/order/ is an endpoint for the form page. Once the form is filled and submitted, the information is submitted using POST method akin to the code afore-mentioned to a dedicated CREATE endpoint (C in the CRUD), which normally can be found in the <form> html tag.
<form action="posttargetendpoint" method="POST">...</form>
Once the POST operation is successful, usually a web service would redirect you to another page. In your case, it is https://www.dominos.com/en/pages/order/#/section/Food/category/AllEntrees/
However, any good web service wouldn't expose the POST endpoint in the clear since it is the vulnerable point of attack. You're welcome to find out by inspect he Domino's page source and adjust the field values in the Go code accordingly.
Now to make a command line prompt to wrap around the PostForm code, I suggest you look into https://github.com/codegangsta/cli which is a very nice package for creating quick command line app.
I assume you mean pipe information originating from your backend to another site on behalf of a user?
The standard way of passing information between domains is via HTTP params, usually via a GET request, but this capability would need to be supported by established protocols the remote site. You can also use an iframe to embed the page of another site onto your page, however, you wouldn't be able to remotely interact, call JS code, or even query the page at all. Cross-domain security safeguards justifiably prohibit such capability, and generally speaking, interacting on behalf of the user via their browser is also restricted for security reasons.
However, if you're looking to emulate user behavior such as with a bot or web scraper from your own host or browser then that's a different story. There are tons of frameworks provide rich capability for interacting with a page. I'd recommend checking out Selenium, which acts as a virtual browser. There are also tons of libraries in Python for processing data from HTML and structured data. You might want to check out Beatiful Soup and Scrapy.
Hope this helps.

Include Build request user in jenkins groovy email

After a build is finished I use the mail-ext-plugin (Jenkins Email Extension Plugin) to send an email to certain users. I would like to include the user who started (requested) the build in that email. I have tried the suggestion here however, that didn't seem to work I just got this error.
Error in script or template: groovy.lang.MissingPropertyException: No such property: CAUSE for class: SimpleTemplateScript4
After much searching I found a page on jelly usage on the Jenkins wiki (here). There is a link on this page which contains all the useable classes. I was able to find the cause class and used this great example to help me implement it in my code. I added
<%
for (hudson.model.Cause cause : build.causes) {
%>
${cause.shortDescription}
<%
}
%>
which produced -
Started by user Matthew Armstrong

How to add a contact form to a static web site?

I have a mostly "static" web site with no server-side code and just a little JavaScript. Now I would like to add a contact form. I do not care how I get the contact form data (so just writing this data to a text file in the server will be ok).
What is the simplest solution for this problem? How do people usually handle this?
I believe I can add some server-side code (PHP or something) to handle the form (and write the form data to a file, for instance) but I would prefer a client-side solution.
Use an external tool, they are commonly referred to as "formmailer". You basically submit the form to their server, and they send the form contents via mail to you.
If you don't want that, you have to do something server-sided: Storing data on the server, without having a server side program that accepts the data from the client, is just not possible.
You could install CouchDB and interface that from Javascript :) Everyone could use that then, too :)
The most easy PHP script that stores POST data on your harddisk:
<?php file_put_contents('/path/to/file', serialize($_POST) . "\n", FILE_APPEND); ?>
You can use Google Drive and create form with required fields. and embed code (which will be iframe) in your static web page.
You will be able to get submitted data in spreadsheet.
You can use qontacto . it is a free contact form you can add to any website. it forwards you the messages.
I set up the fwdform service for this exact need.
Just two simple steps to get your form forwarded to your email.
1.Register
Make an HTTP POST request to register your email.
$ curl --data "email=<your_email>" https://fwdform.herokuapp.com/register
Token: 780a8c9b-dc2d-4258-83af-4deefe446dee
2. Set up your form
<form action="https://fwdform.herokuapp.com/user/<token>" method="post">
Email: <input type="text" name="name"><br>
Name: <input type="text" name="email"><br>
Message: <textarea name="message" cols="40" rows="5"></textarea>
<input type="submit" value="Send Message">
</form>
With a couple of extra seconds you can spin up your own instance on Heroku.

Is there a way to force $c->uri_for in Catalyst to generate a URI that begins with https?

I've written a web application using Catalyst that has a lot of forms and needs to run over https. There are no hard-coded URLs, everything uses $c->uri_for or $c->req->uri. Everything worked great in the development environment using the dev server running over http.
Today, when I went ahead and deployed the application, I noticed a problem. The way our production environment is currently setup, client browsers talk to a F5 load-balancer over HTTPS and the F5 talks to the web server on the internal network over HTTP.
[ Browser ] ---HTTPS---> [ F5 ] ---HTTP---> [ Web Server ]
Now, because the web server only gets HTTP requests, all URIs are generated starting with HTTP. This means:
<form action='[% c.uri_for('/secure/form') %]' method='post'>
becomes:
<form action='http://websitename.org/secure/form' method='post'>
and now all browsers complain you are submitting data over an insecure connection. I need that c.uri_for to begin with https.
The app needed to go live today, so I did a mass search/replace for all form actions to this:
<form action='[% c.uri_for('/secure/form') | replace('http:', 'https:'%]' method='post'>
Well, now that breaks development, so I conditionalized the form actions based on a config key:
[% IF c.config.production %]
<form action='[% c.uri_for('/secure/form') | replace ('http:', 'https:') %]' method='post'>
[% ELSE %]
<form action='[% c.uri_for('/secure/form') %]' method='post'>
[% END %]
Needless to say, this all just seems wrong on multiple levels. Anyone have a better idea? And is there a way to force $c->uri_for to generate a URI that begins with https?
Solution
If you're using Catalyst 5.80008 or later, set MyApp->config(using_frontend_proxy => 1); and simply have your proxy set the X-Forwarded-Port header. For Catalyst versions prior to 5.80008, still set using_frontend_proxy so you get the actual client_ip, but to generate the correct URIs have your web server set the environment variable HTTPS to ON
You might try this configuration option:
MyApp->config(using_frontend_proxy => 1);
It's described in Catalyst's documentation
The following works (tested):
In MyApp.pm, add the following sub:
sub secure_uri_for {
my ($self, #args) = #_;
my $u = $self->uri_for(#args);
$u->scheme('https');
return $u;
}
Now any time you want a guaranteed https, you can call $c->secure_uri_for('whatever')
I don't use Catalyst, but the docs for uri_for point to the request object's base method.
I read the source, and found that base is a read/write method. So, you should be able to squeeze $req->base('https://foo.bar.com/') into your code somewhere to get your https uris.
Update:
singingfish says that the above advice is incorrect--which wouldn't surprise me at all, it was based on a quick look at TFM. S/He also says that the scheme method should be set instead. I assume s/he is referring the the uri object's scheme method.
Further searching turned up HTTPS Tricks on the Catalyst Wiki. It shows an example of setting the scheme on the uri objects returned by the uri_for_action method. It looks like you would need to set the scheme on every uri you request, all over your code. So, I can't help but feel that the scheme method may not be the best choice.
I also found this thread on the mailing list. Setting base or setting an environment variable are both recommended methods.
This gives you several avenues of investigation. Good luck.