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 ... 3 4 5 6 7 8
61
error resolved by modificate the code

Quote
function Tmainfrm.addFilesFromString(files:string; under:Ttreenode=NIL):Tfile;
......
var
  f: Tfile;
  kind, s, fn, fntemp: string;  //mod by mars
  doubles: TStringDynArray;
  res: integer;
.........
// warn upon double filenames
doubles:=NIL;
s:=files;
while s > '' do
   begin
  fn:=chopLine(s);
  if isExtension(fn, '.lnk')
  or directoryExists(fn) and fileExists(fn+'\target.lnk')
  then
    begin
    fntemp:=resolveLnk(fn);
    files:=xtpl(files,[fn,fntemp]);
    fn:=fntemp;
    end;

  if (length(fn) = 3) and (fn[2] = ':') then fn:=fn[1]+fn[2] // unit root folder
   else fn:=ExtractFileName(fn);
  if existsNodeWithName(fn, under) then
    if addString(fn, doubles) > MAX_DUPE then
      break;
  end;

now there is no sharing filename with ''on 'computer' " and the warning make his come back

BUG if you answer yes on the warning, the name is incremented
 

62
Ici vous pourrez discuter en FRANÇAIS de HFS en général, et de la version française en particulier :) diffusée sous la bannière de SilentPliz et co-transformée par mes soins.

Voila ;)

63
Programmers corner / http:// only ?
« on: April 30, 2009, 01:09:49 PM »
Am I right to add:

Quote
  procedure load(fn:string; varname:string='');
  begin
  if ansiStartsText('http://', fn) or ansiStartsText('https://', p) then result:=httpGet(fn)
  else result:=loadFile(uri2diskMaybe(fn));

.......

if name = 'filesize' then
      begin
      if ansiStartsText('http://', p) or ansiStartsText('https://', p) then i:=httpFileSize(p)
      else i:=sizeOfFile(uri2diskMaybe(p));
      result:=intToStr(max(0,i));
      end;

Otherwise macros load and filesize cannot work through ssl with https://......
 ;)

64
Programmers corner / missing alias.txt
« on: April 30, 2009, 11:54:16 AM »
There is an error during the use recompile data.bat, the file dat.res is not reconstituted, the reason is a reference to the alias.txt file which does not exist in sources, to fill this gap it is enough to create a file alias.txt empty and to recompile.

For information:
 the alias.txt file contains all the equivalences of the macro alias which also can beings defined in the section 
[ special:alias ] of the template


By default, them alias defined in the section are priority on those of the file

to rejetto: c'est malin , j'ai cherché ce post partout ;D

65
Programmers corner / numbers files, folders, links ....
« on: April 28, 2009, 10:47:59 AM »
There are at present three variables [%number-folders%,%number-files%,%number-links%]which count(record) the various types (see %item-type% in build 236) of elements with a total of %numbers% , but there was nothing to index each of these elements in the category, a small addition in the code of delphi and the problem is resolved with  %item-number%:

Every time an element is added to the list, he is associated with him an index of position

by example inside of template:

[folder=link=file]
%item-number% / {.switch|%item-type%||folder|%number-folders%|file|%number-files%|link|%number-links%.}


 Rejetto: if you are not convinced by %item-number%, I propose you %item-type-idx%

Quote
  procedure handleItem(f:Tfile);
  var
    type_, s, url, fingerprint, itemFolder: string;
    nonPerc: TStringDynArray;
    number_: integer;    //add by mars
  begin
 ......
  // select appropriate template
  if f.isLink() then
    begin
    s:=linkTpl;
    inc(numberLinks);
    number_:=numberLinks;    //add by mars
    type_:='link';
    end
  else if f.isFolder() then
    begin
    s:=folderTpl;
    inc(numberFolders);
    number_:=numberFolders;      //add by mars
    type_:='folder';
    end
  else
    begin
    s:=diffTpl.getTxtByExt(ExtractFileExt(f.name));
    if s = '' then s:=diffTpl.getTxtByExt(ExtractFileExt(f.name));
    if s = '' then s:=fileTpl;
    inc(numberFiles);
    number_:=numberFiles;        //add by mars
    type_:='file';
    end;

  addArray(md.table, [
    '%item-type%', type_,
    '%item-number%', inttostr(number_)   
  //add by mars
  ]);

  s:=xtpl(s, nonPerc);
  md.f:=f;
  tryApplyMacrosAndSymbols(s, md, FALSE);
  fast.append(s);
  end; // handleItem

