Go Back   vb.org Archive > vBulletin Modifications > vBulletin 3.8 Modifications > vBulletin 3.8 Add-ons
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
Open Toggle - Automate Site Opening and Closing Details »»
Open Toggle - Automate Site Opening and Closing
Version: 1.00, by MrEyes MrEyes is offline
Developer Last Online: May 2017 Show Printable Version Email this Page

Category: Administrative and Maintenance Tools - Version: 3.8.4 Rating:
Released: 09-27-2009 Last Update: 09-27-2009 Installs: 11
Re-useable Code Additional Files Translations Is in Beta Stage  
No support by the author.

Open Toggle v1.0 BETA
Advanced (ish)


What this does

Anybody who has read through the guidelines available at vbulletin.com will know that you should perform regular backups of your database. You may also know that it is best to use mysqldump via an operating system scheduled task as using vBulletin cron may result in backup failures, especially on large databases. It is also wise to lock all tables (to prevent inserts etc) that may corrupt your backup.

Now this is all well and good, however if you have tried to do this on an active site you will have seen the site grind to a halt and on occasion spit out errors to the end user. If you have any interest in user experience you should really close the site down gracefully with a meaningful user message, for example "We are currently backing up, please check back in 10 minutes".

The problem is that although you can do this through admincp there is no automated way to do this from an external process (i.e. your scheduled backup script). Most of us run backups during off time and most of us probably don't want to get up at 3am to gracefully close the site for 10 minutes. This modification fixes that problem and automates the entire thing.

This is not a "real" modification rather a standalone PHP script that you can call from a shell script (using wget on similar) that will open or close the site. So before you start your script mysqldump back you call the script to close the site, once done you call the script to open the site. Simples

Note: This script does not do any backups

Installation

There is no installation, all you need to do is:
  1. Download the attached script and extract to your computer.
  2. Review the configuration options at the top of the script and amend as you see fit.
  3. Upload the amended script to your forum home directory, i.e. where forumdisplay.php is.

Using the script

This script is designed to be called from wget, as an example your backup script would look like this:

Code:
wget "http://yoursite/forum/opentoggle.php?do=close"

... Do you mysqldump here

wget "http://yoursite/forum/opentoggle.php?do=open"
Security

While this script isn't data destructive if somebody "malicious" was constantly calling it and closing/opening your site you would probably be a tad miffed. So the script has various inbuilt security mechanisms, so the script can be configured to:
  • Only execute if the call is from a user agent your define, so you could change the wget call above to something like this:

    Code:
    wget --user-agent="wibble my user agent wobble la la blah" "http://yoursite/forum/opentoggle.php?do=close"
  • To use custom values for "do=", the default is open/close however you could configure these to be monkeys to open and parrots to close, e.g.:

    Open the site
    Code:
    wget "http://yoursite/forum/opentoggle.php?do=monkeys"
    Close the site
    Code:
    wget "http://yoursite/forum/opentoggle.php?do=parrots"
  • Output or not a result detailing what was done with XML. This output can be parsed by your backup script to check that it can proceed.
  • You can rename the script to any valid file name and it will still work, e.g. wibblewobble.php

Other Configuration

There are a few other configuration values, I won't get into specifics here as the php script is well commented. In summary you can do the following:
  • Run the script in test mode
  • Switch user agent checks on or off
  • Customise the responses
  • Customise the structure of the response XML
  • Define multiple closed messages, you might be closing for a backup or maybe something else.
  • Switch output XML on or off

Sample Output

If you have configured the script to create outputs you will get something like this when you call it:

Code:
<toggle timestamp="Mon, 28 Sep 09 15:40:20 +0100" requesturi="/forum/opentoggle.php?do=close&amp;msg=2" testmode="">
	<result code="0">closed</result>
</toggle>
In this example the script was called to close the site, it shows the time of the request, the requested uri (url & query string), testmode not enabled (it would be testmode="1" if it was), the result code and the result text.

All the text you see above is customisable.

Other Information

As mentioned above this script was primarily designed to be called from wget (or similar) however there is nothing to stop you from calling it in a browser or any other mechanism capable of performing http calls.

Finally, for those that are more technical. You may have noticed the following line:

Code:
define('THIS_SCRIPT', 'login');
Yes this is deliberate, we are pretending to be the login script. The reason for this is that when the script is called it is executed as a guest user, this means that when attempting to open a closed site the VB backend will abort and return back the "site currently offline" message rather than opening the site. Impersonating the login script allows this script to bypass the internal "is offline" check.

Download Now

File Type: zip opentoggle.zip (2.4 KB, 50 views)

