forked from FreePBX/cdr
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.php
More file actions
168 lines (160 loc) · 6.56 KB
/
install.php
File metadata and controls
168 lines (160 loc) · 6.56 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<?php
if (!defined('FREEPBX_IS_AUTH')) { die('No direct script access allowed'); }
// License for all code of this FreePBX module can be found in the license file inside the module directory
// Portions Copyright (C) 2011 Mikael Carlsson
// Copyright 2013 Schmooze Com Inc.
//
// Update cdr database with did field
//
global $db;
global $amp_conf;
// Retrieve database and table name if defined, otherwise use FreePBX default
$db_name = !empty($amp_conf['CDRDBNAME'])?$amp_conf['CDRDBNAME']:"asteriskcdrdb";
$db_table_name = !empty($amp_conf['CDRDBTABLENAME'])?$amp_conf['CDRDBTABLENAME']:"cdr";
// if CDRDBHOST and CDRDBTYPE are not empty then we assume an external connection and don't use the default connection
//
if (!empty($amp_conf["CDRDBHOST"]) && !empty($amp_conf["CDRDBTYPE"])) {
$db_hash = array('mysql' => 'mysql', 'postgres' => 'pgsql');
$db_type = $db_hash[$amp_conf["CDRDBTYPE"]];
$db_host = $amp_conf["CDRDBHOST"];
$db_port = empty($amp_conf["CDRDBPORT"]) ? '' : ':' . $amp_conf["CDRDBPORT"];
$db_user = empty($amp_conf["CDRDBUSER"]) ? $amp_conf["AMPDBUSER"] : $amp_conf["CDRDBUSER"];
$db_pass = empty($amp_conf["CDRDBPASS"]) ? $amp_conf["AMPDBPASS"] : $amp_conf["CDRDBPASS"];
$datasource = $db_type . '://' . $db_user . ':' . $db_pass . '@' . $db_host . $db_port . '/' . $db_name;
$dbcdr = DB::connect($datasource); // attempt connection
if(DB::isError($dbcdr)) {
die_freepbx($dbcdr->getDebugInfo());
}
} else {
$dbcdr = $db;
}
if (! function_exists("out")) {
function out($text) {
echo $text."<br />";
}
}
out(_("Checking if field did is present in cdr table.."));
$sql = "SELECT did FROM $db_name.$db_table_name";
$confs = $dbcdr->getRow($sql, DB_FETCHMODE_ASSOC);
if (DB::IsError($confs)) { // no error... Already there
out(_("Adding did field to cdr"));
out(_("This might take a while......"));
$sql = "ALTER TABLE $db_name.$db_table_name ADD did VARCHAR ( 50 ) NOT NULL DEFAULT ''";
$results = $dbcdr->query($sql);
if(DB::IsError($results)) {
die($results->getMessage());
}
out(_("Added field did to cdr"));
} else {
out(_("did field already present."));
}
out(_("Checking if field recordingfile is present in cdr table.."));
$sql = "SELECT recordingfile FROM $db_name.$db_table_name";
$confs = $dbcdr->getRow($sql, DB_FETCHMODE_ASSOC);
if (DB::IsError($confs)) { // no error... Already there
out(_("Adding recordingfile field to cdr"));
$sql = "ALTER TABLE $db_name.$db_table_name ADD recordingfile VARCHAR ( 255 ) NOT NULL DEFAULT ''";
$results = $dbcdr->query($sql);
if(DB::IsError($results)) {
out(_('Unable to add recordingfile field to cdr table'));
freepbx_log(FPBX_LOG_ERROR,"failed to add recordingfile field to cdr table");
} else {
out(_("Added field recordingfile to cdr"));
}
} else {
out(_("recordingfile field already present."));
}
$cid_fields = array('cnum', 'cnam', 'outbound_cnum', 'outbound_cnam', 'dst_cnam');
foreach($cid_fields as $cf) {
out(_("Checking if field $cf is present in cdr table.."));
$sql = "SELECT $cf FROM $db_name.$db_table_name";
$confs = $dbcdr->getRow($sql, DB_FETCHMODE_ASSOC);
if (DB::IsError($confs)) { // no error... Already there
out(_("Adding $cf field to cdr"));
$sql = "ALTER TABLE $db_name.$db_table_name ADD $cf VARCHAR ( 40 ) NOT NULL DEFAULT ''";
$results = $dbcdr->query($sql);
if(DB::IsError($results)) {
out(_("Unable to add $cf field to cdr table"));
freepbx_log(FPBX_LOG_ERROR,"failed to add $cf field to cdr table");
} else {
out(_("Added field $cf to cdr"));
// TODO: put onetime notification about old src field searches and query that could be
// done if user wants to get that into cnum field.
}
} else {
out(_("$cf field already present."));
}
}
$sql = "SHOW KEYS FROM $db_name.$db_table_name WHERE Key_name='uniqueid'";
$check = $dbcdr->getOne($sql);
if (empty($check)) {
$sql = "ALTER TABLE $db_name.$db_table_name ADD INDEX `uniqueid` (`uniqueid` ASC)";
$result = $dbcdr->query($sql);
if(DB::IsError($result)) {
out(_("Unable to add index to uniqueid field in cdr table"));
freepbx_log(FPBX_LOG_ERROR, "Failed to add index to uniqueid field in the cdr table");
} else {
out(_("Adding index to uniqueid field in the cdr table"));
}
}
$db_cel_name = !empty($amp_conf['CELDBNAME'])?$amp_conf['CELDBNAME']:$db_name;
$db_cel_table_name = !empty($amp_conf['CELDBTABLENAME'])?$amp_conf['CELDBTABLENAME']:"cel";
outn(_("Creating $db_cel_table_name if needed.."));
$sql = "
CREATE TABLE IF NOT EXISTS `" . $db_cel_name . "`.`" . $db_cel_table_name . "` (
`id` int(11) NOT NULL auto_increment,
`eventtype` varchar(30) NOT NULL,
`eventtime` datetime NOT NULL,
`cid_name` varchar(80) NOT NULL,
`cid_num` varchar(80) NOT NULL,
`cid_ani` varchar(80) NOT NULL,
`cid_rdnis` varchar(80) NOT NULL,
`cid_dnid` varchar(80) NOT NULL,
`exten` varchar(80) NOT NULL,
`context` varchar(80) NOT NULL,
`channame` varchar(80) NOT NULL,
`src` varchar(80) NOT NULL,
`dst` varchar(80) NOT NULL,
`channel` varchar(80) NOT NULL,
`dstchannel` varchar(80) NOT NULL,
`appname` varchar(80) NOT NULL,
`appdata` varchar(80) NOT NULL,
`amaflags` int(11) NOT NULL,
`accountcode` varchar(20) NOT NULL,
`uniqueid` varchar(32) NOT NULL,
`linkedid` varchar(32) NOT NULL,
`peer` varchar(80) NOT NULL,
`userdeftype` varchar(255) NOT NULL,
`eventextra` varchar(255) NOT NULL,
`userfield` varchar(255) NOT NULL,
PRIMARY KEY (`id`),
KEY `uniqueid_index` (`uniqueid`),
KEY `linkedid_index` (`linkedid`)
)
";
$check = $dbcdr->query($sql);
if(DB::IsError($check)) {
die_freepbx("Can not create $db_cel_table_name table");
} else {
out(_("OK"));
}
$freepbx_conf =& freepbx_conf::create();
if (!$freepbx_conf->conf_setting_exists('CEL_ENABLED')) {
// CEL_ENABLED
//
//$value = $dbcdr->getOne("SELECT count(*) FROM $db_cel_name.$db_cel_table_name") > 0 ? true : false;
$value = true;
$set['value'] = $value;
$set['defaultval'] = false;
$set['readonly'] = 0;
$set['hidden'] = 0;
$set['level'] = 3;
$set['module'] = 'cdr';
$set['category'] = 'CDR Report Module';
$set['emptyok'] = 0;
$set['sortorder'] = 10;
$set['name'] = 'Enable CEL Reporting';
$set['description'] = 'Setting this true will enable the CDR module to drill down on CEL data for each CDR. Although the CDR module will assure there is a CEL table available, the reporting functionality in Asterisk and associated ODBC database and CEL configuration must be done outside of FreePBX either by the user or at the Distro level.';
$set['type'] = CONF_TYPE_BOOL;
$freepbx_conf->define_conf_setting('CEL_ENABLED',$set,true);
}