FreePBX / issue-tracker

The unified FreePBX issue tracker.
https://www.freepbx.org
GNU General Public License v3.0
12 stars 1 forks source link

[bug]: in ./libraries/BMO/Database.class.php the port to the db server is ignored for the CDR database connection #499

Closed mjrider closed 3 weeks ago

mjrider commented 1 month ago

FreePBX Version

FreePBX 17

Issue Description

we have a secondary mysql server, which listens to a different port 6033, this works in version 15, but we are trying to migrate to 17 and there it doesn't work

the problem is on this line and after this $dsnarr['port'] = '3306'; // initialize with default port

what happens is that the input mysql:dbname=asteriskcdrdb;host=127.0.0.2;port=6033 is parsed

this results in

array(4) {
  ["engine"]=>
  string(5) "mysql"
  ["dbname"]=>
  string(13) "asteriskcdrdb"
  ["host"]=>
  string(9) "127.0.0.2"
  ["port"]=>
  string(4) "6033"
}

this is exactly like i i expect, but then it's just ignored $dsnarr['port'] = '3306'; // initialize with default port

and after that the following block could also overwrite this port

        if (isset($amp_conf['AMPDBPORT'])) {
            // Make sure this is an int
            $port = (int) $amp_conf['AMPDBPORT'];
            if ($port > 1024) {
                $dsnarr['port'] = $port;
            }
        }

i think the whole block should be wrapped in a if check, that if a port is supplied in the configuration it should not be overwritten

something like this should work

                if(!array_key_exists('port', $dsnarr) || $dsnarr['port'] == ''  || $dsnarr['port'] == 0) {
                        $dsnarr['port'] = '3306'; // initialize with default port

                        // We only want to add port to the DSN if it's actually defined.
                        if (isset($amp_conf['AMPDBPORT'])) {
                                // Make sure this is an int
                                $port = (int) $amp_conf['AMPDBPORT'];
                                if ($port > 1024) {
                                        $dsnarr['port'] = $port;
                                }
                        }
                }      

unrelated issue The freepbx interface breaks when the CDR databaselink is not reachable, and the only way to fix the configuration is by editing the freepbx database by hand update freepbx_settings set value='' where keyword in ('CDRDBHOST','CDRDBPASS','CDRDBPORT','CDRDBUSER');

Operating Environment

Installation: fresh debian bookworm instance, and added proxysql 2.6 and freepbx installed on with the installscript provided by freepbx after installing we registered our install with the commandline and restored a backup so we could test the upgrade

OS: debian bookworm 12.7, all updates installed

From freepbx:

root@freepbx-test:~# dpkg -s freepbx17 | grep -i version Version: 17.1-1.sng12

root@freepbx-test:~# dpkg -s asterisk21 | grep Version Version: 21.4.3-1.sng12

