Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

figlet tool / display ascii art to html/webpage

twaintwain Member

I'd like to use the figlet command line tool to input text into figlet, then process the output to html.

** note ** figlet processes text into ascii art **

Is there an easiest method to do this? Should I just try php exec? Or what it be easier/better/cleaner/safer etc with python or ruby/camping or node.js or whatever else?

Thanks for any suggetions.

Comments

  • awsonawson Member

    Use PHP's Text_Figlet package?

    http://pear.php.net/package/Text_Figlet

  • twaintwain Member
    edited July 2013

    Thanks @awson, however I just went ahead and did it with shell_exec..

    Show client IP address in ascii art (eg what is my ip in ascii hehe):

    
    <?php
    $client_addr = filter_var((!empty($_SERVER['HTTP_CLIENT_IP']))? $_SERVER['HTTP_CLIENT_IP']:
    (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))? $_SERVER['HTTP_X_FORWARDED_FOR']:
    (!empty($_SERVER['REMOTE_ADDR']))? $_SERVER['REMOTE_ADDR']:'UNKNOWN', FILTER_SANITIZE_STRING);
    
    $asciip = shell_exec("figlet " .$client_addr. "| sed 's/./& /g;s/ / /g'");
    echo "<h2><*pre>$asciip</*pre>";
    ?>
    
    

    The * in the pre in the code is so it does not conflict with the LET comment pre :)

    Not sure about the security but it works.

  • AdducAdduc Member
    edited July 2013

    @twain, I'd be able to bypass your filters and potentially cause harm with a HTTP_X_FORWARDED_FOR header of asdf|rm -rf /. To remedy this, use escapeshellarg($client_addr) to properly escape input for command line usage.

  • twaintwain Member
    edited July 2013

    @Adduc, thanks very much for that tip; added and very good to know.

    Demo on koding if anyone wants to see... (appears to be showing the koding proxy ip only perhaps.. hmmm)

    http://indigodaddy.kd.io/asciip/

    Just have to say just logged in to koding for the first time in like 4-6 months and it's gotten a hell of a lot better since then.. instead of a shared environment you spin up your own vm now... really great for playing around with code/stuff/testbeds etc. Beats the heck out of http://1.ai now.

Sign In or Register to comment.