rejetto forum

Software => HFS ~ HTTP File Server => Topic started by: rleidt on September 02, 2016, 01:04:59 PM

Title: set expiry to delete content
Post by: rleidt on September 02, 2016, 01:04:59 PM
I would be nice to be able to set expiry date on folders so that any posted file would be auto-deleted within "x hours/days/etc." time of it being uploaded. At minimal the root folder and all sub folders, but would be nicer if it could be set differently for each folder.

For me I'm thinking at the HFS console, but others may want an option for the users to be able to set also. Maybe even at the file level.

If just at the console at the root directory (inherited by sub directories) that would be a nice start.

If this can't be done, what happened to the option to allow/disallow folder creation? I am currently using a batch file and task manager to clean up, but people keep making folders which the batch file doesn't know about.

I moved from an FTP server to HFS many years ago because it allowed me to easily remove files on a schedule using batch files after a manger found staff had left confidential material in a folder for many months. That folder was intended for general info with credentials shared with many of our clients. Now I am faced with the same problem (using Ver 2.3i).

I think an expiry feature would make HFS complete.
Title: Re: set expiry to delete content
Post by: bmartino1 on September 02, 2016, 02:38:04 PM
this looks to be an interesting challenge with html program and macros, i believe this to be accomplished via the macros and the hfs template.

-------------------------------
or even have the PC do it on a schedule task with a trigger

http://www.sevenforums.com/general-discussion/234715-how-schedule-folder-content-deleting-task.html
https://community.spiceworks.com/topic/447841-automatically-delete-files-older-than-x-days
http://stackoverflow.com/questions/51054/batch-file-to-delete-files-older-than-n-days

i can see a trigger when hfs revives file to countdown and delete the file...

-------------------------------

or you can setup folder redirects so you copy temp info as teh fiels upladoed stay on teh server....
http://www.rejetto.com/forum/hfs-~-http-file-server/file-link-redirects-code-301/

Either way, this is a programming side of HFS
so start here:
http://www.rejetto.com/wiki/index.php?title=HFS:_scripting_commands

Title: Re: set expiry to delete content
Post by: rleidt on September 02, 2016, 05:41:14 PM
I don't see anything here that solves the issue when new subfolders are created except "forfiles". However, "forfiles" is based on the date of the file modification, not when it was uploaded to HFS. Maybe in the HFS scripting, but that's beyond me.

Another useful option might be to delete after x successful downloads, but I think the expiry would still be very important for me.

Thank you!
Title: Re: set expiry to delete content
Post by: Mars on September 02, 2016, 05:45:21 PM
if you have the opportunity to use batch files on windows (cmd or bat files) for drain work in files, you can start using them from a hfs event at regular intervals

http://www.rejetto.com/forum/programmers-corner/scripts-and-events-in-hfs/msg1042304/#msg1042304

by using macro like

[at 00:45]
{.exec|c:\purge.bat.}


EDIT:
@rleidt
according to the conditions you want to use, I finally found a relatively simple solution by overloading part of the existing template using a diff-template


This use is based on the default template of  hfs

on VFS -> select the real folder -> go to his properties -->edit diff template

Quote from: adaptation
[file=folder=link|private]
{.if|{.and|{.is file|%item-resource%.}|{.>|{.round|{.calc|%now%-%item-modified-dt%.}.}|60.}/and.}|
{:{.delete|%item-resource%|bin=0|forced=1.}:}|

[+file=+folder=+link|private]
   <tr class='{.if|{.mod|{.count|row.}|2.}|even.}'><td>
        <input type='checkbox' class='selector' name='selection' value="%item-url%" {.if not|{.or|{.get|can delete.}|{.get|can access.}|{.get|can archive item.}.}|disabled='disabled'.} />
      {.if|{.is file protected|%item-name%.}|<span class='flag'>&nbsp;NEW&nbsp;</span>.}
      {.if not|{.get|can access.}|<img src='/~img_lock'>.}
      <a href="%item-url%"><img src="%item-icon%"> %item-name%</a>
      {.if| {.length|{.?search.}.} |{:{.123 if 2|<div class='item-folder'>{.!item folder.} |{.breadcrumbs|{:<a href="%bread-url%">%bread-name%/</a>:}|from={.count substring|/|%folder%.}/breadcrumbs.}|</div>.}:} .}
      {.123 if 2|<div class='comment'>|{.commentNL|%item-comment%.}|</div>.}

[+file]
<td>%item-size%B<td>%item-modified%<p>{.round|{.calc|%now%-%item-modified-dt%.}.}<td>%item-dl-count%

[+folder]
<td class='nosize'>folder<td>%item-modified%<p>{.round|{.calc|%now%-%item-modified-dt%.}.}<td>%item-dl-count%

[+link]
<td class='nosize'>link<td colspan='2'>

[+file=+folder=+link|private]
/if.}

