* Added template directory support
* Added session variable support
This commit is contained in:
parent
c128b16996
commit
19c9ea042f
|
@ -19,8 +19,33 @@
|
||||||
<VersionInfo>
|
<VersionInfo>
|
||||||
<StringTable ProductVersion=""/>
|
<StringTable ProductVersion=""/>
|
||||||
</VersionInfo>
|
</VersionInfo>
|
||||||
<BuildModes Count="1">
|
<BuildModes Count="2">
|
||||||
<Item1 Name="Default" Default="True"/>
|
<Item1 Name="Default" Default="True"/>
|
||||||
|
<Item2 Name="Release">
|
||||||
|
<CompilerOptions>
|
||||||
|
<Version Value="11"/>
|
||||||
|
<Target>
|
||||||
|
<Filename Value="restemplate"/>
|
||||||
|
</Target>
|
||||||
|
<SearchPaths>
|
||||||
|
<IncludeFiles Value="$(ProjOutDir)"/>
|
||||||
|
<OtherUnitFiles Value="jtemplate;synapse"/>
|
||||||
|
<UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
|
||||||
|
</SearchPaths>
|
||||||
|
<CodeGeneration>
|
||||||
|
<SmartLinkUnit Value="True"/>
|
||||||
|
<Optimizations>
|
||||||
|
<OptimizationLevel Value="3"/>
|
||||||
|
</Optimizations>
|
||||||
|
</CodeGeneration>
|
||||||
|
<Linking>
|
||||||
|
<Debugging>
|
||||||
|
<GenerateDebugInfo Value="False"/>
|
||||||
|
</Debugging>
|
||||||
|
<LinkSmart Value="True"/>
|
||||||
|
</Linking>
|
||||||
|
</CompilerOptions>
|
||||||
|
</Item2>
|
||||||
</BuildModes>
|
</BuildModes>
|
||||||
<PublishOptions>
|
<PublishOptions>
|
||||||
<Version Value="2"/>
|
<Version Value="2"/>
|
||||||
|
|
|
@ -20,7 +20,8 @@
|
||||||
program restemplate;
|
program restemplate;
|
||||||
|
|
||||||
uses
|
uses
|
||||||
SysUtils, Classes, strutils, JTemplate, httpsend;
|
SysUtils, Classes, strutils, JTemplate, httpsend, IniFiles,
|
||||||
|
ssl_openssl;
|
||||||
|
|
||||||
var
|
var
|
||||||
data: TextFile;
|
data: TextFile;
|
||||||
|
@ -30,14 +31,29 @@ var
|
||||||
method: String;
|
method: String;
|
||||||
content: TStringList;
|
content: TStringList;
|
||||||
commandMode: Boolean;
|
commandMode: Boolean;
|
||||||
|
configDir, templateDir: String;
|
||||||
|
templateFile, templateName: String;
|
||||||
|
sessionIni: TIniFile;
|
||||||
|
|
||||||
procedure CmdAskUser(AName: String);
|
procedure CmdAskUser(AName: String);
|
||||||
var
|
var
|
||||||
value: String;
|
value, default: String;
|
||||||
begin
|
begin
|
||||||
Write(AName, ': ');
|
Write(AName);
|
||||||
|
default := sessionIni.ReadString(templateName, AName, '');
|
||||||
|
if default <> '' then
|
||||||
|
Write(' [', default, ']: ')
|
||||||
|
else
|
||||||
|
Write(': ');
|
||||||
|
|
||||||
ReadLn(value);
|
ReadLn(value);
|
||||||
|
|
||||||
|
if value = '' then
|
||||||
|
value := default;
|
||||||
|
|
||||||
parser.Fields.Add(AName, value);
|
parser.Fields.Add(AName, value);
|
||||||
|
|
||||||
|
sessionIni.WriteString(templateName, AName, value);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure CmdHeader(AHeader: String);
|
procedure CmdHeader(AHeader: String);
|
||||||
|
@ -70,7 +86,11 @@ begin
|
||||||
content.LoadFromStream(http.Document);
|
content.LoadFromStream(http.Document);
|
||||||
writeln(content.Text);
|
writeln(content.Text);
|
||||||
end else
|
end else
|
||||||
writeln('FAILED !!!');
|
begin
|
||||||
|
ExitCode := 2;
|
||||||
|
writeln;
|
||||||
|
writeln('FAILED! Last Socket Error: ', http.Sock.SocksLastError);
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function ProcessCommand(ALine: String): Boolean;
|
function ProcessCommand(ALine: String): Boolean;
|
||||||
|
@ -98,10 +118,53 @@ begin
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure ListProfiles;
|
||||||
|
var
|
||||||
|
sr: TSearchRec;
|
||||||
|
begin
|
||||||
|
Writeln('Known profiles:');
|
||||||
|
if FindFirst(templateDir + '*.rest', faAnyFile, sr) = 0 then
|
||||||
|
begin
|
||||||
|
repeat
|
||||||
|
writeln(' ', Copy(sr.Name, 1, Length(sr.Name) - 5));
|
||||||
|
until FindNext(sr) <> 0;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
begin
|
||||||
|
configDir := GetAppConfigDir(False);
|
||||||
|
templateDir := configDir + 'templates' + PathDelim;
|
||||||
|
|
||||||
|
templateFile := templateDir + ParamStr(1) + '.rest';
|
||||||
|
|
||||||
|
if ParamCount <> 1 then
|
||||||
|
begin
|
||||||
|
Writeln('Usage: ', ExtractFileName(ParamStr(0)), ' <profile or file>');
|
||||||
|
Writeln;
|
||||||
|
ListProfiles;
|
||||||
|
Halt(0);
|
||||||
|
end;
|
||||||
|
|
||||||
|
if FileExists(ParamStr(1)) then
|
||||||
begin
|
begin
|
||||||
AssignFile(data, ParamStr(1));
|
AssignFile(data, ParamStr(1));
|
||||||
|
templateName := ExtractFileName(ParamStr(1));
|
||||||
|
if AnsiEndsStr('.rest', templateName) then
|
||||||
|
templateName := Copy(templateName, 1, Length(templateName) - 5);
|
||||||
|
end else
|
||||||
|
if FileExists(templateFile) then
|
||||||
|
begin
|
||||||
|
AssignFile(data, templateFile);
|
||||||
|
templateName := ParamStr(1);
|
||||||
|
end else
|
||||||
|
begin
|
||||||
|
writeln('Template not found!');
|
||||||
|
Halt(1);
|
||||||
|
end;
|
||||||
Reset(data);
|
Reset(data);
|
||||||
|
|
||||||
|
sessionIni := TIniFile.Create(configDir + 'session.ini');
|
||||||
|
|
||||||
parser := TJTemplateParser.Create;
|
parser := TJTemplateParser.Create;
|
||||||
http := THTTPSend.Create;
|
http := THTTPSend.Create;
|
||||||
content := TStringList.Create;
|
content := TStringList.Create;
|
||||||
|
@ -118,6 +181,7 @@ begin
|
||||||
content.Add(line);
|
content.Add(line);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
sessionIni.Free;
|
||||||
parser.Free;
|
parser.Free;
|
||||||
http.Free;
|
http.Free;
|
||||||
content.Free;
|
content.Free;
|
||||||
|
|
Loading…
Reference in New Issue