Calling cfoutput within cfscript - coldfusion

I'm using a cftry catch to send an email to our alerts box when a widget on our site fails to load.
the cfcatch.message and cfcatch.detail don't provide enough detail on which page in particular is failing.
We have an attribute r_page which returns the page id when output.
However the email is generated using CFScript. How do i call <cfoutput>"#r_page#"</cfoutput> within my script to display in the email body?
<cfscript>
mailObj = new mail();
mailObj.setFrom(application.errorEmail);
mailObj.setTo(application.errorEmail);
mailObj.setSubject("THIS IS THE SUBJECT");
mailObj.setBody("A page is broken. Details: " & cfcatch.detail & " Message: "& cfcatch.message);
mailObj.send();
</cfscript>
Thanks

If you don't quote it, it will be evaluated automatically in the setBody() method, just like your current cfcatch members are being evaluated.
<cfscript>
mailObj = new mail();
mailObj.setFrom(application.errorEmail);
mailObj.setTo(application.errorEmail);
mailObj.setSubject("THIS IS THE SUBJECT");
mailObj.setBody("A page is broken. - " & r_page & " Details: " & cfcatch.detail & " Message: "& cfcatch.message);
mailObj.send();
</cfscript>
You can also evaluate it inline too using ##.
<cfscript>
mailObj = new mail();
mailObj.setFrom(application.errorEmail);
mailObj.setTo(application.errorEmail);
mailObj.setSubject("THIS IS THE SUBJECT");
mailObj.setBody("A page is broken. - #r_page# Details: " & cfcatch.detail & " Message: "& cfcatch.message);
mailObj.send();
</cfscript>

Related

Some Functions seems to be not exist when creating new bucket or checking if bucket exists using OpenBD

I am using OpenBD and trying to check whether bucket exists or not on my S3 server, if it is not exist then, to create new bucket. Here's my code:
index.cfm
<cfset request.awsaccess = "zzzzawsaccesszzzz">
<cfset request.awskey = "zzzzzzzzawskeyzzzzzzzz">
<cfset request.datasource="tcs">
<cfset request.region="us-west-2">
<cfscript>
AmazonRegisterdatasource(datasource=request.datasource,awsaccess=request.awsaccess,awskey=request.awskey,region=request.region );
result = AmazonS3listbuckets( datasource=request.datasource );
WriteDump(result);
WriteOutput(result.bucket[1]);
</cfscript>
For the above code I am getting this output:
Now I am adding one more function AmazonS3createbucket(),
<cfscript>
result = AmazonS3createbucket( datasource=request.datasource, bucket="anyBucket" );
</cfscript>
For the above script I am getting error: that No such function exists - amazons3createbucket.. Here's the screenshot:
I am referring the OpenBD Manual to filter these function.
Also faced the same problem while using this functions also:
<cfscript>
result = AmazonS3bucketexists( datasource=request.datasource, bucket="anyBucket" );
</cfscript>
Have you tried using an alternate syntax?
<cfscript>
result = AmazonS3bucketexists(ArgumentCollection = {
datasource : request.datasource,
bucket : "anyBucket"
});
</cfscript>

Passing cookies in Response.Redirect

I work with Classic ASP (vbscript), I add cookies to the Response like so:
Response.Cookies("mycookie") = "var_cookie"
Then I issue a redirect to "etape2.asp" file:
Response.Redirect("etape2.asp");
On the new page ("etape2.asp") that I am redirected to, I try to retrieve a cookie like so:
Request.Cookies("mycookie");
But the cookie is empty!!
Can anyone think of why the cookies are not being passed?
Might be worthwhile making sure you have set an expiry for the cookie far enough in advance, and set the path to which it applies:
So, in e.g. etape1.asp, do this...
var_cookie_mycookie = "this is the contents of mycookie"
response.cookies("mycookie").expires = now + 1
response.cookies("mycookie").path = "/"
response.cookies("mycookie") = trim(cstr("" & var_cookie_mycookie))
response.redirect "etape2.asp"
And in etape2.asp, do this...
var_cookie_mycookie = trim(cstr("" & request.cookies("mycookie")))
response.write "<p>Value of 'mycookie' cookie: " &_
server.htmlencode(var_cookie_mycookie) &_
"</p>"

Adding appointments to your calendar through email notifications