the operating principle is the following
On each visit of the folder and his sub-folders, we compare the date of each file with the current date, if the number of days exceeds the figure set in red (here 60), the the file is not listed on web page and is deleted from the server (when his read-only attribute is not set) without using the trash, destruction is final

This works only on files, folders cannot been deleted by using this method

if you plan to experiment this, I suggest the utility "Attribute Changer" to change the dates of the files in the directory

download link : https://www.petges.lu/home/

Title: Re: set expiry to delete content
Post by: rleidt on September 06, 2016, 05:12:51 PM
Cool!

This is counting days from the time the file is uploaded to HFS? (as opposed to the creation date of the file). If so, it's exactly what I need and seems like it would be steps away from being in the GUI, if there was a desire to add the feature. "0" would have to mean "don't expire".  Some users might want to be able to take it down to hours, but days works for me.

Thanks!,
Bob

Edit:
Oh, I see your using a utility to change the date/time. Users uploading would all be required to do that including our clients. That's not going to work for me.

Next edit:
I just uploaded a file and the date of the file was changed to the current date which means this should work.

I've made a test folder with 5 additional levels of folders. Level 4 purposely has no files uploaded and levels 1,2,3,5 and 6 have varying numbers of files. I've set the days to "1" (or in your language "1." LOL). I've also thrown in extra empty and populated folders at a couple of levels. I'll report back tomorrow or Friday.
Title: Re: set expiry to delete content
Post by: rleidt on September 09, 2016, 11:48:17 AM
OK, the day before yesterday I set up the folders and had the script set to delete after 1 day.

Some files were uploaded in the AM and some later in the day. Mid day nothing had been deleted. I was quite busy in the PM and didn't check, but this morning all the test files were gone.

I don't understand the script language but maybe "round" takes the file date to midnight? If so then perhaps these were all deleted at midnight 1 day later? That would make it wipe, in this case, a minimum of 1 day and not more than two from the time of upload, which would be perfect. I assume if set to, say, 30 days it would delete between 30 and 31 days of the time of upload.

Is this what it was supposed to do of should those files uploaded two mornings ago have been deleted yesterday morning (24 hours later)?

Thank, Bob

Oh, two other questions:
How would I put a REM line into this. I'd like to add instruction just before Line 2 on how to set the # of days.
Is there any sort of limit? (like can I set it for five years (however many days that would be))
Title: Re: set expiry to delete content
Post by: bmartino1 on September 09, 2016, 01:17:15 PM
you can bring the script to ".5" 12 hours or ".25" 6 hours....etc...
(try to change to hours for the day fix)

but yes, from what i tested, once the file is there, within a 24(1day) hour perid, any file uploded should be gone...

-------------------------------------------------
for comments in the code (REM):
http://www.rejetto.com/wiki/index.php?title=HFS:_Comment_files&action=edit

you can use html comments as well
http://www.w3schools.com/tags/tag_comment.asp
 
Title: Re: set expiry to delete content
Post by: rleidt on September 09, 2016, 05:38:00 PM
I'll have to test again as a sanity check. I'm 100%sure my files were there over 24 hours after the upload with days set to 1. Maybe because my login hadn't expired? It seems to hang on for quite a while. I never really took much notice to how long before it times out and I need to re-enter credentials.

