Koozali.org formerly Contribs.org

Mojolicious

Offline ReetP

  • *
  • 1,193
Mojolicious
« on: January 17, 2018, 11:59:30 AM »
I have posted on the devinfo list but thought I'd add something here.

I have been messing with mojolicious. There has been a lot of chat about trying to build a new server manager with it, but that would need an entire framework designed and built and is well beyond me.

So I was curious about it and my aim was to try and produce a simple panel which could integrate with the existing server manager to allow me to easily change my ipsec stuff as it has lots of config items and is tricky on the CLI and easy to make typos for important settings.

I have no idea whether I can successfully do this. However, I can see the potential of Mojo.

I have opened a git repo here if anyone is interested in playing - either make a PR or mail me your username and I can add you as a collaborator:

https://github.com/reetp/mojotests

Essentially create an ibay, make sure it allows executable content, drop the file into the cgi-bin dir and make sure the perms are set as follows:

Code: [Select]
chown root:www *.cgi;chmod 0750 *.cgi;chmod u+s *.cgi
(I am not 100% sure if that is tight enough, but it will at least run!)

Install mojo:

yum install perl-Mojolicious --enablerepo=fws

You can clone the file into the cgi-bin dir like this:

Code: [Select]
git clone https://github.com/reetp/mojotests .
The code has a hard coded link to a css file which you may want to modify.

It has a dropdown that you can select and then submit which returns you back to the original page. I am not sure yet how to capture the selected items..... I'll figure that today I hope :-)

Something that the documentation didn't easily explain here http://mojolicious.org/perldoc/Mojolicious/Plugin/TagHelper was how to get the form to actually react.

I realised you had to wrap the template tags with <form> tags which it doesn't mention !

I had this code form the docs:

Code: [Select]
<%= select_field 'networks' => [ @{ stash('stuff') }], id=> 'dropdown' %>

But it actually needed wrapping like this:

Code: [Select]
<form name="networks" action="./readtest1.cgi/agent" method="POST">
<%= select_field 'networks' => [ @{ stash('stuff') }], id=> 'dropdown' %>
<input type="submit" value="Submit">
</form>

That applies to all the helper tags....

Once I had figured that we were off to the races.

Please have a play and let me know how you get on !

...
1. Read the Manual
2. Read the Wiki
3. Don't ask for support on Unsupported versions

Bugs are easier than you think: http://wiki.contribs.org/Bugzilla_Help

If you love SME and don't want to lose it, join in: http://wiki.contribs.org/Koozali_Foundation

Offline TerryF

  • ****
  • 872
Re: Mojolicious
« Reply #1 on: January 25, 2018, 11:45:08 PM »
Just a little bit of action beginning, and I do mean a beginning, first steps, BUT, if more of you get involved it has the potential to be a revolution.

Join in - https://lists.contribs.org/pipermail/devinfo/2018-January/date.html
--
qui scribit bis legit

Offline ReetP

  • *
  • 1,193
Re: Mojolicious
« Reply #2 on: January 26, 2018, 12:11:06 AM »
The dev posts are long. In short I took the following bootstrap/jquery template that Tony Keane (RIP mate) built as a quick demo:

https://home.reetspetit.net/testbay/server-manager/main.html

(Note nothing works.... it is just a framework)

And recreated the same thing plus a few simple form elements with perl-mojo:

https://home.reetspetit.net/testbay/cgi-bin/template.cgi

(The form bits do return values as proof of concept)

The basics were surprisingly easy. I built it in about 4 days of spare time having known nothing of mojo.

I spelled out my thoughts on the dev list but there is a limit to my coding.

One key point is how to modify some core elements so you get an effective API that ANY app could call with no perl knowledge. For an exprerenced dev it is probably trivial, but I am not that person.

I can probably do a certain amount but it needs greater minds than mine.

Any ideas or assistance appreciated.
...
1. Read the Manual
2. Read the Wiki
3. Don't ask for support on Unsupported versions

Bugs are easier than you think: http://wiki.contribs.org/Bugzilla_Help

If you love SME and don't want to lose it, join in: http://wiki.contribs.org/Koozali_Foundation