To all:
I think I have a working solution with PHP code for KnoppMyth R5F27 users.
My search involved trying to find a convenient way to lock my master backend from going to sleep using MythWelcome with MythShutdown and a custom MythPreshutdown Script. I use an iPhone over wireless to Wake my backend from sleep, then use Safari browser with iPodFeed scripting to see content pseudo-streamed over my WiFi network. I needed a convenient way to avert a shutdown timeout, which the base MythWeb will not prevent. I did NOT want to get into ssh stuff, since with the iPhone keyboard is a royal pain in the petoot.
This is not earth shattering stuff here. Just a recast and tweak of the great work of many others, particularly 'Xris' who authored much of the code I have modded. By doing a little detective work, I have created a modified init.php script for the MythWeb 'settings' module and two new files called 'locker.php'. One resides in the main settings module directory, the other is copied to MythWeb template directories called 'default' and 'compact'
CAVEATS (big time). The scripts created may have unforeseen effects on your system, as I am NOT a PHP coder nor do I claim to have a detailed understanding of all the intricacies of MythTV and its underlying database.
I am monkeying with an integer value in the "settings" datatable in the 'mythconverg' database at the heart of MythTV.
Further, I am the SOLE user of MythWeb in my setup. I cannot foresee all the end-user setups out there and cannot predict how multiple users of MythWeb all connects and using this universally available page will do.
OK -- scare tactics and FUD are over. If you are still interested...here we go...this appears to work quite nicely.
For KnoppMyth R5F27:
1) start up a root terminal session any way you prefer;
2) goto
Code:
root# cd /usr/share/mythtv/mythweb/modules/settings
3) In this folder you will modify the file 'init.php' and append a module so that it will display this link to your lock/unlock routine.
This is the modified file with the new code right near the end
Code:
<?php
/**
* Initialization routines for the MythWeb settings module
* MAKE SURE you copy original init.php to init.old first
* save this file under ./modules/settings/init.php
* @url $URL$
* @date $Date$
* @version $Revision$
* @author $Author$
* @license GPL
*
* @package MythWeb
* @subpackage Settings
*
/**/
// The settings module is always enabled.
$Modules['settings'] = array('path' => 'settings',
'sort' => 999,
'name' => t('Settings'),
'description' => t('settings'),
'links' => array('session' => t('MythWeb session settings'),
'mythweb' => t('MythTV global defaults'),
'channels' => t('MythTV channel info'),
'keys' => t('MythTV key bindings'),
'settings' => t('MythTV settings table'),
'locker' => 'MythTV backend locker', //this is the new code
),
);
The new code is the 'locker' line that you will add.
RECOMMENDATION: copy your original init.php to init.old (or similar) in case you want to undo this mod later more easily.
4) Now, you will use your favorite editor to create a file called 'locker.php' that will also reside in the '/usr/share/mythtv/mythweb/modules/settings' directory.
Its contents are:
Code:
<?php
/**
* Configure MythTV Shutdown Lock
* Save this file to ./modules/settings/locker.php
* @url $URL$
* @date $Date$
* @version $Revision$
* @author $Author$
* @license GPL
*
* @package MythWeb
* @subpackage Settings
*
/**/
// Specific host?
isset($_GET['host']) or $_GET['host'] = $_GET['host'];
if (empty($_GET['host']))
$_GET['host'] = null;
// Save?
if ($_POST['set']) {
foreach ($_POST['locker'] as $value => $data) {
setting('MythShutdownLock', 'null', $data);
}
}
// LOCK ?
if ($_POST['lock']) {
setting(MythShutdownLock, null, 1);
}
// UNLOCK
if ($_POST['unlock']) {
setting(MythShutdownLock, null, 0);
}
// Load all of the known mythtv hosts
$Hosts = array();
$sh = $db->query('SELECT DISTINCT hostname FROM settings ORDER BY hostname');
while (list($host) = $sh->fetch_row()) {
if (empty($host))
continue;
$Hosts[] = $host;
}
$sh->finish();
// Load just the MythShutdownLock setting for the requested host
$Locker = array();
if (is_null($_GET['host']))
$sh = $db->query('SELECT value, data
FROM settings
WHERE hostname IS NULL AND value="MythShutdownLock"
');
else
$sh = $db->query('SELECT value, data
FROM settings
WHERE hostname=? AND value="MythShutdownLock"',
$_GET['host']);
while (list($value, $data) = $sh->fetch_row()) {
$Locker[$value] = $data;
}
$sh->finish();
// Load the class for this page
require_once tmpl_dir.'locker.php';
// Exit
exit;
This is essentially a mod to the original 'settings.php' file created for MythWeb.
However, since we need only one setting to change in the settings data table in mythconverg, I hard-coded the writes to the table.
5) Now you will use your favourite editor again to create another file called 'locker.php' but this will be saved in the template folders for the default MythWeb and compact MythWeb.
This 'locker.php' will be save to:
/usr/share/mythtv/mythweb/modules/settings/tmpl/default
AND
/usr/share/mythtv/mythweb/modules/settings/tmpl/compact
The file contents are:
Code:
<?php
/**
* Configure MythTV MythShutdownLock toggle
* store as ./modules/settings/tmpl/default/locker.php
* and to ./modules/settings/tmpl/compacy/locker.php
* @url $URL$
* @date $Date$
* @version $Revision$
* @author $Author$
* @license GPL
*
* @package MythWeb
* @subpackage Settings
*
/**/
// Set the desired page title
$page_title = 'MythWeb - Backend Locker';
// Print the page header
require 'modules/_shared/tmpl/'.tmpl.'/header.php';
?>
<form class="form" method="post" action="<?php echo root ?>settings/locker?host=<?php echo rawurlencode($_GET['host']) ?>">
<br />
<p align="center">
<?php echo 'Myth Backend Locker' ?>
</p>
<center>
<?php
foreach ($Locker as $value => $data) {
switch ($data) {
case 1:
echo "Backend is currently LOCKED";
// $chkLock = "checked";
break;
case 0:
echo "Backend is UNLOCKED";
// $chkLock = "unchecked";
break;
}
}
?>
<br />
<p align="center">
<input type="submit" name="lock" value="LOCK" style="height:3em; width:10em;"> ------------
<input type="submit" name="unlock" value="unlock" style="height:3em; width:10em;">
</p>
</form>
<?php
// Print the page footer
require 'modules/_shared/tmpl/'.tmpl.'/footer.php';
?>
The buttons are extra large to make them visible on my iPhone. Again, this file is a recast settings table.
If all worked correctly, you will see a new hyperlink on the Settings Page and your locker will allow you to enforce a 'MythShutdownLock' via MythWeb.
User Feedback Please.
Any PHP folks out there who can clean up my mess...thanks in advance.