Show Your Support

  • This modification may not be copied, reproduced or published elsewhere without author's permission.

Comments
  #2  
Old 09-28-2009, 01:41 PM
MrEyes MrEyes is offline
 
Join Date: Nov 2004
Posts: 380
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Reserved for when it goes horribly wrong
Reply With Quote
  #3  
Old 09-28-2009, 08:30 PM
Elenna Elenna is offline
 
Join Date: Jan 2006
Location: St. Charles, MO
Posts: 422
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hey, very nice.

I haven't tried this yet, but I wanted to confirm a few things:

To use this, we should likely be making our own backup via a *nix Chron job, and add in the call(s) to this script in that same PHP file?

So, in other words, we shouldn't add anything in to the vB Scheduled Tasks, but use our web host's chron job?
Reply With Quote
  #4  
Old 09-28-2009, 08:58 PM
Adrian Schneider's Avatar
Adrian Schneider Adrian Schneider is offline
 
Join Date: Jul 2004
Posts: 2,528
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks for sharing
Reply With Quote
  #5  
Old 09-28-2009, 11:29 PM
Elenna Elenna is offline
 
Join Date: Jan 2006
Location: St. Charles, MO
Posts: 422
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I'm not sure if this is the intended functionality or not, but this is downloading the script into a directory. I am using a PHP script to run the

Here is the output that is emailed to me (one for the close command and one for the open):

Quote:
--16:55:01-- http://www.mysite/opentoggle.php?do=close
=> `opentoggle.php?do=close'
Resolving www.mysite.com... my.ip.address.here
Connecting to www.mysite.com|my.ip.address.here|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/xml]

0K 25.47 MB/s

16:55:01 (25.47 MB/s) - `opentoggle.php?do=close' saved [148]
The saved file is named "opentoggle.php?do=close"

If that isn't the intended functionality, is there another way that I can do this in a PHP script, or should I have different cronjobs, one for the forum close, one for the backup, and the other for the forum open?
Reply With Quote
  #6  
Old 09-29-2009, 06:05 AM
MrEyes MrEyes is offline
 
Join Date: Nov 2004
Posts: 380
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
So, in other words, we shouldn't add anything in to the vB Scheduled Tasks, but use our web host's chron job?
Yes this is entirely independent from vBulletin scheduled tasks you don't need to go anywhere near it.

Quote:
Originally Posted by Elenna View Post
I haven't tried this yet, but I wanted to confirm a few things:

To use this, we should likely be making our own backup via a *nix Chron job, and add in the call(s) to this script in that same PHP file?
If you are using a cron you might have an sh script that looks something like this:

Code:
mysqldump --opt -Q -u dbusername -p databasename > /path/to/backupname.sql
You would edit that script to:

Code:
wget "http://yoursite/forum/opentoggle.php?do=close"
mysqldump --opt -Q -u dbusername -p databasename > /path/to/backupname.sql
wget "http://yoursite/forum/opentoggle.php?do=open"
So when the script is run it first closes the site, then calls mysqldump then opens the site.
Reply With Quote
  #7  
Old 09-29-2009, 06:08 AM
MrEyes MrEyes is offline
 
Join Date: Nov 2004
Posts: 380
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Elenna View Post
I'm not sure if this is the intended functionality....... the backup, and the other for the forum open?
wget will download the response to the calling machine, this allows you to parse/view/manage the response. If you are not going to do that then there is no need to store the response so pass the --spider command line argument to wget.

You not need any additional scheduled scripts just edits to existing ones.
Reply With Quote
  #8  
Old 09-29-2009, 01:33 PM
lazydesis lazydesis is offline
 
Join Date: Sep 2006
Posts: 234
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Most of us probably use cpanel/whm to do a backup everyday. Could you may be provide more specific instructions for such users?

Thanks. Nice job
Reply With Quote
  #9  
Old 09-29-2009, 01:48 PM
Elenna Elenna is offline
 
Join Date: Jan 2006
Location: St. Charles, MO
Posts: 422
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks very much. I do not have access to shell, so I am needing to do this via a PHP script.

Will do some more testing and see if I can get it to work. Thanks again!
Reply With Quote
  #10  
Old 09-29-2009, 04:35 PM
OcR Envy's Avatar
OcR Envy OcR Envy is offline
 
Join Date: May 2008
Location: Boston
Posts: 248
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Interesting. Tagged.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 02:13 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04893 seconds
  • Memory Usage 2,328KB
  • Queries Executed 24 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (8)bbcode_code
  • (4)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_post
  • (1)navbar
  • (4)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (9)postbit
  • (1)postbit_attachment
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_attachment
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete