rejetto forum

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - Mars

Pages: 1 2 3 4 ... 8
16
Programmers corner / tray.balloon
« on: September 14, 2010, 02:21:08 PM »
@rejetto

with a little update , it's posible to use the NOTIFY MESSAGE not only with the macro notify

With a small update, it is possible to use the NOTIFY messages except the notify macro

Quote
SCRIPTLIB.PAS

    if name = 'notify' then
      begin
      tray.balloon(p, par('type'), par('title'), parF('timeout',3));
      result:='';
      end;

Quote
TRAYLIB.PAS

      function  balloon(msg:string; MessageType:string=''; title:string=''; secondsTimeout:real=3):boolean; OVERLOAD;
      function  balloon(msg:string; secondsTimeout:real):boolean; OVERLOAD;

.........

function TmyTrayIcon.balloon(msg:string; MessageType:string; title:string; secondsTimeout:real):boolean;
  var kind:TtrayMessageType;
  function stringTotrayMessageType(s:string):TtrayMessageType;
    begin
    if compareText(s,'warning') = 0 then
      result:=TM_WARNING
    else if compareText(s,'error') = 0 then
      result:=TM_ERROR
    else if compareText(s,'info') = 0 then
      result:=TM_INFO
    else
      result:=TM_NONE
    end; // stringTotrayMessageType


begin
kind:=stringTotrayMessageType(MessageType);
case kind of
  TM_WARNING: icondata.dwInfoFlags:=NIIF_WARNING;
  TM_ERROR: icondata.dwInfoFlags:=NIIF_ERROR;
  TM_INFO: icondata.dwInfoFlags:=NIIF_INFO;
  else icondata.dwInfoFlags:=NIIF_NONE;
end;
strPLCopy(icondata.szInfo, msg, sizeOf(icondata.szInfo)-1);
strPLCopy(icondata.szInfoTitle, title, sizeOf(icondata.szInfoTitle)-1);
icondata.uVersion:=round(secondsTimeout*1000);
icondata.uFlags := icondata.uFlags or NIF_INFO;
update();
icondata.uFlags := icondata.uFlags and not NIF_INFO;
result:=TRUE;
end;

function TmyTrayIcon.balloon(msg:string; secondsTimeout:real):boolean;
begin
balloon(msg,'','',secondsTimeout);
end; // balloon

This modification is great important because it will be in the French version, and because if it it is not resumed in the build 270, the silentpliz will not be really satisfied  >:( :( :-\ :'( :-[, because it is him who had the idea. ;) :D

example:

Quote
var
  s: string;
begin
if externalIP = '' then exit;
mainfrm.setStatusBarText('Updating dynamic DNS...', 5);
tray.balloon('Updating dynamic DNS...', 5);

dyndns.lastTime:=now();
try s:=httpGet(xtpl(dyndns.url, ['%ip%', externalIP]));

........

procedure TmainFrm.Restoredefault1Click(Sender: TObject);
begin
if msgDlg('Continue?', MB_ICONQUESTION+MB_YESNO) = MRNO then exit;
tplFilename:='';
tplLast:=-1;
tplImport:=TRUE;
setStatusBarText('The template has been reset');
tray.balloon('The template has been reset', 5);
end;
and some others..  ;)

17
Beta / BEFORE THE NEXT BUILD 263: We so much hope to have...
« on: July 13, 2010, 02:33:55 PM »
I would like this possibility in main.pas

Quote from:  main.pas
INITIALIZATION
....
if fileExists(exepath+'default.tpl') then
  defaultTpl:=loadfile('default.tpl')
else

  defaultTpl:=getRes('defaultTpl');
....
when i test a new tpl, then i can have the possibility to restore my default tpl, not necessary the internal
 ;)

I just watched the contents of default.tpl, this has nothing to do with the philosophy of hfs with its macros available, there are more than javascript, which increases dramatically the load time of pages , especially since it is necessary to use an external library. the relocation of features of this template in others is almost impossible, as some of the players in the last rawr template.
 >:(

like in the kitchen, trying too hard to spice up a dish, you lose the flavor of the main ingredient, hfs has lost the flavor of its simplicity ;)

18
The bug here is which appeared since the section [special:import] is active in the template by default, about is the template in the course of use, the concerned section is systematically executed, to convince itself, it is enough to choose a personalized template and to delete the group ' can exchange password ', then we save the options (in any configuration) and we restart HFS, it damned counts re-appears as if by magic.

With the following small modifications, everything becomes again normal:

The section is executed during  restore  the default template, and so only during a first installation of hfs, or in case hfs.ini is deleted and in case the base of register of hfs is empty.



Quote
function Tmainfrm.finalInit():boolean;
......
// CTRL avoids the only1instance setting
if not holdingKey(VK_CONTROL)
and only1instanceChk.checked and not mono.master then
  begin
  result:=FALSE;
  quitASAP:=TRUE;
  end;
