<?php

chdir(dirname(__FILE__) . '/../');
include_once "./config.php";
include_once "./lib/loader.php";
include_once "./lib/threads.php";
set_time_limit(0);
// connecting to database
$db = new mysql(DB_HOST, '', DB_USER, DB_PASSWORD, DB_NAME);
include_once "./load_settings.php";
include_once DIR_MODULES . "control_modules/control_modules.class.php";
include_once DIR_MODULES . 'scripts/scripts.class.php';
$ctl = new control_modules();
$sc = new scripts();
$checked_time = 0;
while (1) {
    echo date("H:i:s") . " running " . basename(__FILE__) . "\n";
    if (time() - $checked_time > 5) {
        $checked_time = time();
        setGlobal(str_replace('.php', '', basename(__FILE__)) . 'Run', time());
    }
    runScheduledJobs();
    $sc->checkScheduledScripts();
    if (file_exists('./reboot') || $_GET['onetime']) {
        $db->Disconnect();
        exit;
    }
    sleep(1);
}
DebMes("Unexpected close of cycle: " . basename(__FILE__));
Exemple #2
0
 public function upgrade()
 {
     //get the db variables
     $config = new config();
     $config_exists = $config->exists();
     $config_path = $config->find();
     $config->get();
     $db_type = $config->db_type;
     $db_name = $config->db_name;
     $db_username = $config->db_username;
     $db_password = $config->db_password;
     $db_host = $config->db_host;
     $db_path = $config->db_path;
     $db_port = $config->db_port;
     //get the PROJECT PATH
     include "root.php";
     //get the list of installed apps from the core and app directories (note: GLOB_BRACE doesn't work on some systems)
     $config_list_1 = glob($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "/*/*/app_config.php");
     $config_list_2 = glob($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "/*/*/app_menu.php");
     $config_list = array_merge((array) $config_list_1, (array) $config_list_2);
     unset($config_list_1, $config_list_2);
     $db = $this->db;
     $x = 0;
     foreach ($config_list as &$config_path) {
         include $config_path;
         $x++;
     }
     //get the domains
     $sql = "select * from v_domains ";
     $prep_statement = $this->db->prepare($sql);
     $prep_statement->execute();
     $domains = $prep_statement->fetchAll(PDO::FETCH_NAMED);
     unset($prep_statement);
     //get the domain_settings
     $sql = "select * from v_domain_settings ";
     $sql .= "where domain_setting_enabled = 'true' ";
     $prep_statement = $this->db->prepare($sql);
     $prep_statement->execute();
     $domain_settings = $prep_statement->fetchAll(PDO::FETCH_NAMED);
     unset($prep_statement);
     //get the default settings
     $sql = "select * from v_default_settings ";
     $sql .= "where default_setting_enabled = 'true' ";
     $prep_statement = $this->db->prepare($sql);
     $prep_statement->execute();
     $database_default_settings = $prep_statement->fetchAll(PDO::FETCH_NAMED);
     unset($prep_statement);
     //get the domain_uuid
     foreach ($domains as $row) {
         if (count($domains) == 1) {
             $_SESSION["domain_uuid"] = $row["domain_uuid"];
             $_SESSION["domain_name"] = $row['domain_name'];
         } else {
             if (lower_case($row['domain_name']) == lower_case($domain_array[0]) || lower_case($row['domain_name']) == lower_case('www.' . $domain_array[0])) {
                 $_SESSION["domain_uuid"] = $row["domain_uuid"];
                 $_SESSION["domain_name"] = $row['domain_name'];
             }
             $_SESSION['domains'][$row['domain_uuid']]['domain_uuid'] = $row['domain_uuid'];
             $_SESSION['domains'][$row['domain_uuid']]['domain_name'] = $row['domain_name'];
         }
     }
     //loop through all domains
     $domain_count = count($domains);
     $domains_processed = 1;
     foreach ($domains as &$row) {
         //get the values from database and set them as php variables
         $domain_uuid = $row["domain_uuid"];
         $domain_name = $row["domain_name"];
         //get the context
         $context = $domain_name;
         //show the domain when display_type is set to text
         if ($display_type == "text") {
             echo "\n";
             echo $domain_name;
             echo "\n";
         }
         //get the default settings - this needs to be done to reset the session values back to the defaults for each domain in the loop
         foreach ($database_default_settings as $row) {
             $name = $row['default_setting_name'];
             $category = $row['default_setting_category'];
             $subcategory = $row['default_setting_subcategory'];
             if (strlen($subcategory) == 0) {
                 if ($name == "array") {
                     $_SESSION[$category][] = $row['default_setting_value'];
                 } else {
                     $_SESSION[$category][$name] = $row['default_setting_value'];
                 }
             } else {
                 if ($name == "array") {
                     $_SESSION[$category][$subcategory][] = $row['default_setting_value'];
                 } else {
                     $_SESSION[$category][$subcategory]['uuid'] = $row['default_setting_uuid'];
                     $_SESSION[$category][$subcategory][$name] = $row['default_setting_value'];
                 }
             }
         }
         //get the domains settings for the current domain
         foreach ($domain_settings as $row) {
             if ($row['domain_uuid'] == $domain_uuid) {
                 $name = $row['domain_setting_name'];
                 $category = $row['domain_setting_category'];
                 $subcategory = $row['domain_setting_subcategory'];
                 if (strlen($subcategory) == 0) {
                     //$$category[$name] = $row['domain_setting_value'];
                     $_SESSION[$category][$name] = $row['domain_setting_value'];
                 } else {
                     //$$category[$subcategory][$name] = $row['domain_setting_value'];
                     $_SESSION[$category][$subcategory][$name] = $row['domain_setting_value'];
                 }
             }
         }
         //get the list of installed apps from the core and mod directories and execute the php code in app_defaults.php
         $default_list = glob($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "/*/*/app_defaults.php");
         foreach ($default_list as &$default_path) {
             include $default_path;
         }
         //track of the number of domains processed
         $domains_processed++;
     }
     //synchronize the dialplan
     if (function_exists('save_dialplan_xml')) {
         save_dialplan_xml();
     }
     //update config.lua
     if (file_exists($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . '/app/scripts/resources/classes/scripts.php')) {
         $obj = new scripts();
         $obj->write_config();
     }
     //clear the session variables
     unset($_SESSION['domain']);
     unset($_SESSION['switch']);
 }