I need an example for adding events to my calendars through emails. For example when I send an email to my clients regarding their appointment, i want them to have an option in the email that will allow them to add the event on their calendar by just clicking on a button or something.
Is there anything out there that someone can direct me to it?
I need this mainly to use it with coldfusion 9.
Thanks!
I'd recommend the iCalUs UDF from http://www.cflib.org/udf/icalus
WebDH provides a great example here.
Here's an example using CF9 that I quickly put together but haven't tested yet.
<cfscript>
eventStr = {};
eventStr.organizerName = "John Doe"; //Organizer Name
eventStr.organizerEmail = "john.doe#email.com"; //Organizer Email
eventStr.startTime = ParseDateTime("12/30/2011 11:00"); //format: m/d/yyyy HH:mm OR h:mm TT -- this is Eastern time
eventStr.subject = "Demo Example";
eventStr.location = "StackOverflow.com";
eventStr.description = "Example iCalendar using CF9";
// Display in browser
//pc = getpagecontext().getresponse();
//pc.getresponse().setcontenttype('text/calendar');
//pc.setHeader("Content-Disposition","inline;filename=newAppointment.ics");
//writeOutput(iCalUS(eventStr));
//Email
m = new mail();
m.setSubject( "Event" );
m.setTo( "user#email.com" );
m.setFrom( "me#email.com" );
m.setServer( "localhost" );
//m.addParam( file="#ACCOUNT_TXT_FILE#" );
m.addPart( type="text", charset="utf-8", wraptext="72", body="Attached is a calendar event..." );
m.addPart( type="text/calendar" body="#iCalUS(eventStr)#");
m.send();
</cfscript>
Here's another example reference that shows how to email the calendar event.
Here is a very basic implementation of the ICS format. This is designed to be accessed through a browser, but it'd be fairly academic to change to create a text file with ICS extension and send it via e-mail.
<cfheader name="Content-Disposition" value="attachment; filename=event.ics" />
<cfcontent reset="true" type="text/calendar" />
<cfscript>
// handle all-day events
if (NOT isDate(starttime) OR NOT isDate(endtime)) {
dtstart=';VALUE=DATE:#dateFormat(eventdate,"yyyymmdd")#';
dtend=';VALUE=DATE:#dateFormat(dateAdd("d",1,eventdate),"yyyymmdd")#';
} else {
dtstart=';TZID="Eastern Standard Time":#dateFormat(eventdate,"yyyymmdd")#T#timeFormat(starttime,"HHmmss")#';
dtend=';TZID="Eastern Standard Time":#dateFormat(eventdate,"yyyymmdd")#T#timeFormat(endtime,"HHmmss")#';
}
</cfscript>
<cfoutput>
BEGIN:VCALENDAR
PRODID:-//Company//Source//EN
VERSION:2.0
METHOD:PUBLISH
BEGIN:VTIMEZONE
TZID:Eastern Standard Time
BEGIN:STANDARD
DTSTART:16011104T020000
RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=11
TZOFFSETFROM:-0400
TZOFFSETTO:-0500
END:STANDARD
BEGIN:DAYLIGHT
DTSTART:16010311T020000
RRULE:FREQ=YEARLY;BYDAY=2SU;BYMONTH=3
TZOFFSETFROM:-0500
TZOFFSETTO:-0400
END:DAYLIGHT
END:VTIMEZONE
BEGIN:VEVENT
CLASS:PUBLIC
CREATED:#dateFormat(dateAdded,"yyyymmdd")#T#timeFormat(dateAdded,"HHmmss")#Z
DESCRIPTION:#desc#
DTEND#dtend#
DTSTAMP:#dateFormat(dateAdded,"yyyymmdd")#T#timeFormat(dateAdded,"HHmmss")#Z
DTSTART#dtstart#
LAST-MODIFIED:#dateFormat(dateApproved,"yyyymmdd")#T#timeFormat(dateApproved,"HHmmss")#Z
LOCATION:#location#
PRIORITY:5
SEQUENCE:0
SUMMARY;LANGUAGE=en-us:#title#
TRANSP:OPAQUE
UID:#dateFormat(now(),"yyyymmdd")#T#timeFormat(now(),"HHmmss")#Z##uniqueID#
BEGIN:VALARM
TRIGGER:-PT15M
ACTION:DISPLAY
DESCRIPTION:Reminder
END:VALARM
END:VEVENT
END:VCALENDAR
</cfoutput>

Does Classic ASP have an object that I can use to browse and modify DOM elements on the server?