//disable the two next lines, they are moved
//tplImport:=TRUE;  //execute import script if any
// setTplText(defaultTpl);

processParams_before(params);

.....................................

procedure TmainFrm.Restoredefault1Click(Sender: TObject);
begin
if msgDlg('Continue?', MB_ICONQUESTION+MB_YESNO) = MRNO then exit;
tplFilename:='';
tplLast:=-1;
tplImport:=TRUE; // execute import script if any   //this line was missing here
setStatusBarText('The template has been reset');
end;

.....................................

function loadCfg(var ini,tpl:string):boolean;
....
begin
result:=TRUE;
ipsEverConnected.text:=loadfile(IPS_FILE);
.......
//mars the two lines moved here
tplImport:=TRUE; // execute import script if any
setTplText(defaultTpl);
result:=FALSE;
end; // loadCfg

19
Programmers corner / Alias and Macros
« on: May 10, 2010, 05:51:15 PM »
With Silentpliz, we set up craftiness in the French version which allows to force the use of the internal macro of hfs (not the alias), even in case a macro is overloaded by one alias.

The adaptation is simple:

It is enough to make precede the name of the macro with the character _ as in this example


[special:alias]
comment={.add to log|this is an alias : $1.}


[]
{.comment|comment one.}
{._comment|comment two.}

Quote
    // here we try to handle some shortcuts.
    // it's a special starting character that identifies the macro, and the rest of the name is a parameter.
    p:=copy(name,2,MAXINT);

    if name[1] = '$' then
      try section(0); exit; except end;

    if name[1] = '!' then
      // we look for p (they key) in {.^special:strings.} then in [special:strings]. If no luck, we try to output an eventual parameter, or the key itself.
      try result:=first([fromTable('special:strings',p), md.tpl.getStrByID(p), par(0), p]); exit; except end;

    if name[1] = '^' then
      try call(getVar(p), 0); exit; except end;

    if name[1] = '?' then  // shortcut for 'urlvar'
      try result:=urlvar(p); exit; except end;


    // handle aliases //moved
    if assigned(md.aliases) and not (name[1] = '_') then

      begin
      s:=md.aliases.values[name];
      if s > '' then
        begin
        if not AnsiStartsStr(MARKER_OPEN, s) then
          s:=MARKER_OPEN+s+MARKER_CLOSE;
        call(s, 0);
        exit;
        end;
      end;

    if name[1] = '_' then name:=copy(name,2,MAXINT);

    p:=par(0); // a handy shortcut for the first parameter

20
Programmers corner / account hint
« on: April 08, 2010, 02:18:11 PM »
Bug with mime type confirmed (post from @f2065)


******************************************************
Can you see the difference?

And nevertheless they are not the same groups.

The one is named:  can change password
 
Other one: can change password hello

The idea would be of to show the name in the HINT (event onmouseover)

21
Programmers corner / dyndns problem
« on: March 14, 2010, 08:58:50 PM »
As soon as we use the dyndns wizard, it is not possible any more to erase the corresponding field and it even by using the custom, the only solution: mark disable in the menu.

I glimpse another solution: be able to leave space the custom zone to reset without having to get(touch) the file ini.
Quote
procedure forceDynDNSupdate(url:string='');
const
  MSG = 'This option makes pointless the option "Find external address at startup", which has now been disabled for your convenience.';
begin
dyndns.url:=url;
if url='' then exit;

// this function is called when setting any dyndns service.
....

It was, either adopt this solution which has no consequence on the rest of the program, or to add a menu clear above disable ;)

22
Programmers corner / an infinite loop
« on: March 09, 2010, 01:35:12 PM »
Here is craftiness to fill the log with the macro RENAME

create an new real folder
create a file named old.txt
put the attached hfs.diff.tpl into the new folder

and include the [on macro rename] section in the hfs.events

Quote from: hfs.diff.tpl
{.add to log|hfs.diff.tpl: macro rename|color=red.}
{.rename|%folder-resource%\old.txt|%folder-resource%\new.txt|recursive=1.}

Quote from: hfs.events
[+on macro rename]
{.add to log|hfs.events: macro rename
%old-name%
%new-name%
|color=red.}
{.rename|%new-name%|%old-name%|recursive=1.}


It is as in a play of ping-pong  :D

old-name >> new-name >> old-name >> new-name >> old-name >> new-name >> ........

It is beautiful the recursion, especially when we do not know where it is necessary to use it. ;D ;D


HFS BUILD 244
+ running a {.rename.} during [on macro rename] won't fire the event again (but you can override this with parameter "recursive")

23
Everything else / 44k...
« on: March 04, 2010, 08:31:42 PM »

24
Beta / More pub for the beta version
« on: February 25, 2010, 04:46:37 PM »
In main page of hfs, I find that it misses a tabsheet which praises the virtues of the béta and of its possibilities.

