rejetto forum

Software => HFS ~ HTTP File Server => Topic started by: Johannes51 on June 11, 2015, 04:49:02 PM

Title: On - Off Script on website
Post by: Johannes51 on June 11, 2015, 04:49:02 PM
Hello,

Is it possible to automatically create a script on and off at HFS server. I have a website where you can go to the HFS server, but no one can see if he is on or off. I can through a script on my website which then shows that it is on or off by a plate of On and Off. I am really a beginner, but would like to learn. sorry for my bad English

Is there anyone who can help me with it.

thanks

Johan
Title: Re: On - Off Script on website
Post by: bmartino1 on June 11, 2015, 06:07:33 PM
let me get this straight, you want a site to show the hfs log to see who is/has connected?

or you want a template that shows your users and who is currently online/connected?

This is possible via macros in the hfs template and new scripting commands....
You would have to accomplish this by going to a website on hfs???

(i don't know the commands / macros enough to help you on this....)
Just trying to be sure what your are trying to accomplish...?
Title: Re: On - Off Script on website
Post by: Johannes51 on June 11, 2015, 06:41:22 PM
thanks for your answer,

I turn an ordinary website. through an iframe you can on the website come on the HFS server. Now I would like my regular website will show whether the server on or offline state.

Can this be made with a script and where can I find it? Maybe I did not properly explains.


Johannnes
Title: Re: On - Off Script on website
Post by: Mars on June 11, 2015, 09:35:10 PM
There are two macros to stop or restart HFS, they are more useful in the events for example define the hours of access, you must realize that if you Stop the server, the program continues to run but the connection to http server is lost until you restart it manualy or by an event    (see wiki hfs.events)
Title: Re: On - Off Script on website
Post by: rejetto on June 29, 2015, 10:35:18 AM
an easy (not perfect) solution is: your main website tries to call HFS. If it doesn't reply, you remove the iframe and display a message.
If you are good with jquery this is not hard. Something like

<script>
$(function(){
  $.ajax(HFS_URL).fail(function(){
     $('iframe').replaceWith('Sorry, not available');
  });
});
</script>

I didn't test it
Trying to do the opposite (HFS notifying of its state) would be unreliable.
Title: Re: On - Off Script on website
Post by: Johannes51 on July 02, 2015, 03:35:44 PM
thnx for help, i have to try this script, but don't work.

Try to make it a little clearer

I just have a website, I want to show on the website or the server off or on state. Here I actually looking for a script that I can put on the website so that members can see if the server on or off

Is this possible and where can I find such a thing.

Johannes
Title: Re: On - Off Script on website
Post by: bmartino1 on July 02, 2015, 11:05:13 PM
What rejeto was saying is instead of HFS notifying you, have a webpage to run a script to see if that link is live.

so a html page that has Iframes, that run a script simalr to this...

Lets call the site
AmIUp

<!DOCTYPE html>
<html>
<head>
<title>Am I Up</title>
</head>

<body>
<!-- Iframe test script wil be hear -->
<!-- Using jquery??? -->
<script>
$(function(){
  $.ajax("Site URL will be here www.domain.com without quotes").fail(function(){
     $('iframe').replaceWith('Sorry, not available');
  });
});
</script>
</body>
</html>

---------------
From there you will need remote desktop control to login and start/ stop server...

The script Rejeto postede isn't test / not guaranteed to work, need the site address and some other info to "html program" what rejeto is recommending...

this script doesn't work , it will display a balnk page... need to find html coding/ other way to get a redirect on iframes....
http://stackoverflow.com/questions/3922989/how-to-check-if-page-exists-using-javascript
Title: Re: On - Off Script on website
Post by: Johannes51 on July 03, 2015, 11:10:38 AM
Thank you for your clear explanation, but I do not really like I have in my mind. I have therefore made a picture how it should be.

Johannes ;) ;)
Title: Re: On - Off Script on website
Post by: bmartino1 on July 03, 2015, 11:28:25 AM
ok, thats fine, unfortunate, i haven't seen that feature, nor of a way to accomplish waht you want from the picture...

i would direct you to vhost and appache for that type of setup...

http://www.rejetto.com/forum/hfs-~-http-file-server/multiple-websites-with-hfs-like-vhost-in-apache/msg1060317/#msg1060317

