I'm experiencing difficulties with a jwt token, turns out it's because coldfusion is converting an int to a float. I'm not sure where the problem is or how to fix it.
Token timestamp and expiration:
<cfset TimeStamp = '#VAL( int( getTickCount() / 1000 ) )#' >
<cfset Exp = '#VAL( int( (getTickCount() / 1000)+43200 ) )#' >
<cfscript>
Variables.payload = StructNew();
Variables.payload[ "nbf" ] = "#TimeStamp#";
Variables.payload[ "exp" ] = "#Exp#";
Variables.result = JWT.encode( payload, Variables.secretKey);
</cfscript>
The JWT.Encode call looks like this:
<cffunction name="encode" access="public" returntype="String">
<!--- ****************** Arguments ************************ --->
<cfargument name="payload" type="any" required="true">
<cfargument name="key" type="string" required="true">
<cfargument name="algo" type="string" required="false" default="HS256">
<!--- ****************** /Arguments *********************** --->
<!--- define our variables here --->
<cfset var currentTime = getCurrentUtcTime()>
<cfset var header = createObject("java", "java.util.LinkedHashMap").init() /> <!--- StructNew doesnt work because coldfusion 8 orders the keys --->
<cfset var claims = createObject("java", "java.util.LinkedHashMap").init() /> <!--- StructNew doesnt work because coldfusion 8 orders the keys --->
<cfset var segments = ArrayNew(1)>
<!---
creation of first segment of our JWT: the header
--->
<cfset header[ "typ" ] = "JWT">
<cfset header[ "alg" ] = "HS256">
<!--- add header an json with base64 encoding to segment array --->
<cfset arrayAppend( segments, replace( toBase64( serializeJSON( header ) ), "=", "", "all" ) )>
<!---
creation of the middle segment: the claims set
--->
<cfset claims = Arguments.payload>
<!---
escape forward slashes in generated JSON
--->
<cfset claimsJson = replace( serializeJSON( claims ), "/", "\/", "all" )>
<!--- add header and json with base64 encoding (with padding REMOVED!) to segment array --->
<cfset arrayAppend( segments, replace( toBase64( claimsJson ), "=", "", "all" ) )>
<!---
create the last segment: the signature
--->
<cfset signingInput = ArrayToList( segments, "." )>
<cfset signature = sign( signingInput, Arguments.key, Arguments.algo )>
<!---
add signature as last the element to our string
--->
<cfreturn ListAppend( signingInput, signature, ".")>
</cffunction>
Run through a base64 decoder, I get something like exp":1.498696809E9,"nbf":1.498653609E9
Get Nathan Mische's JSONUtil.cfc. Then replace the line
<cfset claimsJson = replace( serializeJSON( claims ), "/", "\/", "all" )>
with
<cfset jsonTool = createobject("component","jsonutil")>
<cfset claimsJson = replace(jsonTool.serializeJSON(claims,false,true), "/", "\/", "all" )>
I have the following working Calendar page (lqCalendar.cfm) that places events from MySQL to the calendar.
<html>
<head>
<link rel="stylesheet" href="../fullcalendar-3.1.0/fullcalendar.min.css" />
<script src="../fullcalendar-3.1.0/lib/jquery.min.js"></script>
<script src="../fullcalendar-3.1.0/lib/moment.min.js"></script>
<script src="../fullcalendar-3.1.0/fullcalendar.min.js"></script>
<script>
$(document).ready(function() {
var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();
var calendar = $('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
selectable: true,
selectHelper: true,
select: function(start, end, allDay) {
var title = prompt('Event Title:');
if (title) {
calendar.fullCalendar('renderEvent',
{
title: title,
start: start,
end: end,
allDay: allDay
},
true // make the event "stick"
);
}
calendar.fullCalendar('unselect');
},
editable: true,
events: "getLeaveRequests.cfc?method=getMyData",
eventDrop: function(event, delta) {
alert(event.title + ' was moved ' + delta + ' days\n' +
'(should probably update your database)');
}
});
});
</script>
</head>
<body>
<div id='calendar'>
</div>
</body>
</html>
Here is my working CFC (getLeaveRequests.cfc) which queries the data:
<!--- Don't forget to VAR scope all local variables. --->
<cfset var getEvents = "">
<cfset var row = "">
<cfset var result = "">
<cfquery name="getEvents" datasource="care">
SELECT lqID AS id,
lqStartDate AS myStart,
lqEndDate AS myEnd,
CONCAT(lqUser, " (",lqTotalHours,") ", (COALESCE(lqDescription,'')),"") AS title
FROM tblleaverequest
</cfquery>
<cfset result = []>
<cfloop query="getEvents">
<!--- start new structure. must use array notation to preserve case of structure keys--->
<cfset row = {}>
<cfset eventurl ="leave_request_a01z.cfm?id=" & "id">
<cfset row["id"] = id>
<cfset row["title"] = title>
<cfset row["start"] = myStart>
<cfset row["end"] = myEnd>
<!--- append to results --->
<cfset arrayAppend(result, row)>
</cfloop>
<!--- convert to json --->
<cfreturn serializeJSON(result)>
<!---
<cfreturn getEvents>
--->
</cffunction>
</cfcomponent>
What is the best way to "color" the calendar items based on the value of "lqUser"?
- The colors can be dynamically assigned, or if needed, I can add a color field to the User table for each user, but how do I assign it to the FullCalendar?
Here is my updated CFC trying to get colors to work: (using code from "dwayne anderson" post on Raymond Camden site)
- I added a field to my User table called "category_id", then assigned values 1 thru 9 for colors.
The page gives me no errors, just a blank calendar?
<!--- Component to get all of the Leave Request Dates and place on FullCalendar page--->
<cfcomponent>
<cfsetting showDebugOutput='No'>
<cffunction name="getMyData" output="false" access="remote" returntype="any" returnformat="JSON">
<cfargument name="filter" type="string" required="no" default="">
<cfquery name="getallevents" datasource="care">
SELECT lqID AS id,
lqStartDate AS event_start_datetime,
lqEndDate AS event_end_datetime,
IF(category_id IS NULL, '1', category_id) AS color_id,
CONCAT(lqUser, " (",lqTotalHours,") ", (COALESCE(lqDescription,'')),"") AS title
FROM tblusers RIGHT OUTER JOIN tblleaverequest ON tblusers.username = tblleaverequest.lqUser
</cfquery>
<cfquery name="getallcolors" dbtype="query">
Select distinct color_id
from getallevents
</cfquery>
<cfset colorlist="red,green,blue,yellow,black,brown,aqua,orange,darkred">
<cfset colorpos=1>
<cfset colors = []>
<cfloop query = "getallcolors">
<cfset thecolor='#listgetat(colorlist,colorpos)#'>
<cfif colorpos eq listlen(colorlist)>
<cfset colorpos=0>
</cfif>
<cfset colorpos=colorpos+1>
<cfset colors[#color_id#] = thecolor>
</cfloop>
<cfset url.returnformat="json">
<cfset results = []>
<cfloop query = "getallevents">
<cfset eventurl ="eventdetails.cfm?id=" & "id">
<cfset eventcolor ="#colors[color_id]#">
<cfset s = structnew()>
<cfset s["id"] = id>
<cfset s["title"] = title>
<cfset s["start"] = getEpochTime(event_start_datetime)>
<cfset s["end"] = getEpochTime(event_end_datetime)>
<cfset s["url"] = eventurl>
<cfset s["color"] = eventcolor>
<cfset s["allDay"] = false>
<cfset arrayappend(results, s)>
</cfloop>
<cfreturn results>
</cffunction>
<cffunction access="private" name="getEpochTime" returntype="date">
<cfargument name="thedatetime" type="date"/>
<cfif (ArrayLen(Arguments) is 0)>
<cfset thedatetime = Now() />
<cfelseif IsDate(Arguments[1])>
<cfset thedatetime=Arguments[1] />
<cfelse>
return NULL;
</cfif>
<cfreturn DateDiff("s", DateConvert("utc2Local", "January 1 1970 00:00"), thedatetime) />
</cffunction>
</cfcomponent>
What is the best way to "color" the calendar items based on the value of "lqUser"?
You have two options if I am understanding this correctly.
You could set the color for the user in the query itself so its easier to manage at query level via case statments or any other logic
You could do div with classes for specific user or type of user.
HTH.
Got it working! Here is the final & working CFC that includes coloring the calendar events. Thanks for the help.
<!--- Component to get all of the Leave Request Dates and place on FullCalendar page--->
<cfcomponent>
<cfsetting showDebugOutput='No'>
<cffunction name="getMyData" output="false" access="remote" returntype="any" returnformat="JSON">
<cfargument name="filter" type="string" required="no" default="">
<!--- Don't forget to VAR scope all local variables. --->
<cfset var getEvents = "">
<cfset var row = "">
<cfset var result = "">
<cfset var getallcolors = "">
<!--- Query the Leave Requests table and get data for all employees --->
<cfquery name="getEvents" datasource="care">
SELECT lqID AS id,
lqStartDate AS myStart,
lqEndDate AS myEnd,
IF(category_id IS NULL, "", category_id) AS color_id,
CONCAT(lqUser, " (",lqTotalHours,") ", (COALESCE(lqDescription,'')),"") AS title
FROM tblusers RIGHT OUTER JOIN tblleaverequest ON tblusers.username = tblleaverequest.lqUser
</cfquery>
<!--- Do a Query of Queries to get all of the users color values --->
<cfquery name="getallcolors" dbtype="query">
Select distinct color_id
FROM getEvents
</cfquery>
<cfset result = []>
<!--- Assign colors to be used by the FullCalendar variable --->
<cfset colorlist="red,green,blue,black,gray,brown,orange,darkred,darkgreen,darkblue,darkgrey,purple,darkorange,">
<cfset colorpos=1>
<cfset colors = []>
<cfloop query = "getallcolors">
<cfset thecolor='#listgetat(colorlist,colorpos)#'>
<cfif colorpos eq listlen(colorlist)>
<cfset colorpos=0>
</cfif>
<cfset colorpos=colorpos+1>
<cfset colors[#color_id#] = thecolor>
</cfloop>
<cfloop query="getEvents">
<!--- start new structure. must use array notation to preserve case of structure keys--->
<cfset row = {}>
<cfset eventcolor ="#colors[color_id]#">
<cfset eventurl ="leave_request_a01z.cfm?id=" & "id">
<cfset row["id"] = id>
<cfset row["title"] = title>
<cfset row["start"] = myStart>
<cfset row["end"] = myEnd>
<cfset row["color"] = eventcolor>
<!--- append to results --->
<cfset arrayAppend(result, row)>
</cfloop>
<!--- convert to json --->
<cfreturn serializeJSON(result)>
<!---
<cfreturn getEvents>
--->
</cffunction>
</cfcomponent>
I have a few session variables I need setup for permissions and only the userID, userName and sessionAdmin variables are making it through. I do a cfdump and see all of the variables set to 0, which is the cfparam default. I also can not get the page to redirect to my sample address.
login.cfm
<cfif isDefined("FORM.login")>
<cfset Encryptpwd = Encrypt(FORM.password, application.PsswrdKy)>
<cfset loginInfo = CFCmain.getLogin(FORM.username,Encryptpwd)>
<cflock timeout=20 scope="session" type="exclusive">
<cfset session.UserName = loginInfo.username>
<cfset session.userid = loginInfo.id>
<cfset session.Access_admin = loginInfo.superadmin>
<cfset session.Access_var1 = loginInfo.var1>
<cfset session.Access_var2 = loginInfo.var2>
<cfset session.Access_var3 = loginInfo.var3>
<cfset session.Access_var4= loginInfo.var4>
<cfset session.Access_agency = loginInfo.agency>
</cflock>
<cflocation url="http://www.google.com">
</cfif>
and main.cfc where my variables are pulled from the db
<cffunction name= "getLogin" access="remote" returntype="any" >
<cfargument name="uname" type="string">
<cfargument name="pwd" type="string">
<cfquery name="getdata" datasource="#application.db#">
select * from users2 where username = '#arguments.uname#' and password = '#arguments.pwd#'
</cfquery>
<cfreturn getdata>
</cffunction>
For me it looks like the variable FORM.login is not defined!?
try:
<cfif isDefined("FORM.login")>
<cfdump var="hello">
<cfabort>
....
if you don't see the "hello", FORM.login is not defined...
try also:
<cfdump var="#form#" abort>
to see what is defined in the form scope.
And how others said, use cfqueryparam!! (security)
<cfquery name="getdata" datasource="#application.db#">
select *
from users2
where username = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.uname#">
and password = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.pwd#">
</cfquery>
I have implemented ColdFusion XMPP Event Gateway in coldfusion server 10 and it is working fine with google talk. The same thing i want to implement in Railo server but no luck to find something.
Please suggest something to "Railo to talk to XMPP/Jabber/Google Talk from within Railo"
Used cfc file in coldfusion XMPP event gateway
<cfcomponent displayname="EventGateway" hint="Process events from the test gateway and return echo">
<cffunction name="onIncomingMessage" output="no">
<cfargument name="CFEvent" type="struct" required="yes">
<cflog file="#CFEvent.GatewayID#Status" text=" onIncomingMessage; SENDER: #CFEvent.Data.SENDER# MESSAGE:
#CFEvent.Data.MESSAGE# TIMESTAMP: #CFEvent.Data.TIMESTAMP# ">
<!--- Get the message --->
<cfset data=cfevent.DATA>
<cfset message="#data.message#">
<!--- where did it come from? --->
<cfset orig="#CFEvent.originatorID#">
<cfset retValue = structNew()>
<cfif listcontains("XMPP ", arguments.CFEVENT.GatewayType) gt 0>
<cfset retValue.BuddyID = orig>
<cfset retValue.MESSAGE = "echo: " & message>
<cfelseif arguments.CFEVENT.GatewayType is "Socket">
<cfset retValue.originatorID = orig>
<cfset retValue.message = "echo: " & message>
<cfelseif arguments.cfevent.gatewaytype is "SMS">
<cfset retValue.command = "submit">
<cfset retValue.sourceAddress = arguments.CFEVENT.GatewayID>
<cfset retValue.destAddress = orig>
<cfset retValue.shortMessage = "echo: " & message>
</cfif>
<!--- we can write our script to process like database Query here --->
<!--- send the return message back --->
<cfreturn retValue>
</cffunction>
<cffunction name="onAddBuddyRequest">
<cfargument name="CFEvent" type="struct" required="YES">
<cflock scope="APPLICATION" timeout="10" type="EXCLUSIVE">
<cfscript>
// If the name is in the DB once, accept; if it is missing, decline.
// If it is in the DB multiple times, take no action.
action="accept";
reason="Valid ID";
//Add the buddy to the buddy status structure only if accepted.
if (NOT StructKeyExists(Application,"buddyStatus")) {
Application.buddyStatus=StructNew();
}
if (NOT StructKeyExists(Application.buddyStatus,CFEvent.Data.SENDER)) {
Application.buddyStatus[#CFEvent.Data.SENDER#]=StructNew();
}
Application.buddyStatus[#CFEvent.Data.SENDER#].status="Accepted Buddy Request";
Application.buddyStatus[#CFEvent.Data.SENDER#].timeStamp=
CFEvent.Data.TIMESTAMP;
Application.buddyStatus[#CFEvent.Data.SENDER#].message=CFEvent.Data.MESSAGE;
</cfscript>
</cflock>
<!--- Log the request and decision information. --->
<cflog file="#CFEvent.GatewayID#Status" text="onAddBuddyRequest; SENDER: #CFEvent.Data.SENDER# MESSAGE:
#CFEvent.Data.MESSAGE# TIMESTAMP: #CFEvent.Data.TIMESTAMP# ACTION: #action#">
<!--- Return the action decision. --->
<cfset retValue = structNew()>
<cfset retValue.command = action>
<cfset retValue.BuddyID = CFEvent.DATA.SENDER>
<cfset retValue.Reason = reason>
<cfreturn retValue>
</cffunction>
<cffunction name="onAddBuddyResponse">
</cffunction>
<cffunction name="onBuddyStatus">
</cffunction>
<cffunction name="onIMServerMessage">
</cffunction>
</cfcomponent>
Thanks,
Arun
Can anyone help me by suggesting a function to extract a .7z file in ColdFusion? I use ColdFusion 10 and cfscript based code. Indeed we have the cfzip tag, but it only extracts .zip and .jar files.
You can use cfexecute, which unfortunately is not availble in cfscript, to execute the 7z extractor on your server and pass through the various commands to extract the file to a place of your choosing.
Luckily for you, it seems Raymond Camden has gone into it in some detail:
http://www.raymondcamden.com/index.cfm/2011/2/21/Working-with-RARs-in-ColdFusion
Function to unrar .rar file in given destination.. use cfexecute tag to run rar exe in command line
<cffunction name="Unrar" access="public" returnType="boolean" output="false">
<cfargument name="archivefile" type="string" required="true">
<cfargument name="destination" type="string" required="true">
<cfset var exeName = "">
<cfset var result = "">
<cfset var errorresult = "">
<cfif not fileExists(arguments.archivefile)>
<cfthrow message="Unable to work with #arguments.arvhiefile#, it does not exist.">
</cfif>
<cfif findnocase(".rar",arguments.archivefile)>
<cfset var exeName = expandpath("WinRAR\rar.exe")>
<cfset var args = []>
<cfif directoryExists(#arguments.destination#)>
<cfset args[1] = "x +o">
<cfelse>
<cfset directoryCreate(#arguments.destination#)>
<cfset args[1] = "x">
</cfif>
<cfset args[2] = arguments.archivefile>
<cfset args[3] = "#arguments.destination#">
</cfif>
<cfexecute name="#exeName#" arguments="#args#" variable="result" errorvariable="errorresult" timeout="99" />
<cfif findNoCase("OK All OK", result)>
<cfreturn true>
<cfelse>
<cfreturn false>
</cfif>
</cffunction>