/
attach2Agents.pl
executable file
·95 lines (90 loc) · 3.96 KB
/
attach2Agents.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/perl
BEGIN { use CGI::Carp qw(fatalsToBrowser); };
use DBI;
use Cwd;
use FindBin qw($Bin);
use lib "$Bin/lib";
use SPF;
use CGI ':cgi-lib';
my %FORM = Vars();
$number1 = $FORM{"agentPhNo"};
$number21 = $FORM{"controlPhNo"};
$path1 = $FORM{"agentURLPath"};
$key1 = $FORM{"agentControlKey"};
$platform1 = $FORM{"platformDD1"};
##----- put your code here
my %Variables = SPF::readconfig();
my $dbh = SPF::dbconnect(%Variables);
$Variables{"OS"} = $^O;
$webserver = $Variables{"WEBSERVER"};
$fullpath = $webserver. $path;
$command1 = "mkdir " . $fullpath;
system($command1);
$controlfile = $fullpath . "/control";
$command2 = "touch " . $controlfile;
system($command2);
$command3 = "chmod 777 " . $controlfile;
system($command3);
$picturefile = $fullpath . "/picture.jpg";
$command4 = "touch " . $picturefile;
system($command4);
$command5 = "chmod 777 " . $picturefile;
system($command5);
$textfile = $fullpath . "/text.txt";
$command6 = "touch " . $textfile;
system($command6);
$command7 = "chmod 777 " . $textfile;
system($command7);
$pictureupload = $fullpath . "/pictureupload.php";
$command8 = "touch " . $pictureupload;
system($command8);
$command9 = "chmod 777 " . $pictureupload;
system($command9);
$pictureuploadtext = "<?php\n\$base=\$_REQUEST['picture'];\necho \$base;\n\$binary=base64_decode(\$base);\nheader('Content-Type: bitmap; charset=utf-8');\n\$file = fopen('picture.jpg', 'wb');\nfwrite(\$file, \$binary);\nfclose(\$file);\n?>";
open(PICFILE, ">",$pictureupload) or die "Couldn't open $pictureupload for writing! ($!)";
print PICFILE $pictureuploadtext;
close(PICFILE);
$textupload = $fullpath . "/textuploader.php";
$command10 = "touch " . $textupload;
system($command10);
$command11 = "chmod 777 " . $textupload;
system($command11);
$textuploadtext = "<?php\n\$base=\$_REQUEST['text'];\nheader('Content-Type: text; charset=utf-8');\n\$file = fopen('text.txt', 'wb');\nfwrite(\$file, \$base);\n?>";
open(TEXTFILE, ">",$textupload) or die "Couldn't open $textupload for writing! ($!)";
print TEXTFILE $textuploadtext;
close(TEXTFILE);
$controlupload = $fullpath . "/controluploader.php";
$command12 = "touch " . $controlupload;
system($command12);
$command13 = "chmod 777 " . $controlupload;
system($command13);
$controluploadtext = "<?php\n\$base=\$_REQUEST['text'];\nheader('Content-Type: text; charset=utf-8');\n\$file = fopen('control','wb');\nfwrite(\$file, \$base);\n?>";
open(CONTROLFILE, ">",$controlupload) or die "Couldn't open $controlupload for writing ($!)";
print CONTROLFILE $controluploadtext;
close(CONTROLFILE);
$putfile = $fullpath . "/putfunc";
$command14 = "touch " . $putfile;
system($command14);
$command15 = "chmod 777 " . $putfile;
system($command15);
$sql = $dbh->prepare("INSERT INTO agents (id,number,path,controlkey,controlnumber,platform) VALUES (DEFAULT,?,?,?,?,?)");
$sql->execute($number1,$path1,$key1,$number21,$platform1);
$sql2 = $dbh->prepare("INSERT INTO data (id,sms,contacts,picture,root) VALUES (DEFAULT, NULL, NULL, NULL, NULL)");
$sql2->execute();
$sql = $dbh->prepare("SELECT id from agents where number=?");
$idblah = $sql->execute($number1);
@rows = $sql->fetchrow_array();
$id = @rows[0];
@exec = (qw(perl agentpoll.pl),$path1,$key1,$id);
$pid = fork;
die "fork failed" unless defined $pid;
if ($pid ==0)
{
open STDIN,'<','/dev/null';
open STDOUT,'<','/dev/null';
open STDERR,'>&STDOUT';
exec {$exec[0]} @exec;
}
##----- end of your code
my $url = "menu.pl";
print "Location: $url\n\n";