Ticket #1146: mythfrontend.diff

File mythfrontend.diff, 11.8 KB (added by phatfil@…, 20 years ago)
  • themes/default/frontends/jump.php

     
     1<?php
     2/* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */
     3// Set the desired page title
     4    $page_title = 'MythWeb - ' . t('Frontends') . ' - ' . $host;
     5
     6// Print the page header
     7    require_once(theme_dir . '/header.php');
     8    echo "Current location: $location<br/>";
     9    echo '<table align="center" width="90%" cellspacing="2" cellpadding="2">';
     10    echo '<tr><td>Jump Point</td></tr>';
     11    foreach ($jumppoints as $jp => $jumppoint) {
     12        echo '<tr><td><a href="' . root . 'frontends/' . $host . '/jump/' . $jp . '">' . $jumppoint . '</a></td></tr>';
     13    }
     14    echo '</table>';
     15    require_once(theme_dir . '/footer.php');
     16?>
  • themes/default/frontends/keys.php

     
     1<?php
     2/* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */
     3// Set the desired page title
     4    $page_title = 'MythWeb - ' . t('Frontends') . ' - ' . $host;
     5
     6// Print the page header
     7    require_once(theme_dir . '/header.php');
     8    if ($key_status === false) {
     9        echo 'Bad key!<br/>';
     10    }
     11    echo "Current location: $location<br/>";
     12    echo '<form action="' . root . 'frontends/' . $host . '/keys/" method="POST">';
     13    echo 'Keypress to send: <input type="text" name="key" />';
     14    echo '</form>';
     15    echo '<p>Keypress can be a letter, number or one of the following: backslash, backspace, bracketleft, bracketright, colon, down, enter, equal, escape, f1, f10, f11, f12, f2, f3, f4, f5, f6, f7, f8, f9, greater, left, less, pagedown, pageup, right, semicolon, slash, space, up</p>';
     16    require_once(theme_dir . '/footer.php');
     17?>
  • themes/default/frontends/welcome.php

     
     1<?php
     2    echo '<div id="info_frontends" class="hidden">',
     3         t('welcome: frontends'),
     4         '</div>';
     5?>
  • themes/default/frontends/main.php

     
     1<?php
     2/* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */
     3// Set the desired page title
     4    $page_title = 'MythWeb - ' . t('Frontends');
     5
     6// Print the page header
     7    require_once(theme_dir.'/header.php');
     8
     9    echo '<table align="center" width="90%" cellspacing="2" cellpadding="2">';
     10    echo '<tr><td>Frontend</td><td>Status</td></tr>';
     11    foreach ($frontend_loc as $host => $loc) {
     12        echo '<tr><td>' . $host . '</td><td>' . $loc. '</td><td><a href="' . root . 'frontends/' . $host . '/jump/">jump</a></td><td><a href="' . root . 'frontends/' . $host . '/keys/">keys</a></td></tr>';
     13    }
     14    echo '</table>';
     15    require_once(theme_dir . '/footer.php');
     16?>
  • themes/default/header.php

     
    11<?php
     2/* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */
    23/**
    34 * This header file is shared by all MythWeb modules.
    45 *
     
    176177                    &nbsp; | &nbsp;
    177178                    <a href="<?php echo root ?>backend_log"><?php echo t('Backend Logs') ?></a>
    178179<?php } ?>
     180<?php if ($Modules['frontends']) { ?>
     181                    &nbsp; | &nbsp;
     182                    <a href="<?php echo root ?>frontends"><?php echo t('Frontends') ?></a>
     183<?php } ?>
    179184                </div></td>
    180185        </tr>
    181186        </table></td>
  • languages/English.php

     
    11<?php
     2/* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */
    23/***                                                                        ***\
    34    languages/English.php
    45
     
    221222    'Please search for something.' => '',
    222223// modules/video/init.php
    223224    'Video' => '',
     225// modules/frontend/init.php
     226    'Frontends' => '',
     227    'Frontend Status' => '',
     228    'welcome: frontends' => 'Show frontend status, send jumppoints, send keypresses',
    224229// themes/default/backend_log/welcome.php
    225230    'welcome: backend_log' => 'Show the server logs.',
    226231// themes/default/header.php
  • includes/init.php

     
    11<?php
     2/* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */
    23/**
    34 * This file is part of MythWeb, a php-based interface for MythTV.
    45 * See http://www.mythtv.org/ for details.
     
    174175                     'status'      => null,
    175176                     'backend_log' => null,
    176177                     'stream'      => null,
     178                     'frontends'   => null,
    177179                    );
    178180
    179181// Load the various modules (search for the "tv" subdirectory in case it might
  • includes/mythfrontend.php

     
     1<?php
     2/* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */
     3
     4$sock = socket_create(AF_INET, SOCK_STREAM, 0);
     5
     6function get_network_frontends() {
     7    $inputquery = "SELECT hostname, data FROM settings WHERE value = 'NetworkControlEnabled' AND data = '1'";
     8    $res = mysql_query($inputquery) or die ("Couldn't open the settings table in the mythconverg database.");
     9    $hosts = array();
     10    while ($row = mysql_fetch_array($res, MYSQL_ASSOC)) {
     11        $portres = mysql_query("SELECT data FROM settings WHERE value = 'NetworkControlPort' AND hostname = '" . $row['hostname'] . "'");
     12        $portrow = mysql_fetch_row($portres);
     13        mysql_free_result($portres);
     14        $hosts[$row['hostname']] = $portrow[0];
     15    }
     16    mysql_free_result($res);
     17    return $hosts;
     18}
     19
     20function frontend_keypress($key) {
     21    $lines = __get_rows("key $key");
     22    if (strpos($lines[0], 'OK') !== false) {
     23        return true;
     24    }
     25    return false;
     26}
     27
     28function frontend_get_jumppoints() {
     29    $lines = __get_rows('help jump');
     30    $jumppoints = array();
     31    foreach ($lines as $line) {
     32        if (preg_match('/(\w+)\s+- (.*)/', $line, $matches)) {
     33            $jumppoints[$matches[1]] = $matches[2];
     34        }
     35    }
     36    return $jumppoints;
     37}
     38
     39function frontend_jump($jumppoint) {
     40    global $sock;
     41    __get_rows("jump $jumppoint");
     42}
     43
     44function frontend_query_location() {
     45    $ret = __get_rows('query location');
     46    return $ret[0];   
     47}
     48
     49function frontend_connect($host, $port) {
     50    global $sock;
     51    if (!@socket_connect($sock, $host, $port)) {
     52        if (socket_last_error() == 106) {
     53            //already connected
     54            return true;
     55        }
     56        return false;
     57    }
     58    $buf = '';
     59    $recv = '';
     60    while (true) {
     61        @socket_recv($sock, $buf, 32, 0);
     62        $recv .= $buf;
     63        if (strstr($buf, '#')) {
     64            break;
     65        }
     66    }
     67    return true;
     68}
     69
     70function frontend_disconnect() {
     71    global $sock;
     72    socket_close($sock);
     73    $sock = socket_create(AF_INET, SOCK_STREAM, 0);
     74}
     75
     76function __get_rows($query) {
     77    global $sock;
     78    $buf = '';
     79    $recv = '';
     80    @socket_write($sock, $query . "\n");
     81    while (true) {
     82        //don't know if this is the best way to do things...
     83        @socket_recv($sock, $buf, 1024, 0);
     84        $recv .= $buf;
     85        if (strstr($buf, '#')) {
     86            break;
     87        }
     88    }
     89    return explode("\n", $recv);
     90}
     91
     92?>
  • modules/frontends/jump.php

     
     1<?php
     2/* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */
     3    require_once('includes/mythfrontend.php');
     4    $frontends = get_network_frontends();
     5    frontend_connect($host, $frontends[$host]);
     6    if ($jumppoint) {
     7        frontend_jump($jumppoint);
     8    }
     9    $jumppoints = frontend_get_jumppoints();
     10    $location = frontend_query_location();
     11    frontend_disconnect();
     12    require_once(theme_dir . 'frontends/jump.php');
     13?>
  • modules/frontends/keys.php

     
     1<?php
     2/* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */
     3    require_once('includes/mythfrontend.php');
     4    $frontends = get_network_frontends();
     5    frontend_connect($host, $frontends[$host]);
     6    if ($_POST['key']) {
     7        $key_status = frontend_keypress($_POST['key']);
     8        //give the frontend time to do it's thing
     9        sleep(1);
     10    }
     11    $location = frontend_query_location();
     12    frontend_disconnect();
     13    require_once(theme_dir . 'frontends/keys.php');
     14?>
  • modules/frontends/handler.php

     
     1<?php
     2/* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */
     3    require_once('includes/mythfrontend.php');
     4    $frontends = get_network_frontends();
     5    $host = $Path[1];
     6    if ($Path[2] == 'jump' && in_array($host, array_keys($frontends))) {
     7        $jumppoint = $Path[3];
     8        require_once('modules/frontends/jump.php');
     9        exit;
     10    } else if ($Path[2] == 'keys' && in_array($host, array_keys($frontends))) {
     11        require_once('modules/frontends/keys.php');
     12        exit;
     13    }
     14    require_once('modules/frontends/main.php');
     15?>
  • modules/frontends/init.php

     
     1<?php
     2/* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */
     3/**
     4 * Initialization routines for the MythWeb TV module.
     5 *
     6 * @url         $URL: http://svn.mythtv.org/svn/branches/release-0-19-fixes/mythplugins/mythweb/modules/tv/init.php $
     7 * @date        $Date: 2006-01-01 11:00:31 +1100 (Sun, 01 Jan 2006) $
     8 * @version     $Revision: 8460 $
     9 * @author      $Author: Philip Nelson <phatfil@optusnet.com.au> $
     10 * @license     GPL
     11 *
     12 * @package     MythWeb
     13 * @subpackage  TV
     14 *
     15/**/
     16
     17// The TV module is always enabled.
     18    $Modules['frontends'] = array('path'        => 'frontends',
     19                                  'name'        => t('Frontends'),
     20                                  'links'       => array('status' => t('Frontend Status'),
     21                                 ),
     22                          );
     23
  • modules/frontends/main.php

     
     1<?php
     2/* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */
     3        require_once('includes/mythfrontend.php');
     4        $frontend_loc = array();
     5        $frontends = get_network_frontends();
     6        foreach ($frontends as $host => $port) {
     7                if (!frontend_connect($host, $port)) {
     8                        $frontend_loc[$host] = 'Not Running';
     9                } else {
     10                        $frontend_loc[$host] = frontend_query_location();
     11                }
     12                frontend_disconnect();
     13        }
     14        require_once(theme_dir . 'frontends/main.php');
     15?>