+---------------------+------------+----------------------------------------+-------------+-----------+
| Module              | Version    | Status                                 | License     | Signature |
+---------------------+------------+----------------------------------------+-------------+-----------+
| accountcodepreserve | 17.0.0.1   | Enabled                                | GPLv2       | Sangoma   |
| adv_recovery        | 17.0.4     | Enabled                                | Commercial  | Sangoma   |
| allowlist           | 17.0.1.1   | Enabled                                | GPLv3+      | Sangoma   |
| amd                 | 17.0.1     | Enabled                                | GPLv3+      | Sangoma   |
| announcement        | 17.0.2.1   | Enabled                                | GPLv3+      | Sangoma   |
| api                 | 17.0.1.6   | Enabled                                | AGPLv3+     | Sangoma   |
| areminder           | 17.0.3.10  | Enabled                                | Commercial  | Sangoma   |
| arimanager          | 17.0.1.1   | Enabled                                | GPLv3+      | Sangoma   |
| asterisk-cli        | 17.0.2     | Enabled                                | GPLv3+      | Sangoma   |
| asteriskinfo        | 17.0.2     | Enabled                                | GPLv3+      | Sangoma   |
| backup              | 17.0.5.61  | Enabled                                | GPLv3+      | Sangoma   |
| blacklist           | 17.0.1.2   | Enabled                                | GPLv3+      | Sangoma   |
| broadcast           | 17.0.1.6   | Enabled                                | Commercial  | Sangoma   |
| builtin             |            | Enabled                                |             | Unsigned  |
| bulkhandler         | 17.0.5     | Enabled                                | GPLv3+      | Sangoma   |
| calendar            | 17.0.4.20  | Enabled                                | GPLv3+      | Sangoma   |
| callaccounting      | 17.0.5     | Enabled                                | Commercial+ | Sangoma   |
| callback            | 17.0.2.1   | Enabled                                | GPLv3+      | Sangoma   |
| callerid            | 17.0.1     | Enabled                                | Commercial  | Sangoma   |
| callforward         | 17.0.1.6   | Enabled                                | AGPLv3+     | Sangoma   |
| calllimit           | 17.0.1.2   | Enabled                                | Commercial  | Sangoma   |
| callrecording       | 17.0.3.8   | Enabled                                | AGPLv3+     | Sangoma   |
| callwaiting         | 17.0.3.4   | Enabled                                | GPLv3+      | Sangoma   |
| cdr                 | 17.0.4.22  | Enabled                                | GPLv3+      | Sangoma   |
| cdrpro              | 17.0.3.21  | Enabled                                | Commercial  | Sangoma   |
| cel                 | 17.0.2.9   | Disabled; Pending upgrade to 17.0.2.10 | GPLv3+      | Sangoma   |
| certman             | 17.0.3.13  | Enabled                                | AGPLv3+     | Sangoma   |
| cidlookup           | 17.0.1.1   | Enabled                                | GPLv3+      | Sangoma   |
| conferences         | 17.0.3.2   | Enabled                                | GPLv3+      | Sangoma   |
| conferencespro      | 17.0.1.7   | Enabled                                | Commercial  | Sangoma   |
| configedit          | 17.0.1.4   | Enabled                                | AGPLv3+     | Sangoma   |
| contactmanager      | 17.0.5.11  | Enabled                                | GPLv3+      | Sangoma   |
| core                | 17.0.17    | Enabled                                | GPLv3+      | Sangoma   |
| cos                 | 17.0.1.1   | Enabled                                | Commercial  | Sangoma   |
| customappsreg       | 17.0.1     | Enabled                                | GPLv3+      | Sangoma   |
| customcontexts      | 17.0.1.3   | Enabled                                | GPLv2+      | Sangoma   |
| dashboard           | 17.0.4.5   | Enabled                                | AGPLv3+     | Sangoma   |
| daynight            | 17.0.1.1   | Enabled                                | GPLv3+      | Sangoma   |
| dictate             | 17.0.1.2   | Enabled                                | GPLv3+      | Sangoma   |
| directory           | 17.0.1.1   | Enabled                                | GPLv3+      | Sangoma   |
| disa                | 17.0.5     | Enabled                                | AGPLv3+     | Sangoma   |
| donotdisturb        | 17.0.2.3   | Enabled                                | GPLv3+      | Sangoma   |
| dynroute            | 17.0.3.2   | Enabled                                | GPLv3+      | Sangoma   |
| endpoint            | 17.0.1.87  | Enabled                                | Commercial  | Sangoma   |
| extensionroutes     | 17.0.1     | Enabled                                | Commercial  | Sangoma   |
| extensionsettings   | 17.0.1     | Enabled                                | GPLv3+      | Sangoma   |
| fax                 | 17.0.3.4   | Enabled                                | GPLv3+      | Sangoma   |
| faxpro              | 17.0.1.19  | Enabled                                | Commercial  | Sangoma   |
| featurecodeadmin    | 17.0.2     | Enabled                                | GPLv3+      | Sangoma   |
| filestore           | 17.0.2.30  | Enabled                                | AGPLv3      | Sangoma   |
| findmefollow        | 17.0.4.10  | Enabled                                | GPLv3+      | Sangoma   |
| firewall            | 17.0.1.26  | Enabled                                | AGPLv3+     | Sangoma   |
| framework           | 17.0.19.13 | Enabled                                | GPLv2+      | Sangoma   |
| hotelwakeup         | 17.0.1.6   | Enabled                                | GPLv2       | Sangoma   |
| iaxsettings         | 17.0.1     | Enabled                                | AGPLv3      | Sangoma   |
| infoservices        | 17.0.1.1   | Enabled                                | GPLv2+      | Sangoma   |
| ivr                 | 17.0.8     | Enabled                                | GPLv3+      | Sangoma   |
| languages           | 17.0.1     | Enabled                                | GPLv3+      | Sangoma   |
| logfiles            | 17.0.3.3   | Enabled                                | GPLv3+      | Sangoma   |
| manager             | 17.0.6     | Enabled                                | GPLv2+      | Sangoma   |
| miscapps            | 17.0.3     | Enabled                                | GPLv3+      | Sangoma   |
| miscdests           | 17.0.1.1   | Enabled                                | GPLv3+      | Sangoma   |
| missedcall          | 17.0.1.2   | Enabled                                | GPLv3+      | Sangoma   |
| music               | 17.0.5     | Enabled                                | GPLv3+      | Sangoma   |
| oracle_connector    | 17.0.1.1   | Enabled                                | Commercial  | Sangoma   |
| outcnam             | 17.0.1     | Enabled                                | GPLv3+      | Sangoma   |
| outroutemsg         | 17.0.1     | Enabled                                | GPLv3+      | Sangoma   |
| paging              | 17.0.3     | Enabled                                | GPLv3+      | Sangoma   |
| pagingpro           | 17.0.1.6   | Enabled                                | Commercial  | Sangoma   |
| parking             | 17.0.2.5   | Enabled                                | GPLv3+      | Sangoma   |
| parkpro             | 17.0.1.4   | Enabled                                | Commercial  | Sangoma   |
| pbxmfa              | 17.0.2.3   | Enabled                                | Commercial+ | Sangoma   |
| phpinfo             | 17.0.1     | Enabled                                | GPLv2+      | Sangoma   |
| pinsets             | 17.0.3.2   | Enabled                                | GPLv3+      | Sangoma   |
| pinsetspro          | 17.0.2     | Enabled                                | Commercial  | Sangoma   |
| pm2                 | 17.0.3.3   | Enabled                                | AGPLv3+     | Sangoma   |
| pms                 | 17.0.2.30  | Enabled                                | Commercial  | Sangoma   |
| presencestate       | 17.0.2.4   | Enabled                                | GPLv3+      | Sangoma   |
| printextensions     | 17.0.1.2   | Enabled                                | GPLv3+      | Sangoma   |
| queueprio           | 17.0.1.4   | Enabled                                | GPLv3+      | Sangoma   |
| queues              | 17.0.1.12  | Enabled                                | GPLv2+      | Sangoma   |
| queuestats          | 17.0.1.7   | Enabled                                | Commercial  | Sangoma   |
| qxact_reports       | 17.0.3     | Enabled                                | Commercial  | Sangoma   |
| recording_report    | 17.0.3.8   | Enabled                                | Commercial  | Sangoma   |
| recordings          | 17.0.2.2   | Enabled                                | GPLv3+      | Sangoma   |
| restapps            | 17.0.1.25  | Enabled                                | Commercial  | Sangoma   |
| ringgroups          | 17.0.2.6   | Enabled                                | GPLv3+      | Sangoma   |
| sangomaconnect      | 17.0.1.39  | Enabled                                | Commercial  | Sangoma   |
| sangomacrm          | 17.0.1.16  | Enabled                                | Commercial  | Sangoma   |
| sangomartapi        | 17.0.2.12  | Enabled                                | Commercial  | Sangoma   |
| setcid              | 17.0.1.2   | Enabled                                | GPLv3+      | Sangoma   |
| sipsettings         | 17.0.6.9   | Enabled                                | AGPLv3+     | Sangoma   |
| sipstation          | 17.0.3.4   | Enabled                                | Commercial  | Sangoma   |
| sms                 | 17.0.1.15  | Enabled                                | Commercial  | Sangoma   |
| smsplus             | 17.0.3     | Enabled                                | Commercial  | Sangoma   |
| soundlang           | 17.0.4.1   | Enabled                                | GPLv3+      | Sangoma   |
| superfecta          | 17.0.3.5   | Enabled                                | GPLv2+      | Sangoma   |
| sysadmin            | 17.0.1.96  | Enabled                                | Commercial  | Sangoma   |
| timeconditions      | 17.0.1.18  | Enabled                                | GPLv3+      | Sangoma   |
| tts                 | 17.0.1.1   | Enabled                                | GPLv3+      | Sangoma   |
| ttsengines          | 17.0.1     | Enabled                                | AGPLv3      | Sangoma   |
| ucp                 | 17.0.4.23  | Enabled                                | AGPLv3+     | Sangoma   |
| userman             | 17.0.6.28  | Enabled                                | AGPLv3+     | Sangoma   |
| vmblast             | 17.0.2     | Enabled                                | GPLv3+      | Sangoma   |
| vmnotify            | 17.0.1.7   | Enabled                                | Commercial  | Sangoma   |
| voicemail           | 17.0.5.22  | Enabled                                | GPLv3+      | Sangoma   |
| voicemail_report    | 17.0.1.1   | Enabled                                | Commercial  | Sangoma   |
| voipinnovations     | 17.0.1.4   | Enabled                                | Commercial  | Sangoma   |
| vqplus              | 17.0.1.17  | Enabled                                | Commercial  | Sangoma   |
| weakpasswords       | 17.0.1     | Enabled                                | GPLv3+      | Sangoma   |
| webcallback         | 17.0.4     | Enabled                                | Commercial  | Sangoma   |
| webrtc              | 17.0.2.2   | Enabled                                | GPLv3+      | Sangoma   |
+---------------------+------------+----------------------------------------+-------------+-----------+