/**
* Title
*
* Description
*
* @access public
*/
function runScript($id, $params = '')
{
    include_once DIR_MODULES . 'scripts/scripts.class.php';
    $sc = new scripts();
    return $sc->runScript($id, $params);
}
Exemple #4
0
            $display .= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">' . LB;
            break;
        default:
            // fallback: HTML 4.01 Transitional w/o system identifier
            $display .= '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">' . LB;
            break;
    }
    $display .= '<html>' . LB;
    $display .= '<head>' . LB;
    $display .= "<meta http-equiv=\"Content-Type\" content=\"text/html; charset={$LANG_CHARSET}\"" . XHTML . ">" . LB;
    $display .= '<meta name="robots" content="NOINDEX"' . XHTML . '>' . LB;
    $display .= '<title>Forum Preview</title>' . LB;
    if (version_compare($_CONF['supported_version_theme'], '2.0.0', '>=')) {
        $func = "theme_css_" . $_CONF['theme'];
        if (function_exists($func)) {
            $FORUM_SCRIPTS = new scripts();
            foreach ($func() as $info) {
                $file = $info['file'];
                $name = md5($file);
                $constant = !empty($info['constant']) ? $info['constant'] : true;
                $attributes = !empty($info['attributes']) ? $info['attributes'] : array();
                $FORUM_SCRIPTS->setCssFile($name, $file, $constant, $attributes);
            }
            $display .= $FORUM_SCRIPTS->getHeader();
        }
        $display .= '</head>' . LB;
    } else {
        $display .= "<link rel=\"stylesheet\" type=\"text/css\" href=\"{$_CONF['site_url']}/layout/{$_CONF['theme']}/style.css\"></head>\n";
    }
    $display .= '<body class="sitebody">';
} else {
            } else {
                $_USER['theme'] = $_CONF['theme'];
            }
        }
    }
}
// Set template class default template variables option
$TEMPLATE_OPTIONS['default_vars']['layout_url'] = $_CONF['layout_url'];
$TEMPLATE_OPTIONS['default_vars']['anonymous_user'] = COM_isAnonUser();
/**
* Include the Scripts class
*
* This provides the ability to set css and javascript.
*/
require_once $_CONF['path_system'] . 'classes/scripts.class.php';
$_SCRIPTS = new scripts();
/**
* Include theme functions file which may/may not do anything
*/
if (file_exists($_CONF['path_layout'] . 'functions.php')) {
    require_once $_CONF['path_layout'] . 'functions.php';
}
/**
 * Get the configuration values from the theme
 */