nécessaire? je l'utilise dans le mode page et cela évite bien des macros 'if' et des compteurs.. ;)

66
Programmers corner / 3 Correctives for events
« on: April 16, 2009, 01:02:50 PM »
Three events following , [upload name],  [download name] and [archive name],necessarily have to supply a result of type string containing no illegal character, but after several tries,  the results of these events, which have to supply a name of coherent file, had some surprises in reserve: every result has to like on a single line, it was not thus possible to use a formulation of the kind:
 
Quote
[xxxx name]
{.if|%user%|%user%-|anonymous-.}
%date%
%item-name%

At present only the first line is held(retained) as being valid, thus it is necessary to use this:
Quote
[xxxx name]
{.if|%user%|%user%-|anonymous-.}%date%%item-name%

When there is not enough information to be converted or to calculate, then a line is sufficient, but for more clarity, if we wish a resultat which takes into account all lines them of the section then here is the code adequate

Quote
  // see if an event script wants to change the upload name
  s:=xtpl(trim(runEventScript('upload name')),[#10,'',#13,'',#09,'']);

  // see if an event script wants to change the download name
  s:=or_(xtpl(trim(runEventScript('download name')),[#10,'',#13,'',#09,'']), f.name); 
  // see if an event script wants to change the archive name
      data.lastFN:=or_(trim(xtpl(runEventScript('archive name',
                                 ['%archive-name%', data.lastFN,
                                  '%mode%', if_(selection, 'selection','folder')
                                 ]),[#10,'',#13,'',#09,''],)), data.lastFN);


all cararcters Tab LineFeed and CariageReturn are deleted in the result name.

An excellent test is to use for example

[xxxx name]
this is
 the new
 name.tmp

You should obtain 'this is the new name.tmp' and not 'this is'

 ;D




67
Everything else / increase, increase,.....
« on: April 12, 2009, 11:58:47 PM »
With the recession, price lists increase of everywhere ;D


Do you like this software?
 Donate!
Consider even $2

The parity of the euro is nevertheless in favour of the dollar, our purchasing power is weaker than before,


Will the European have l straight ahead in a discount on behalf of rejetto? ;D

68
Programmers corner / USER AGENT (or the connected browser)
« on: April 12, 2009, 11:19:55 PM »
Here is thus a small proposition in my long existing list.

one new  variable and one new macro
%user-agent% amounts in macro {.header|user-agent}, but in shorter,
 
{ .get|know agents|separator.} if separator is not specified or empty, then a semicolon is used by default.

one usage is:
 hfs.events
[request]
{if not|{is substring|%user-agent%| list of browsers.} | {:{.disconnect.}:} .}


That allows among others to let no download manager connect in the server.

Every new type of connection is registered(recorded) in hfs.ini in the variable 'users-agents' and so available for a later usage with the macro {.get|know agents.}
users-agents=MSIE 6.0|Mozilla/5.0|GetRightPro/6.0

main.pas
Quote
....
type
  TmacroData = record
    cd: TconnData;
    tpl: Ttpl;
    folder, f: Tfile;
    afterTheList, archiveAvailable, hideExt: boolean;
    aliases: THashedStringList;
    end;

function getAgentID(conn:ThttpConn):string; overload; forward;     // add by mars

function cbMacros(fullMacro:string; pars:Tstrings; cbData:pointer):string;

........
   else if name = '%user%' then
      result:=macroQuote(usr)
    else if name = '%password%' then
      result:=macroQuote(md.cd.conn.request.pwd)
    else if name = '%user-agent%' then        // add by mars
      result:=macroQuote(getAgentID(md.cd.conn))       // add by mars

    else if name = '%loggedin%' then
      result:=if_(usr>'', tpl['loggedin'])
........
    if name = 'get' then
      if p = 'can recur' then trueIf(mainFrm.recursiveListingChk.Checked)
      else if p = 'known agents' then result:=join(or_(pars[1],';'),usersagents) // add by mars
      else if p = 'can upload' then trueIf(assigned(md.cd) and accountAllowed(FA_UPLOAD, md.cd.conn, md.folder))
      else if p = 'can delete' then trueIf(assigned(md.cd) and accountAllowed(FA_DELETE, md.cd.conn, md.folder))
      else if p = 'can archive' then canArchive(md.folder)
.......
  // all URIs must begin with /
  if (url = '') or (url[1] <> '/') then
    begin
    conn.reply.mode:=HRM_BAD_REQUEST;
    exit;
    end;
  addUniqueString(getAgentID(conn),usersAgents); // add by mars
  runEventScript('request');
.......
+'enable-no-default='+yesno[enableNoDefaultChk.checked]+CRLF
+'browse-localhost='+yesno[browseUsingLocalhostChk.checked]+CRLF
+'users-agents='+join('|',usersAgents)+CRLF          // add by mars
+'add-folder-default='+addFolderDefault+CRLF
+'default-sorting='+defSorting+CRLF
.......
    if h = 'enable-no-default' then enableNoDefaultChk.checked:=yes;
    if h = 'browse-localhost' then browseUsingLocalhostChk.checked:=yes;
    if h = 'users-agents' then usersAgents:=split('|',l);     // add by mars
    if h = 'tpl-file' then tplFilename:=l;
    if h = 'tpl-editor' then tplEditor:=l;
......

69
Programmers corner / Small reminder about EVENTS and hfs.events
« on: April 12, 2009, 10:11:06 PM »
Small reminder: Available sections in hfs.events   ( hfs.exe build 232)

[start]
-->> Launched at every time hfs.exe is executed
-->>  you can put in this section some macro as {.set ini|...... .}

[quit]
-->> before hfs.exe is closed

[server start]
-->>  Lauched every time hfs is switched ON  (key F4  or macro {set ini|active=yes.} )

[server stop]
-->>  Lauched every time hfs is switched OFF  (key F4  or macro {set ini|active=no.} )

[connected]
-->> similar to the 'connected event' in log

[disconnected]
-->> similar to the 'disconnected event' in log

[request]
-->> launched every time hfs becomme a request from a browser

[unauthorized]
-->> launched before the  'unauthorized' section of hfs.tpl

[on macro rename]
-->>perform renaming via {.rename.} macro.
    
****************************************************************

[archive name]
%archive-name%
optional:  %mode%          ->> %mode%  is 'selection' or 'folder'
-->> used to rename a tar file before sending it to the user

*******************************************************************************

[download]
-->> launched when anybody download a file or a TAR archive

[download name]
%item-name%           (it is the default value to be used or nothing)
-->> can be used to rename a download file before sending to the user

[download completed]
-->> Lauched when the last byte of a download file is sended to the user

*******************************************************************************

[upload name]
%item-name%            (it is the default value to be used or nothing)
-->> can be used to rename an uploaded file before saving it in the current folder

[upload completed]
-->> launched every time that an upload of one file is finish with success  

[upload failed]
-->> launched every time that an upload of one file has failed  

*******************************************************************************
[on macro rename]
  %old-name%   and  %new-name%
-->> launched every time that a file is renamed by macro
[on macro move]    not implemented yet
[on macro copy]     not implemented yet
[on macro delete]     not implemented yet
*******************************************************************************

[every (time)]  and    [at (time)]  

[every XXX] and [at HH:MM]

XXX is in seconds, but you can use minutes or hours. examples

[every 5]   (that is 5 seconds)
[every 3 hours]
[every 4h]
[every 15 minutes]
[every 1.5m]   (that is 90 seconds)
[every 1:15 min]  (that is 75 minutes)

HH:MM is instead in standard 24 hours format, but you can do things like

[at 0:00=at 6:00=at 12:00=at 18:00]
this will trigger every six hours, but at specific times.
while [every 6 hours] would trigger at same intervals but differently placed in time.


70
Programmers corner / some changes and corrected bugs
« on: April 10, 2009, 10:13:40 PM »
In aid of rejetto, this topic contains several parts which are dependent downstream

1) An error with %parent-folder%, spaces are codified while with %folder%, they are not it: 
The corrective is:

Quote
    else if name = '%parent-folder%' then
      result:=md.folder.getFolder()        //mod by mars
//     result:=md.folder.parentURL()
    else if name = '%folder-name%' then

2) I discovered some errors of exceptions concerning uploaded and downloaded files, which led me to spend two full days between modifications of main.pas and results  more than functional

When we upload a file, the directory of destination is already known  'md.folder' , no temp folder is needed.

with the correct folder It is possible to find the missing information.


Both variables %item-folder% and %item-url% are defined in the procedure handleitem which is not accessible here, I thus have of to add them for reasons of homogeneity.

an example to test the correct event is
Quote
[upload completed=download completed]
{.set|print|upload is finish with %item-name%
folder : %folder%
folder-resource : %folder-resource%
url : %url%
parent-folder : %parent-folder%
item-url : %item-url%
item-folder : %item-folder%
.}
{.add to log|{.^print.}.}


and it is possible to change the back link into the section [upload-results]
<a href="." target='_parent' class='big'><img src="/~img14"> {.!Back to the folder.}</a>
to
<a href="%url%" class='big'><img src="/~img14"> {.!Back to the folder url.}</a>



Quote
  function runEventScript(event:string; table:array of string):string; overload;
  var
    sa: TStringDynArray;
    md: TmacroData;
  begin
  result:=trim(eventScripts[event]);
  if result = '' then exit;
  sa:=NIL;
  addArray(sa, table);
  fillchar(md, sizeOf(md), 0);
  md.cd:=data;
  try
    if assigned(data.f) then // a file has been uploaded
      // we must encapsulate it in a Tfile to expose file properties to the script. we don't need to cache the object because we need it only once.
      begin
      md.f:=Tfile.createTemp(getFilename(data.f^));
 //    md.folder:=Tfile.createTemp(extractFilePath(md.f.resource));     //disabled by mars
      md.folder:=findfileByURL(decodeURL(md.cd.conn.request.url));  // we must create it here, because getParent() won't work   
      md.f.node:=md.folder.node;
      addArray(sa, [
        '%item-folder%', md.f.getFolder(),
        '%item-url%', md.folder.url()+md.f.name
      ]);

      end
    else if assigned(f) then
      md.f:=f
    else if assigned(data.lastFile) then
      begin

      md.f:=data.lastFile;
      md.folder:=findfileByURL(md.f.getFolder());
      addArray(sa, [
        '%item-folder%', md.f.getFolder(),
        '%item-url%', md.folder.url()+md.f.name
      ]);
      end;


    if assigned(md.f) and (md.folder = NIL) then
      md.folder:=md.f.getParent();
    tryApplyMacrosAndSymbols(result, md, sa);

  finally
    if assigned(data.f) then
      begin
      freeAndNIL(md.f);
 //      freeAndNIL(md.folder);    //disabled by mars
      end;
    end;
  end; // runEventScript

71
Programmers corner / how stop section's hacker ( ACCEPTED BY THE BOSS)
« on: April 08, 2009, 12:45:42 AM »
Since the extension of the call of sections through the url /~section, it is possible to obtain certain not wished effects

All the sections are accessible since the url  http://ip:port/~section

To prevent that certain sections are visible by url, but available by a call with a macro {.$name.}, here is what I propose:

[name| no log | private ]     ('no log' is optionnal).

classelib.pas
Quote
  TtplSection = record
    name, txt: string;
    nolog: boolean;
    nourl: boolean;    //add by mars
    end;
......

  procedure saveInSection();
  ....
  // there may be flags after |
  s:=cur_section;
  cur_section:=chop('|', s);
  ss:=split('|', s);               //add by mars
  for i:=0 to length(ss)-1 do ss:=trim(ss); //add by mars
  base.nolog:=idxOf('no log', ss) >= 0;     //add by mars
  base.nourl:=(ansiPos('private', s) > 0)or(ansiPos('protect', s) > 0);   //add by mars

//  base.nolog:=ansiPos('no log', s) > 0;
  // there may be several section names separated by =
.....

main.pas
Quote
....
  // provide access to any [section] in the tpl, included [progress]
  if data.urlvars.values['mode'] = 'section' then
    s:=or_(data.urlvars.values['id'], 'no-id') // no way, you must specify the id
  else if (f = rootFile) and (urlCmd > '') then
    s:=copy(urlCmd,2,MAXINT)
  else
    s:='';
  if (s > '') and tpl.sectionExist(s)
    and not tpl.getSection(s).nourl //add by mars
    then // section [] is not accessible
    begin
    getPage(s, data);
    exit;
    end;

  // from here on, we manage only services with no urlCmd.
.....

All the sections referenced in a template by one /~name shall not have to be private at the risk of inaccessibility as this example:

  <link rel="stylesheet" href="/~style.css" type="text/css">
  <link rel="stylesheet" href="/~style.menu.css" type="text/css">

 <frame name='progress' src="/~progress" scrolling='auto' marginwidth='0'>

 and more ...

72
Programmers corner / server ON/OFF events
« on: April 08, 2009, 12:13:08 AM »
main.pas
Quote
function startServer():boolean;
.......
result:=TRUE;
runeventscript('startserver');      //add by mars
end; // startServer

procedure stopServer();
begin
if assigned(srv) then
  begin
  runeventscript('stopserver');      //add by mars
  srv.stop();
  end;

end;

hfs.events
Quote
For help on how to use this file please refer http://www.rejetto.com/wiki/?title=HFS:_Event_scripts

[startserver]
{.add to log|Hfs entered phase of activity.}

[stopserver]
{.add to log|Hfs entered phase of sleep.}


Here we are, it can be of use to the other more interesting features as the macro {.set ini.} ;)

73
Programmers corner / error with macro 'member of'
« on: April 03, 2009, 09:26:56 PM »
I ask me a question about the macro 'to member of'. When a user's name is given in parameter, the macro return a result not empty if it is up to one of the groups that we wish to test.

It seems in the sources that if the account does not exist, then the name of the on-line user is taken and can give a bad  result.

Quote
  s:=par(1, 'user');
  if s > '' then
    a:=getAccount(s);
  if (a = NIL) and assigned(md.cd) then
    a:=md.cd.account;

I make a mistake certainly, but in my opinion if a name is then supplied the current user should not interfere. To convince itself, it is enough to associate its own account to an existing group 'group1' and to use the macro following one with the unexisting account 'taratata':

Quote
<body>
{.if|{.member of|group1|taratata.}|<hr>yep<hr>.}

The obtained result is a magnificent 'YEP', what is not in accordance with the reality of the made test.

The code adequate would rather be the one this
Quote
   procedure memberOf();
  var
    a: Paccount;
    s: string;
  begin
  a:=NIL;
  s:=par(1, 'user');
  if s > '' then a:=getAccount(s)
    else if (pars.count<2) and assigned(md.cd) then a:=md.cd.account;
  result:='';
  if a = NIL then exit;
  trueIf(findEnabledLinkedAccount(a, split(';',par(0,'group'))) <> NIL);
  end; // memberOf


current user by using
{.member of|group1.}     and not by  {.member of|group1|.}

74
Programmers corner / Programmer's request for rejetto
« on: March 20, 2009, 03:12:39 PM »
Demand for some macro supplementary

one switch ON/OFF   
{.server on.} and {.server off.}
     or
{.server|on.} and {.server|off.}

to be using with a time event: 
  {.if|{.in range|22|%time%|24.}{.in range|00|%time%|08.}| {.server|off.} | {.server|on.} /if.}

In accompaniment of the macro 'disconnect', it would indeed be necessary have a macro 'busy' which prevents a person from logging by sending him a web page indicating to him that the server is at present occupied and with re-trying later

{.if|condition|{.busy.}.}

I know this quer you are going to answer me: use a section {.$busy }. But I do not want to use of sections because so it will be possible to use a button 'server as busy' in hfs to put the server in busy mode, and not inevitably in mode off.

75
Quote
....
  end; // allowedTo

  function timeFiltered(filetime: Tdatetime):boolean;       //mars time good
  var
    older, newer, curtime: Tdatetime;
  begin
  curtime:=now();
  if not TryStrToDate(data.urlvars.Values['older'], older) then
    older:=incDay(curtime,-strtointdef(data.urlvars.Values['older'],-1));
  if not TryStrToDate(data.urlvars.Values['newer'], newer) then
    newer:=incDay(curtime,-strtointdef(data.urlvars.Values['newer'],integer(trunc(curtime))));
  result:=if_(newer <= older,(newer <= filetime) and (filetime <= older),(filetime < older)or(newer < filetime));
  end;


  procedure includeFilesFromDisk();
  var
.....

  procedure includeFilesFromDisk();
......
   // we don't list these entries
        if (sr.name = '.') or (sr.name = '..')
        or isCommentFile(sr.name) or isFingerprintFile(sr.name) or sameText(sr.name, DIFF_TPL_FILE)
        or not hasRightAttributes(sr.attr)
        or stringExists(sr.name, namesInVFS)
        or not timefiltered(filedateToDatetime(sr.Time))      //mars time good
        then continue;

        filteredOut:=not fileMatch( if_(sr.Attr and faDirectory > 0, foldersFilter, filesFilter), sr.name)
          or not fileMatch( if_(sr.Attr and faDirectory > 0, urlFoldersFilter, urlFilesFilter), sr.name);
        // if it's a folder, though it was filtered, we need to recur 
.....
  end; // includeFilesFromDisk
......

  procedure includeItemsFromVFS();
......
    // filtered out
    if not fileMatch( if_(f.isFolder(), foldersfilter, filesfilter), f.name)
    or not fileMatch( if_(f.isFolder(), urlFoldersfilter, urlFilesfilter), f.name)
    or not timefiltered(f.mtime)  //mars time good
     then
      begin
      if recursive then recurOn(f);
      continue;
      end;
....

two new urlvars:    newer and older     ( than a date or number of days)

usage examples:
   files newest since a date to now             ?sort=d&reverse&newer=22/02/2009
   files newest since a few days to now       ?sort=d&reverse&newer=20

   files oldest that a date                          ?sort=d&reverse&older=01/03/2009
   files oldest since a few days before now   ?sort=d&reverse&older=15

files between two dates or days
                  ?sort=d&reverse&newer=20&older=15
                  ?sort=d&reverse&newer=22/02/2009&older=01/03/2009
                  ?sort=d&reverse&newer=20&older=01/03/2009
                  ?sort=d&reverse&newer=22/02/2009&older=15


only files since never=22/02/2009 to older=01/03/2009

files outside two dates or days
    we have to invert values of dates never=01/03/2009 and older=22/02/2009
     files are those from 01/01/1889 to  oldest than older=22/02/2009  + from newest never=01/03/2009 to now

             ?sort=d&reverse&older=22/02/2009&newer=01/03/2009
             ?sort=d&reverse&older=20&newer=15
             ?sort=d&reverse&older=22/02/2009&newer=15
             ?sort=d&reverse&older=20&newer=01/03/2009


Pages: 1 ... 3 4 5 6 7 8