opennetadmin / ona

OpenNetAdmin IP Address Management (IPAM) system
opennetadmin.com
GNU General Public License v2.0
142 stars 35 forks source link

"dcm -r domain_display" reading file from current working directory. #72

Open dongreer opened 10 years ago

dongreer commented 10 years ago

Doing some scripting to process some domain files exported from Windows for updates. Found that I was getting the following error:

"ERROR => Unable to find the domain record using Name Type Data Timestamp"

This was followed by the complete listing of a file, named the same as the domain I was looking up. If I changed directories, the problem disappears.

I presume that this is something that was written to make it easy to process a bunch of domains in bulk by making a list of them in a file, but this may not be complete, and is definitely not documented when you do "dcm.pl -r domain_display".

Might I suggest that a switch should be used to enable this treatment of values as file names? This behavior is part of the configuration read process (starting around line 1505).

I'm working around this by simply commenting out the if() block which detects and reads the file.

mattpascoe commented 10 years ago

This is noted at the very bottom of the DCM.pl readme file:

NOTE: One feature of dcm.pl is that it can take files as input. So if I pass dcm.pl the option 
file=myfile.txt it will look in the current path for myfile.txt. This is a great feature for passing things into
 ONA. There is however a drawback at times. For example, if you are passing in an option like 
host=test.example.com and you also happen to be in a directory where there is a file or directory
 named test.example.com the dcm.pl script will probably not behave as you expect. Be aware of this
 behavior, it bites me still sometimes.

I think the option of having a switch is probably wise. That way the functionality is there but it becomes a deliberate thing. Next time I'm in that code I'll see what it will take. (or I'll take any pull requests/patches you come up with! )

dongreer commented 10 years ago

Ok, -f options added, documented in help and it all appears to work. Here's the patch:

--- dcm.pl.orig 2014-02-06 12:40:44.012666628 -0600
+++ dcm.pl      2014-02-06 12:57:45.358482099 -0600
@@ -71,6 +71,8 @@
 ##
 ##  Changelog:
 ##
+##     02/06/2014 - v1.21b - Don Greer 
+##          - Added "-f" switch to control "option=filename" behavior.
 ##     07/05/2012 - v1.21 - Matt Pascoe
 ##          - Fix deprication warnings about qw
 ##     06/22/2012 - v1.20 - Matt Pascoe
@@ -192,7 +194,8 @@
     'authorName'           => 'Brandon Zehm/Matt Pascoe',      ## Author's Name
     'authorEmail'          => 'caspian@dotconf.net/matt@opennetadmin.com',           ## Author's Email Address
     'configurationFile'    => '',                              ## Configuration file location
-
+    'optionFilenames'      => 0,                               ## tells DCM that the options being passed my contain filenames.
+
 );
@@ -805,10 +808,10 @@
     --list                  list available modules
     --symlink               create symlinks of each module name to dcm.pl
     -r MODULE [K=V] ...     run specified module with KEY=VALUE options
-                              VALUE may also be a filename or - for STDIN
 $conf{'colorGreen'}  General Options: $conf{'colorNormal'}
     -c FILE                 configuration file [$conf{'configurationFile'}]
+    -f                      in the module options, VALUE may also be a filename or - for STDIN
     -u URL                  connector url, format: http[s]://server[:port]/url
     -l LOGIN                login for http authentication
     -p PASSWORD             password for http authentication
@@ -952,6 +955,11 @@
             }
         }
+        ## options may have filenames
+        elsif ($ARGS[$counter] eq '-f') {
+            $conf{'optionFilenames'} = 1;
+        }
+
         ## connector url
         elsif ($ARGS[$counter] eq '-u') {
             $counter++;
@@ -1399,7 +1407,7 @@
 $opt{'unix_username'} = $conf{'unix_username'};
 foreach my $key (keys(%opt)) {
     ## If the value specified is a file, or -, load the file's contents (or STDIN) as the value
-    if ( (-e $opt{$key} and -r $opt{$key}) or ($opt{$key} eq '-') ) {
+    if ( $conf{'optionFilenames'} and ( (-e $opt{$key} and -r $opt{$key}) or ($opt{$key} eq '-') ) ) {
         my $FILE;
         if(!open($FILE, ' ' . $opt{$key})) {
             quit("ERROR => couldn't open input file, $opt{$key}, $!", 1);