Welcome to WebmasterWorld Guest from 35.171.45.91

Forum Moderators: Ocean10000 & phranque

Message Too Old, No Replies

time window to serve request?

     
1:10 am on Apr 8, 2015 (gmt 0)

Junior Member

5+ Year Member Top Contributors Of The Month

joined:Sept 13, 2013
posts: 193
votes: 1


Just out of curiosity, is there any way to do a conditional serve based on time/date? As in, you ask for this file, and you can have it if it's after 2:30pm on April 10. If not, something else happens.

I'd like to post something to coincide with a particular event, but I might not be around to do that posting. It would be nice to set it up so the file is made available when I want it to be made available and not before. That would be quite handy.
4:09 am on Apr 8, 2015 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 9, 2011
posts:15932
votes: 887


is there any way to do a conditional serve based on time/date?

Yes, but I'm ### if I can find it.

phranque? You out there? I remember this question coming up once-- but can't remember any further details, and "question asked at WebmasterWorld, possibly but not necessarily in the Apache subforum, within the past four years" will not get us far enough :(

:: buying time ::

Is a detour to php viable? This is the closest [webmasterworld.com] I can find, but I'm not sure it was the post I was thinking of.
7:12 am on Apr 8, 2015 (gmt 0)

Senior Member

WebmasterWorld Senior Member penders is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2006
posts: 3153
votes: 7


mod_rewrite has quite a few TIME_xxx variables which I'm sure you can do something with, coupled with the >, < and = (lexicographical) operators.

Maybe something like... if the date/time is before 2:30pm on April 10 then serve a 403... (?)


RewriteCond %{TIME} <20150410143000
RewriteRule ^mypost\.html - [F]
4:15 pm on Apr 8, 2015 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 9, 2011
posts:15932
votes: 887


Oh, ###, oh, ###. And not even tucked away on the Obscure Extra Stuff page, or newly added in 2.4. Right there in the main block of RewriteCond options. (Would be nice if they'd offer some hint what format each of them comes in, but I'll do some experimenting later and then I'll know.)

... and that's why we tell people to ask questions in the public forums instead of addressing one individual person by PM.

Remember to adjust if your server is located in a different time zone, or in a jurisdiction with different DST rules.
4:48 pm on Apr 8, 2015 (gmt 0)

Senior Member

WebmasterWorld Senior Member wilderness is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Nov 11, 2001
posts:5507
votes: 5


Cron jobs allow such things
6:46 pm on Apr 8, 2015 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 9, 2011
posts:15932
votes: 887


I checked format. It's pretty straightforward, barring one detail.

TIME = 20150408114155
which is composed of
TIME_YEAR
TIME_MON
TIME_DAY
TIME_HOUR
TIME_MIN
TIME_SEC
The year is four digits; all others are two digits, with leading 0 as needed. I didn't check the 12 o'clock hours, but it seems safe to assume it's a 24-hour clock beginning at 0, same as ordinary logs. Europeans note that the month comes before the day, since it's ordered from biggest to smallest unit.

The one extra is
TIME_WDAY
which is one digit, starting with Monday -- that is, today (Wednesday where I and my server live) is 3, not 4. I don't know whether Sunday is 0 or 7; if nobody knows for sure, I'll check one of these weekends when I remember.
6:59 pm on Apr 8, 2015 (gmt 0)

Senior Member

WebmasterWorld Senior Member wilderness is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Nov 11, 2001
posts:5507
votes: 5


Sunday is 0
per [drupal.org...]
5:30 pm on Apr 9, 2015 (gmt 0)

Junior Member

5+ Year Member Top Contributors Of The Month

joined:Sept 13, 2013
posts: 193
votes: 1


That's pretty slick. Thanks! I'll try it. And yes, certainly, the time will be checked against the servers own clock.

Now, I guess the way one would use TIME_WDAY is just if the test was against day of week. So maybe

RewriteCond %{TIME_WDAT} <3
RewriteRule ^mypost\.html - [F]

Means you get 403'd if it's before Wednesday? Is that right? Of course Tuesday could be after before or after Wednesday, so it isn't quite clear how that would work,
6:43 pm on Apr 9, 2015 (gmt 0)

Senior Member

WebmasterWorld Senior Member penders is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2006
posts: 3153
votes: 7


Means you get 403'd if it's before Wednesday?


Well... you get 403'd if today is Sunday, Monday or Tuesday - that's any Sunday, Monday or Tuesday - which I think answers the second part of your question.

(Thanks Lucy24 and wilderness for the research)
6:52 pm on Apr 9, 2015 (gmt 0)

Junior Member

5+ Year Member Top Contributors Of The Month

joined:Sept 13, 2013
posts: 193
votes: 1


Ah, OK, so it's before a specified day in THAT week. That clarifies. Thanks. So I guess

RewriteCond %{TIME_WDAT} <0
RewriteRule ^mypost\.html - [F]

Would end up never serving it at all!
7:03 pm on Apr 9, 2015 (gmt 0)

Senior Member

WebmasterWorld Senior Member penders is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2006
posts: 3153
votes: 7


...so it's before a specified day in THAT week


Well, not just "THAT" week; any week! The last Tuesday before Christmas would also be denied access. TIME_WDAY is simply a number representing the day of the week.

And that should be TIME_WDAY (not TIME_WDAT).
7:08 pm on Apr 9, 2015 (gmt 0)

Junior Member

5+ Year Member Top Contributors Of The Month

joined:Sept 13, 2013
posts: 193
votes: 1


Excuse me. TIME_WDAY.

And yes, it would refuse to serve on ANY Sunday, Monday or Tuesday if TIME_WDAY was set to 3. So it's not a setting to refuse service any day before a particular Wednesday, but any real day of the week that is before Wednesday, but after Saturday. That would include only those three days.

All clear.
8:16 pm on Apr 9, 2015 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 9, 2011
posts:15932
votes: 887


RewriteCond %{TIME_WDAT} <0
RewriteRule ^mypost\.html - [F]
Would end up never serving it at all!

I think it would end up always serving it, since TIME_WDAY is never <0. The WDAY element is most useful if you want to serve different content on weekends, say, or all Fridays. For your purposes, it's probably easiest to use the full TIME string, and compare access time to that.

Since < and > mean "lexicographically blahblah" (Apache-speak for "comes before or after it in the dictionary") I think you can omit the hours, minutes and seconds. If < and > were interpreted numerically, you would of course need to have all digits.
8:49 pm on Apr 9, 2015 (gmt 0)

Junior Member

5+ Year Member Top Contributors Of The Month

joined:Sept 13, 2013
posts: 193
votes: 1


I guess that's right. TIME_WDAY is always 0,1,2,3,4,5,6.