I wonder how difficult it would be to have it not delete on a Saturday or Sunday? If someone uploads a file at 4:00 Friday PM I'd want to there for Monday, however during the week I only want it there for the next day. The odd long weekend shouldn't be a terribly big issue. Everyone here bails out early on the Friday before anyway, it seems.
Title: Re: set expiry to delete content
Post by: Mars on September 09, 2016, 07:56:44 PM
just for example, back the clock of the server the number of days required, then uploading files using browser transfer, from the client to the server, so it should be dated a few days, and then deliver the server to the right date and preview the contents of the file from the browser, all files older than the number of days selected should disappear

IMPORTANT:
the files are not automatically deleted after the number of selected days, it's necessary that a person visits the web page containing the files concerned that they are effectively removed, this is the drawback of the simplicity of this solution

otherwise you have to make development, external to hfs, using a file containing the names and number of days of life for each of them, and manage the counting values,
 
if it is not too difficult to add data to each download for numbers of days from HFS, deletions management can be done at a certain time using VBS or BAT scripts from windows
Title: Re: set expiry to delete content
Post by: dj on September 10, 2016, 06:27:55 AM
I wonder how difficult it would be to have it not delete on a ... Sunday?

replace 1 (number of days) with
Code: [Select]
{. if |{.{.time|ddd.}=Sun.} | 2 | 1 .}
Title: Re: set expiry to delete content
Post by: bmartino1 on September 10, 2016, 06:01:28 PM
just for example, back the clock of the server the number of days required, then uploading files using browser transfer, from the client to the server, so it should be dated a few days, and then deliver the server to the right date and preview the contents of the file from the browser, all files older than the number of days selected should disappear

IMPORTANT:
the files are not automatically deleted after the number of selected days, it's necessary that a person visits the web page containing the files concerned that they are effectively removed, this is the drawback of the simplicity of this solution

otherwise you have to make development, external to hfs, using a file containing the names and number of days of life for each of them, and manage the counting values,
 
if it is not too difficult to add data to each download for numbers of days from HFS, deletions management can be done at a certain time using VBS or BAT scripts from windows

My solution to the "VISIT for file DELETION" is to add the folder as a real folder and have a cmd script to open/close a web browser("or keep one open at the page...") run with the meta page refresh X amount of time....(so there will be two folder of the same directory added, one for scripts to delete, the other for "clients" to VIST)

http://www.w3schools.com/tags/att_meta_http_equiv.asp


---------------------------------

replace 1 (number of days) with
Code: [Select]
{. if |{.{.time|ddd.}=So.} | 2 | 1 .}
 
if it is not too difficult to add data to each download for numbers of days from HFS, deletions management can be done at a certain time using VBS or BAT scripts from windows

I'm not sure the macros can be programmed for days of week, as it doesn't know when "monday" or "sunday" is ....
best i know is to use css for a calendar, and probably pull days form that
http://www.w3schools.com/howto/howto_css_calendar.asp
Title: Re: set expiry to delete content
Post by: Mars on September 10, 2016, 07:54:44 PM
Quote
I'm not sure the macros can be programmed for days of week, as it doesn't know when "monday" or "sunday" is

it must never despair ;)

(monday,tuesday,wednesday,thursday,friday,saturday,sunday)
Because time is given in the system language, monday to sunday have to be replaced by their translations

in file  hfs.events
[at 0:00]
{.switch|theday|,|monday,tuesday,saturday|{:{if|{.=|{.lower|{.time|dddd.}.}|{.^theday.}/=.}|{:{.exec|external_clear_cmd.}:}/if.}:}/switch.}

every 0h00, EXEC will be performed on days specified to run the script external_clear_cmd
Title: Re: set expiry to delete content
Post by: rleidt on September 12, 2016, 12:48:36 PM
DJ, Re:

{. if |{.{.time|ddd.}=Sun.} | 2 | 1 .}

