Community discussions

MikroTik App
 
cinders
newbie
Topic Author
Posts: 46
Joined: Fri Oct 28, 2011 3:09 am

Script to change login background .jpg daily

Tue Jul 09, 2013 1:07 pm

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.
 
User avatar
normis
MikroTik Support
MikroTik Support
Posts: 26968
Joined: Fri May 28, 2004 11:04 am
Location: Riga, Latvia
Contact:

Re: Script to change login background .jpg daily

Tue Jul 09, 2013 1:10 pm

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?
 
cinders
newbie
Topic Author
Posts: 46
Joined: Fri Oct 28, 2011 3:09 am

Re: Script to change login background .jpg daily

Tue Jul 09, 2013 1:23 pm

Surely it would be easier just to change a single background image file each day?
 
User avatar
normis
MikroTik Support
MikroTik Support
Posts: 26968
Joined: Fri May 28, 2004 11:04 am
Location: Riga, Latvia
Contact:

Re: Script to change login background .jpg daily

Tue Jul 09, 2013 1:24 pm

it would not be, as routeros doesn't have file operation functions, like rename.
 
cinders
newbie
Topic Author
Posts: 46
Joined: Fri Oct 28, 2011 3:09 am

Re: Script to change login background .jpg daily

Tue Jul 09, 2013 1:30 pm

Ah OK. :D

Thanks for the info. I'll start working on it. :D
 
SurferTim
Forum Guru
Forum Guru
Posts: 4636
Joined: Mon Jan 07, 2008 10:31 pm
Location: Miramar Beach, Florida

Re: Script to change login background .jpg daily

Tue Jul 09, 2013 1:38 pm

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.
 
cinders
newbie
Topic Author
Posts: 46
Joined: Fri Oct 28, 2011 3:09 am

Re: Script to change login background .jpg daily

Tue Jul 09, 2013 1:48 pm

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 ?
 
SurferTim
Forum Guru
Forum Guru
Posts: 4636
Joined: Mon Jan 07, 2008 10:31 pm
Location: Miramar Beach, Florida

Re: Script to change login background .jpg daily

Tue Jul 09, 2013 1:49 pm

That I have not tried, but an interesting concept. Give it a shot and see how it does. Let me know! :D
 
cinders
newbie
Topic Author
Posts: 46
Joined: Fri Oct 28, 2011 3:09 am

Re: Script to change login background .jpg daily

Tue Jul 09, 2013 1:55 pm

No worries - I'll drop an update on this thread, thanks again for the great idea! :D
 
cinders
newbie
Topic Author
Posts: 46
Joined: Fri Oct 28, 2011 3:09 am

Re: Script to change login background .jpg daily

Thu Jul 11, 2013 2:32 am

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.
 
tvermoes
just joined
Posts: 10
Joined: Thu Mar 29, 2012 11:38 pm

Re: Script to change login background .jpg daily

Mon Jul 15, 2013 7:12 am

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>
 
cinders
newbie
Topic Author
Posts: 46
Joined: Fri Oct 28, 2011 3:09 am

Re: Script to change login background .jpg daily

Mon Jul 15, 2013 9:57 am

Many thanks for the script above. :D