<h1>Project "FreeSWITCH Source" received a push.</h1>

<h2>branch: master updated</h2>
<pre>
       via: 5e6123ef5f21580f5cbce2fac7bd47702387245b (commit)
      from: 2f9357b2a7cd262863459fbce042e17f47563ef8 (commit)


</pre>= COMMIT LOG ===========================================================
<div class="highlight"><pre>committer: Michael S Collins
comments: 
Add randomize-passwords.pl script to main tree

<span style="color: #000080; font-weight: bold">diff --git a/scripts/perl/randomize-passwords.pl b/scripts/perl/randomize-passwords.pl</span>
new file mode 100755
<span style="color: #000080; font-weight: bold">index 0000000..d792f2b</span>
<span style="color: #A00000">--- /dev/null</span>
<span style="color: #00A000">+++ b/scripts/perl/randomize-passwords.pl</span>
<span style="color: #800080; font-weight: bold">@@ -0,0 +1,179 @@</span>
<span style="color: #00A000">+#!/usr/bin/perl</span>
<span style="color: #00A000">+#</span>
<span style="color: #00A000">+# randomize-passwords.pl</span>
<span style="color: #00A000">+#</span>
<span style="color: #00A000">+# Randomizes the auth passwords for any file in the file spec given by the user</span>
<span style="color: #00A000">+# Randomizes the vm passwords for the same files</span>
<span style="color: #00A000">+# Creates a backup copy of each file altered; optionally will remove backups</span>
<span style="color: #00A000">+# </span>
<span style="color: #00A000">+# This program uses only pure Perl modules so it should be portable.</span>
<span style="color: #00A000">+#</span>
<span style="color: #00A000">+# Michael S. Collins</span>
<span style="color: #00A000">+# 2009-11-11</span>
<span style="color: #00A000">+# </span>
<span style="color: #00A000">+# Freely contributed to the FreeSWITCH project for use as the developers and community see fit</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+use strict;</span>
<span style="color: #00A000">+use warnings;</span>
<span style="color: #00A000">+use Getopt::Long;</span>
<span style="color: #00A000">+use File::Basename;</span>
<span style="color: #00A000">+use File::Copy;</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+$|++;</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+## &#39;CHARACTERS&#39; contains punctuation marks</span>
<span style="color: #00A000">+use constant CHARACTERS =&gt; &#39;abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-=+?&gt;&lt;/.,!@#$%^&amp;*();:&#39;;</span>
<span style="color: #00A000">+my $numchars = length(CHARACTERS);</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+## &#39;ALPHACHARS&#39; contains upper and lower case letters and digits but no punctuation</span>
<span style="color: #00A000">+use constant ALPHACHARS =&gt; &#39;abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890&#39;;</span>
<span style="color: #00A000">+my $numalphas = length(ALPHACHARS);</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+my $vmlen = 4;         # Length of VM password</span>
<span style="color: #00A000">+my $authlen = 10;      # Length of auth password</span>
<span style="color: #00A000">+my $filespec;          # File specification </span>
<span style="color: #00A000">+my $delbak;            # Flag - delete backups (default = keep backups)</span>
<span style="color: #00A000">+my $nopunct;           # Flag - set to true to disable punction marks (i.e. alphanumerics only) in auth passwords</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+my $opts_ok = GetOptions (&quot;h&quot;         =&gt; \&amp;usage,</span>
<span style="color: #00A000">+                          &quot;help&quot;      =&gt; \&amp;usage,</span>
<span style="color: #00A000">+                          &quot;vmlen=i&quot;   =&gt; \$vmlen,</span>
<span style="color: #00A000">+                          &quot;authlen=i&quot; =&gt; \$authlen,</span>
<span style="color: #00A000">+                          &quot;files=s&quot;   =&gt; \$filespec,</span>
<span style="color: #00A000">+                          &quot;D&quot;         =&gt; \$delbak,</span>
<span style="color: #00A000">+                          &quot;nopunct&quot;   =&gt; \$nopunct,</span>
<span style="color: #00A000">+                          );</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+## Confirm that a file spec was provided</span>
<span style="color: #00A000">+if ( ! $filespec ) {</span>
<span style="color: #00A000">+    warn &quot;\nPlease provide a file specification.\n&quot;;</span>
<span style="color: #00A000">+    die &quot;Example: --files=/usr/local/freeswitch/conf/directory/default/1*.xml\n\n&quot;;</span>
<span style="color: #00A000">+}</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+## Collect the files</span>
<span style="color: #00A000">+my @FILELIST = glob($filespec);</span>
<span style="color: #00A000">+if ( ! @FILELIST ) {</span>
<span style="color: #00A000">+    print &quot;\nNo files found matching this spec:\n$filespec\n&quot;;</span>
<span style="color: #00A000">+    exit(0);</span>
<span style="color: #00A000">+} else {</span>
<span style="color: #00A000">+    print &quot;\nFound &quot; . @FILELIST . &quot; file(s).\n\n&quot;;</span>
<span style="color: #00A000">+}</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+## Iterate through the list, process each file</span>
<span style="color: #00A000">+foreach my $file ( @FILELIST ) {</span>
<span style="color: #00A000">+    print &quot;Processing file: $file\n&quot;;</span>
<span style="color: #00A000">+    my $bakfile = $file . &#39;.bak&#39;;</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+    if ( move($file,$bakfile) ) {</span>
<span style="color: #00A000">+        print &quot;  $file ===&gt; $bakfile\n&quot;;</span>
<span style="color: #00A000">+    } else {</span>
<span style="color: #00A000">+        print &quot;  Unable to backup $file to $bakfile. Skipping...\n&quot;;</span>
<span style="color: #00A000">+        next;</span>
<span style="color: #00A000">+    }</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+    ## FILEIN is the backup file, FILEOUT is the updated file</span>
<span style="color: #00A000">+    open(FILEIN ,&#39;&lt;&#39;,$bakfile) or die &quot;Could not open $bakfile - aborting operation.\n&quot;;</span>
<span style="color: #00A000">+    open(FILEOUT,&#39;&gt;&#39;,$file   ) or die &quot;Could not open $file - aborting operation.\n&quot;;</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+    ## Retrieve new passwords from random generators</span>
<span style="color: #00A000">+    my $newauth =  &amp;get_random_chars($authlen);</span>
<span style="color: #00A000">+    my $newvm   =  &amp;get_random_digits($vmlen);</span>
<span style="color: #00A000">+    </span>
<span style="color: #00A000">+    ## Loop through &quot;bak&quot; file, replace passwords, write out to original file</span>
<span style="color: #00A000">+    while(&lt;FILEIN&gt;) {</span>
<span style="color: #00A000">+        ## Check for passwords; if found swap</span>
<span style="color: #00A000">+        if ( m/param name=&quot;password&quot;/ ) {</span>
<span style="color: #00A000">+            # Found auth password, swap it</span>
<span style="color: #00A000">+            s/value=&quot;(.*?)&quot;/value=&quot;$newauth&quot;/;</span>
<span style="color: #00A000">+            print &quot;    Old/new auth pass: $1 ==&gt; $newauth\n&quot;;</span>
<span style="color: #00A000">+        }</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+        if ( m/param name=&quot;vm-password&quot;/ ) {</span>
<span style="color: #00A000">+            # Found vm password, swap it</span>
<span style="color: #00A000">+            s/value=&quot;(.*?)&quot;/value=&quot;$newvm&quot;/;</span>
<span style="color: #00A000">+            print &quot;      Old/new vm pass: $1 ==&gt; $newvm\n&quot;;</span>
<span style="color: #00A000">+        }</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+        print FILEOUT $_;</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+    } ## while(&lt;FILEIN&gt;)</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+    close(FILEIN);</span>
<span style="color: #00A000">+    close(FILEOUT);</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+    ## Clear out the backup file if user asked for it</span>
<span style="color: #00A000">+    if ( $delbak ) {</span>
<span style="color: #00A000">+        print &quot;    Removing $bakfile...\n&quot;;</span>
<span style="color: #00A000">+        unlink $bakfile;</span>
<span style="color: #00A000">+    }</span>
<span style="color: #00A000">+    print &quot;    Finished with $file.\n\n&quot;;</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+} ## foreach my $file ( @FILELIST )</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+exit(0);</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+## Return random chars for auth password</span>
<span style="color: #00A000">+sub get_random_chars () {</span>
<span style="color: #00A000">+    my $length = shift;</span>
<span style="color: #00A000">+    if ( ! $length ) { $length = $authlen; }</span>
<span style="color: #00A000">+    my $chars;</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+    if ( $nopunct ) {</span>
<span style="color: #00A000">+        foreach my $i (1 .. $length) {</span>
<span style="color: #00A000">+            my $nextchar = substr( ALPHACHARS,int(rand $numalphas),1 );</span>
<span style="color: #00A000">+            $chars .= $nextchar;</span>
<span style="color: #00A000">+        }</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+    } else {</span>
<span style="color: #00A000">+        foreach my $i (1 .. $length) {</span>
<span style="color: #00A000">+            my $nextchar = substr( CHARACTERS,int(rand $numchars),1 );</span>
<span style="color: #00A000">+            $chars .= $nextchar;</span>
<span style="color: #00A000">+        }</span>
<span style="color: #00A000">+    }</span>
<span style="color: #00A000">+    return $chars;</span>
<span style="color: #00A000">+}</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+## Return only digits for vm password</span>
<span style="color: #00A000">+sub get_random_digits () {</span>
<span style="color: #00A000">+    my $length = shift;</span>
<span style="color: #00A000">+    if ( ! $length ) { $length = $vmlen; }</span>
<span style="color: #00A000">+    my $digits;</span>
<span style="color: #00A000">+    foreach my $i (1 .. $length) {</span>
<span style="color: #00A000">+        my $nextdigit = int(rand 10);</span>
<span style="color: #00A000">+        $digits .= $nextdigit;</span>
<span style="color: #00A000">+    }</span>
<span style="color: #00A000">+    return $digits;</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+}</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+sub usage () {</span>
<span style="color: #00A000">+print &lt;&lt;END_USAGE</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+Randomize passwords for FreeSWITCH directory entries.</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+Usage:  ./randomize-passwords.pl --files=&lt;file spec&gt; [-D] [--vmlen=&lt;vm pass length&gt;] [--authlen=&lt;auth pass length&gt;]</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+Options:</span>
<span style="color: #00A000">+  </span>
<span style="color: #00A000">+  -h, --help       Display this help page</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+  -D               Delete backups (default is to save backups)</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+  --files          Specify files to process. Use typical file globs. On a standard Linux install it would look like:</span>
<span style="color: #00A000">+                   --files=/usr/local/freeswitch/conf/directory/default/1*.xml</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+  --vmlen          Set length of voice mail password. (Default is 4 digits)</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+  --authlen        Set length of auth password. (Default is 10 characters)</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+  --nopunct        Disable punction marks in auth passwords, i.e. alphanumerics only</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+Example:</span>
<span style="color: #00A000">+  To randomize all the passwords for a default Linux install, with 6 digit VM passwords, use this command:</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+  ./randomize-passwords.pl --files=/usr/local/freeswitch/conf/directory/default/1*.xml -D --vmlen=6</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+END_USAGE</span>
<span style="color: #00A000">+;</span>
<span style="color: #00A000">+exit(0);</span>
<span style="color: #00A000">+}</span>
</pre></div>
========================================================================<pre>

Summary of changes:
 scripts/perl/randomize-passwords.pl |  179 +++++++++++++++++++++++++++++++++++
 1 files changed, 179 insertions(+), 0 deletions(-)
 create mode 100755 scripts/perl/randomize-passwords.pl
</pre>
<p>this email was generated because of /git/your-repo.git/hooks/post-receive by the file /git-core/contrib/hooks/post-receive-email<br />
For more info, see <a href="http://blog.chomperstomp.com/?p=630">http://blog.chomperstomp.com/?p=630</a>
-- <br />
FreeSWITCH Source</p>