- Код: Выделить всё
- action=date - скрипт возвращает текущую дату
 action=time - скрипт возвращает текущее время
 action=datetime - скрипт возвращает текущие дату и время
 action=serverinfo - скрипт возвращает информацию о сервере
 action=selfinfo - скрипт возвращает информацию о себе (метод запроса, версия CGI, местоположение скрипта)
 action=userinfo - скрипт возвращает информацию о пользователе (IP-адрес пользователя, информацию о браузере)
 action=readfile, info="имя файла" - скрипт возвращает содержимое текстового файла, имя которого задано в параметре "info"
 action=relocate, info="имя ресурса" - скрипт перенаправляет клиента к ресурсу, имя которого задано в параметре "info"
вот код программы:
- Код: Выделить всё
- {$mode objfpc}
 {$H+}
 Uses SysUtils,cgivars,DateUtils;
 function first():string;
 begin
 result:='<form method="get"><input name="action"><br><br>'
 +'<form method="get"><input name="info"><br><br>'
 +'<input type="submit" value="Oтправить"></form>'
 end;
 function ac(s:string):string;
 var c,b:integer;
 begin
 c:=pos('=',s);
 b:=pos('&',s);
 result:=copy(s,c+1,b-c-1);
 end;
 function inf(s:string):string;
 var c,b:integer;
 begin
 c:=pos('&',s);
 b:=length(s);
 result:=copy(s,c+6,b-c+5);
 end;
 var h:string;action,info:string;
 f:text; i,n:integer;
 a:real;
 begin
 writeln('status: 200 ok');
 writeln('Content-type:text/html');
 writeln;
 h:=getEnvironmentVariable('QUERY_STRING');
 if h='' then
 writeln(first)
 else
 begin
 action:=ac(h);
 info:=inf(h);
 if action='time' then
 writeln('Time is:',TimeToStr(TimeOf(Now)))
 else if action='date' then
 writeln('Date is:',DateTimeToStr(DateOf(Now)))
 else if action='datetime' then begin
 writeln('DateTime is:',TimeToStr(TimeOf(Now)),' ',DatetimeToStr(DateOf(Now)));
 end
 else if action='serverinfo' then begin
 writeln(GetEnvironmentVariable('SERVER_NAME'));
 writeln(GetEnvironmentVariable('SERVER_PORT'));
 writeln(GetEnvironmentVariable('SERVER_PROTOCOL'));
 writeln(GetEnvironmentVariable('SERVER_SOFTWARE'));
 end
 else if action='selfinfo' then begin
 writeln(GetEnvironmentVariable('SCRIPT_NAME'));
 writeln(GetEnvironmentVariable('REQUEST_METHOD'));
 writeln(GetEnvironmentVariable('GATEWAY_INTERFACE'));
 end
 else if action='userinfo' then begin
 writeln(GetEnvironmentVariable('REMOTE_ADDR'));
 writeln(GetEnvironmentVariable('HTTP_USER_AGENT'));
 end
 else if action='readfile'then begin
 Assign(f,info);
 reset(f);
 while not eof(f) do begin
 readln(f,info);
 writeln(info);
 end;
 close(f);
 
 end
 else if action='relocate' then begin
 writeln('location://',info);
 end;
 end;
 end.



 
  