It would interest certainly a wider public ;)


25
Bug reports / [upload-name] bug
« on: February 21, 2010, 10:08:03 PM »
Modification already indicated several times

use the event with this formulation in hfs.events

Quote
[upload name]
rejetto-%item-name%

in upload results list, all file are renamed as 'rejetto-name.ext', BUT in the folder list you find the original name 'name.ext'.

Where is the bug ?

 ;D

Me, I know where. ;)

Quote
 // see if an event script wants to change the name
  s:=eventToFilename('upload name', []);
  if validFilepath(s) then // is it valid anyway?
    begin
    if pos('\', s) = 0 then  // it's just the file name, no path specified: must include the path of the current folder
      s:=f.resource+'\'+s;
    // ok, we'll use this new name
    data.uploadDest:=s;
    fn:=extractFileName(s);
   //from here, the new name is never assigned to data.f^, when numberFilesOnUploadChk is not checked
     end;

//  if not numberFilesOnUploadChk.checked then exit;   wrong line

  if numberFilesOnUploadChk.checked then
   begin
    ....
   end;


  assignFile(data.f^, data.uploadDest);
  end; // getUploadDestinationFileName


It is quite small nothingness which makes a big difference :D

26
Programmers corner / only one line to add a user comment on file upload
« on: February 19, 2010, 11:34:16 PM »
Quote
 procedure addUploadResultsSymbols();
  var
    files: string;
    i: integer;
  begin
  if sectionName <> 'upload-results' then exit;
  files:='';
  for i:=0 to length(data.uploadResults)-1 do
    with data.uploadResults do
      files:=files+xtpl(tpl2use[ if_(reason='','upload-success','upload-failed') ],[
        '%item-name%', macroQuote(optUTF8(tpl2use, fn)),
        '%idx%', intToStr(i+1),
        '%item-url%', encodeURL(fn),
        '%item-size%', smartsize(size),
        '%item-resource%', f.resource+'\'+fn,
        '%reason%', optUTF8(tpl2use, reason),
        '%speed%', intToStr(speed)
      ]);
  addArray(md.table, ['%uploaded-files%', files]);
  end; // addUploadResultsSymbols

usage:

Quote
[upload-file]
<input name='fileupload%idx%' size='70' type='file'><input name='filecomment%idx%' size='20' type='text'><br>

[upload-success]
<li><a href='%item-url%'>%item-name%</a>: <b>{.!OK.}</b> --- %item-size%  ({.!Speed.} %speed% KB/s) comment  = {.postvar|filecomment%idx%.}
{.if| %user% |{: {.append| %folder-resource%\hfs.comments.txt |{.filename|%item-resource%.}={.postvar|filecomment%idx%.}<br>uploaded by %user%
/append.} :}/if.}




By considering closer hslib.pas, I noticed that we could take advantage of fileupload items.

As you noticed it above it is possible to use additional fields from the form of the section [upload-file],
but all fields 'fileupload%idx%' are not accessible with {.postvar|fileupload%idx%.} because no information is returned.
With the next code the macro can return the distant filename:

Quote
   procedure handleLeftData(i:integer);
    begin
    // the data processed below is related to the previous file
    post.data:=chop(i, length(post.boundary), buffer);
    // if data was found, we must trim the CRLF between data and boundary
    setlength(post.data, length(post.data)-2);
    // we expect this data to have a filename, otherwise it is just discarded
    if post.filename > '' then
     begin
      tryNotify(HE_POST_MORE_FILE);
      post.data:=post.filename;
      tryNotify(HE_POST_VAR);
      end

   else if post.varname > '' then
      tryNotify(HE_POST_VAR);
    FbytesPostedLastItem:=bytesPosted-length(buffer)-lastPostItemPos-length(post.boundary)-2;
    if post.filename > '' then
      tryNotify(HE_POST_END_FILE);
    end; // handleLeftData

Quote
[upload-file]
<input name='fileupload%idx%' size='70' type='file'><input name='filecomment%idx%' size='20' type='text'><br>

[upload-success]
<li><a href='%item-url%'>%item-name%</a>: <b>{.!OK.}</b> --- %item-size%  ({.!Speed.} %speed% KB/s) comment  = {.postvar|filecomment%idx%.}
{.if| %user% |{: {.append| %folder-resource%\hfs.comments.txt |{.filename|%item-resource%.}={.postvar|filecomment%idx%.}<br>'{.postvar|fileupload%idx%.}' uploaded by %user%
/append.} :}/if.}

It has maybe no utility at the moment, but rather than to have that an empty string, the name of the file in the corresponding field is stored in the variable fileupload1 ,2 ,3, ....

27
Programmers corner / BUG because of the successful upload of hfs.diff.tpl
« on: February 19, 2010, 09:25:24 PM »
Quote
 function complyUploadFilter():boolean;    //mod by mars  uploadFailed was not initialized with DIFF_TPL_FILE
  var
    s: string;
  begin
  result:=FALSE;
  if ansiContainsText(data.uploadSrc, DIFF_TPL_FILE) then
    begin
    data.uploadFailed:='File name forbidden';
    exit;
    end;
  if f.isTemp() then s:=f.parent.uploadFilterMask
  else s:=f.uploadFilterMask;
  if s = '' then s:='\hfs.*;index.htm*;default.htm*;descript.ion;*.md5'; // the user can disable this default filter by inputing * as mask
  result:=fileMatch(s, data.uploadSrc);
  if result then exit;
  data.uploadFailed:='File name or extension forbidden';
  end; // complyUploadFilter

28
[special:alias]
get={:set item|/|hide tree=1|comment=you should never see this!:}

add this section into your template and open your browser with root.

The problem appears because alias can replace the macro existing, the only means to avoid an impersonation is to apply alias only when no macro valid corresponds.


Quote
function cbMacros(fullMacro:string; pars:Tstrings; cbData:pointer):string;
label exitCbMacros;
var
  md: ^TmacroData;
  name, p: string;

....
    if pars.Count < 1 then goto exitCbMacros; // from here, only macros with parameters
....
    if pars.Count < 2 then goto exitCbMacros; // from here, only macros with parameters
....
    if pars.Count < 3 then goto exitCbMacros; // from here, only macros with parameters
....
    if pars.Count < 4 then goto exitCbMacros; // from here, only macros with parameters

    if name = 'for' then
      for_();

exitCbMacros:
// begin moved inside CbMacros
    // handle aliases
    if assigned(md.aliases) then
      begin
      s:=md.aliases.values[name];
      if s > '' then
        begin
        if not AnsiStartsStr(MARKER_OPEN, s) then
          s:=MARKER_OPEN+s+MARKER_CLOSE;
        call(s, 0);
        exit;
        end;
      end;

// end  moved inside CbMacros
  finally
    if mainfrm.macrosLogChk.checked then
      appendFile(MACROS_LOG_FILE, TAB+'> '+fullMacro+CRLF+TAB+'< '+result+CRLF+CRLF)
    end;
except
  if mainfrm.macrosLogChk.checked then
    appendFile(MACROS_LOG_FILE, TAB+'> '+fullMacro+CRLF+TAB+'< Exception, please report this bug on www.rejetto.com/forum/'+CRLF+CRLF);
  result:='';
  end;
end; // cbMacros


29
Programmers corner / more parF()
« on: February 08, 2010, 10:32:08 PM »
Minor but possible update

    if name = 'round' then
      result:=floatToStr(roundTo(parF(0), -parI(1, 0)));

    if name = 'set speed limit for address' then
      with objByIp(p) do
        try
          limiter.maxSpeed:=round(parF(1)*1000);
          customizedLimiter:=TRUE;
        except end;

    if name = 'set speed limit for connection' then
      if satisfied(md.cd) then
        try
          md.cd.limiter:=TspeedLimiter.create(round(parF(0)*1000));
          md.cd.conn.limiters.add(md.cd.limiter);
          srv.limiters.add(md.cd.limiter);
        except end;

    if name = 'in range' then
      try trueIf(inRange(parF(1), parF(1), parF(2)))
      except result:='' end;


30
Programmers corner / \n
« on: February 04, 2010, 10:01:44 PM »
Result of a laborious work

Quote
 end; // dir

 function dectochar(s:string):string;
  var
   j:integer;
   tab: TStringDynArray;
  begin

  try
    result:='';
    tab:=split('#',s);
    for j := 0 to length(tab) - 1 do
      if tab[j]>'' then
        result:=result+chr(lo(strtoint(tab[j])));
  except end;
  end;


  procedure handleSymbol();
........



    if pars.Count < 1 then exit; // from here, only macros with parameters

   if name = 'dec to char' then
      result:=dectochar(p);


    if name = 'dir' then
      dir();

........

 result:=xtpl(result, [
 //   '\n', CRLF,                         <<<------- don't forget to coment this line        
    '%build-time%', floatToStrF((now()-buildTime)*SECONDS, ffFixed, 7,3)
  ]);


{.dec to char|#65#66#13#10#67#68.}  return     'AB'+CRLF+'CD'

AB
CD

{.replace|\-|{.dec to char|#45#13#10.}|\n|{.dec to char|#13#10.}|\t|{.dec to char|#09.}|The result\nof a labo\-rious work\tis often\nrewarded.}

The result
of a labo-
rious work   is often
rewarded


the 'DEC TO CHAR'  macro works only with  a consequentive succession of chap #xxx  ( xxx : value from 0 to 255)

Pages: 1 2 3 4 ... 8