/* : Define www.rexxtags.org pages */ /* */ /* Parameters: */ /* title="page title" Mandatory (not checked) */ /* type="page type" Optional; default: "" (ommited): standard page */ /* Other values: "Tutorial" : tutorial page */ /* request="apache request" Automatic */ /* */ /* Version: 1.0 */ /* */ /* Author: (c) Jose Maria Blasco */ /* */ /* This software is subject to the terms of the Common Public License. You */ /* must accept the terms of this license to use this software. Refer to */ /* the license at the following URL for more information: */ /* http://oss.software.ibm.com/developerworks/opensource/CPLv1.0.htm */ /* */ /* This is the tag used in http://www.rexxtags.org to describe pages. It is */ /* provided AS A SAMPLE so that others can start writing page tags. */ /* */ /* Modifications: */ /* */ /* Date Author Description */ /* ---------- ----------- --------------------------------------------------- */ /* 2002/12/13 J.M.Blasco v1.0 Initial release */ Parse arg verb, parms Parse version objrexx . objrexx = (objrexx = "OBJREXX") If verb == 'START' Then Signal StartTag /* Handle start tag */ If verb == 'END' Then Signal EndTag /* Handle end tag */ If verb == 'QUERY APACHE REQUEST' Then /* Get the apache request as.. */ Return 1 /* ..a parameter */ Return 0 /* Standard rexx tag exit */ /*----------------------------------------------------------------------------*/ /* Common 'get parameters' routine. Used by both 'StartTag' and 'EndTag' */ /*----------------------------------------------------------------------------*/ GetParms: Parse value ' 'parms with ' title="'title'"' Parse value ' 'parms with ' type="'type'"' Parse value ' 'parms with ' request="'request'"' /* Store a boolean indicating whether this is a tutorial page */ tutorial = Translate(type) = 'TUTORIAL' /* If this is a tutorial page, store the page number and alter the title. */ If tutorial Then Do Parse var wwwfilename 'tutorial/page'page'.html' page = page + 0 title = 'Tutorial -' page':' title End /* This will allow for future support of different header and title */ header = title title = 'REXXTAGS - 'title Return /*----------------------------------------------------------------------------*/ /* Start tag handling */ /*----------------------------------------------------------------------------*/ StartTag: /* 1: Get the parameters */ Call GetParms /* 2: Connect to a back-end database. In the rexxtags site we use DB2. */ /* We are connecting to the database at the start tag, and resetting.. */ /* ..the connection at the end tag. This way, all intermediate tags.. */ /* ..can benefit from the same connection (and don't have to establish.. */ /* ..their own connection. */ If \ObjRexx Then Call SqlExec "Connect to G0BCN" /* 3: Special handling of tutorial pages. */ /* If this is a tutorial page, we build a small navigation bar with.. */ /* ..'home', 'prev' and 'next' links. The later are only displayed.. */ /* ..when needed (i.e., no 'next' link for the last page, etc) */ nl = '00'x /* new line indicator */ extra = '' /* This will get the extra 'tutorial page' html code */ If tutorial Then Do prevnext = ' ' p = LastPos('/',wwwFileName) nextfile = Left(wwwFileName,p)'page'Right(page+1,2,0)'.html' nextfile = Stream(nextFile,'C','QUERY EXISTS') anext = 'Next >>' aprev = '<< Prev' If page = 1 Then prevnext = anext Else If nextfile = '' Then prevnext = aprev Else prevnext = aprev '|' anext extra = nl'
' , nl'Home Tutorial' , nl'' , nl prevnext , nl '
' End /* 4: Return html for the startting part of the page */ Return '', nl'', nl'' , nl'' , nl''title'' , nl'', nl'' , nl'' , nl'' , nl' ', nl' ', nl' ' , nl'
REXXTAGS.org :: 'header'
' , extra /*----------------------------------------------------------------------------*/ /* End tag handling */ /*----------------------------------------------------------------------------*/ EndTag: /* 1: Get the parameters */ Call GetParms /* 2: Evaluate the URI for stats collection */ /* We discard the path info part, if any, and normalize indexes */ uri = wwwuri uri = left(uri,length(uri)-length(wwwpath_info)) if right(uri,11) = '/index.html' then uri = left(uri,length(uri)-11) If ObjRexx Then Do Call GetSem Call Connect End /* 3: Collect statistics */ /* EZSelect interacts with DB2 and returns a rexx stem for every column */ Call EZselect "Select N, date From Web.Counters Where URI='"uri"' and SERVER='"wwwServer_Name"'" If n.0 = 0 Then n = 0 Else n = n.1 If n.0 = 0 Then date.1 = date('e') /* First visit to a page */ If Left(wwwremote_addr,12) <> '192.168.2.11' Then Do /* Developer's IP */ n = n + 1 /* We keep a separate fast table of counters */ if n.0 = 0 then stmt = "Insert into web.counters(uri,n,date,Server) values('"uri"',"n",current date,'"wwwServer_name"')" else stmt = "Update web.counters set n = n + 1 where uri='"uri"' and server='"wwwServer_Name"'" Call SqlExec "Execute immediate :stmt" Call SqlExec "Commit" /* Because of these two calls, we needed the apache request parameter */ referer = WWWReqRecHeader_in(request, "Referer") Call WWWGetCookies request /* Log everything */ stmt = "Insert into web.log (Server, uri, date, time, user_agent, user, referer, visitor, ip)", "Values('"wwwServer_Name"','"uri"',current date, current time,'"add_quotes("'",WWWHTTP_USER_AGENT)"','"add_quotes("'",WWWRemote_USER)"','"add_quotes("'",referer)"','"wwwcookies.visitor"','"wwwRemote_addr"')" Call SqlExec "Execute immediate :stmt" End Call SqlExec "Commit" /* 4: Reset the SQL connection */ If ObjRexx Then Call RelSem Else Call SqlExec "Connect reset" /* 5: Build the page footer */ Parse value stream(wwwfilename,'C','QUERY DATETIME') with mm'-'dd'-'aa' 'h':'m':'s If n = 1 Then visitas = "1 visit" Else visitas = n "visits" /* 6: Special handling of tutorial pages */ /* We parse the next page, look for its title, and display it in the..*/ /* ..current page as a link after 'Next section:' */ nl = '00'x extra = '' If tutorial Then Do p = LastPos('/',wwwFileName) nextfile = Left(wwwFileName,p)'page'Right(page+1,2,0)'.html' nextfile = Stream(nextFile,'C','QUERY EXISTS') If nextFile <> '' Then Do Do While lines(nextFile) > 0 l = LineIn(nextFile) Parse var l ' '' Then Leave End Call Stream nextFile,'C','CLOSE' If nextChapter <> '' Then nextSection = 'Next section: 'nextChapter'' Else nextSection = 'Next section' End Else nextSection = ' ' extra = '' nl, '
'nextsection'View the XML code for this page
' End /* 7: Return the footer */ Return extra '
' , ||'00'x||'' , ||'00'x||' ' , ||'00'x||' ' , ||'00'x||' ' , ||'00'x||' ' , ||'00'x||' ' , ||'00'x||'
'uri' ['visitas 'since' date.1']
' , ||'00'x||' Last update: 'dd'/'mm'/'aa' at 'h':'m , ||'00'x||'
' , ||'00'x||' ' , ||'00'x||' ' , ||'00'x||'
Valid XHTML 1.0! ' , ||'00'x||' Valid CSS!
' , ||'00'x||'
' , ||'00'x||'' , ||'00'x||'' MonthName: Select When arg(1) = 1 Then Return "jan" When arg(1) = 2 Then Return "feb" When arg(1) = 3 Then Return "mar" When arg(1) = 4 Then Return "apr" When arg(1) = 5 Then Return "may" When arg(1) = 6 Then Return "jun" When arg(1) = 7 Then Return "jul" When arg(1) = 8 Then Return "aug" When arg(1) = 9 Then Return "sep" When arg(1) = 10 Then Return "oct" When arg(1) = 11 Then Return "nov" When arg(1) = 12 Then Return "dec" Otherwise Return "" End Syntax: Return "Syntax error at line" sigl /* From rspcomp.rex */ add_quotes: procedure quote = arg(1) line = arg(2) x = pos(quote, line) do while x > 0 line = substr(line, 1, x) || quote || substr(line, x + 1) x = pos(quote, line, x + 2) end return line Connect: Call EZSelect "Values (Current Date)" If EZMsg = "EZMSG" Then Do Call SqlExec "Commit" Return 1 End Call SQLEXEC "CONNECT TO G0BCN" If SQLCA.SQLCode <> 0 Then Do Return 0 End Return 1 GetSem: SemName = SysCreateMutexSem("/SEM32/DB2SEM") res = SysRequestMutexSem(SemName) Return RelSem: res = SysReleaseMutexSem(SemName) res = SysCloseMutexSem(SemName) Return