Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contribution: Web Front-end for vsd #31

Open
oliverschmidt opened this issue Oct 20, 2016 · 1 comment
Open

Contribution: Web Front-end for vsd #31

oliverschmidt opened this issue Oct 20, 2016 · 1 comment

Comments

@oliverschmidt
Copy link

The vsd script is a great addition to ADTPro. However opening a Telnet session might not be the most straight forward thing to do in every scenario. Therefore I created a simplistic web front-end for vsd. I see two primary usage scenarios:

  • Upload a new disk image from a PC to the 'disks' directory using SMB and then use a web browser on that PC to mount it right away as virtual disk.
  • Sort of "replace" the second serial connection between the A2 and the RPi with an Ethernet connection: Use an A2 Ethernet card (LANceGS, Uthernet, Uthernet II) and the Contiki web browser to mount a different disk image as virtual disk from the A2. Below there's a screenshot showing how the Contiki web browser renders the web front-end for vsd.

The web front-end makes use of the web server capabilities built into the standard Python libraries. So it doesn't depend on any additional installation:

#!/usr/bin/python
import BaseHTTPServer, subprocess, urlparse

class Handler(BaseHTTPServer.BaseHTTPRequestHandler):
    def do_GET(self):
        url = urlparse.urlsplit(self.path)
        if url.path != '/':
            self.send_error(404)
            return
        if url.query:
            query = dict(urlparse.parse_qsl(url.query))
            if 'vsd1' in query:
                subprocess.call(['vsd', '-1', query['vsd1']])
            if 'vsd2' in query:
                subprocess.call(['vsd', '-2', query['vsd2']])
        try:
            vsd1 = subprocess.check_output(['vsd', '-1'])[17:-1]
            vsd2 = subprocess.check_output(['vsd', '-2'])[17:-1]
        except subprocess.CalledProcessError:
            vsd1 = ""
            vsd2 = ""
        self.send_response(200)
        self.send_header('Content-type', 'text/html')
        self.end_headers()
        self.wfile.write('<html>\n')
        self.wfile.write('  <head>\n')
        self.wfile.write('    <title>A2CLOUD</title>\n')
        self.wfile.write('    <meta name="viewport" content="width=device-width, initial-scale=1">\n')
        self.wfile.write('  </head>\n')
        self.wfile.write('  <body style="font-family:sans-serif;">\n')
        self.wfile.write('    <h2>A2CLOUD</h2>\n')
        self.wfile.write('    <form action="/"><p>Drive 1\n')
        self.wfile.write('      <input type="text" name="vsd1" value="' + vsd1 + '" size="60" maxlength="120">\n')
        self.wfile.write('      <input type="submit" name="s" value="Mount">\n')
        self.wfile.write('    </form>\n')
        self.wfile.write('    <form action="/"><p>Drive 2\n')
        self.wfile.write('      <input type="text" name="vsd2" value="' + vsd2 + '" size="60" maxlength="120">\n')
        self.wfile.write('      <input type="submit" name="s" value="Mount">\n')
        self.wfile.write('    </form>\n')
        self.wfile.write('  </body>\n')
        self.wfile.write('</html>')

httpd = BaseHTTPServer.HTTPServer(('', 80), Handler)
httpd.serve_forever()

Beside using the HTML form it is as well possible to mount a disk image by specifying it right in the URL like http://<ip addr of Raspple II/?vsd1=<disk image name to mount in drive 1> which allows for further scenarios.

The web front-end can be started together with the ADTPro server by saving it as /usr/local/bin/webvsd.py, making it executable and adding it to adtpro-start right after the call to adtpro.sh as sudo nohup webvsd.py &> /dev/null &.

screenshot

@oliverschmidt
Copy link
Author

oliverschmidt commented Oct 25, 2016

I think it would be cleaner to replace

            if 'vsd1' in query:
                subprocess.call(['vsd', '-1', query['vsd1']])
            if 'vsd2' in query:
                subprocess.call(['vsd', '-2', query['vsd2']])

with

            if 'vsd1' in query:
                subprocess.call(['vsd', '-1', '-f', query['vsd1']])
            if 'vsd2' in query:
                subprocess.call(['vsd', '-2', '-f', query['vsd2']])

in order to avoid reading from stdin in the first place instead of relying on Python to make it work ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants