program demo; uses pwinit, pwmain; begin out('hello'); end.
In version 1.6.0.2 a basic web program is as follows:
program demo; uses pwumain; begin webwrite('hello'); end.
Most of the Powtils units are prefixed with 'pw' so that they do not conflict with other projects. Some general units or older may not be prefixed with 'pw'
The program can run on linux/bsd/windows servers. The machine you compile it on is the one it runs on - but we have tools such as FPW/FPWSERV and compile-studio so that you can remotely control your server and create programs right on it.
Out, OutLn, or WebWrite, TemplateOut, and similar output calls are all easy to use without you having to worry about the low level details of HTTP/CGI. You can however take full control and override Powtils to be however powerful you want.. with such functions as SetHeader, and plugin units such as pwinit, pwsdssess, etc.
A simple demo using the DLL in freepascal is as follows:
program demo; uses dynpwu; // pwu-1.6.0.0 DLL must be uploaded begin webwrite('demo test'); end;
program tpltest; uses pwumain; // note: use "pwu" in version 1.5 var mymacro: string; begin mymacro:= 'Red Bike'; setwebvar('macrovar', mymacro); webtemplateout('mytemplate.tpl', true); end.Create a file called MyTemplate.tpl and store it in the cgi program directory..
In the template file, place a line like this:
He found a {$macrovar}. He decided to ride it.The macro var will get replaced with 'Red Bike'.
http://example.com/cgi-bin/prog.cgi?var1=test&var2=5To access these variables in the url such as VAR1 and VAR2, simply call GetCgiVar('var1') and GetCgiVar('var2'). These functions return the value of the variables.
Note that there is built in security when using GetCgiVar, so if some hacker tries to inject unix commands or javascript...
http://example.com/cgi-bin/prog.cgi?var1=./ls|./cat<script>java</script>...then characters like pipes, less than, greater than, and dots will get trimmed right out.
If you want to filter those pipes and dots into HTML equivalents.. then you should bypass security, and use the FilterHTML function or use the GetCgiVar_SafeHtml function.
To bypass security completely without any automatic filtering use the GetCgiVar_S function and specify zero (0) security as a parameter.
The reason GetCgiVar_S function contains a underscore suffix naming scheme, is so that it jumps_OUT at you when you are looking at that code months later. Bypassing the security needs to be made clear in the program. The extra zero param makes it even more obvious that you are setting security to none.