Page 1 of 1

Script to change login background .jpg daily

Posted: Tue Jul 09, 2013 1:07 pm
by cinders
Can anyone help me? I have no idea how I would do this via a script.

I'm trying to write a script to daily change my login page background.

The idea was to keep 30 small jpg files in \hotspot\img\background\ - The file names would be 1.jpg, 2.jpg - all the way to 30.jpg

Currently my hotspot login uses the file \hotspot\img\background.jpg as the background.

I would need a script that would copy \hotspot\img\background\1.jpg to \hotspot\img\background.jpg at a set time (maybe 5am) each day, but on the next day copy 2.jpg, next day 3.jpg, etc.

Could any point me in the right direction?

Cheers,
Cinders.

Re: Script to change login background .jpg daily

Posted: Tue Jul 09, 2013 1:10 pm
by normis
can't you just create 3 directories with different login pages, and use the script to change "hotspot directory" parameter in the hotspot server settings?

Re: Script to change login background .jpg daily

Posted: Tue Jul 09, 2013 1:23 pm
by cinders
Surely it would be easier just to change a single background image file each day?

Re: Script to change login background .jpg daily

Posted: Tue Jul 09, 2013 1:24 pm
by normis
it would not be, as routeros doesn't have file operation functions, like rename.

Re: Script to change login background .jpg daily

Posted: Tue Jul 09, 2013 1:30 pm
by cinders
Ah OK. :D

Thanks for the info. I'll start working on it. :D

Re: Script to change login background .jpg daily

Posted: Tue Jul 09, 2013 1:38 pm
by SurferTim
If you download the image from a server using "/tool fetch", you can rename the file enroute.
/tool fetch mode=http address=1.2.3.4 src-path=background2.gif dst-path=/hotspot/img/background.gif
edit: Oops! Forgot to add the mode parameter.

Re: Script to change login background .jpg daily

Posted: Tue Jul 09, 2013 1:48 pm
by cinders
Tim,

That's a great idea!

Because the hotspot runs at http server, is it possible to download it from itself? i.e. 127.0.0.1 ?

Re: Script to change login background .jpg daily

Posted: Tue Jul 09, 2013 1:49 pm
by SurferTim
That I have not tried, but an interesting concept. Give it a shot and see how it does. Let me know! :D

Re: Script to change login background .jpg daily

Posted: Tue Jul 09, 2013 1:55 pm
by cinders
No worries - I'll drop an update on this thread, thanks again for the great idea! :D

Re: Script to change login background .jpg daily

Posted: Thu Jul 11, 2013 2:32 am
by cinders
Tim,

Unfortunately it wouldn't work with the image files in the hotspot folder and trying to grab them from local host.

No problem, I put them on my Radius server and it works perfectly! Thanks again for the idea. :)

All the best,
Cinders.

Re: Script to change login background .jpg daily

Posted: Mon Jul 15, 2013 7:12 am
by tvermoes
Try using javascript on the page you wish to change background on.

You can easily modify this to your needs :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
  <title></title>
</head>

<body>
<script  type="text/javascript">
/*<![CDATA[*/
var ToDay=new Date();
var Month=ToDay.getMonth();
var Date=ToDay.getDate();
var Image=false;

if (ToDay.getFullYear()==2010){
 if (Month==0){  // January
  if (Date>=20&&Date<=30){
   Image='One.gif';
  }
 }
 if (Month==1){  // Febuary
  if (Date>=20&&Date<=25){
   Image='Three.gif';
  }
 }

}

if (Image){
 document.body.style.backgroundImage='url(http://192.168.88.1/img/'+Image+')';
}

/*]]>*/
</script>
</body>

</html>

Re: Script to change login background .jpg daily

Posted: Mon Jul 15, 2013 9:57 am
by cinders
Many thanks for the script above. :D