how to create a EU bucket on Amazon S3 using Coldfusion? - coldfusion

I'm running Coldfusion8 and am using the Amazon S3 Rest Wrapper CFC trying to set it up with a EU bucket.
I can use the cfc to set up buckets in the US, but whenever I'm changing to the EU setting, it does not work.
Here is the function being used:
<cffunction name="putBucket" access="public" output="false" returntype="boolean" description="Creates a bucket.">
<cfargument name="bucketName" type="string" required="true">
<cfargument name="acl" type="string" required="false" default="public-read">
<cfargument name="storageLocation" type="string" required="false" default="">
<cfset var strXML = "">
<cfset var dateTimeString = GetHTTPTimeString(Now())>
<cfset var destination = "http://s3.amazonaws.com/">
<!--- Create a canonical string to send based on operation requested --->
<cfset var cs = "PUT\n\ntext/html\n#dateTimeString#\nx-amz-acl:#arguments.acl#\n/#arguments.bucketName#">
<cfset var signature = createSignature(cs)>
<!--- added switch to EU --->
<cfif arguments.storageLocation EQ "EU">
<cfset destination = "http://s3-eu-west-1.amazonaws.com/">
</cfif>
<!--- Create a proper signature --->
<cfif compare(arguments.storageLocation,'')>
<cfsavecontent variable="strXML">
<CreateBucketConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"><LocationConstraint>#arguments.storageLocation#</LocationConstraint></CreateBucketConfiguration>
</cfsavecontent>
<cfelse>
<cfset strXML = "">
</cfif>
<!--- put the bucket via REST --->
<cfhttp method="PUT" url="#destination##arguments.bucketName#" charset="utf-8">
<cfhttpparam type="header" name="Content-Type" value="text/html">
<cfhttpparam type="header" name="Date" value="#dateTimeString#">
<cfhttpparam type="header" name="x-amz-acl" value="#arguments.acl#">
<cfhttpparam type="header" name="Authorization" value="AWS #variables.accessKeyId#:#signature#">
<cfhttpparam type="body" value="#trim(strXML)#">
</cfhttp>
<cfreturn true>
</cffunction>
I have added the switch to the EU region URL, but this doesn't work either.
Any idea what I need to do in order to create a bucket in the EU?
EDIT:
I have fixed the regional values. It still doesn't work tough, because if I pass a regional value other than "", this line:
<cfif compare(arguments.storageLocation,'')>
<cfsavecontent variable="strXML">
<CreateBucketConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"><LocationConstraint>#arguments.storageLocation#</LocationConstraint></CreateBucketConfiguration>
</cfsavecontent>
<cfelse>
<cfset strXML = "">
</cfif>
will produce a strXML like so:
<CreateBucketConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"><LocationConstraint>#arguments.storageLocation#</LocationConstraint></CreateBucketConfiguration>
which creates the bad request error again

You need to use the proper values for the storage location. From the API documents, I believe those values are:
The preferred geographical location for the bucket. [Allowed values: AmazonS3::REGION_US_E1, AmazonS3::REGION_US_W1, AmazonS3::REGION_EU_W1, AmazonS3::REGION_APAC_SE1, AmazonS3::REGION_APAC_NE1]

If you are running this on Linux, you could alternatively use the S3CMD tools
sudo apt-get install s3cmd
You will then need to run the configuration procedure or even better, build and maintain configuration in your source control and deploy to the server making the S3 commands
s3cmd --configure
Generally, the configuration includes information (in particular keys) about your S3 account. Make sure if you use a file you set permissions on the file correctly so you don't have to execute the s3cmd's as root
and then in you application
<cfexecute name="s3cmd" arguments="mb s3://my-new-bucket-name">

Related

coldfusion hang after file upload

