Plugin Development Questions & Some Bugs?

Started by TotalGriffLock, August 14, 2024, 09:53:36 PM

Previous topic - Next topic
August 14, 2024, 09:53:36 PM Last Edit: August 14, 2024, 10:17:37 PM by jgriffith-ecs
Hi,

I am porting the scan agent for phpIPAM into OPNSense so you can perform subnet scans directly from the firewall/gateway/DHCP server/whatever role OPNSense has in your network. The agent itself is a threaded (using prctl) CLI PHP application from https://github.com/phpipam/phpipam-agent

I have written a plugin to perform GUI configuration of the agent and add scanning tasks as cron jobs in the web gui which all works fine and as expected. However there are some packaging questions I have:

  • The phpipam-agent needs to reside somewhere. It is essentially a php script so there is no FreeBSD port of it for example. In my dev setup I have put it in /usr/local/share/phpipam-agent - where would be the appropriate place for this to live on the filesystem in production, and how would I package it into my plugin for it to live somewhere outside of the /usr/local/opnsense tree? I suspect I am going about this part incorrectly. Will I need to package the agent and the OPNsense plugin separately and somehow make both available?

  • The phpipam-agent requires quite a few PHP packages that are not in the OPNsense ports collection but are in the FreeBSD ports collection, namely php82-gmp php82-pdo_mysql php82-iconv php82-posix. I have seen that one can request these ports be made available for OPNsense by opening a git issue - is that still the right approach?

Then, some possible bugs! I think there may be a couple of mistakes in the documentation regarding building. Several times in the build documentation the package vim-console is referenced, but this does not appear to be installable anymore. 

I believe there is a line of code in the example for the settingscontroller jquery which is incorrect. By this I mean the code shown in the documentation at https://docs.opnsense.org/development/examples/helloworld.html - the file in the github repo is correct. There is a line:

$result["validations"]["general.".$msg->getField()] = $msg->getMessage();
Which I think should be:
$result["validations"]["helloworld.".$msg->getField()] = $msg->getMessage();

The original code results in an object being returned called general.general.fieldname when I think it should be helloworld.general.fieldname?

Additionally it does not appear possible to have an entry in the menu.xml file for a plugin where the tag name starts with php

This did not work in my testing:
<menu>
    <Services>
        <PhpIpamAgent visibleName="phpIPAM Agent" cssClass="fa fa-list-ol fa-fw">
            <Settings url="/ui/phpipamagent" />
        </PhpIpamAgent>
    </Services>
</menu>


This does work:
<menu>
    <Services>
        <ipamAgent visibleName="phpIPAM Agent" cssClass="fa fa-list-ol fa-fw">
            <Settings url="/ui/phpipamagent" />
        </ipamAgent>
    </Services>
</menu>


Thanks!

Ah, I am an idiot. The answer to question 1 is obvious - put it in /usr/local/opnsense/scripts