Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl -w
- use DBI;
- #This script updates the FOP2 and Asteridex phone books in PIAF from a vcf file.
- #It clears out the phonebooks before recreating them, so this is one way sync only. All changes will be lost.
- #Records with more then one phone number have an entry created for each number.
- #10 or 7 digits US phone numbers only.
- #3/10/2014
- $dbh = DBI->connect ( "dbi:mysql:host=localhost;database=asteridex","root","********"); #Asterdex phonebook
- $dbh2 = DBI->connect ( "dbi:mysql:host=localhost;database=asterisk","root","********"); #FOP2 phone book.
- #clear out both phone books before adding
- $dbh->do("DELETE FROM user1;");
- $dbh2->do("DELETE FROM visual_phonebook;");
- open(FILE1, "contacts.vcf");
- while (<FILE1>) {
- $line=$_;
- if ($line =~ /FN:/) { $FN=$line };
- if ($line =~ /TEL/) { ParseData($FN,$line); };
- }
- sub ParseData {
- my $fn = $_[0];
- my $tel = $_[1];
- chomp $fn;
- chomp $tel;
- $fn =~ s/FN://;
- #strip out all the extra stuff in the phone numbers. 7 or 10 digits only
- $tel =~ s/-//g;
- $tel =~ s/ //g;
- $tel =~ s/\(//g;
- $tel =~ s/\)//g;
- $tel =~ s/\+//g;
- my @tel2 = $tel =~ /(\d{7}$|\d{10}$)/; #get the phone number off the back.
- if (! $tel2[0]) {return;} #skip if no phone number
- if (! $fn) {return;} #skip if no name
- my @fn2 = $fn =~ /^(\w*)\s(.*)$/; #split out the first name (first word) and use whatever is left for the last name.
- if (! $fn2[0] && $fn) {$fn2[0] = $fn;} #if we don't get anything out of the above regex, then it's first name only, use that.
- my $fnfirst = $dbh2->quote($fn2[0]);
- my $fnlast = $dbh2->quote($fn2[1]);
- my $fnsafe = $dbh->quote($fn);
- my $tel2safe = $dbh->quote($tel2[0]);
- #insert into visual_phonebook, need to change user1 to the user.
- $dbh->do("INSERT user1 SET
- name=$fnsafe,
- `out`=$tel2safe");
- #insert into fop2 database, need to change owner to the extension.
- $dbh2->do("INSERT visual_phonebook SET
- firstname=$fnfirst,
- lastname=$fnlast,
- phone1=$tel2safe,
- owner=200");
- #print $fn."-----".$tel2[0]."\n";
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement