troglobit / pimd

PIM-SM/SSM multicast routing for UNIX and Linux
http://troglobit.com/projects/pimd/
BSD 3-Clause "New" or "Revised" License
194 stars 86 forks source link

pimctl output OK via cmdline <> but NOK when integrated in html #235

Open LouisAtGH opened 1 year ago

LouisAtGH commented 1 year ago

Joachim,

I compiled the actual code using freebsd 14-currenct in favor of the actual pfSense development release. Works OK, no problem, apart from an layout issue.

pfsense is integrating the pimctl output in its html screens like this

<?= htmlspecialchars(shell_exec('/usr/local/sbin/pimctl show')); ?>

And pimctl reacts with an output intended for a vt100 command line using control like

ESC[4m  ESC[24m     set underline mode
ESC[7m  ESC[27m     set inverse/reverse mode
ESC[0m             reset all modes (styles and colors)

However that does not fit in an html page :( (see example below)

To solve this the pmctl headers format should be either OK for both command line and html or there should be an option to select 'the formatting format'

I also have been considering two other options:

Below an example of the pimctl output as it shows up in the pfsense gui, and below that some compiler warnings I discovered. Not dramatic however hot really OK as well.

Louis

pimctl output as displayed in an html screen

How formatted headers are shown in an html page:

lagg0.5           Up        192.168.5.1               1     30    0  192.168.5.1               1
                                                                               
PIM Neighbor Table
Interface         Address            Priority  Mode  Uptime/Expires                  
                                                                               
Multicast Routing Table
Source            Group            RP Address       Flags                      
ANY               239.255.255.250  192.168.14.15    WC RP
192.168.1.2       239.255.255.250  192.168.14.15    SPT CACHE SG

Compiler warnings

configure.ac:8: warning: The macro `AC_CONFIG_HEADER' is obsolete.
configure.ac:8: You should run autoupdate.
configure.ac:51: warning: The macro `AC_HEADER_STDC' is obsolete.
configure.ac:51: You should run autoupdate.
configure.ac:3: warning: name 'aux' is reserved on W32 and DOS platforms
kern.c:212:24: warning: unused parameter 'socket' [-Wunused-parameter]
void k_set_pktinfo(int socket, int val)
kern.c:212:36: warning: unused parameter 'val' [-Wunused-parameter]
void k_set_pktinfo(int socket, int val)
pim.c:447:53: warning: unused parameter 'frag' [-Wunused-parameter]
static int send_frame(char *buf, size_t len, size_t frag, size_t mtu, struct sockaddr *dst, size_t salen)
                                                    ^
pim.c:447:66: warning: unused parameter 'mtu' [-Wunused-parameter]
static int send_frame(char *buf, size_t len, size_t frag, size_t mtu, struct sockaddr *dst, size_t salen)
troglobit commented 1 year ago

Edit: changed markup syntax of issue to Markdown

troglobit commented 1 year ago

Thank you for the report. See my comments below:

LouisAtGH commented 1 year ago

Joachim, pfSense uses PHP, I worked around the issue this way.

I did work around the problem in the following way:

The ANSI controls available in the output where ESC[4m ESC[24m set underline mode ESC[7m ESC[27m set inverse/reverse mode ESC[0m reset all modes (styles and colors) More info in https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797

With as complicating factor that every modified line was terminated by the generic ESC[0m, which forced me to use a generic html termination code as well.

I defined an string array like this $dictionary = array( '#[4m' => '
____' , '#[24m' => '
' , '#[7m' => '' , '#[27m' => '' , '#[0m' => '' , ); Where the '#' is an replacement for the original ESC-character ( I do not know how to insert an ESC-character in a static string array)

Then the following line did the job


        
LouisAtGH commented 1 year ago

Joachim,

What seems minimal to me is that the formatting is symmetrical / consistent. As example

  • starting bold should be terminated with end bold ESC[4m should be followed by ESC[24m and not by ESC[0m !
  • and of course a control starting 1st should be closed last
troglobit commented 1 year ago

Sorry, but no. This is not HTML tags, it's ANSI escape sequences, and there's no standard that says one cannot use ESC[0m to disable all formatting. If you go for translating ANSI escape codes you need to handle all these cases. If you do it right, such a function would be useful for parsing output from many other system tools as well.

My recommendation is still to go for an alternate output format, I suggest JSON since that's sort the industry standard at this point.

Btw, I suppose you've seen the pimctl -p option to disable ANSI escape sequences altogether?

LouisAtGH commented 1 year ago

Oeps! I did not notice the -p option, but that surely improves the situation! Thanks for the tip ! (the idea is not great, but the result of my workarround is not even bad)

Whatever if you want to convert e.g. the ANSI escapes to for example html layout controls, than you you need not only the start of the style change but also the end.

I can convert ansi "start bold" to the equivalent html command but than I also have to insert the "stop bold" and it is not a big deal to translate ^ESC[4m^ into start underline and to translate ^ESC[24m^ into stop underline, but there is no way I can do something with ^ESC[0m^. No way to translate that in some equivalent code

troglobit commented 1 year ago

State machine. You can always track the latest set of HTML tags you've inserted. It's definitely possible, we did it in javascript for many other applications at my old job, so it should be in other languages as well.

I'm not going to change the ANSI escape sequences.