$_CONF['theme_default'] = '';
// Default is none
$_CONF['path_layout_default'] = '';
// Default is none
$_CONF['supported_version_theme'] = '1.8.1';
// if the themes supported version of the theme engine not found assume lowest version
/*
	FusionPBX
	Version: MPL 1.1

	The contents of this file are subject to the Mozilla Public License Version
	1.1 (the "License"); you may not use this file except in compliance with
	the License. You may obtain a copy of the License at
	http://www.mozilla.org/MPL/

	Software distributed under the License is distributed on an "AS IS" basis,
	WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
	for the specific language governing rights and limitations under the
	License.

	The Original Code is FusionPBX

	The Initial Developer of the Original Code is
	Mark J Crane <*****@*****.**>
	Portions created by the Initial Developer are Copyright (C) 2008-2016
	the Initial Developer. All Rights Reserved.

	Contributor(s):
	Mark J Crane <*****@*****.**>
*/
//process this only one time
if ($domains_processed == 1) {
    $obj = new scripts();
    $obj->copy_files();
    $obj->write_config();
}
 protected function app_defaults()
 {
     //write a progress message
     $this->write_progress("\tRunning app_defaults");
     //set needed session settings
     $_SESSION["username"] = $this->admin_username;
     $_SESSION["domain_uuid"] = $this->global_settings->domain_uuid();
     require $this->config_php;
     require "resources/require.php";
     $_SESSION['event_socket_ip_address'] = $this->global_settings->event_host;
     $_SESSION['event_socket_port'] = $this->global_settings->event_port;
     $_SESSION['event_socket_password'] = $this->global_settings->event_password;
     //get the groups assigned to the user and then set the groups in $_SESSION["groups"]
     $sql = "SELECT * FROM v_group_users ";
     $sql .= "where domain_uuid=:domain_uuid ";
     $sql .= "and user_uuid=:user_uuid ";
     $prep_statement = $this->dbh->prepare(check_sql($sql));
     $prep_statement->bindParam(':domain_uuid', $this->global_settings->domain_uuid);
     $prep_statement->bindParam(':user_uuid', $this->admin_uuid);
     $prep_statement->execute();
     $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
     $_SESSION["groups"] = $result;
     unset($sql, $row_count, $prep_statement);
     //get the permissions assigned to the groups that the user is a member of set the permissions in $_SESSION['permissions']
     $x = 0;
     $sql = "select distinct(permission_name) from v_group_permissions ";
     foreach ($_SESSION["groups"] as $field) {
         if (strlen($field['group_name']) > 0) {
             if ($x == 0) {
                 $sql .= "where (domain_uuid = '" . $this->global_settings->domain_uuid . "' and group_name = '" . $field['group_name'] . "') ";
             } else {
                 $sql .= "or (domain_uuid = '" . $this->global_settings->domain_uuid . "' and group_name = '" . $field['group_name'] . "') ";
             }
             $x++;
         }
     }
     $prep_statement_sub = $this->dbh->prepare($sql);
     $prep_statement_sub->execute();
     $_SESSION['permissions'] = $prep_statement_sub->fetchAll(PDO::FETCH_NAMED);
     unset($sql, $prep_statement_sub);
     //include the config.php
     $db_type = $this->global_settings->db_type();
     $db_path = $this->global_settings->db_path();
     $db_host = $this->global_settings->db_host();
     $db_port = $this->global_settings->db_port();
     $db_name = $this->global_settings->db_name();
     $db_username = $this->global_settings->db_username();
     $db_password = $this->global_settings->db_password();
     //add the database structure
     require_once "resources/classes/schema.php";
     $schema = new schema();
     echo $schema->schema();
     //run all app_defaults.php files
     $default_language = $this->install_language;
     $domain = new domains();
     $domain->upgrade();
     //get the switch default settings
     $sql = "select * from v_default_settings ";
     $sql .= "where default_setting_category = 'switch' ";
     $sql .= "and default_setting_enabled = 'true' ";
     $prep_statement = $this->dbh->prepare($sql);
     $prep_statement->execute();
     $default_settings = $prep_statement->fetchAll(PDO::FETCH_NAMED);
     foreach ($default_settings as $row) {
         $name = $row['default_setting_name'];
         $category = $row['default_setting_category'];
         $subcategory = $row['default_setting_subcategory'];
         if ($category == "switch") {
             $_SESSION[$category][$subcategory]['uuid'] = $row['default_setting_uuid'];
             $_SESSION[$category][$subcategory][$name] = $row['default_setting_value'];
         }
     }
     unset($prep_statement, $sql);
     //update config.lua
     $obj = new scripts();
     $obj->copy_files();
     $obj->write_config();
     //synchronize the config with the saved settings
     save_switch_xml();
     //do not show the apply settings reminder on the login page
     $_SESSION["reload_xml"] = false;
     //clear the menu
     $_SESSION["menu"] = "";
 }