Relevant log output

snapshots from the browser, i couldn't find the log where this is logged

 Exception
Unable to connect to CDR Database
/var/www/html/admin/modules/cdr/Cdr.class.php

            } else {
                throw new \Exception("Datasource set to sqlite, but no cdrdatasource or datasource provided");
            }
            $user = "";
            $pass = "";
        } else {
            // Not SQLite.
            $user = $cdr["CDRDBUSER"];
            $pass = $cdr["CDRDBPASS"];

            // Note - http_build_query() is a simple shortcut to change a key=>value array
            // to a string.
            $dsn = "$engine:".http_build_query($dsnarray, '', ';');
        }
        // Now try to get a DB handle using our DSN
        try {
            $this->cdrdb = new \Database($dsn, $user, $pass);
        } catch(\Exception $e) {
            throw new \Exception('Unable to connect to CDR Database');
        }
        //Set the CDR session timezone to GMT if CDRUSEGMT is true
        if (isset($cdr["CDRUSEGMT"]) && $cdr["CDRUSEGMT"]) {
            $sql = "SET time_zone = '+00:00'";
            $sth = $this->cdrdb->prepare($sql);
            $sth->execute();
        }
    }

    public function getCdrDbHandle() {
        // Simply returns the DB Handle created in __construct
        return $this->cdrdb;
    }

    public function ucpDelGroup($id,$display,$data) {
    }

    /* UCP template to get the user assigned vm extension details
    * @defaultexten is the default_extensionof the userman userid
    * @userid is userman user id

Arguments

    "Unable to connect to CDR Database"

Environment & details:
GET Data
display     

"cdr"

POST Data empty
Files empty
Cookies
lang    

"en_US"

searchHide  

"1"

PHPSESSID   

"<<HIDDEN>>"

Session
langdirection   

"ltr"

module_name     

"sysadmin"

module_page     

"sysadmin"

AMP_user    

ampuser {#1}

force_remove_stack_trace    

true

Server/Request Data
SCRIPT_URL  

"/admin/config.php"

SCRIPT_URI  

"http://<<HIDDEN>>/admin/config.php"

SSLSETUP    

"true"

HTACCESS    

"on"

HTTP_HOST   

<<HIDDEN>>

HTTP_USER_AGENT     

"Mozilla/5.0 (X11; Linux x86_64; rv:130.0) Gecko/20100101 Firefox/130.0"

HTTP_ACCEPT     

"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/png,image/svg+xml,*/*;q=0.8"

HTTP_ACCEPT_LANGUAGE    

"en-US,en;q=0.5"

HTTP_ACCEPT_ENCODING    

"gzip, deflate"

HTTP_REFERER    

"http://<<HIDDEN>>/admin/config.php?display=sysadmin"

HTTP_CONNECTION     

"keep-alive"

HTTP_COOKIE     

"lang=en_US; searchHide=1; PHPSESSID=<<HIDDEN>>; lang=en_US"

HTTP_UPGRADE_INSECURE_REQUESTS  

"1"

HTTP_PRIORITY   

"u=0, i"

PATH    

"/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

SERVER_SIGNATURE    

""

SERVER_SOFTWARE     

"Apache"

SERVER_NAME     

<<HIDDEN>>

SERVER_ADDR     

"10.53.1.38"

SERVER_PORT     

"80"

REMOTE_ADDR     

"10.53.250.5"

DOCUMENT_ROOT   

"/var/www/html"

REQUEST_SCHEME  

"http"

CONTEXT_PREFIX  

""

CONTEXT_DOCUMENT_ROOT   

"/var/www/html"

SERVER_ADMIN    

"[no address given]"

SCRIPT_FILENAME     

"/var/www/html/admin/config.php"

REMOTE_PORT     

"59962"

GATEWAY_INTERFACE   

"CGI/1.1"

SERVER_PROTOCOL     

"HTTP/1.1"

REQUEST_METHOD  

"GET"

QUERY_STRING    

"display=cdr"

REQUEST_URI     

"/admin/config.php?display=cdr"

SCRIPT_NAME     

"/admin/config.php"

PHP_SELF    

"/admin/config.php"

REQUEST_TIME_FLOAT  

1728991502.9726

REQUEST_TIME    

1728991502

Environment Variables empty
Registered Handlers
0. Whoops\Handler\PrettyPageHandler