Webshell/WebIf via TV Portal

/df

Well-Known Member
There was this exchange:
...For instance, could there be a WebIf "app" by linking the IR key-handling JS from the Portal to WebIf?

What about a WebShell app, maybe usable with a USB keyboard?
...
Are you volunteering?...
Let's start with expressions of interest and then see if there's any demand and then if there's anyone with prior knowledge and requisite skills.

It's possible that I don't have the latter as my brief attempt to access WebShell through new-portal just gave a WebIf 404 page, leading to the WebIf home page with Back on the remote. Or maybe I should try harder.
I should. CF's Webshell doesn't use the documented port 4200, just 80 as normal. If you use that, you can get a Webshell page displayed in the TV Portal, and auto-magically the PIN entry comes with the RC data entry widget that everyone will know from setting WiFi passwords, etc. But I couldn't find an easy way to get it back, so although I could display the telnet menu there was no way to select any of the options. Less critically and presumably fixable, the cursor was shown several characters to the left of its correct position, and the font was only really readable from less than two screen widths away. So clearly there is also some scope for experimentation with the entire WebIf. However being able to get the telnet menu up on the screen and enable the one-shot commands, even without cli, could be very useful.

Here's the procedure so far.
  1. Install webshell if not already installed.
  2. Install the new-portal package if not already installed. new-portal sets up a configurable local portal that forwards to the Humax site for their apps.
  3. Create /mod/webif/plugin/webshell/webshell.html:
    Code:
    <!doctype html>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta charset="UTF-8">
    <title>Humax Webshell</title>
    <link href="style.css" rel=stylesheet type=text/css />
    <!-- needed to put the terminal in a visible part of the TV screen -->
    <style>body { padding: 5%; }</style>
    </head>
    <body>
    <div id=iframewrapper>
    <iframe src=/cli/menu></iframe>
    </div>
    </body>                 
    </html>
  4. Make the icon /mod/webif/plugin/webshell/icon-128.png by shrinking /mod/webif/plugin/webshell/icon.png to 128 pixels square.
  5. Add a prototype Webshell app, initially just as a Favourite app by running this:
    Code:
    # sqlite3 /mod/etc/portal.db
    sqlite> INSERT INTO favourites VALUES(NULL,'http://localhost/plugin/webshell/webshell.html','Webshell','http://localhost/plugin/webshell/icon-128.png',strftime('%s', 'now')*1000);
    sqlite>
    Once, if ever, it's working properly, the right way to install it will be by editing /mod/webif/html/portal/js/TVApps.js.
  6. Just for safety's sake, restart the webshell service service webshell restart (or use the WebIf, or restart the HD/R).
 
Last edited:
Obviously, several things could be done from the telnet menu using just the remote control if it understood numbers as well as item names, and now it can:
Code:
--- /mod/boot/2/tmenu-1.22
+++ /mod/boot/2/tmenu
@@ -2,7 +2,7 @@
 
 # $Id: tmenu 3552 2017-01-15 16:07:16Z af $
 
-vers=1.22
+vers=1.22df
 
 # Use the package-delivered script if it's newer.
 pkgtmenu=/var/lib/humaxtv_backup/mod/tmenu
@@ -315,8 +315,9 @@
 
 item()
 {
-       arg=$1; shift
-       printf "%8s - %s\n" $arg "$*"
+       local arg=$1; shift
+       itmno="$(( itmno + 1 ))"
+       printf "%1d. %8s - %s\n" "$itmno" "$arg" "$*"
 }
 
 mmode_menu()
@@ -729,6 +730,39 @@
        fi
 }
 
+show_menu() {
+       [ $mmode -eq 1 ] && mmode_menu || main_menu
+       item diag "Run a diagnostic."
+       item cli "System command line (advanced users)."
+}
+
+get_menu_cmd() { # cmd_number
+       itmno=0
+       show_menu |
+               ( IFS=".$IFS"
+                 while read -r itmno cmd _; do
+                       if [ "$itmno" -eq "$a" ] 2>/dev/null; then
+                               echo "$cmd"
+                               break;
+                       fi
+                 done )
+}
+
+do_selection() { # cmd
+       
+       case $1 in
+               diag) diagnostic ;;
+               cli) cli ;;
+               *)
+                       if [ $mmode -eq 1 ]; then
+                               mmode_opt $a
+                       else
+                               main_opt $a
+                       fi
+               ;;
+       esac
+}
+
 # Main menu loop
 
 echo "Menu version $vers"
@@ -740,6 +774,7 @@
 fi
 
 while :; do
+       itmno=0
        if [ "$model" = "HD" ]; then
                [ -d /mod/bin ] && modok=1 || modok=0
        else
@@ -762,9 +797,7 @@
                echo
        fi
 
-       [ $mmode -eq 1 ] && mmode_menu || main_menu
-       item diag "Run a diagnostic."
-       item cli "System command line (advanced users)."
+       show_menu
        echo
 
        a=
@@ -773,19 +806,13 @@
                read a
        done
 
-       a=`echo $a | sed 's/[[:space:]]//g'`
+       a=`echo $a | sed 's/[[:space:]]//g;s/^0\+\([1-9]\)/\1/'`
 
-       case $a in
-               diag) diagnostic ;;
-               cli) cli ;;
-               *)
-                       if [ $mmode -eq 1 ]; then
-                               mmode_opt $a
-                       else
-                               main_opt $a
-                       fi
-               ;;
-       esac
+       if [ "$a" -ge 0 ] 2>/dev/null; then
+               a="$(get_menu_cmd "$a")"
+       fi
+
+       do_selection "$a"
 
        echo
        echo -n "Press return to continue: "
IIRC there was a suggestion to do this for some other reason, and perhaps this could make it into CF 3.14.

The result looks like this, and similar in the TV Portal Webshell app from post #1.
Code:
# tmenu
Menu version 1.22df
Enter system PIN: ****

      /-------------------------\
      |  T E L N E T   M E N U  |
      \-------------------------/

  [ Humax HD-Fox T2 (humax) 1.03.02/3.13 ]

1.    maint - Restart into maintenance mode.
2.     safe - Enable safe mode on next boot.
3.    reset - Reset custom firmware environment.
4.  upgrade - Upgrade all installed packages.
5.   passwd - Remove web interface password.
6.   fixweb - Re-install web interface.
7.     stat - Show current activity.
8.        x - Exit and close connection.
9.   reboot - Reboot the Humax.
10.     diag - Run a diagnostic.
11.      cli - System command line (advanced users).

Please select option: 7

Collecting status information...

Watching 704: BBC Radio 4 - Crossing Continents (20:30 - 21:00) [29%]
Idle: 00:02:16

Press return to continue:
But the status report is misleading in the TV Portal context; it should say "Running TV Portal ..."!
 
Definitely. I hadn't realised the menu would go into 2 digits of lines.

Also, it's convenient to let Yes/No questions be answered with 1 for Yes.

With those changes in my latest version, as well as "8. x", it's possible to "9. reboot" and "4. upgrade", and presumably other more disruptive options that I didn't try:
I suppose some of the maintenance mode operations could be packaged up into a sequence "go to maint mode; do operation; leave maint mode":
  • "Clear persistent EPG data";
  • "Reset DLNA server database".
Also, surely the SMART disk check options could be run directly, without going to maintenance mode, as the Humax s/w does, and extended for the HD as well?
 
Back
Top