@orbital recently had a requirement where the admin could put the site offline from within the admin-panel.

As you know, the existing way of doing this in Couch is by editing the couch/config.php file.
I was not too keen on making this file editable from the admin-panel so came up with the following quick-n-dirty solution.
Quoting it verbatim -

1. Assuming your settings template is named 'settings.php' (and it is non-clonable), place the following editable region in it -
Code: Select all
<cms:editable name='site_offline' type='checkbox' label='Put Site Offline?' opt_values='Yes=yes' />

Needless to say, visit the changed template on the frontend as super-admin for the field to appear in the admin-panel.

2. Next place the following code in your couch/addons/kfunctions.php -
Code: Select all
$FUNCS->add_event_listener( 'page_saved', function(&$pg, &$errors){

    // set these values to match your settings..
    $settings_template = 'settings.php';
    $field_name = 'site_offline';

    // work begins ..
    if( $pg->tpl_name!=$settings_template ) return; // not interested in any other template
    if( !$errors ){
        $flag_file = K_COUCH_DIR . 'cache/__site_offline__.dat';

        if( $pg->_fields[$field_name]->modified ){
            $site_offline = $pg->_fields[$field_name]->get_data();
            if( $site_offline ){
                if( !file_exists($flag_file) ){
                    @fclose( @fopen($flag_file, 'a') );
                }
            }
            else{
                if( file_exists($flag_file) ){
                    @unlink( $flag_file );
                }
            }
        }
    }
});

Notice the following lines in the code above -
$settings_template = 'settings.php';
$field_name = 'site_offline';

Please modify them if the template name or the field name we put in it above are different.

3. Finally, modify your couch/config.php and change the very first setting from this -
Code: Select all
define( 'K_SITE_OFFLINE', 0 );

to this -
Code: Select all
define( 'K_SITE_OFFLINE', file_exists(K_COUCH_DIR . 'cache/__site_offline__.dat') ? 1 : 0 );

And now you should be able to put the site offline/online form the settings template in admin-panel.
Please test it out and let me know if this helps.