Can this code have Saturday added to it? Like ' or if  {.time|ddd.}=Sat.}. '

(Excuse me for not being a programmer. I did some "basic" many years ago and still do some fancy batch files now and again.)
Title: Re: set expiry to delete content
Post by: bmartino1 on September 12, 2016, 02:50:40 PM
DJ, Re:

{. if |{.{.time|ddd.}=Sun.} | 2 | 1 .}

Can this code have Saturday added to it? Like ' or if  {.time|ddd.}=Sat.}. '

(Excuse me for not being a programmer. I did some "basic" many years ago and still do some fancy batch files now and again.)

...
that what this code is ....

in file  hfs.events
[at 0:00]
{.switch|theday|,|monday,tuesday,wednesday,thursday,friday,saturday,saturday|{:{if|{.=|{.lower|{.time|dddd.}.}|{.^theday.}/=.}|{:{}:}/if.}:}/switch.}

now you can call "theday" and it will say it it is saturday/sunday/etc.... which can be put if saturday do ntohing, if sunday do nothing, if monday restart teh deltins stuff.. if friday at ...bla bla  time... etc..etc...

i would even add it to hfs info box to verfy waht "day " HFS is saying it is...
Title: Re: set expiry to delete content
Post by: Mars on September 12, 2016, 04:34:34 PM
@bmartino1

I made a mistake by using a switch, it is not the good macro, I fix my mistake

[at 0:00]
{.set|#actionday|0.}
{.for each|theday|,|monday,tuesday,saturday|{:{if|{.=|{.lower|{.time|dddd.}.}|{.^theday.}/=.}|{:{.set|#actionday|1.}:}/if.}:}/switch.}

theday is locally variable in event file
#actionday is a persistent variable, it can be used in the template as a boolean var {.^#actionday.}
Title: Re: set expiry to delete content
Post by: dj on September 12, 2016, 05:36:20 PM
pseudocode:

if Sunday then 3
else if Saturday then 2
else 1

Code: [Select]
{. if |{.{.time|ddd.}=Sun.} | 3 | {:{.if|{.{.time|ddd.}=Sat.}|2|1.}:} .}
remind to replace Mon to Sun by their translations
Title: Re: set expiry to delete content
Post by: rleidt on September 16, 2016, 01:50:47 PM
So for 3 days from time of upload to delete but no deletion done Saturday, Sunday or Monday I would add into it like this (below) and set the #days to 3 as before ?

Or maybe DJ's post (just before this post) works too:

"if Sunday then 3
else if Saturday then 2
else 1

Code: [Select]
{. if |{.{.time|ddd.}=Sun.} | 3 | {:{.if|{.{.time|ddd.}=Sat.}|2|1.}:} .}

Can one of you piece this together so that I can copy and paste to test. In the end I'd just like to know where to set the # of days before deletion. I apologize again for not knowing this language but very happy you all jumped on the challenge.

********

[file=folder=link|private]

[at 0:00]
{.set|#actionday|0.}
{.for each|theday|,|tuesday,wednesday,thursday,friday|{:{if|{.=|{.lower|{.time|dddd.}.}|{.^theday.}/=.}|{:{.set|#actionday|1.}:}/if.}:}/switch.}

{.if|{.and|{.is file|%item-resource%.}|{.>|{.round|{.calc|%now%-%item-modified-dt%.}.}|3.}/and.}|
{:{.delete|%item-resource%|bin=0|forced=1.}:}|

[+file=+folder=+link|private]
   <tr class='{.if|{.mod|{.count|row.}|2.}|even.}'><td>
        <input type='checkbox' class='selector' name='selection' value="%item-url%" {.if not|{.or|{.get|can delete.}|{.get|can access.}|{.get|can archive item.}.}|disabled='disabled'.} />
      {.if|{.is file protected|%item-name%.}|<span class='flag'>&nbsp;NEW&nbsp;</span>.}
      {.if not|{.get|can access.}|<img src='/~img_lock'>.}
      <a href="%item-url%"><img src="%item-icon%"> %item-name%</a>
      {.if| {.length|{.?search.}.} |{:{.123 if 2|<div class='item-folder'>{.!item folder.} |{.breadcrumbs|{:<a href="%bread-url%">%bread-name%/</a>:}|from={.count substring|/|%folder%.}/breadcrumbs.}|</div>.}:} .}
      {.123 if 2|<div class='comment'>|{.commentNL|%item-comment%.}|</div>.}

[+file]
<td>%item-size%B<td>%item-modified%<p>{.round|{.calc|%now%-%item-modified-dt%.}.}<td>%item-dl-count%

[+folder]
<td class='nosize'>folder<td>%item-modified%<p>{.round|{.calc|%now%-%item-modified-dt%.}.}<td>%item-dl-count%

[+link]
<td class='nosize'>link<td colspan='2'>

[+file=+folder=+link|private]
/if.}
Title: Re: set expiry to delete content
Post by: rejetto on September 18, 2016, 09:04:35 AM
nice project guys,
anyway since upload time translates to creation time of the file, you should consider and independent solution that's not really bound to HFS.

https://www.google.com/search?q=windows+delete+files+older+than

The perfect solution i'd look for is a software that monitors the file system, so to be efficient and not have to scan the file system periodically.

Otherwise you can accept simpler solutions requiring periodic execution, that you can accomplish thanks to HFS, like

[every 3h]
{.exec| your command .}


refer to the documentation for details about it
Title: Re: set expiry to delete content
Post by: Mars on September 18, 2016, 05:03:08 PM
@rleidt

I think you made a little mix

go to Menu -->Other Options -->Edit event scripts
or
in the hfs.exe  directory, create a text file called HFS.EVENTS and edit it

 add only the quoted following content in it

Quote
[at 0:00]
{.set|#actionday|0.}
{.switch|{.lower|{.time|dddd.}.}|,|tuesday,wednesday,thursday,friday|{:{.set|#actionday|1.}:}/switch.}

at 0:00 set the var #actionday to 1 when the current day is in the list, else 0


----------------------------------------------------------------------------
on VFS -> select the real folder -> go to his properties -->edit diff template

Quote
    [file=folder=link|private]
    {.if|{.and|{.^#actionday.}|{.is file|%item-resource%.}|{.>|{.round|{.calc|%now%-%item-modified-dt%.}.}|60.}/and.}|
    {:{.delete|%item-resource%|bin=0|forced=1.}:}|

    [+file=+folder=+link|private]
       <tr class='{.if|{.mod|{.count|row.}|2.}|even.}'><td>
            <input type='checkbox' class='selector' name='selection' value="%item-url%" {.if not|{.or|{.get|can delete.}|{.get|can access.}|{.get|can archive item.}.}|disabled='disabled'.} />
          {.if|{.is file protected|%item-name%.}|<span class='flag'>&nbsp;NEW&nbsp;</span>.}
          {.if not|{.get|can access.}|<img src='/~img_lock'>.}
          <a href="%item-url%"><img src="%item-icon%"> %item-name%</a>
          {.if| {.length|{.?search.}.} |{:{.123 if 2|<div class='item-folder'>{.!item folder.} |{.breadcrumbs|{:<a href="%bread-url%">%bread-name%/</a>:}|from={.count substring|/|%folder%.}/breadcrumbs.}|</div>.}:} .}
          {.123 if 2|<div class='comment'>|{.commentNL|%item-comment%.}|</div>.}

    [+file]
    <td>%item-size%B<td>%item-modified%<p>{.round|{.calc|%now%-%item-modified-dt%.}.}<td>%item-dl-count%

    [+folder]
    <td class='nosize'>folder<td>%item-modified%<p>{.round|{.calc|%now%-%item-modified-dt%.}.}<td>%item-dl-count%

    [+link]
    <td class='nosize'>link<td colspan='2'>

    [+file=+folder=+link|private]
    /if.}

the action is running every day indicated, and only if a user display the directory on that day

otherwise you have to use an external program to perform the actions of delete, launched with the exec macro as told by rejetto