I am working in a classic asp application that requires functionality that will modify code that the user copy and pastes into a form. The user is considered a trusted user who is not familiar with html.
I am trying to make it so that if the user wants to change all width="" attributes in the supplied code then all he has to do is fill a textbox label Width with the correct value and press save/submit. Then the script will find all width attributes and update their values in the html snippet that was supplied.
I've been working on a regular expression to do this, but while researching I read that a lot of people do not recommend regexps for this type of thing and would rather use a html parser object of some sort.
Is there an html parser or DOM browser/editor available in classic asp or do I just need to continue my regexp development?
For the regexp, this is what I have so far... still need to modify it to perform replacements on all matches, not just the first one:
function replaceBetween(sSource, sStart, sStop, sValue)
thisNewValue = sStart & sValue & sStop
set re = new regexp
re.pattern = "(" & "" &sStart & ")(.*?)(" & sStop & ")"
re.IgnoreCase = true
response.write "Pattern: <b>" & re.pattern & "</b><br />" & vbnewline
response.write "thisNewValue: <b>" & thisNewValue & "</b><br />" & vbnewline
response.write "match: <b>" & re.test(sSource) & "</b><br />" & vbnewline
replaceBetween = re.replace(sSource, thisNewValue)
end function
sourceText = ("<div class='thisclass' id=""thisID""><a anotherthing="""" attribute=""one""><a attribute=""2""><a anotherattribute="" attribute=""three 3""></div>")
replacestart = "attribute="""
replacestop = """"
newvalue = "XXXX"
response.write "updated source: <b>" & server.HTMLEncode(replaceBetween(sourceText,replacestart,replacestop,newvalue)) & "</b><br />" & vbnewline
Is your HTML well formed? If so you could simply use an XML DomDocument. Use XPath to find the attributes you want to replace.
You can actually use JScript serverside as well in ASP, whicdh might give you access to HTMLDom libraries you could use.

How do I create Search Engine Safe URLs in Fusebox 5.1 noxml?

How do I create Search Engine Safe URLs in Fusebox 5.1 noxml?
For instance, I want this:
http://www.site.com/index.cfm/app.welcome/
Instead of this:
http://www.site.com/index.cfm?fuseaction=app.welcome
Fusebox 5.1 is suppose to be able to do this. I've read this article, but it only applies to the xml version. I know so little, I am not sure where to start. How do I do it with the noxml version of fusebox?
Update:
It looks like I need to add this to my Application.cfc file. Still not working though...
FUSEBOX_PARAMETERS.myself = "index.cfm/fuseaction/";
FUSEBOX_PARAMETERS.queryStringStart = "/";
FUSEBOX_PARAMETERS.queryStringSeparator = "/";
FUSEBOX_PARAMETERS.queryStringEqual = "/";
Fusebox 5.1 allows you to use SES URLs by allowing you to change ? & to /. You still need to provide your own rewriter. However, if you are able to upgrade to 5.5 it supposedly handles rewriting, too.
Example Rewriter
http://www.fusebox.org/forums/messageview.cfm?catid=31&threadid=6117&STARTPAGE=2
<cfscript>
// SES converter
qrystring = ArrayNew(1);
if ( Find("/",cgi.path_info) eq 1 and Find("/#self#",cgi.path_info) eq 0 ) {
qrystring = cgi.path_info;
} else if ( Len(Replace(cgi.path_info,"#self#/","")) gt 0 ) {
qrystring = ListRest(Replace(cgi.path_info,"#self#/","#self#|"),"|");
} else if ( FindNoCase("#self#/",cgi.script_name) gt 0 ) {
qrystring = ListRest(Replace(cgi.script_name,"#self#/","#self#|"),"|");
}
arQrystring = ListToArray(cgi.path_info,'/');
for ( q = 1 ; q lte ArrayLen(arQrystring) ; q = q + 2 ) {
if ( q lte ArrayLen(arQrystring) - 1 and not ( arQrystring[ Q ] is myFusebox.getApplication().fuseactionVariable and arQrystring[ q+1] is self ) ) {
attributes['#arQrystring[ Q ]#'] = arQrystring[ q+1];
}
}
</cfscript>
If you choose to use Coldcourse...
http://coldcourse.riaforge.com
Below will help you get started. You can ignore server-side rewriting (ISAPI for IIS) if you want /index.cfm/circuit/action/ formatted URLs. But if you want /circuit/action/ or /blah/ you'll need to make it server side.
application.cfc
Put on onApplicationStart (or onRequestStart for testing) to put in memory.
<cfset application.coldcourse = createObject("component","components.util.coldcourse").init("/config/coldcourse.config.cfm")>
index.cfm
Place this before the framework loads
<cfset application.coldcourse.dispatch(cgi.path_info, cgi.script_name) />
coldcourse.config.cfm (example config)
<cfset setEnabled(true)>
<cfset setFrameworkEvent("action")>
<cfset setFrameworkSeparator(".")>
<cfset setFrameworkActionDefault("")>
<cfset setUniqueURLs(true)>
<cfset setBaseURL("http://www.mysite.com/index.cfm")>
<!--- CUSTOM COURSES GO HERE (they will be checked in order) --->
<!--- for http://www.mysite.com/about/ pages --->
<cfset addCourse("components")>
<cfset addCourse(pattern="about",controller="main",action="about")>
<cfset addCourse(pattern="contact",controller="main",action="contact")>
<cfset addCourse(pattern="help",controller="main",action="help")>
<!--- If nothing else matches, fall back to the standard courses (you probably shouldn't edit these) --->
<cfset addCourse(":controller/:action/:id")>
<cfset addCourse(":controller/:action")>
<cfset addCourse(":controller")>
Install ISAPI Rewrite
Make sure you are using the correct rewrite regex because version 2.0 is different from 3.0.
Example for 2.0 script:
# Coldcourse URL Rewrite for CF
IterationLimit 0
RewriteRule ^(/.+/.+/.*\?.+\..*)$ /index.cfm/$1
RewriteRule ^(/[^.]*)$ /index.cfm/$1
Disable Check if File Exists on web server
Do this for IIS if you're getting a 404 error in your web logs.
Open the IIS manager
Right click on a site and choose Properties
Click the Home Directory tab
Click the Configuration button
(lower right of dialog)
Click the .cfm extension and choose
'Edit'
The lower left checkbox: "Check that
File Exists"
riaforge is your friend:
http://coldcourse.riaforge.org/