[mythtv] [PATCH][MythWeb]: Fix for setting key bindings when hostname contains a dot

Richard Gering RGering at serena.com
Wed Feb 23 01:06:35 UTC 2005


Greetings,

If the hostname of the system running Myth contains a dot (eg.
"myth.mydomain.com") then the key mapping code in MythWeb will not be
able to save the settings.

The reason for this is that settings_keys.php iterates through the
various "name" input fields of the submitted form, which it splits out
into a key name, context, action and host name.  However, PHP also turns
these name fields into their own variables, and there is PHP logic that
automatically converts any dot into an underscore if that dot would have
otherwise been used as part of a variable name (which is illegal in
PHP).

The result of this is that the $key value in "foreach
(array_keys($_POST) as $key)" will not contain

   "key:context:action:myth.mydomain.com"

but

   "key:context:action:myth_domain_com"

which doesn't match the hostname values in the database, and the UPDATE
statements subsequently don't do anything at all.

There are two was to fix this:

1. Encode the dots in hostname before generating the HTML and decode
them when parsing the $key values.

2. Remove the hostname from the name="" values and put it into is own
field.

I opted for solution #2, as it seemed a cleaner way to address the
problem and there appears to be no scenario where we generate a single
form with values from/for multiple hostnames (the only reason that would
have required solution #1).

The patch against the CVS tree from yesterday has been attached.  If
there are reasons why option #1 would be preferable, please let me know
and I'll re-code the patch that way.

Kind regards,

- Richard Gering.




**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply e-mail and destroy all copies of the original message.

-------------- next part --------------
Index: settings_keys.php
===================================================================
RCS file: /var/lib/mythcvs/mythweb/settings_keys.php,v
retrieving revision 1.6
diff -u -r1.6 settings_keys.php
--- settings_keys.php	24 Jan 2005 03:35:54 -0000	1.6
+++ settings_keys.php	21 Feb 2005 23:57:51 -0000
@@ -20,18 +20,18 @@
 // Save?
     $usehost = "";
     if ($_POST['save']) {
+        $host = $_POST['use_host'];
+        $usehost = $host;
         foreach (array_keys($_POST) as $key) {
-            if (preg_match('/^jump:([\\w_\/]+):(\\w+)$/', $key, $matches)) {
-                list($match, $dest, $host) = $matches;
+            if (preg_match('/^jump:([\\w_\/]+)$/', $key, $matches)) {
+                list($match, $dest) = $matches;
                 $dest = str_replace("_", " ", $dest);
-                $usehost = $host;
                 $query = 'UPDATE jumppoints SET keylist='.escape($_POST[$key]).' WHERE destination='.escape($dest).' AND hostname='.escape($host).';';
                 $result = mysql_query($query)
                     or trigger_error('SQL Error: '.mysql_error(), FATAL);
             }
-            elseif (preg_match('/^key:([\\w_\/]+):(\\w+):(\\w+)$/', $key, $matches)) {
-                list($match, $context, $action, $host) = $matches;
-                $usehost = $host;
+            elseif (preg_match('/^key:([\\w_\/]+):(\\w+)$/', $key, $matches)) {
+                list($match, $context, $action) = $matches;
                 $context = str_replace("_", " ", $context);
                 $query = 'UPDATE keybindings SET keylist='.escape($_POST[$key]).' WHERE context='.escape($context).' AND action='.escape($action).' AND hostname='.escape($host).';';
                 $result = mysql_query($query)
Index: themes/Default/settings_keys.php
===================================================================
RCS file: /var/lib/mythcvs/mythweb/themes/Default/settings_keys.php,v
retrieving revision 1.7
diff -u -r1.7 settings_keys.php
--- themes/Default/settings_keys.php	5 Feb 2005 06:39:18 -0000	1.7
+++ themes/Default/settings_keys.php	21 Feb 2005 23:57:51 -0000
@@ -57,6 +57,9 @@
 </p>
 <form class="form" method="post" action="settings_keys.php">
 <table border="0" cellpadding="4" cellspacing="2" class="list small" align="center">
+<tr>
+    <td><input type="hidden" name="use_host" value="<?php echo $usehost ?>" /></td>
+</tr>
 <tr class="menu large" align="center">
     <td colspan="3">JumpPoints Editor</td>
 </tr>
@@ -69,7 +72,7 @@
 ?><tr class="settings" align="center">
     <td><?php echo htmlentities($jumppoint['destination'])?></td>
     <td><?php echo htmlentities($jumppoint['description'])?></td>
-    <td><input type="text" size="35" name="jump:<?php echo $jumppoint['destination'].':'.$usehost?>" value="<?php echo str_replace("\\\\", "\\", htmlentities($jumppoint['keylist']))?>"></td>
+    <td><input type="text" size="35" name="jump:<?php echo $jumppoint['destination']?>" value="<?php echo str_replace("\\\\", "\\", htmlentities($jumppoint['keylist']))?>"></td>
 </tr>
 <?php
         }
@@ -91,7 +94,7 @@
         <td><?php echo htmlentities($keyb['context'])?></td>
         <td><?php echo htmlentities($keyb['action'])?></td>
         <td><?php echo htmlentities($keyb['description'])?></td>
-        <td><input type="text" size="25" name="key:<?php echo $keyb['context'].':'.$keyb['action'].':'.$usehost?>" value="<?php echo str_replace("\\\\", "\\", htmlentities($keyb['keylist']))?>
+        <td><input type="text" size="25" name="key:<?php echo $keyb['context'].':'.$keyb['action']?>" value="<?php echo str_replace("\\\\", "\\", htmlentities($keyb['keylist']))?>
 "></td>
 </tr>
 <?php


More information about the mythtv-dev mailing list