"Fossies" - the Fresh Open Source Software Archive

Member "sendpage-1.001001/sendpage-db" (3 Jan 2008, 2475 Bytes) of package /linux/privat/old/sendpage-1.001001.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 #!/usr/bin/perl
    2 #
    3 # dbi is the tool that will assist in loading data into a database
    4 #
    5 # $Id: sendpage-db 175 2004-09-25 06:20:58Z nemies $
    6 #
    7 # Copyright (C) 2004 Todd T. Fries
    8 # todd@fries.net, http://FreeDaemonConsulting.com/
    9 #
   10 # This program is free software; you can redistribute it and/or
   11 # modify it under the terms of the GNU General Public License
   12 # as published by the Free Software Foundation; either version 2
   13 # of the License, or (at your option) any later version.
   14 #
   15 # This program is distributed in the hope that it will be useful,
   16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18 # GNU General Public License for more details.
   19 #
   20 # You should have received a copy of the GNU General Public License
   21 # along with this program; if not, write to the Free Software
   22 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
   23 # http://www.gnu.org/copyleft/gpl.html
   24 
   25 
   26 use Getopt::Std;
   27 use Sendpage::Db;
   28 
   29 getopts('hpadvtc:U:P:');
   30 
   31 if ($opt_c) {
   32     $dbtype = $opt_c;
   33 } else {
   34     $dbtype = "dbi:mysql:database=test;host=localhost;port=3306";
   35 }
   36 
   37 if ($opt_U) {
   38        $dbuser = $opt_U;
   39 }
   40 
   41 if ($opt_P) {
   42        $dbpass = $opt_P;
   43 }
   44 
   45 my $db = Sendpage::Db->new($dbtype,$dbuser,$dbpass);
   46 
   47 sub HELP_MESSAGE {
   48     printf STDERR "Usage: \n";
   49     printf STDERR "-v          verbose\n";
   50     printf STDERR "-p          show table entries\n";
   51     printf STDERR "-a          add an entry\n";
   52     printf STDERR "-d          remove an entry\n";
   53     printf STDERR "-c <dbtype> database connection type, e.g. dbi:mysql:\n";
   54         printf STDERR "-U <dbuser> database user (optional)\n";
   55         printf STDERR "-P <dbpass> database password (optional)\n";
   56     exit(0);
   57 }
   58 
   59 if ($opt_h) {
   60     HELP_MESSAGE;
   61     exit(0);
   62 }
   63 if ($opt_v) {
   64     # verbose
   65     $debug = 1;
   66 } else {
   67     $debug = 0;
   68 }
   69 
   70 if ($opt_p) {
   71     $db->show;
   72     exit(0);
   73 }
   74 
   75 if ($opt_a) {
   76     while(<stdin>) {
   77         ($recip,$var,$value) = split(/ /,$_);
   78         chomp($value);
   79         if ($var eq "email-cc" or $var eq "dest") {
   80             if($debug) {
   81                 print "adding $recip with $var = $value\n";
   82             }
   83             $db->update("$recip:$var",$value);
   84         } else {
   85             print "invalid synatx, parsed: ";
   86             print "recip = $recip, var = $var, val = $value\n";
   87         }
   88     }
   89     if($debug) {
   90         $db->show;
   91     }
   92     exit(0);
   93 }
   94 
   95 if ($opt_d) {
   96     while(<stdin>) {
   97         chomp($recip = $_);
   98         if($debug) {
   99             print "deleting $recip info\n";
  100         }
  101         $db->delete("$recip:dest");
  102         $db->delete("$recip:email-cc");
  103     }
  104     exit(0);
  105 }
  106 
  107 HELP_MESSAGE;
  108 
  109 0;