Skip to content

Commit

Permalink
Create DB file and connections to DB only if -db param is used
Browse files Browse the repository at this point in the history
  • Loading branch information
Pepelux committed May 9, 2019
1 parent d85be43 commit 128520e
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 39 deletions.
30 changes: 18 additions & 12 deletions sipcrack.pl
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@
my $efin;
my $hini = 0;

my $db;
my $usersid;

my $versionfile = 'version';
open(my $fh, '<:encoding(UTF-8)', $versionfile)
or die "Could not open file '$versionfile' $!";
Expand All @@ -66,27 +69,29 @@
$version = $row;
}

my $database = "sippts.db";
my $database_empty = "sippts_empty.db";

mkdir ("tmp") if (! -d "tmp");
my $tmpfile = "tmp/sipcrack".time().".txt";

unless (-e $database || -e $database_empty) {
die("Database $database not found\n\n");
}

system("cp $database_empty $database") if (! -e $database);

my $db = DBI->connect("dbi:SQLite:dbname=$database","","") or die $DBI::errstr;
my $usersid = last_id();

open(OUTPUT,">$tmpfile");

OUTPUT->autoflush(1);
STDOUT->autoflush(1);

$SIG{INT} = \&interrupt;

sub prepare_db() {
my $database = "sippts.db";
my $database_empty = "sippts_empty.db";

unless (-e $database || -e $database_empty) {
die("Database $database not found\n\n");
}

system("cp $database_empty $database") if (! -e $database);

$db = DBI->connect("dbi:SQLite:dbname=$database","","") or die $DBI::errstr;
$usersid = last_id();
}

sub init() {
# check params
Expand All @@ -108,6 +113,7 @@ ()

help() if (($host eq "" || $wordlist eq "") && $resume eq 0);
check_version();
prepare_db() if ($withdb eq 1);

$proto = lc($proto);
$proto = "udp" if ($proto ne "tcp");
Expand Down
33 changes: 20 additions & 13 deletions sipexten.pl
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
my $alwaysok = '';
my $server = '';

my $db;
my $extensid;
my $hostsid;

my $versionfile = 'version';
open(my $fh, '<:encoding(UTF-8)', $versionfile)
or die "Could not open file '$versionfile' $!";
Expand All @@ -51,29 +55,31 @@
$version = $row;
}

my $database = "sippts.db";
my $database_empty = "sippts_empty.db";

mkdir ("tmp") if (! -d "tmp");
my $tmpfile = "tmp/sipexten".time().".txt";

unless (-e $database || -e $database_empty) {
die("Database $database not found\n\n");
}

system("cp $database_empty $database") if (! -e $database);

my $db = DBI->connect("dbi:SQLite:dbname=$database","","") or die $DBI::errstr;
my $extensid = last_id("extens");
my $hostsid = last_id("hosts");

open(OUTPUT,">$tmpfile");

OUTPUT->autoflush(1);
STDOUT->autoflush(1);

$SIG{INT} = \&interrupt;

sub prepare_db() {
my $database = "sippts.db";
my $database_empty = "sippts_empty.db";

unless (-e $database || -e $database_empty) {
die("Database $database not found\n\n");
}

system("cp $database_empty $database") if (! -e $database);

$db = DBI->connect("dbi:SQLite:dbname=$database","","") or die $DBI::errstr;
$extensid = last_id("extens");
$hostsid = last_id("hosts");
}

sub init() {
my $pini;
my $pfin;
Expand All @@ -98,6 +104,7 @@ ()

help() if ($host eq "");
check_version();
prepare_db() if ($withdb eq 1);

$lport = "5070" if ($lport eq "");
$dport = "5060" if ($dport eq "");
Expand Down
33 changes: 20 additions & 13 deletions sipscan.pl
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
my $to_ip = '';
my $from_ip = '';

my $db;
my $hostsid;

my $versionfile = 'version';
open(my $fh, '<:encoding(UTF-8)', $versionfile)
or die "Could not open file '$versionfile' $!";
Expand All @@ -57,29 +60,31 @@
chomp $row;
$version = $row;
}

my $database = "sippts.db";
my $database_empty = "sippts_empty.db";

mkdir ("tmp") if (! -d "tmp");
my $tmpfile = "tmp/sipscan".time().".txt";

unless (-e $database || -e $database_empty) {
die("Database $database not found\n\n");
}

system("cp $database_empty $database") if (! -e $database);

my $db = DBI->connect("dbi:SQLite:dbname=$database","","") or die $DBI::errstr;
my $hostsid = last_id();

open(OUTPUT,">$tmpfile");

OUTPUT->autoflush(1);
STDOUT->autoflush(1);

$SIG{INT} = \&interrupt;

sub prepare_db() {
my $database = "sippts.db";
my $database_empty = "sippts_empty.db";

unless (-e $database || -e $database_empty) {
die("Database $database not found\n\n");
}

system("cp $database_empty $database") if (! -e $database);

$db = DBI->connect("dbi:SQLite:dbname=$database","","") or die $DBI::errstr;
$hostsid = last_id();
}

sub init() {
my $pini;
my $pfin;
Expand All @@ -102,7 +107,9 @@ ()

help() if ($host eq "");
check_version();


prepare_db() if ($withdb eq 1);

$lport = "5070" if ($lport eq "");
$dport = "5060" if ($dport eq "");
$user = "100" if ($user eq "");
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.2.6
1.2.7

0 comments on commit 128520e

Please sign in to comment.