--------------------------
HFS doesn't have a offline mode where it can be turned on form a website... there is no picture for it...

if its is in offline mode, you would still need a script to test it...

This may be of help:
http://www.rapidtables.com/web/tools/redirect-generator.htm

good luck

these may be of help, i can't seem to debug/ program a good working script...

http://stackoverflow.com/questions/3922989/how-to-check-if-page-exists-using-javascript

http://javascriptkit.com/script/script2/ajaxtooltip.shtml

i did find that the notepad doc had to be saved as a "*.xhtml file to test the script...

in either events, it still fails.../ doen't give results
The zip file is the end where i essentially give up... Tis an html button when clicked runs the script, it suppose to show online / offline, but does neither...

Good luck
Title: Re: On - Off Script on website
Post by: Johannes51 on July 03, 2015, 11:51:09 AM
Hello,

Many thanks for your quick response, and thank you for a new challenge for me, I will try what I can do everything myself. I am a beginner in scripts and go to battle.

Many thanks for your advice and time

Johannes
Title: Re: On - Off Script on website
Post by: LeoNeeson on July 03, 2015, 08:03:33 PM
Doing a Google search (http://lmgtfy.com/?q=Check+if+website+if+offline+if+fails+to+load+an+image), I've found this...

Code: [Select]
http://stackoverflow.com/questions/23997675/checking-if-web-server-is-online-offline
http://stackoverflow.com/questions/189430/detect-that-the-internet-connection-is-offline
http://stackoverflow.com/questions/4282151/is-it-possible-to-ping-a-server-from-javascript/

IMHO, this (http://stackoverflow.com/a/23997795) seems to be the easiest solution: (https://archive.is/5GFOH)

Code: [Select]
<img src="http://your-hfs-server.com/online.png" alt="status" onerror="this.src='files/offline.png'" />

"The setup is: An online icon (online.png) on the remote server [the HFS Server] you want to see the status of. An offline icon (offline.png) on the server that is going to show the status page." [Sourc (https://khromov.wordpress.com/2012/02/07/minimalist-server-online-status-checker-htmljavascript/)e (https://archive.is/PJ1zW)]

Let us know which solution worked, if any of them do please! ;)
Greetings...
Leo.-
Title: Re: On - Off Script on website
Post by: bmartino1 on July 05, 2015, 06:11:41 PM

Code: [Select]
<img src="http://your-hfs-server.com/online.png" alt="status" onerror="this.src='files/offline.png'" />

Thank you Leo, i was able to make a working script with the events... here is a working test...

http://stackoverflow.com/questions/3984287/how-to-show-alternate-image-if-source-image-is-not-found-onerror-working-in-ie
---------
<!DOCTYPE html>
<html>
<body>

<p> <a href="Your HFS HTML SITE"> click here to go to HFS </a> </p>

<!-- Picture must come form your HFS SITE  -->
<img src="Your HFS HTML SITE\Online.jpg" onerror="myFunction()">

<!-- Write your comments here -->
<!-- http://www.w3schools.com/jsref/event_onerror.asp -->
<!-- If server is down, picture will not load, and display this text -->

<p id="demo"></p>
<script>
function myFunction() {
    document.getElementById("demo").innerHTML = "The server is offline.";
}
</script>

</body>
</html>
-------------
Title: Re: On - Off Script on website
Post by: Johannes51 on July 08, 2015, 11:20:59 AM
Hello

Many thanks for your good script and explanation, and it works perfectly just need just a picture online and it all works.

I hope that more members have fun at it because really top


Johannes  ;D ;D ;D
Title: Re: On - Off Script on website
Post by: rejetto on July 12, 2015, 02:42:49 PM
i didn't know the onerror. Nice find.
Title: Online & Offline server on website
Post by: Johannes51 on January 31, 2017, 08:17:15 PM
Put this on your website :

<script type="text/javascript">
   var url = "http://www.yourprivateserver.com/foo.gif";
   var img = new Image();
   img.src = url;

   img.onload = function()
   {
      // If the server is up, do this.
      alert("Server is up!");
   }

   img.onerror = function()
   {
      // If the server is down, do that.
      alert("Server is down!");
   }
</script>


and works great