PRELOAD
NAME
preload - Function executed before handling the request.
SYNOPSIS
preload()
DESCRIPTION
preload is defined in the config file.:
#
# Preload these functions
#
Preload : "/usr/local/website/v5/preload.snc"
This function can be used to abort a request before doing it. The function can modify the returned status. Returned statuses are defined in file extenso.sn:
Note: In the followings examples, the _ between the { should be removed to make it work.
Preload : "/usr/local/website/v5/preload.snc"
This function can be use to abort a request before doing it. The function can modify the return status. Return status are defined in file extenso.sn:
{_{
// Definitions for files functions
%define FILE_SOURCE_PERMS 0x1000; // Copy source file's permissions
// Definitions for set file permissions
%define USETID 0x8000; /* Set user id */
%define UREAD 0x0400; /* Read by user */
%define UWRITE 0x0200; /* Write by user */
%define UEXECUTE 0x0100; /* Execute by user */
%define GSETID 0x4000; /* Set group id */
%define GREAD 0x0040; /* Read by group */
%define GWRITE 0x0020; /* Write by group */
%define GEXECUTE 0x0010; /* Execute by group */
%define WSTICKY 0x2000; /* Sticky bit */
%define WREAD 0x0004; /* Read by others */
%define WWRITE 0x0002; /* Write by others */
%define WEXECUTE 0x0001; /* Execute by others */
%define OS_DEFAULT 0x0FFF; /* use OS's default permissions */
// Definitions for APACHE
%define HTTP_DECLINED -1;
%define HTTP_OK 0;
%define HTTP_CONTINUE 100;
%define HTTP_SWITCHING_PROTOCOLS 101;
%define HTTP_PROCESSING 102;
%define HTTP_OK 200;
%define HTTP_CREATED 201;
%define HTTP_ACCEPTED 202;
%define HTTP_NON_AUTHORITATIVE 203;
%define HTTP_NO_CONTENT 204;
%define HTTP_RESET_CONTENT 205;
%define HTTP_PARTIAL_CONTENT 206;
%define HTTP_MULTI_STATUS 207;
%define HTTP_MULTIPLE_CHOICES 300;
%define HTTP_MOVED_PERMANENTLY 301;
%define HTTP_MOVED_TEMPORARILY 302;
%define HTTP_SEE_OTHER 303;
%define HTTP_NOT_MODIFIED 304;
%define HTTP_USE_PROXY 305;
%define HTTP_TEMPORARY_REDIRECT 307;
%define HTTP_BAD_REQUEST 400;
%define HTTP_UNAUTHORIZED 401;
%define HTTP_PAYMENT_REQUIRED 402;
%define HTTP_FORBIDDEN 403;
%define HTTP_NOT_FOUND 404;
%define HTTP_METHOD_NOT_ALLOWED 405;
%define HTTP_NOT_ACCEPTABLE 406;
%define HTTP_PROXY_AUTHENTICATION_REQUIRED 407;
%define HTTP_REQUEST_TIME_OUT 408;
%define HTTP_CONFLICT 409;
%define HTTP_GONE 410;
%define HTTP_LENGTH_REQUIRED 411;
%define HTTP_PRECONDITION_FAILED 412;
%define HTTP_REQUEST_ENTITY_TOO_LARGE 413;
%define HTTP_REQUEST_URI_TOO_LARGE 414;
%define HTTP_UNSUPPORTED_MEDIA_TYPE 415;
%define HTTP_RANGE_NOT_SATISFIABLE 416;
%define HTTP_EXPECTATION_FAILED 417;
%define HTTP_UNPROCESSABLE_ENTITY 422;
%define HTTP_LOCKED 423;
%define HTTP_FAILED_DEPENDENCY 424;
%define HTTP_UPGRADE_REQUIRED 426;
%define HTTP_INTERNAL_SERVER_ERROR 500;
%define HTTP_NOT_IMPLEMENTED 501;
%define HTTP_BAD_GATEWAY 502;
%define HTTP_SERVICE_UNAVAILABLE 503;
%define HTTP_GATEWAY_TIME_OUT 504;
%define HTTP_VERSION_NOT_SUPPORTED 505;
%define HTTP_VARIANT_ALSO_VARIES 506;
%define HTTP_INSUFFICIENT_STORAGE 507;
%define HTTP_NOT_EXTENDED 510;
// Alignament options for a cell to be used with xls functions
%define ALIGN_GENERAL 0;
%define ALIGN_LEFT 1;
%define ALIGN_CENTER 2;
%define ALIGN_RIGHT 3;
%define ALIGN_FILL 4;
%define ALIGN_MULTIPLAN_DEFAULT 7;
// the border values for a cell to be used with xls functions
%define BORDER_LEFT 0x08;
%define BORDER_RIGHT 0x10;
%define BORDER_TOP 0x20;
%define BORDER_BOTTOM 0x40;
}}
If the returned status is zero, Sncode will execute the file. If the status is -1, Sncode will decline the will and the file will be processed as usual by Apache.
Apache must be restarted after this file is installed. The file must be compiled with:
preload.snc: preload.sn
sncode -o preload.snc -f preload.sn
install preload.snc /usr/local/website/v5
Variables defines in preload stays during the execution of the file.
EXAMPLES
Note: In the followings examples, the _ between the { should be removed to make it work.
{_{
%include "/usr/local/website/v5/includes/extenso.sn";
cfg = config();
a = request();
ext = extention(a.filename);
if cfg.site eq "html" && ext eq "jpg" then
status(HTTP_FORBIDDEN);
elseif ext ne "sn" && ext ne "snc" then
status(-1);
else
status(0);
endif
}}
SEE ALSO
AUTHOR
Written by Pierre Laplante and Caroline Laplante, <laplante@sednove.com>
MODIFICATIONS
1.0 2014-09-09 21:24:14 laplante@sednove.com
Edit