I have a page that accepts user images, renames them and returns the new filename for further processing
<cffunction name="uploadfile" access="public" returntype="string">
<!--- TODO files should not be uploaded to web accesible directories - use #GetTempDirectory()# to use the temporary directory--->
<cfargument name="forma" type="struct" required="yes">
<cfargument name="db" type="string" required="yes">
<cfargument name="user_id" type="string" required="yes">
<cfparam name="new_filename" default="">
<cfset mediapath = expandpath('/ugc_images/images')>
<cfset thumbpath = expandpath('/ugc_images/images/thumbs')>
<cfif structKeyExists(forma,"fileUpload") and len(forma.fileUpload)>
<cffile action="upload" filefield="FileUpload" destination="#MediaPath#" nameconflict="makeunique" accept="image/jpeg,image/gif,image/png">
<!---<cfset serverfile.extension = right(file.serverFile, 3)> --->
<cfset new_filename= "#user_id#_#DateFormat(Now(), "mm-dd-yyyy")#.jpg">
<cffile action="rename" source="#MediaPath#/#file.serverFile#" destination="#MediaPath#/#new_filename#"/>
<cfimage source="#MediaPath#/#new_filename#" name="myImage">
<cfset ImageSetAntialiasing(myImage,"on")>
<cfif myImage.width gt 1000 or myImage.height gt 1000><cfset ImageScaleToFit(myImage,1000,1000)> </cfif>
<cfset ImageWrite(myImage,"#MediaPath#/#new_filename#")>
<cfif myImage.width gt 300 or myImage.height gt 300><cfset ImageScaleToFit(myImage,300,300)></cfif>
<cfset ImageWrite(myImage,"#thumbpath#/#new_filename#")>
</cfif>
<cfreturn "#new_filename#">
</cffunction><!---EO uploadfile--->
after calling that function (which does indeed upload and save the file and its thumbnail as intended, all coldfusion fucntions seem to hang. The webserver still serves plain text, but any coldfusion tag no matter how simple, timesout
for example, after the above I have this:
This text is served to the browser
<hr>
and this
<hr>
<cfoutput >but this times out</cfoutput>
and it never gets here
<hr>
It all works well on my local machine for development but on the remote (production) server it crashes. It's on a shared hosting so I have limited access to settings
any idea what's going on?

CFML and Exchange - CFexchange tags have stopped working

I need a little hand holding to convert my CFML cfexchange tags to the EWS API. I'm using CF 9.0.1 and need to add mail/calendar items to a hosted Exchange server.
I get the following error:
Error:
Could not log in to the Exchange server.
________________________________________
connection="exchangeConn"
server="EXVMBX016-5.exch016.msoutlookonline.net"
username="exch016\j_ttt"
mailboxname="j#ttt.com"
password="[removed]"
Protocol="http"
port="80"
formbasedauthentication="TRUE"
formbasedauthenticationURL="https://owa016.msoutlookonline.net/owa/auth/logon.aspx"
I have come up with the following code so far;
<cffunction name="EWSAddEvent" output="false" returntype="Boolean">
<!--- EWS added by vjl 2013/10/31 --->
<!---
CFExchange in CF server 9 or older will not talk with Exchange 2010 at all, it is promissed to be fixed in CF 10.
As a solution you can use the EWS API. Read the stuff below. I hope my hint is helpfull to you.
---------------------------------------------------------------------- ----------------------
With Exchange 2007 Microsoft abandoned WebDav as an interface to Exchangeserver.
The standard Coldfusion Tags relied on WebDav and will not work anymore.
Since I needed a way to interface with Exchange Server a started looking for possible solutions and this is what i came up with.
In december 2010 Microsoft released the Exchange Managed Services Library for java.
You can find it here: http://archive.msdn.microsoft.com/ewsjavaapi/Release/ProjectReleases.a spx?ReleaseId=5691
In the getting started document it tells you it depends on 4 3rd party libraries which you need to be download separately:
- Apache Commons HttpClient 3.1 (commons-httpclient-3.1.jar)
- Apache Commons Codec 1.4 (commons-codec-1.4.jar)
- Apache Commons Logging 1.1.1 (commons-codec-1.4.jar)
- JCIFS 1.3.15 (jcifs-1.3.15.jar)
With Coldfusion 9.1 (the version I tested with) you only need
- JCIFS 1.3.15 (jcifs-1.3.15.jar) which you can download here: http://jcifs.samba.org/src/
Place the EWS Jar and the JCIFS Jar in your Coldfusion libray folder and after restarting CF server the following code should work.
If you understand this you will be able to figure out your specific needs from the EWS API documentation.
--->
<cfargument name="EmailAddress" type="String" required="True" />
<cfargument name="EventName" type="String" />
<cfargument name="EventStartDateTime" type="Date" />
<cfargument name="EventEndDateTime" type="Date" />
<cfargument name="EventSubject" type="String" />
<cfargument name="EventDescription" type="String" />
<cfargument name="EventLocation" type="String" Required="False" Default="" />
<!--- <cfargument name="EventSensitivity" type="String" Required="False" Default="Normal" />
<cfargument name="EventImportance" type="String" Required="False" Default="Normal" /> --->
<cfargument name="EventReminder" type="String" Required="False" default=0 />
<!--- <cfargument name="Organizer" type="String" Required="False" Default="" /> --->
<cfargument name="OptionalAttendees" type="String" Required="False" Default="" />
<cfargument name="leadID" type="numeric" required="no" default="0" />
<cfargument name="serviceID" type="numeric" required="no" default="0" />
<cfargument name="userID" type="numeric" required="no" default="0" />
<cfargument name="companyID" type="numeric" required="no" default="0" />
<cfargument name="serviceTypeID" type="numeric" required="no" default="0" />
<cfmail to="v#g.com" from="info#t.com" subject="Exchange EWSAddEvent debug Arguments" type="html"><cfdump var="#Arguments#"></cfmail>
<!--- Build Mailbox --->
<cfset UserName = Left(Arguments.EmailAddress,Find("#",Arguments.EmailAddress)-1) />
<cfset Arguments.UserName = Application.Exchange.Domain & "\" & lcase(UserName) & Application.Exchange.MailboxPostFix />
<cfset Arguments.Pword = Trim(FetchExchangePassword(Arguments.EmailAddress)) />
<!--- 1. I need an instance of the ExchangeService class --->
<cfobject type="Java" class="microsoft.exchange.webservices.data.ExchangeService" name="service">
<cfset service.init()>
<cfmail to="v#g.c" from="info#t.com" subject="Exchange EWSAddEvent debug service" type="html"><cfdump var="#service#"></cfmail>
<!--- 2. I need to set the credentials --->
<!--- 2a. Create an instance of the WebCredentials class --->
<cfobject type="Java" class="microsoft.exchange.webservices.data.WebCredentials" name="credentials">
<!--- 2b. Set the credentials --->
<cfset credentials.init("#arguments.UserName#","#Arguments.Pword#", "t.com")>
<!--- 2c. Set the credentials in the service object --->
<cfset service.setCredentials(credentials) />
<!--- 3. In need to set the URL to Exchange (stay away from autodsicovery) --->
<!--- 3a. Create an instance of the Uri class --->
<cfobject type="Java" class="java.net.URI" name="uri">
<!--- 3b. Set the full path --->
<cfset uri.init("https://mail.t.com/ews/Exchange.asmx")>
<!--- 3c. Set the url in the service object --->
<cfset service.setUrl(uri) />
<!--- These are the steps you need to create valid a service object. --->
<!--- Now we need to do something with it. --->
<!--- I create a test message to my own mailbox to see if it works --->
<cfobject type="Java" action="create" class="microsoft.exchange.webservices.data.EmailMessage" name="message">
<cfset message = message.init(service) />
<cfset message.SetSubject("EWSTest")>
<cfset messageBody = CreateObject("java", "microsoft.exchange.webservices.data.MessageBody")>
<cfset messageBody.init("My EWS test message")>
<cfset message.SetBody( messageBody )>
<cfset message.ToRecipients.Add("v#t.com") >
<cfmail to="v#g.c" from="info#t.com" subject="Exchange EWSAddEvent debug message" type="html"><cfdump var="#message#"></cfmail>
<cfoutput>
#message.SendAndSaveCopy()#
</cfoutput>
<cfreturn True />
</cffunction>
Did you get any operation to work using EWS? Or are you facing problem when trying to send mails? If EWS itself is not working for you can you try the following snippet(Change the URL, user name and password) of code?
<cfscript>
service = createObject("java", "microsoft.exchange.webservices.data.ExchangeService");
service.init();
serviceURI = createObject("java", "java.net.URI");
serviceURI.init("http://10.192.37.30/ews/Exchange.asmx");
service.setUrl( serviceURI );
credentials = createObject("java", "microsoft.exchange.webservices.data.WebCredentials");
credentials.init("user", "password");
service.setCredentials(credentials);
folderAPI = createObject("java", "microsoft.exchange.webservices.data.Folder");
folderName = createObject("java", "microsoft.exchange.webservices.data.WellKnownFolderName");
result = folderAPI.bind(service, folderName.Inbox);
writeOutput(result.getDisplayName());
The corresponding java code is
ExchangeService service = new ExchangeService();
URI url = new URI( "http://10.192.37.30/ews/Exchange.asmx" );
service.setUrl( url );
service.setCredentials( new WebCredentials( "username", "password" ) );
System.out.println( "Created ExchangeService" );
Folder folder = Folder.bind( service, WellKnownFolderName.Inbox );
System.out.println( folder.getDisplayName() );
If this works, we can try more complex operations.
Please make sure you are using the correct ASMX URL, user name and password. Try accessing the URL in the browser. Provide the user name and password. If you are able to see the WSDL, then it is fine.
Also make sure that you are using Basic Authentication in Exchange Server.
Thanks,
Paul

fusebox5 noxml Parsed file 'app.deleterecord.cfm' changed or did not exist

I have a code below
<cffunction name="DeleteRecord">
<cfargument name="myFusebox" />
<cfargument name="event" />
<cfset event.xfa("ShowForm", "app.ShowForm") />
<cfset event.xfa("AddNew", "app.AddNew") />
<cfset event.xfa("EditRecord", "app.EditRecord") />
<cfset event.xfa("DeleteRecord", "app.DeleteRecord") />
<cfset event.xfa("UpdateRecord", "app.UpdateRecord") />
<cfset DeleteForecastRecord = application.report.ForecastRecordDelete(event.getValue("id"))/>
<cflocation url="#myFusebox.getMyself()##event.xfa('manageforecastreport')#" addtoken="false" />
</cffunction>
and in my cfc file below
<!--- ::::: Forecast Record Show ::::: --->
<cffunction name="ForecastRecordShow" returntype="query" access="public" output="true" hint="Add Forecast Record">
<cfargument name="ForecastID" type="any" default="">
<cfquery name="qryGetForcastRecord" datasource="#variables.dsn#">
SELECT * FROM tbl_forecast
WHERE ForecastID = <cfqueryparam cfsqltype="cf_sql_integer" value="#trim(arguments.ForecastID)#">
</cfquery>
<cfreturn qryGetForcastRecord>
</cffunction>
i have an error
Parsed file 'app.deleterecord.cfm' changed or did not exist
Request failed with exception 'Application' (The method ForecastRecordDelete was not found in component C:\Websites\LiquidMetalWheel.com\DiscountTire_dev\model\report.cfc.)
The method ForecastRecordDelete was not found in component C:\Websites\mysite.com\model\report.cfc.
Please help me about what can i do to solve this error
Make sure the "mode" is set to dev and not to prod (prod I think). When set to prod it will assume the file in the parsed directory is the correct one. When set to dev it "reparses" all your fuses with each request.
The "mode" setting is buried in your fusebox setttings - check the fbx_settings.cfm file. I'm doing this from memory so I might be wrong about the name of the setting (maybe appsettingStyle or something like that).

Upload google docs with coldfusion

I've built a forum-like app in ColdFusion and I want to add a feature with which the users can upload files to Google Docs using their Google accounts and then other users can edit those files.
I've been using this CFC: http://cfgoogle.riaforge.org/ to retrieve Google Docs, but the upload function is currently missing. I need the upload function for the first upload of the file and then for the second part of editing it. I hope that it makes sense.
That's what I'm asking help for. I'm not that experienced with cffunctions and I was wondering if someone could give me a hand with it.
This is what I have so far:
<cffunction name="upload" access="public" returnType="any" hint="I upload the document." output="false">
<cfargument name="myFile" type="string" required="true" hint="file to upload.">
<cfset var result = "">
<cfset var service = variables.docservice>
<cfset theUrl = "https://docs.google.com/feeds/documents/private/full HTTP/1.1">
<cfhttp url="#theURL#" method="post" result="result">
<cfhttpparam type="header" name="Authorization" value="GoogleLogin auth=#getAuth(service)#">
<cfhttpparam type="header" name="Content-Length" value="81047">
<cfhttpparam type="header" name="Content-Type" value="application/msword">
<cfhttpparam type="header" name="Slug" value="#myFile#">
</cfhttp>
<cfreturn result.filecontent>
</cffunction>
But I get the following error when I output the result:
'Invalid request URI'
If someone could help me out with this one (even just show me the way), it would be mostly appreciated.
I would try to expand cfgoogle CFC with upload method using Protocol Guide for uploading.

Unwanted Facebook button at first time use of my FB application in coldfusion

I am playing around with facebook application, making them in iframe using coldfusion.
Following is the url of my app http://apps.facebook.com/firstones/
Instead of going directly going to the permissions page, it goes to the page shown below in picture.
And after clicking on that big 'Facebook' button it goes to ask for applications permission. And once permissions are granted it takes to my website, where I have hosted the application, instead of opening it in Facebook only.
Following is the code of my canvas url [http://www.dkyadav.com/firstOnes/auth/]
index.cfm
<cfparam name="client_id" default="1234"> <!---same as app_id --->
<cfparam name="redirect_uri" default="http://www.dkyadav.com/firstOnes/auth/">
<cfparam name="redirect_uri_final" default="http://www.dkyadav.com/firstOnes/">
<cfparam name="scope" default="user_education_history,user_hometown,friends_education_history ">
<cfparam name="client_secret" default="56789"> <!---- App_secret key ---->
<cfif not isdefined('url.code')>
<Cflocation url="https://www.facebook.com/dialog/oauth?client_id=#client_id#&redirect_uri=#redirect_uri#&scope=#scope#" >
<Cfelse>
<Cfif isdefined('url.error')>
<Cfoutput>
#url.error#<br />
Access denied.
</Cfoutput>
<cfelse>
<cfoutput>#url.code#<br />
<cfhttp url="https://graph.facebook.com/oauth/access_token" result="token">
<cfhttpparam name="client_id" value="#client_id#" encoded="no" type="url">
<cfhttpparam name="redirect_uri" value="#redirect_uri#" encoded="no" type="url">
<cfhttpparam name="client_secret" value="#client_secret#" encoded="no" type="url">
<cfhttpparam name="code" value="#url.code#" encoded="no" type="url">
</cfhttp>
<cflocation url="#redirect_uri_final#?#token.filecontent#" addtoken="no">
</cfoutput>
</Cfif>
</cfif>
And in http://www.dkyadav.com/firstOnes/index.cfm I look for access_token and have rest of my application.
I does the above said things only for the first time it run. Once its permission get approved, it works normally as expected.
You can try out this app running yourself http://apps.facebook.com/firstones/
Please help and let me know what I am actually missing. Thanks!!
I think the problem you have is that your initial display page on Facebook is actually bursting out of the iframe.
You can see the Javascript doing that on http://www.dkyadav.com/firstOnes/index.cfm in the fbLogin() function:
top.location.href = "https://graph.facebook.com/oauth/authorize?...
top refers to the window at the top of your window hierarchy which in your case will mean the actual Facebook home page with the iframe in it.
Hope that helps!
I think I dont need access_token, I just need oauth_token that I get by Decoding the result I got from submitting my client_id to 'https://www.facebook.com/dialog/oauth....'
Below is the code that I am using:
<cfif isdefined('signed_request')>
<cfoutput>
<cfset b64 = signed_request>
<!--- Split the param by the . --->
<cfset raw_str = ListGetAt(b64, 2, ".")>
<cfset res = Len(raw_str) % 4>
<cfif res eq 2>
<cfset raw_str &= "==">
<cfelseif res eq 3>
<cfset raw_str &= "=">
</cfif>
<!--- Base 64 Decode --->
<cfset result = ToString(BinaryDecode(raw_str, "Base64"))>
<!--- String to JSON --->
<cfset json = DeserializeJSON(result)>
<cfif StructKeyExists(json,'oauth_token')>
<Cfset at = json.oauth_token>
<cfhttp url="https://graph.facebook.com/me/friends?access_token=#at#" result="newsFeed" />
<cfif IsJSON(newsFeed.filecontent)>
<cfset cfData=DeserializeJSON(newsFeed.filecontent)>
<cfdump var = #cfData#>
<cfelse>
filecontent not in json format
</cfif>
<cfelse>
<script>
top.location.href='https://www.facebook.com/dialog/oauth?client_id=12345XXX&redirect_uri=http://apps.facebook.com/test_app/&scope=read_stream,email'
</script>
</cfif>
</cfoutput>
</cfif>