Jump to content
IGNORED

WebGUI for sio2bsd on a raspberry pi (extremely hackish)


SenorRossie

Recommended Posts

post-39196-0-39931800-1403432973_thumb.png

When you are at an event and have limited space and even less time to do something usefull I often find myself taking shortcuts. Here's one I took in an hour or so, because I planned on attending an Home Computer event here in NL and wanted to do some coding on a 20 year old demo I couldn't get fixed.

Normally I am more off a CLI kinda GUY, but at an event I don't like leaving my laptop on a desk and keeping a shell open for no good reason. Besides that, more devices take up more space and I was not expecting to have much space available.

In order to quickly swap disks at the event I wanted to have a simple webgui to swap disks on the less than a desk setup I brought along. Here's my setup:

* WRT54G router (DHCP server and WiFi access point)
* Raspberry Pi (installation details here: this post)
* SIO2PC/10502PC Dual-USB (from Atari8Warez)
* Phone and Tablet
* Monitor
* Miscellaneous stuff (power supplies, ethernet cables, etc).

I had already copied a few hundred ATR's to the Raspbery Pi's SD card (Demo's, DOS, Atmas II, etc). So no more dragging along mountains of floppies badly - or mislabeled, but how to make the swapping of disks easy as Pi(e)?

Well I had a credit card size linux server with me, so why not (ab-)use that some more...



The installation

I first installed a webserver and my (web-) scripting language of choice (2nd):
apt-get install -y mini-httpd php5-cgi
mkdir -p /var/www/html && chown -R www-data: /var/www/


I then Modified the mini-httpd config file:

cat << EOF > /etc/mini-httpd.conf
host=0.0.0.0
port=80
user=www-data
nochroot
 
# We are the web files stored?
data_dir=/var/www/html
cgipat=**.php|**.cgi
logfile=/var/log/mini-httpd.log
pidfile=/var/run/mini-httpd.pid
 
charset=iso-8859-1
EOF


I then FIXED the default settings in the .ini file of the php5-cgi package which is apache tailored and does not work with mini-httpd by default:

sed -i 's/\;cgi\.force_redirect\ =\ 1/cgi\.force_redirect\ =\ 0/' /etc/php5/cgi/php.ini

Then I needed to modify /etc/default/mini-httpd to allow the service to start, enable the service in the default runlevels and start it manually for this session:

cat << EOF > /etc/default/mini-httpd
# Defaults for mini_httpd initscript
# Author: Marvin Stark <marv@der-marv.de>

# Start daemon?
# 0 = no
# 1 = yes
START=1

# Additional options that are passed to the Daemon.
DAEMON_OPTS="-C /etc/mini-httpd.conf"
EOF
insserv -d mini-httpd
service mini-httpd start

Now the web server is up and running, it is time to write the code to swap the floppies. First off, it all needs to reside in /var/www/html, as that's where the web server is looking for its files. I attached a copy of the code webgui_4_sio2bsd.tar to this post which can be installed like so:

cd /var/www/html/
tar -xf ~/webgui_4_sio2bsd.tar

A simple config file with some sane defaults (notice that I moved the sio2bsd executable to a directory in the default path (/usr/bin). If you want to store the command someplace else, simply specify the full path for $cfg["sio2bsd"]["cmd"], eg: $cfg["sio2bsd"]["cmd"]="/usr/local/bin/sio2bsd";
If you need warp speed or want to add other parameters to the sio2bsd command by default, put the in $cfg["sio2bsd"]["param"]="" and if you want to load a default disk in a drive, specify the full path to the ATR file here as well.

File: /var/www/html/.config.inc.php

<?php
$cfg["atr"]["path"]="/opt/data/Atari/XL_XE/disks/";  // don't forget to end the path with a /
$cfg["atr"]["dump"]="/var/www/html/atrlist.ser.php";
$cfg["atr"]["drive0"]="-";
$cfg["atr"]["drive1"]="-";
$cfg["atr"]["drive2"]="-";
$cfg["atr"]["drive3"]="-";
$cfg["sio2bsd"]["cmd"]="sio2bsd";
$cfg["sio2bsd"]["param"]="";
$cfg["sio2bsd"]["serial"]="ttyUSB0"; // atari8warez dual usb: ttyUSB0 || sio2pi: ttyAMA0
?>

In order to update your list of images I created a separate script. As the Pi is not the fastest device on the planet and I/O is quite a heavy operation I decided to get store the available images on disk instead of having to create that list every time you load or update the page. You can run it from cron, or via the web server, whatever you prefer. Remember, that it needs to run at least once.

File: gen_atrlist.php

#!/usr/bin/php5-cgi
<?php
  include(".config.inc.php");
 
  /**
   * Sucks given directory into a sorted array
   * Recurses into subdirs if asked
   *
   */
  function it_get_dir($directory, $recurse="true" ) {
    // Disable directory traversal
    if ( strstr ( $directory, ".." ) ) {
      return false;
    }
    $Dir = opendir( $directory );
    $num = 0;
 
    // false !== ... evades problems when encountering '0' or 'false' in names.
    while( false !== ($file = readdir( $Dir )) ) {
      $filename = $directory . $file;
      if( ! is_link($filename) ) {
        if( ! is_dir($filename) ) {
          // FOUND: Regular file
          $dirlist[$num] = $filename;
          $num++;
        } elseif( $recurse ) {
          // FOUND: Directory
          if ( $file != "." && $file != ".." ) {
            $subdir = it_get_dir($filename . "/", $recurse );
            $subdirlist = array_merge( (array)$dirlist, (array)$subdir );
            $num = count( $subdirlist ) + 1;
            $dirlist = $subdirlist;
          }
        }
      }
    }
    @closedir( $Dir );
 
    if( ! empty($dirlist) ) {
      rsort($dirlist);
      reset($dirlist);
    }
    return $dirlist;
  }
 
  /**
   * Dumps array to disk, no more, no less
   *
   */
  function it_dump_array_to_disk( $filename="", $data=array() ) {
    if ( @is_writable($filename) || @file_exists($filename) === false ) {
      if (!$fd = @fopen($filename, 'w')) {
        return false;
      }
 
      if( @fwrite($fd, serialize($data)) === FALSE ) {
        @fclose($fd);
        return false;
      } else {
        fclose($fd);
      }
    }
  }
 
  $atrlist=it_get_dir($cfg["atr"]["path"], true );
  it_dump_array_to_disk( $cfg["atr"]["dump"], $atrlist);
?>

The main hack... Here is where the icky magic part happens
File: index.php

#!/usr/bin/php5-cgi
<html>
 <head>
  <title>Pi2SIO WebGUI</title>
   <style type="text/css">
body {
	background-image:url('img/stripes.gif');
	background-color:#ffffff;
}
  </style>
 </head>
<?php
include( ".config.inc.php" );
 
/**
 * Reads dumped array from disk
 *
 */
function it_get_array_from_disk( $filename="" ) {
  if ( @file_exists($filename) ) {
    $data = @unserialize(file_get_contents($filename));
    return $data;
  } else {
    return false;
  }
}
 
$disk0=$_POST['disk0'];
$disk1=$_POST['disk1'];
$disk2=$_POST['disk2'];
$disk3=$_POST['disk3'];
$do_update=$_POST['update'];
 
isset($disk0) || $disk0=$cfg["atr"]["drive0"];
isset($disk1) || $disk1=$cfg["atr"]["drive1"];
isset($disk2) || $disk2=$cfg["atr"]["drive2"];
isset($disk3) || $disk3=$cfg["atr"]["drive3"];
 
$cmdCLI=$cfg["sio2bsd"]["cmd"] . " " . $cfg["sio2bsd"]["param"];
$cmdCLI.= " -s /dev/" . $cfg["sio2bsd"]["serial"] . " ";
 
if( ($disk0!="-" || $disk1!="-" || $disk2!="-" || $disk3!="-") && (! empty($do_update) ) ) {
  $cmdCLI.="\"" . $disk0 . "\" \"" . $disk1 . "\" \"" . $disk2 . "\" \"" . $disk3 . "\"";
  exec( "pkill -9 sio2bsd" );
  exec( "rm -rf /tmp/sio2bsd*" );
  exec( "nohup " . $cmdCLI . " 1>/var/www/html/sio2bsd.log.txt 2>&1 &" );
}
?>
 <body>
  <center><img src="img/logo-color.gif" alt="A T A R I" align="middle" border="0" /></center>
  <h1 align="center">Simple WebGUI for /sio2bsd/</h1>
  <hr>
  <table with="90%" align="center" border="0">
   <tr>
    <th>Drives</td>
    <th>Available Images</td>
   <tr>
   <tr>
    <td valign="top">
     <form action="<?php echo $PHP_SELF;?>" method="POST">
      D0: <input type="text" name="disk0" value="<?php echo $disk0;?>" /><br />
      D1: <input type="text" name="disk1" value="<?php echo $disk1;?>" /><br />
      D2: <input type="text" name="disk2" value="<?php echo $disk2;?>" /><br />
      D3: <input type="text" name="disk3" value="<?php echo $disk3;?>" /><br />
      <br />
      <input type="reset">
      <input type="submit" name="update" value="Update Drives">
     </form>
    </td>
    <td>
     <ul>
     <?php
      $atrlist=it_get_array_from_disk( "atrlist.ser.php" );
      foreach( $atrlist as $id=>$filename ) {
	if( stristr( $filename, ".atr" ) ) {
	  print( " <li>$filename</li>" );
        }
      }
     ?>
     </ul>
    </td>
   </tr>
  </table>
 </body>
</html>
  • Like 5
Link to comment
Share on other sites

  • 2 weeks later...

I literally just soldered up a logic level converter board with some wires and got it hooked up between my 800XL and the Pi... was looking for the instructions when I saw this thread! Nice work mate, I was wondering about doing something similar myself, so will give this a spin and see how I go :)

Link to comment
Share on other sites

  • 4 years later...

Reviving an old thread, sorry about that!

Wanted to let everyone know, with all the sdrive max craze going on, that I decided to redo the webgui for sio2bsd. The old version has been put up on github: https://github.com/senorrossie/php-sio2bsd-web and I created a 'develop' branch for the new version, which is not yet completed.

 

A quick preview:

1. Browsing through the image section of the fandal archive

post-39196-0-73464000-1532255082_thumb.jpg

 

2. Ejecting D1, all four drives loaded with (atr) images

post-39196-0-42151700-1532255321_thumb.jpg

  • Like 4
Link to comment
Share on other sites

The new version is now in master. I created a release on github (https://github.com/senorrossie/php-sio2bsd-web/releases/tag/v2.0-beta.1) to make clear it is still a beta version.

 

I have not tested this version very intense, there are probably more bugs than noted in the TODO.

 

Enjoy!

 

*EDIT* Should have tested a bit more, the sio2bsd lockfile permissions are a bit too strict for the current code. I created a new release (https://github.com/senorrossie/php-sio2bsd-web/releases/tag/v2.0-beta.2) that includes a patched sio2bsd binary.

Edited by SenorRossie
  • Like 1
Link to comment
Share on other sites

Hi!

 

The new version is now in master. I created a release on github (https://github.com/senorrossie/php-sio2bsd-web/releases/tag/v2.0-beta.1) to make clear it is still a beta version.

 

I have not tested this version very intense, there are probably more bugs than noted in the TODO.

 

Enjoy!

 

*EDIT* Should have tested a bit more, the sio2bsd lockfile permissions are a bit too strict for the current code. I created a new release (https://github.com/senorrossie/php-sio2bsd-web/releases/tag/v2.0-beta.2) that includes a patched sio2bsd binary.

Great GUI, I think that having a web GUI is a great idea.

 

Do you have the source for your modified sio2bsd?

 

I have a local version that I use in my OrangePI-PC (cheaper than a Raspberry PI :) ), and I want to see what modifications you have done.

 

Long term, I think that all the enhancements from RespectQT (support for ATX files and fast XEX loaders) could be ported to sio2bsd, with your GUI it could be very easy to use.

  • Like 1
Link to comment
Share on other sites

The modifications are a quick hack, as I'm not fluent in C ;)

 

Looking at the github version of the Montezuma, in the function serlock(void), below the line

 

(void)mkdir(dpath, S_IRUSR|S_IWUSR|S_IXUSR);

 

Add:

(void)chmod(dpath, 770);

 

A bit further down, find the line

fd = creat(dpath, S_IRUSR|S_IWUSR);

 

Add

(void)chmod(dpath, 660);

 

What these changes accomplish is: give group write permissions to the directory and the lockfile. As the webserver is executing the sio2bsd as root, it is now able to remove its lockfile.

Link to comment
Share on other sites

Hi!

 

The modifications are a quick hack, as I'm not fluent in C ;)

 

Looking at the github version of the Montezuma, in the function serlock(void), below the line

 

(void)mkdir(dpath, S_IRUSR|S_IWUSR|S_IXUSR);

 

Add:

(void)chmod(dpath, 770);

 

A bit further down, find the line

fd = creat(dpath, S_IRUSR|S_IWUSR);

 

Add

(void)chmod(dpath, 660);

 

What these changes accomplish is: give group write permissions to the directory and the lockfile. As the webserver is executing the sio2bsd as root, it is now able to remove its lockfile.

You can give proper permissions in the mkdir and creat calls, just do:

 

(void)mkdir(dpath, S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IWGRP|S_IXGRP);
and

 

fd = creat(dpath, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP);
(those are the same as using 0770 and 0660 in the calls, but symbolic constant can be more portable) Edited by dmsc
  • Like 1
Link to comment
Share on other sites

You are absolutely right about using the more portable constants.

 

I feel the original values used by sio2bsd make more sense than the ones I quickly added to make it work for me: It was late/early and I just released a non working version of the GUI, made me go the easy way out ;)

 

Still need to look into the reason why sio2bsd wouldn't read the atr when run as www-data. As soon as that's fixed, the permissions for the lockfile and the SETUID root permission for the binary are not needed anymore. But that is for a later moment, it works now.

Link to comment
Share on other sites

  • 11 months later...

I had no idea this had undergone such an overhaul! I think I'm too far down the rabbit hole with the older version to switch, though!

 

I have been running with a modified version of the older release, which I changed so that it works from a mobile phone.

I must have grabbed that version shortly before you released the latest version last year.

 

I have spent the last few days modifying the older version to work with the atariserver program from the atarisio project - this gives the ability to use XEX and CAS files as well as ATR files.  CAS file support isn't so useful, as you need access to a terminal to start the tape, and I hadn't realised just how slow tape loading was on the Atari as my tape deck fell apart before I ever used it!  The best tape speed I could get to load Starquake was 125% and that still took 10:30!

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...