Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Tips for integrating bash based application to a website  (Read 3262 times)

0 Members and 1 Guest are viewing this topic.

johananj

    Topic Starter


    Greenhorn

    Thanked: 1
    • Experience: Experienced
    • OS: Linux variant
    Tips for integrating bash based application to a website
    « on: March 23, 2017, 01:56:32 AM »
    Hi,

    I have an application that was fully built on bash. The core frameworks are all in C. There are some perl scripts in there as well. But the use would be through bash scripts that i have written. I need to tightly integrate this to a website. Meaning, the inputs i give to the terminal, the outputs i receive, all have to redirected from/to a web browser. Any tips. Direction, Do's and Dont's or any info from core web developers would be helpful.

    So far i have tried ajax using jquery. I was able to send and receive data from the app dynamically. That was good. But I still feel it needs a much more tighter integration. Like for example changing the shell scripts to php. Am i on the right track?

    camerongray



      Expert
    • Thanked: 296
      • Yes
      • Cameron Gray - The Random Rambings of a Computer Geek
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Mac OS
    Re: Tips for integrating bash based application to a website
    « Reply #1 on: March 23, 2017, 05:30:31 AM »
    It really comes down to how much you want to rebuild.  At the very least you're going to need some sort of backend on the webserver (PHP, Python.etc) that takes inputs from the frontend (either from standard HTML forms or through AJAX) and then call out to your existing scripts and then returns the outputs of the script back to your browser.  It would help if you explained what the shell scripts did as it would be much preferable to have all of the logic handled directly by the backend application wherever possible rather than calling out to external bash scripts.  You also have to be extremely careful when passing user input from a web application into a bash script, if you fail to sanitize user input correctly you run the very real risk of allowing people on the web page to access arbitrary shell commands.

    johananj

      Topic Starter


      Greenhorn

      Thanked: 1
      • Experience: Experienced
      • OS: Linux variant
      Re: Tips for integrating bash based application to a website
      « Reply #2 on: March 23, 2017, 08:57:59 AM »
      Thank you very much for your reply.

      Ajax yes. I need ajax because i need it to feel like an application.

      I am thinking of calling php scripts through ajax. The php scripts are supposed to call the bash scripts. Now i am thinking if i should try to write some of these bash scripts using php. Would that make anything better?... Does it make any difference.?

      I am not sure if i can fully describe what these scripts do. But let me get to another level of abstraction here. They are supposed to receive audio from the browser that will be recorded and sent to the server using a recording script called recorder.js and ajax respectively. You might have come across that. Scripts are supposed to process that and output text and also processed audio back to the browser. Where audio will be played back and text displayed.

      I am currently doing this with ajax and some weird polling mechanism. I do not like it actually, but it 'just works'. The method would not survive the beating of a regular user. Works under ideal conditions on the local host. I need to know how the a true web dev would approach this situation.  :)

      camerongray



        Expert
      • Thanked: 296
        • Yes
        • Cameron Gray - The Random Rambings of a Computer Geek
      • Certifications: List
      • Computer: Specs
      • Experience: Expert
      • OS: Mac OS
      Re: Tips for integrating bash based application to a website
      « Reply #3 on: March 23, 2017, 09:24:32 AM »
      If you're streaming audio.etc I'd definitely be looking into using WebSockets rather than AJAX polling.  I'd try and move as much of the bash code into your application as possible to try to avoid having to talk to the shell.  This application feels like it's going to be a bit beyond the level of "bunch of PHP scripts sitting on an Apache (or similar) webserver". You're probably going to want to look more into developing a standalone application that will run as a service on the server and listen for incoming socket connections from the frontend.

      johananj

        Topic Starter


        Greenhorn

        Thanked: 1
        • Experience: Experienced
        • OS: Linux variant
        Re: Tips for integrating bash based application to a website
        « Reply #4 on: March 23, 2017, 09:41:03 PM »
        Yes i sort of realized that. I think i have to go a bit deeper. I am playing around with very minimal stuff. But i think i will need to do some ground work now.
        Thanks a lot for Web Sockets. That is some good direction. I will look into it. Since i'm not a regular web dev i am lacking ideas. This is a good one. I will follow this trail and get back to you.

        Should i look into any particular frameworks?