#!/usr/bin/scl enable rh-php56 -- php
<?php
/*
 * Copyright (C) 2020 Nethesis S.r.l.
 * http://www.nethesis.it - nethserver@nethesis.it
 *
 * This script is part of NethServer.
 *
 * NethServer is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License,
 * or any later version.
 *
 * NethServer is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with NethServer.  If not, see COPYING.
 *
 *
 * Fix database access for freepbxuser
 *
*/

try {
    include_once('/etc/freepbx.conf');
} catch (Exception $e) {
    if (strpos($e->getMessage(), "Access denied for user 'freepbxuser'") !== false) {
        echo "[NOTICE] Fixing database access for user 'freepbuser'\n";
        $cmd = "/usr/bin/mysql --defaults-file=/root/.my.cnf mysql -e \"set password for 'freepbxuser'@'localhost' = PASSWORD('{$amp_conf['AMPDBPASS']}');\"";
        system($cmd);
   }
}
