Vendor column lost in edit form

2013-07-10
2013-10-07
  • Angelo Turetta

    Angelo Turetta - 2013-07-10

    I wrote a perl script to parse the output of arpscan and feed the results to GestioIP.
    arp-scan can return the vendor for every MAC, and in fact it works very well along with the 'vendor' custom column type. I fill the column with the vendor string returned by arpscan, and GestioIP is displaying icons accordingly.

    Unluckily, there is a small bug in res/ip_modip_form.cgi(274), where the regexp matching is backwards. It should be:

     if ( $cc_entry && $cc_entry =~ /$vendor/ ) {
    

    So when I edit a discovered entry, the combo comes active without any selection, after which the vendor value is lost on save. You can see the effect by putting the value "Hewlett-Packard Company" as a custom vendor string and then re-opening the edit form after saving changes.

    I attach a more complete patch where I polished the code a little, adding the ability to keep the literal value of the vendor column intact during save, if unmodified (currently, in my previous example, the column value is overwritten by the string 'hp').

    If you like my patch, you can download it from http://snipt.org/AGae8: it should apply with "patch -p1"

    Thanks for your useful tool.

    Angelo.

    diff --git a/res/ip_modip_form.cgi b/res/ip_modip_form.cgi
    index 3eb1784..706ecf5 100755
    --- a/res/ip_modip_form.cgi
    +++ b/res/ip_modip_form.cgi
    @@ -210,19 +210,21 @@ foreach my $cc_ele(@custom_columns) {
        }
        if ( $cc_name ) {
            if ( $cc_name eq "vendor" ) {
    -           my $knownvendor="0";
    +           my $knownvendor=0;
    +           my $v=0;
                foreach (@vendors) {
                    if ( $cc_entry =~ /$_/i ) {
    -                   $knownvendor="1"; 
    +                   $knownvendor=$v; 
                        last;
                    }
    +               $v++;
                }
                my $checked_known="";
                my $checked_unknown="";
                my $disabled_known="";
                my $disabled_unknown="";
                my $cc_entry_unknown="";
    -           if ( $knownvendor == 1 ) {
    +           if ( $knownvendor > 0 ) {
                    $checked_known="checked";
                    $disabled_unknown="disabled";
                } elsif ( ! $cc_entry  ) {
    @@ -271,11 +273,15 @@ foreach my $cc_ele(@custom_columns) {
                    } else {
                        $vendor_img=$vendor;
                    }
    -               if ( $cc_entry && $vendors[$j] =~ /$cc_entry/ ) {
    -                   print "<option value=\"$vendor\" style=\"background: url(../imagenes/vendors/$vendor_img.png) no-repeat top left;\" selected>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $vendor</option>";
    -               } else {
    -                   print "<option value=\"$vendor\" style=\"background: url(../imagenes/vendors/$vendor_img.png) no-repeat top left;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $vendor</option>";
    +               my $tmpselected = "";
    +               my $tmpvalue = $vendor;
    +               # Found previously matched vendor, select it in combo
    +               if ( $knownvendor == $j ) {
    +                   $tmpselected=' selected';
    +                   # preserve the original value for the option
    +                   $tmpvalue=$cc_entry;
                    }
    +               print "<option value=\"$tmpvalue\" style=\"background: url(../imagenes/vendors/$vendor_img.png) no-repeat top left;padding-left: 2em;\"$tmpselected>$vendor</option>";
                    $j++;
                }
                print "</select><input name=\"custom_${n}_name\" type=\"hidden\" value=\"$cc_name\"><input name=\"custom_${n}_id\" type=\"hidden\" value=\"$cc_id\"><input name=\"custom_${n}_pcid\" type=\"hidden\" value=\"$pc_id\"></td></tr>\n";
    
     
    • Marc Uebel

      Marc Uebel - 2013-07-10

      Hello Angelo
      Thanks a lot for reporting the bug and for the patch.
      I will check it and tell you something soon.
      Regards
      Marc

      On mié, 2013-07-10 at 17:52 +0000, Angelo Turetta wrote:

      I wrote a perl script to parse the output of arpscan and feed the
      results to GestioIP.
      arp-scan can return the vendor for every MAC, and in fact it works
      very well along with the 'vendor' custom column type. I fill the
      column with the vendor string returned by arpscan, and GestioIP is
      displaying icons accordingly.

      Unluckily, there is a small bug in res/ip_modip_form.cgi(274), where
      the regexp matching is backwards. It should be:

      if ( $cc_entry && $cc_entry =~ /$vendor/ ) {
      So when I edit a discovered entry, the combo comes active without any
      selection, after which the vendor value is lost on save. You can see
      the effect by putting the value "Hewlett-Packard Company" as a custom
      vendor string and then re-opening the edit form after saving changes.

      I attach a more complete patch where I polished the code a little,
      adding the ability to keep the literal value of the vendor column
      intact during save, if unmodified (currently, in my previous example,
      the column value is overwritten by the string 'hp').

      If you like my patch, you can download it from http://snipt.org/AGae8:
      it should apply with "patch -p1"

      Thanks for your useful tool.

      Angelo.

      diff --git a/res/ip_modip_form.cgi b/res/ip_modip_form.cgi
      index 3eb1784..706ecf5 100755
      --- a/res/ip_modip_form.cgi
      +++ b/res/ip_modip_form.cgi
      @@ -210,19 +210,21 @@ foreach my $cc_ele(@custom_columns) {
      }
      if ( $cc_name ) {
      if ( $cc_name eq "vendor" ) {
      - my $knownvendor="0";
      + my $knownvendor=0;
      + my $v=0;
      foreach (@vendors) {
      if ( $cc_entry =~ /$_/i ) {
      - $knownvendor="1";
      + $knownvendor=$v;
      last;
      }
      + $v++;
      }
      my $checked_known="";
      my $checked_unknown="";
      my $disabled_known="";
      my $disabled_unknown="";
      my $cc_entry_unknown="";
      - if ( $knownvendor == 1 ) {
      + if ( $knownvendor > 0 ) {
      $checked_known="checked";
      $disabled_unknown="disabled";
      } elsif ( ! $cc_entry ) {
      @@ -271,11 +273,15 @@ foreach my $cc_ele(@custom_columns) {
      } else {
      $vendor_img=$vendor;
      }
      - if ( $cc_entry && $vendors[$j] =~ /$cc_entry/ ) {
      - print "<option value="\\"$vendor\\"" style="\\"background:" url(..="" imagenes="" vendors="" $vendor_img.png)="" no-repeat="" top="" left;\\"="" selected="">      $vendor</option>";
      - } else {
      - print "<option value="\\"$vendor\\"" style="\\"background:" url(..="" imagenes="" vendors="" $vendor_img.png)="" no-repeat="" top="" left;\\"="">      $vendor</option>";
      + my $tmpselected = "";
      + my $tmpvalue = $vendor;
      + # Found previously matched vendor, select it in combo
      + if ( $knownvendor == $j ) {
      + $tmpselected=' selected';
      + # preserve the original value for the option
      + $tmpvalue=$cc_entry;
      }
      + print "<option value="\\"$tmpvalue\\"" style="\\"background:" url(..="" imagenes="" vendors="" $vendor_img.png)="" no-repeat="" top="" left;padding-left:="" 2em;\\"$tmpselected="">$vendor</option>";
      $j++;
      }
      print "</select><input name="\\"custom_${n}_name\\"" type="\\"hidden\\"" value="\\"$cc_name\\""><input name="\\"custom_${n}_id\\"" type="\\"hidden\\"" value="\\"$cc_id\\""><input name="\\"custom_${n}_pcid\\"" type="\\"hidden\\"" value="\\"$pc_id\\"">\n";


      Vendor column lost in edit form


      Sent from sourceforge.net because you indicated interest in
      https://sourceforge.net/p/gestioip/discussion/981984/

      To unsubscribe from further messages, please visit
      https://sourceforge.net/auth/subscriptions/

      --
      GestióIP is advertisement free.

      If you use GestióIP in a production environment please consider to make a donation to support the project!

      http://www.gestioip.net/donate_gestioip_en.html

       
    • Brian Easley

      Brian Easley - 2013-10-07

      Any chance you'd share the perl script? I'd love to have access to arp information in our gestioip installation.

       

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks