Esempio n. 1
0
/**
 * Processes upgrade.
 *
 * @since 1.0
 * @package facileManager
 * @subpackage Upgrader
 */
function fmUpgrade($database)
{
    global $fmdb, $branding_logo;
    include ABSPATH . 'fm-includes/version.php';
    include ABSPATH . 'fm-modules/facileManager/variables.inc.php';
    $errors = false;
    $GLOBALS['running_db_version'] = getOption('fm_db_version');
    printf('<div id="fm-branding">
		<img src="%s" /><span>%s</span>
	</div>
	<div id="window"><table class="form-table">' . "\n", $branding_logo, _('Upgrade'));
    /** Checks to support older versions (ie n-3 upgrade scenarios */
    $success = $GLOBALS['running_db_version'] < 42 ? fmUpgrade_200($database) : true;
    if ($success) {
        $success = upgradeConfig('fm_db_version', $fm_db_version);
        setOption('version_check', array('timestamp' => date("Y-m-d H:i:s", strtotime("2 months ago")), 'data' => null), 'update', true, 0, $fm_name);
    } else {
        $errors = true;
    }
    displayProgress(_('Upgrading Core Schema'), $success);
    /** Upgrade any necessary modules */
    include ABSPATH . 'fm-modules/' . $fm_name . '/classes/class_tools.php';
    $fmdb->get_results("SELECT module_name FROM fm_options WHERE option_name='version'");
    $num_rows = $fmdb->num_rows;
    $module_list = $fmdb->last_result;
    for ($x = 0; $x < $num_rows; $x++) {
        $module_name = $module_list[$x]->module_name;
        $success = $fm_tools->upgradeModule($module_name, 'quiet');
        if (!$success || $fmdb->last_error) {
            $errors = true;
            $success = false;
        } else {
            $success = true;
        }
        displayProgress(sprintf(_('Upgrading %s Schema'), $module_name), $success);
    }
    echo "</table>";
    if (!$errors) {
        displaySetupMessage(1, $GLOBALS['RELPATH']);
    } else {
        displaySetupMessage(2);
    }
    echo "</div>";
}
Esempio n. 2
0
function installfmFirewallSchema($link = null, $database, $module, $noisy = 'noisy')
{
    global $fm_name;
    /** Include module variables */
    @(include ABSPATH . 'fm-modules' . DIRECTORY_SEPARATOR . $module . DIRECTORY_SEPARATOR . 'variables.inc.php');
    $table[] = <<<TABLE
CREATE TABLE IF NOT EXISTS {$database}.`fm_{$__FM_CONFIG[$module]['prefix']}groups` (
  `group_id` int(11) NOT NULL AUTO_INCREMENT,
  `account_id` int(11) NOT NULL DEFAULT '1',
  `group_type` enum('object','service') NOT NULL,
  `group_name` varchar(255) NOT NULL,
  `group_items` text NOT NULL,
  `group_comment` text,
  `group_status` enum('active','disabled','deleted') NOT NULL DEFAULT 'active',
  PRIMARY KEY (`group_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 ;
TABLE;
    $table[] = <<<TABLE
CREATE TABLE IF NOT EXISTS {$database}.`fm_{$__FM_CONFIG[$module]['prefix']}objects` (
  `object_id` int(11) NOT NULL AUTO_INCREMENT,
  `account_id` int(11) NOT NULL DEFAULT '1',
  `object_type` enum('host','network') NOT NULL,
  `object_name` varchar(255) NOT NULL,
  `object_address` varchar(255) NOT NULL,
  `object_mask` varchar(15) NOT NULL,
  `object_comment` text,
  `object_status` enum('active','disabled','deleted') NOT NULL DEFAULT 'active',
  PRIMARY KEY (`object_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 ;
TABLE;
    $table[] = <<<TABLE
CREATE TABLE IF NOT EXISTS {$database}.`fm_{$__FM_CONFIG[$module]['prefix']}policies` (
  `policy_id` int(11) NOT NULL AUTO_INCREMENT,
  `account_id` int(11) NOT NULL DEFAULT '1',
  `server_serial_no` int(10) NOT NULL,
  `policy_type` enum('rules','nat') NOT NULL DEFAULT 'rules',
  `policy_order_id` int(11) NOT NULL,
  `policy_interface` varchar(150) NOT NULL DEFAULT 'any',
  `policy_direction` enum('in','out') NOT NULL DEFAULT 'in',
  `policy_action` enum('pass','block','reject') NOT NULL DEFAULT 'pass',
  `policy_source_not` enum('0','1') NOT NULL DEFAULT '0',
  `policy_source` text,
  `policy_destination_not` enum('0','1') NOT NULL DEFAULT '0',
  `policy_destination` text,
  `policy_services_not` enum('0','1') NOT NULL DEFAULT '0',
  `policy_services` text,
  `policy_time` text,
  `policy_options` int(3) NOT NULL DEFAULT '0',
  `policy_comment` text,
  `policy_status` enum('active','disabled','deleted') NOT NULL DEFAULT 'active',
  PRIMARY KEY (`policy_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 ;
TABLE;
    $table[] = <<<TABLE
CREATE TABLE IF NOT EXISTS {$database}.`fm_{$__FM_CONFIG[$module]['prefix']}servers` (
  `server_id` int(11) NOT NULL AUTO_INCREMENT,
  `account_id` int(11) NOT NULL DEFAULT '1',
  `server_serial_no` int(10) NOT NULL,
  `server_name` varchar(255) NOT NULL,
  `server_os` varchar(50) DEFAULT NULL,
  `server_os_distro` varchar(150) DEFAULT NULL,
  `server_type` enum('iptables','ipfw','ipfilter','pf') NOT NULL DEFAULT 'iptables',
  `server_version` varchar(150) DEFAULT NULL,
  `server_config_file` varchar(255) NOT NULL DEFAULT '/usr/local/{$fm_name}/{$module}/rules.fw',
  `server_interfaces` text,
  `server_update_method` enum('http','https','cron','ssh') NOT NULL DEFAULT 'http',
  `server_update_port` int(5) NOT NULL DEFAULT '0',
  `server_build_config` enum('yes','no') NOT NULL DEFAULT 'no',
  `server_update_config` enum('yes','no') NOT NULL DEFAULT 'no',
  `server_installed` enum('yes','no') NOT NULL DEFAULT 'no',
  `server_client_version` varchar(150) DEFAULT NULL,
  `server_status` enum('active','disabled','deleted') NOT NULL DEFAULT 'disabled',
  PRIMARY KEY (`server_id`),
  UNIQUE KEY `server_serial_no` (`server_serial_no`)
) ENGINE = MYISAM  DEFAULT CHARSET=utf8;
TABLE;
    $table[] = <<<TABLE
CREATE TABLE IF NOT EXISTS {$database}.`fm_{$__FM_CONFIG[$module]['prefix']}services` (
  `service_id` int(11) NOT NULL AUTO_INCREMENT,
  `account_id` int(11) NOT NULL DEFAULT '1',
  `service_type` enum('icmp','tcp','udp') NOT NULL,
  `service_name` varchar(255) NOT NULL,
  `service_icmp_type` int(3) DEFAULT NULL,
  `service_icmp_code` int(3) DEFAULT NULL,
  `service_src_ports` varchar(11) DEFAULT NULL,
  `service_dest_ports` varchar(11) DEFAULT NULL,
  `service_tcp_flags` varchar(5) DEFAULT NULL,
  `service_established` enum('0','1') NOT NULL DEFAULT '0',
  `service_comment` text,
  `service_status` enum('active','disabled','deleted') NOT NULL DEFAULT 'active',
  PRIMARY KEY (`service_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 ;
TABLE;
    $table[] = <<<TABLE
CREATE TABLE IF NOT EXISTS {$database}.`fm_{$__FM_CONFIG[$module]['prefix']}time` (
  `time_id` int(11) NOT NULL AUTO_INCREMENT,
  `account_id` int(11) NOT NULL DEFAULT '1',
  `time_name` varchar(255) NOT NULL,
  `time_start_date` date DEFAULT NULL,
  `time_end_date` date DEFAULT NULL,
  `time_start_time` time NOT NULL,
  `time_end_time` time NOT NULL,
  `time_weekdays` int(3) NOT NULL DEFAULT '0',
  `time_comment` text,
  `time_status` enum('active','disabled','deleted') NOT NULL DEFAULT 'active',
  PRIMARY KEY (`time_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 ;
TABLE;
    $inserts[] = <<<INSERT
INSERT INTO {$database}.`fm_options` (option_name, option_value, module_name) 
\tSELECT 'version', '{$__FM_CONFIG[$module]['version']}', '{$module}' FROM DUAL
WHERE NOT EXISTS
\t(SELECT option_name FROM {$database}.`fm_options` WHERE option_name = 'version'
\t\tAND module_name='{$module}');
INSERT;
    $inserts[] = <<<INSERT
INSERT INTO {$database}.`fm_options` (option_name, option_value, module_name) 
\tSELECT 'client_version', '{$__FM_CONFIG[$module]['client_version']}', '{$module}' FROM DUAL
WHERE NOT EXISTS
\t(SELECT option_name FROM {$database}.`fm_options` WHERE option_name = 'client_version'
\t\tAND module_name='{$module}');
INSERT;
    $inserts[] = <<<INSERT
INSERT INTO {$database}.`fm_{$__FM_CONFIG[$module]['prefix']}objects` (account_id, object_type, object_name, object_address, object_mask, object_comment) 
\tSELECT '1', 'host', '{$fm_name}', '{$_SERVER['SERVER_ADDR']}', '255.255.255.255', '{$fm_name} Server' FROM DUAL
WHERE NOT EXISTS
\t(SELECT * FROM {$database}.`fm_{$__FM_CONFIG[$module]['prefix']}objects` WHERE 
\tobject_type = 'host' AND object_name = '{$fm_name}' AND account_id = '1'
\t);
INSERT;
    /** Default networks */
    $inserts[] = <<<INSERT
INSERT INTO {$database}.`fm_{$__FM_CONFIG[$module]['prefix']}objects` (account_id, object_type, object_name, object_address, object_mask, object_comment) 
\tSELECT '1', 'network', 'net-10.0.0.0', '10.0.0.0', '255.0.0.0', '10.0.0.0/8 - This block is reserved for use in private networks and should not appear on the public Internet. Its intended use is documented in RFC1918.' FROM DUAL
WHERE NOT EXISTS
\t(SELECT * FROM {$database}.`fm_{$__FM_CONFIG[$module]['prefix']}objects` WHERE 
\tobject_type = 'network' AND object_name = 'net-10.0.0.0' AND account_id = '1'
\t);
INSERT;
    $inserts[] = <<<INSERT
INSERT INTO {$database}.`fm_{$__FM_CONFIG[$module]['prefix']}objects` (account_id, object_type, object_name, object_address, object_mask, object_comment) 
\tSELECT '1', 'network', 'net-172.16.0.0', '172.16.0.0', '255.240.0.0', '172.16.0.0/12 - This block is reserved for use in private networks and should not appear on the public Internet. Its intended use is documented in RFC1918.' FROM DUAL
WHERE NOT EXISTS
\t(SELECT * FROM {$database}.`fm_{$__FM_CONFIG[$module]['prefix']}objects` WHERE 
\tobject_type = 'network' AND object_name = 'net-172.16.0.0' AND account_id = '1'
\t);
INSERT;
    $inserts[] = <<<INSERT
INSERT INTO {$database}.`fm_{$__FM_CONFIG[$module]['prefix']}objects` (account_id, object_type, object_name, object_address, object_mask, object_comment) 
\tSELECT '1', 'network', 'net-192.168.0.0', '192.168.0.0', '255.255.0.0', '192.168.0.0/16 - This block is reserved for use in private networks and should not appear on the public Internet. Its intended use is documented in RFC1918.' FROM DUAL
WHERE NOT EXISTS
\t(SELECT * FROM {$database}.`fm_{$__FM_CONFIG[$module]['prefix']}objects` WHERE 
\tobject_type = 'network' AND object_name = 'net-192.168.0.0' AND account_id = '1'
\t);
INSERT;
    $inserts[] = <<<INSERT
INSERT INTO {$database}.`fm_{$__FM_CONFIG[$module]['prefix']}objects` (account_id, object_type, object_name, object_address, object_mask, object_comment) 
\tSELECT '1', 'network', 'All Multicasts', '224.0.0.0', '240.0.0.0', '224.0.0.0/4 - This block, formerly known as the Class D address space, is allocated for use in IPv4 multicast address assignments. The IANA guidelines for assignments from this space are described in RFC3171.' FROM DUAL
WHERE NOT EXISTS
\t(SELECT * FROM {$database}.`fm_{$__FM_CONFIG[$module]['prefix']}objects` WHERE 
\tobject_type = 'network' AND object_name = 'All Multicasts' AND account_id = '1'
\t);
INSERT;
    $groups[] = array('object', array('network|net-10.0.0.0', 'network|net-172.16.0.0', 'network|net-192.168.0.0'), 'rfc1918', 'RFC1918 networks.');
    /** Default ICMP Services */
    $inserts[] = <<<INSERT
INSERT INTO {$database}.`fm_{$__FM_CONFIG[$module]['prefix']}services` (account_id, service_type, service_name, service_icmp_type, service_icmp_code) 
\tSELECT '1', 'icmp', 'Any ICMP', '-1', '-1' FROM DUAL
WHERE NOT EXISTS
\t(SELECT * FROM {$database}.`fm_{$__FM_CONFIG[$module]['prefix']}services` WHERE 
\tservice_type = 'icmp' AND service_name = 'Any ICMP' AND account_id = '1'
\t);
INSERT;
    $inserts[] = <<<INSERT
INSERT INTO {$database}.`fm_{$__FM_CONFIG[$module]['prefix']}services` (account_id, service_type, service_name, service_icmp_type, service_icmp_code) 
\tSELECT '1', 'icmp', 'Ping Reply', '0', '0' FROM DUAL
WHERE NOT EXISTS
\t(SELECT * FROM {$database}.`fm_{$__FM_CONFIG[$module]['prefix']}services` WHERE 
\tservice_type = 'icmp' AND service_name = 'Ping Reply' AND account_id = '1'
\t);
INSERT;
    $inserts[] = <<<INSERT
INSERT INTO {$database}.`fm_{$__FM_CONFIG[$module]['prefix']}services` (account_id, service_type, service_name, service_icmp_type, service_icmp_code) 
\tSELECT '1', 'icmp', 'Ping Request', '8', '0' FROM DUAL
WHERE NOT EXISTS
\t(SELECT * FROM {$database}.`fm_{$__FM_CONFIG[$module]['prefix']}services` WHERE 
\tservice_type = 'icmp' AND service_name = 'Ping Request' AND account_id = '1'
\t);
INSERT;
    $inserts[] = <<<INSERT
INSERT INTO {$database}.`fm_{$__FM_CONFIG[$module]['prefix']}services` (account_id, service_type, service_name, service_icmp_type, service_icmp_code) 
\tSELECT '1', 'icmp', 'Ping Unreachable', '3', '3' FROM DUAL
WHERE NOT EXISTS
\t(SELECT * FROM {$database}.`fm_{$__FM_CONFIG[$module]['prefix']}services` WHERE 
\tservice_type = 'icmp' AND service_name = 'Ping Unreachable' AND account_id = '1'
\t);
INSERT;
    $inserts[] = <<<INSERT
INSERT INTO {$database}.`fm_{$__FM_CONFIG[$module]['prefix']}services` (account_id, service_type, service_name, service_icmp_type, service_icmp_code) 
\tSELECT '1', 'icmp', 'Host Unreachable', '3', '1' FROM DUAL
WHERE NOT EXISTS
\t(SELECT * FROM {$database}.`fm_{$__FM_CONFIG[$module]['prefix']}services` WHERE 
\tservice_type = 'icmp' AND service_name = 'Host Unreachable' AND account_id = '1'
\t);
INSERT;
    $inserts[] = <<<INSERT
INSERT INTO {$database}.`fm_{$__FM_CONFIG[$module]['prefix']}services` (account_id, service_type, service_name, service_icmp_type, service_icmp_code, service_comment) 
\tSELECT '1', 'icmp', 'Time Exceeded', '11', '0', 'Traceroute requires this type of ICMP messages.' FROM DUAL
WHERE NOT EXISTS
\t(SELECT * FROM {$database}.`fm_{$__FM_CONFIG[$module]['prefix']}services` WHERE 
\tservice_type = 'icmp' AND service_name = 'Time Exceeded' AND account_id = '1'
\t);
INSERT;
    $inserts[] = <<<INSERT
INSERT INTO {$database}.`fm_{$__FM_CONFIG[$module]['prefix']}services` (account_id, service_type, service_name, service_icmp_type, service_icmp_code) 
\tSELECT '1', 'icmp', 'Time Exceeded in Transit', '11', '1' FROM DUAL
WHERE NOT EXISTS
\t(SELECT * FROM {$database}.`fm_{$__FM_CONFIG[$module]['prefix']}services` WHERE 
\tservice_type = 'icmp' AND service_name = 'Time Exceeded in Transit' AND account_id = '1'
\t);
INSERT;
    /** Default TCP/UDP Services */
    $services[] = array('tcp', 'Any TCP', '', '', NULL, '');
    $services[] = array('udp', 'Any UDP', '', '', NULL, '');
    $services[] = array('tcp', 'High TCP Ports', '', '1024:65535', NULL, '');
    $services[] = array('udp', 'High UDP Ports', '', '1024:65535', NULL, '');
    $services[] = array('tcp', 'ssh', '', '22:22', NULL, '');
    $services[] = array('tcp', 'rdp', '', '3389:3389', NULL, '');
    $services[] = array('tcp', 'http', '', '80:80', NULL, '');
    $services[] = array('tcp', 'https', '', '443:443', NULL, '');
    $services[] = array('tcp', 'mysql', '', '3306:3306', NULL, '');
    $services[] = array('tcp', 'mssql', '', '1433:1433', NULL, '');
    $services[] = array('tcp', 'postgre', '', '5432:5432', NULL, '');
    $services[] = array('tcp', 'domain', '', '53:53', NULL, '');
    $services[] = array('udp', 'domain', '', '53:53', NULL, '');
    $services[] = array('tcp', 'ftp', '', '21:21', NULL, '');
    $services[] = array('tcp', 'ftp-data', '20:20', '1024:65535', NULL, '');
    $services[] = array('tcp', 'ftp-data passive', '', '20:20', NULL, '');
    $services[] = array('tcp', 'smtp', '', '25:25', NULL, '');
    $services[] = array('tcp', 'smtps', '', '465:465', NULL, '');
    $services[] = array('tcp', 'pop3', '', '110:110', NULL, '');
    $services[] = array('tcp', 'pop3s', '', '995:995', NULL, '');
    $services[] = array('tcp', 'imap', '', '143:143', NULL, '');
    $services[] = array('tcp', 'imaps', '', '993:993', NULL, '');
    $services[] = array('tcp', 'squid', '', '3128:3128', NULL, 'Standard proxy server');
    $services[] = array('tcp', 'telnet', '', '23:23', NULL, '');
    $services[] = array('tcp', 'afp', '', '548:548', NULL, 'Apple File Sharing over TCP');
    $services[] = array('tcp', 'nfs', '', '2049:2049', NULL, '');
    $services[] = array('udp', 'nfs', '', '2049:2049', NULL, '');
    $services[] = array('tcp', 'kerberos', '', '88:88', NULL, '');
    $services[] = array('udp', 'kerberos', '', '88:88', NULL, '');
    $services[] = array('udp', 'kerberos-adm', '', '749:750', NULL, '');
    $services[] = array('tcp', 'ldap', '', '389:389', NULL, '');
    $services[] = array('tcp', 'ldaps', '', '636:636', NULL, '');
    $services[] = array('tcp', 'eklogin', '', '2105:2105', NULL, '');
    $services[] = array('tcp', 'klogin', '', '543:543', NULL, '');
    $services[] = array('tcp', 'kpasswd', '', '464:464', NULL, '');
    $services[] = array('tcp', 'krb524', '', '4444:4444', NULL, '');
    $services[] = array('tcp', 'ksh', '', '544:544', NULL, '');
    $services[] = array('udp', 'netbios-ns', '', '137:137', NULL, '');
    $services[] = array('udp', 'netbios-dgm', '', '138:138', NULL, '');
    $services[] = array('tcp', 'netbios-ssn', '', '139:139', NULL, '');
    $services[] = array('udp', 'bootps', '', '67:67', NULL, '');
    $services[] = array('udp', 'bootpc', '', '68:68', NULL, '');
    $services[] = array('tcp', 'smb', '', '445:445', NULL, 'SMB over TCP');
    $services[] = array('udp', 'ntp', '', '123:123', NULL, '');
    $services[] = array('udp', 'snmp', '', '161:161', NULL, '');
    $services[] = array('udp', 'snmp-trap', '', '162:162', NULL, '');
    $services[] = array('udp', 'syslog', '', '514:514', NULL, '');
    $services[] = array('udp', 'tftp', '', '69:69', NULL, '');
    $services[] = array('udp', 'traceroute', '', '33434:33524', NULL, '');
    $services[] = array('udp', 'kerberos', '', '88:88', NULL, '');
    $services[] = array('tcp', 'radius', '', '1812:1812', NULL, 'Radius Protocol');
    $services[] = array('tcp', 'radius acct', '', '1813:1813', NULL, 'Radius Accounting');
    $services[] = array('udp', 'radius', '', '1645:1645', NULL, '');
    $services[] = array('tcp', 'WINS replication', '', '42:42', NULL, '');
    $services[] = array('tcp', 'microsoft-rpc', '', '135:135', NULL, '');
    $services[] = array('udp', 'microsoft-rpc', '', '135:135', NULL, '');
    $services[] = array('tcp', 'sunrpc', '', '111:111', NULL, '');
    $services[] = array('udp', 'sunrpc', '', '111:111', NULL, '');
    $services[] = array('tcp', 'cvsup', '', '5999:5999', NULL, 'CVSup file transfers (FreeBSD uses this)');
    $services[] = array('tcp', 'irc', '', '6667:6667', NULL, '');
    $services[] = array('tcp', 'Christmas Tree', '', '', '63:37', 'Packets that are lit up like a Christmas Tree');
    $groups[] = array('service', array('tcp|ssh', 'tcp|rdp'), 'Remote Server Administration', '');
    $groups[] = array('service', array('tcp|http', 'tcp|https'), 'Web Server', '');
    $groups[] = array('service', array('tcp|domain', 'udp|domain'), 'DNS', '');
    $groups[] = array('service', array('tcp|ftp', 'tcp|ftp-data', 'tcp|ftp-data passive'), 'FTP', '');
    $groups[] = array('service', array('tcp|kerberos', 'udp|kerberos', 'udp|kerberos-adm', 'tcp|eklogin', 'tcp|klogin', 'tcp|kpasswd', 'tcp|krb524', 'tcp|ksh'), 'Kerberos', '');
    $groups[] = array('service', array('udp|bootps', 'udp|bootpc'), 'DHCP', '');
    $groups[] = array('service', array('tcp|nfs', 'udp|nfs'), 'NFS', '');
    $groups[] = array('service', array('udp|netbios-ns', 'udp|netbios-dgm', 'tcp|netbios-ssn'), 'NETBIOS', '');
    foreach ($services as $array) {
        list($protocol, $name, $src_port, $dest_port, $tcp_flags, $comment) = $array;
        $inserts[] = <<<INSERT
INSERT INTO {$database}.`fm_{$__FM_CONFIG[$module]['prefix']}services` (account_id, service_type, service_name, service_src_ports, service_dest_ports, service_tcp_flags, service_comment) 
\tSELECT '1', '{$protocol}', '{$name}', '{$src_port}', '{$dest_port}', '{$tcp_flags}', '{$comment}' FROM DUAL
WHERE NOT EXISTS
\t(SELECT * FROM {$database}.`fm_{$__FM_CONFIG[$module]['prefix']}services` WHERE 
\tservice_type = '{$protocol}' AND service_name = '{$name}' AND account_id = '1'
\t);
INSERT;
    }
    /** Create table schema */
    foreach ($table as $schema) {
        if ($link) {
            $result = mysql_query($schema, $link);
            if (mysql_error($link)) {
                return function_exists('displayProgress') ? displayProgress($module, $result, $noisy, mysql_error($link)) : $result;
            }
        } else {
            global $fmdb;
            $result = $fmdb->query($schema);
            if ($fmdb->last_error) {
                return function_exists('displayProgress') ? displayProgress($module, $result, $noisy, $fmdb->last_error) : $result;
            }
        }
    }
    /** Insert site values if not already present */
    foreach ($inserts as $query) {
        if ($link) {
            $result = mysql_query($query, $link);
            if (mysql_error($link)) {
                return function_exists('displayProgress') ? displayProgress($module, $result, $noisy, mysql_error($link)) : $result;
            }
        } else {
            $result = $fmdb->query($query);
            if ($fmdb->last_error) {
                return function_exists('displayProgress') ? displayProgress($module, $result, $noisy, $fmdb->last_error) : $result;
            }
        }
    }
    /** Process groups */
    foreach ($groups as $array) {
        list($group_type, $item_array, $group_name, $comment) = $array;
        $group_ids = null;
        foreach ($item_array as $item) {
            list($protocol, $name) = explode('|', $item);
            if ($protocol == 'group') {
                if ($link) {
                    $query = "SELECT * FROM {$database}.fm_{$__FM_CONFIG[$module]['prefix']}groups WHERE group_status!='deleted'\n\t\t\t\t\t\t\t\tAND account_id=1 AND group_name='{$name}' LIMIT 1";
                    $result = mysql_query($query, $link);
                    $temp_result = mysql_fetch_object($result);
                } else {
                    basicGet($database . "`.`fm_{$__FM_CONFIG[$module]['prefix']}groups", $name, 'group_', 'group_name', null, 1);
                    $temp_result = $fmdb->last_result[0];
                }
                $type_id = 'group_id';
                $prefix = 'g';
            } else {
                if ($link) {
                    $query = "SELECT * FROM {$database}.fm_{$__FM_CONFIG[$module]['prefix']}{$group_type}s WHERE {$group_type}_status!='deleted'\n\t\t\t\t\t\t\t\tAND account_id=1 AND {$group_type}_name='{$name}' AND {$group_type}_type = '{$protocol}' LIMIT 1";
                    $result = mysql_query($query, $link);
                    $temp_result = mysql_fetch_object($result);
                } else {
                    basicGet($database . "`.`fm_{$__FM_CONFIG[$module]['prefix']}{$group_type}s", $name, $group_type . '_', $group_type . '_name', "AND {$group_type}_type = '{$protocol}'", 1);
                    $temp_result = $fmdb->last_result[0];
                }
                $type_id = $group_type . '_id';
                $prefix = substr($group_type, 0, 1);
            }
            $group_ids[] = $prefix . $temp_result->{$type_id};
        }
        $group_items = implode(';', $group_ids);
        $group_inserts[] = <<<INSERT
INSERT INTO {$database}.`fm_{$__FM_CONFIG[$module]['prefix']}groups` (account_id, group_type, group_name, group_items, group_comment) 
\tSELECT '1', '{$group_type}', '{$group_name}', '{$group_items}', '{$comment}' FROM DUAL
WHERE NOT EXISTS
\t(SELECT * FROM {$database}.`fm_{$__FM_CONFIG[$module]['prefix']}groups` WHERE 
\tgroup_type = '{$group_type}' AND group_name = '{$group_name}' AND account_id = '1'
\t);
INSERT;
    }
    /** Insert site values if not already present */
    foreach ($group_inserts as $query) {
        if ($link) {
            $result = mysql_query($query, $link);
            if (mysql_error($link)) {
                return function_exists('displayProgress') ? displayProgress($module, $result, $noisy, mysql_error($link)) : $result;
            }
        } else {
            $result = $fmdb->query($query);
            if ($fmdb->last_error) {
                return function_exists('displayProgress') ? displayProgress($module, $result, $noisy, $fmdb->last_error) : $result;
            }
        }
    }
    if (function_exists('displayProgress')) {
        return displayProgress($module, $result, $noisy);
    } else {
        if ($result) {
            return 'Success';
        } else {
            return 'Failed';
        }
    }
}
Esempio n. 3
0
 while (!$done) {
     $nodeList = $rootNode->subTree(array('Offset' => $offset, 'Limit' => $fetchLimit, 'IgnoreVisibility' => true, 'Limitation' => array()));
     foreach (array_keys($nodeList) as $key) {
         $node = $nodeList[$key];
         $hasChanged = $node->updateSubTreePath();
         if ($hasChanged) {
             ++$changedNodes;
             ++$totalChangedNodes;
         }
         $changeCharacters = array('.', '+', '*');
         $changeCharacter = '.';
         if (isset($changeCharacters[$hasChanged])) {
             $changeCharacter = $changeCharacters[$hasChanged];
         }
         verifyNodeData($changeCharacter, $node);
         list($column, $counter) = displayProgress($changeCharacter, $nodeStartTime, $counter, $nodeCount, $column);
     }
     if (count($nodeList) == 0) {
         $done = true;
     }
     unset($nodeList);
     $offset += $fetchLimit;
     eZContentObject::clearCache();
 }
 flush();
 if ($column > 0) {
     $cli->output();
 }
 $cli->output("Updated " . $cli->stylize('emphasize', "{$changedNodes}/{$nodeCount}") . " for " . $cli->stylize('mark', $rootNode->attribute('name')));
 $cli->output();
 backupTables('node_' . strtolower($rootNode->attribute('name')));
function create($_POST)
{
    if (isset($_POST['back'])) {
        return newcomp("", $_POST['name'], "");
    }
    /**
     * so how does this progress work?
     *
     * just require the progress library and call displayProgress()
     * specifying which template to use.
     */
    require_lib("progress");
    displayProgress("newtemplate.php");
    return creation($_POST);
}
Esempio n. 5
0
function installfmSQLPassSchema($link, $database, $module, $noisy = 'noisy')
{
    /** Include module variables */
    @(include ABSPATH . 'fm-modules' . DIRECTORY_SEPARATOR . $module . DIRECTORY_SEPARATOR . 'variables.inc.php');
    $table[] = <<<TABLE
CREATE TABLE IF NOT EXISTS {$database}.`fm_{$__FM_CONFIG['fmSQLPass']['prefix']}groups` (
  `group_id` int(11) NOT NULL AUTO_INCREMENT,
  `account_id` int(11) NOT NULL DEFAULT '1',
  `group_name` varchar(255) NOT NULL,
  `group_pwd_change` int(10) DEFAULT NULL,
  `group_status` enum('active','disabled','deleted') NOT NULL,
  PRIMARY KEY (`group_id`)
) ENGINE = MYISAM DEFAULT CHARSET=utf8;
TABLE;
    $table[] = <<<TABLE
CREATE TABLE IF NOT EXISTS {$database}.`fm_{$__FM_CONFIG['fmSQLPass']['prefix']}servers` (
  `server_id` int(11) NOT NULL AUTO_INCREMENT,
  `account_id` int(11) NOT NULL DEFAULT '1',
  `server_serial_no` int(10) NOT NULL,
  `server_type` enum('MySQL') NOT NULL,
  `server_port` int(5) DEFAULT NULL,
  `server_name` varchar(255) NOT NULL,
  `server_groups` text,
  `server_credentials` text,
  `server_status` enum('active','disabled','deleted') NOT NULL,
  PRIMARY KEY (`server_id`)
) ENGINE = MYISAM DEFAULT CHARSET=utf8;
TABLE;
    $inserts[] = <<<INSERT
INSERT INTO {$database}.`fm_options` (option_name, option_value, module_name) 
\tSELECT 'version', '{$__FM_CONFIG[$module]['version']}', '{$module}' FROM DUAL
WHERE NOT EXISTS
\t(SELECT option_name FROM {$database}.`fm_options` WHERE option_name = 'version'
\t\tAND module_name='{$module}');
INSERT;
    /** Create table schema */
    foreach ($table as $schema) {
        if ($link) {
            $result = mysql_query($schema, $link);
            if (mysql_error($link)) {
                return function_exists('displayProgress') ? displayProgress($module, $result, $noisy, mysql_error($link)) : $result;
            }
        } else {
            global $fmdb;
            $result = $fmdb->query($schema);
            if ($fmdb->last_error) {
                return function_exists('displayProgress') ? displayProgress($module, $result, $noisy, $fmdb->last_error) : $result;
            }
        }
    }
    /** Insert site values if not already present */
    foreach ($inserts as $query) {
        if ($link) {
            $result = mysql_query($query, $link);
            if (mysql_error($link)) {
                return function_exists('displayProgress') ? displayProgress($module, $result, $noisy, mysql_error($link)) : $result;
            }
        } else {
            $result = $fmdb->query($query);
            if ($fmdb->last_error) {
                return function_exists('displayProgress') ? displayProgress($module, $result, $noisy, $fmdb->last_error) : $result;
            }
        }
    }
    if (function_exists('displayProgress')) {
        return displayProgress($module, $result, $noisy);
    } else {
        if ($result) {
            return 'Success';
        } else {
            return 'Failed';
        }
    }
}
Esempio n. 6
0
function installfmDNSSchema($link = null, $database, $module, $noisy = 'noisy')
{
    /** Include module variables */
    @(include ABSPATH . 'fm-modules' . DIRECTORY_SEPARATOR . $module . DIRECTORY_SEPARATOR . 'variables.inc.php');
    $table[] = <<<TABLE
CREATE TABLE IF NOT EXISTS {$database}.`fm_{$__FM_CONFIG[$module]['prefix']}acls` (
  `acl_id` INT(11) NOT NULL AUTO_INCREMENT ,
  `account_id` int(11) NOT NULL DEFAULT '1',
  `server_serial_no` varchar(255) NOT NULL DEFAULT '0',
  `acl_name` VARCHAR(255) NOT NULL ,
  `acl_predefined` ENUM( 'none',  'any',  'localhost',  'localnets',  'as defined:') NOT NULL ,
  `acl_addresses` TEXT NOT NULL ,
  `acl_comment` text,
  `acl_status` ENUM( 'active',  'disabled',  'deleted') NOT NULL DEFAULT  'active',
  PRIMARY KEY (`acl_id`)
) ENGINE = MYISAM DEFAULT CHARSET=utf8;
TABLE;
    $table[] = <<<TABLE
CREATE TABLE IF NOT EXISTS {$database}.`fm_{$__FM_CONFIG[$module]['prefix']}config` (
  `cfg_id` int(11) NOT NULL AUTO_INCREMENT,
  `account_id` int(11) NOT NULL DEFAULT '1',
  `server_serial_no` varchar(255) NOT NULL DEFAULT '0',
  `cfg_type` varchar(255) NOT NULL DEFAULT 'global',
  `view_id` int(11) NOT NULL DEFAULT '0',
  `domain_id` int(11) NOT NULL DEFAULT '0',
  `cfg_isparent` enum('yes','no') NOT NULL DEFAULT 'no',
  `cfg_parent` int(11) NOT NULL DEFAULT '0',
  `cfg_name` varchar(50) NOT NULL,
  `cfg_data` text NOT NULL,
  `cfg_comment` text,
  `cfg_status` enum('hidden','active','disabled','deleted') NOT NULL DEFAULT 'active',
  PRIMARY KEY (`cfg_id`),
  KEY `domain_id` (`domain_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 ;
TABLE;
    $table[] = <<<TABLE
CREATE TABLE IF NOT EXISTS {$database}.`fm_{$__FM_CONFIG[$module]['prefix']}controls` (
  `control_id` int(11) NOT NULL AUTO_INCREMENT,
  `account_id` int(11) NOT NULL DEFAULT '1',
  `server_serial_no` varchar(255) NOT NULL DEFAULT '0',
  `control_ip` varchar(15) NOT NULL DEFAULT '*',
  `control_port` int(5) NOT NULL DEFAULT '953',
  `control_addresses` text NOT NULL,
  `control_keys` varchar(255) DEFAULT NULL,
  `control_comment` text,
  `control_status` enum('active','disabled','deleted') NOT NULL DEFAULT 'active',
  PRIMARY KEY (`control_id`)
) ENGINE = MYISAM DEFAULT CHARSET=utf8;
TABLE;
    $table[] = <<<TABLE
CREATE TABLE IF NOT EXISTS {$database}.`fm_{$__FM_CONFIG[$module]['prefix']}domains` (
  `domain_id` int(11) NOT NULL AUTO_INCREMENT,
  `account_id` int(11) NOT NULL DEFAULT '1',
  `domain_template` ENUM('yes','no') NOT NULL DEFAULT 'no',
  `domain_default` ENUM('yes','no') NOT NULL DEFAULT 'no',
  `domain_template_id` INT(11) NOT NULL DEFAULT '0',
  `soa_id` int(11) NOT NULL DEFAULT '0',
  `soa_serial_no` INT(2) NOT NULL DEFAULT  '0',
  `domain_name` varchar(255) NOT NULL DEFAULT '',
  `domain_name_servers` varchar(255) NOT NULL DEFAULT '0',
  `domain_view` varchar(255) NOT NULL DEFAULT '0',
  `domain_mapping` enum('forward','reverse') NOT NULL DEFAULT 'forward',
  `domain_type` enum('master','slave','forward','stub') NOT NULL DEFAULT 'master',
  `domain_clone_domain_id` int(11) NOT NULL DEFAULT '0',
  `domain_clone_dname` ENUM('yes','no') NULL DEFAULT NULL,
  `domain_reload` enum('yes','no') NOT NULL DEFAULT 'no',
  `domain_status` enum('active','disabled','deleted') NOT NULL DEFAULT 'active',
  PRIMARY KEY (`domain_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 ;
TABLE;
    $table[] = <<<TABLE
CREATE TABLE IF NOT EXISTS {$database}.`fm_{$__FM_CONFIG[$module]['prefix']}functions` (
  `def_id` int(11) NOT NULL AUTO_INCREMENT,
  `def_function` enum('options','logging','key','view') NOT NULL,
  `def_option_type` enum('global','ratelimit') NOT NULL DEFAULT 'global',
  `def_option` varchar(255) NOT NULL,
  `def_type` varchar(200) NOT NULL,
  `def_multiple_values` enum('yes','no') NOT NULL DEFAULT 'no',
  `def_clause_support` varchar(10) NOT NULL DEFAULT 'O',
  `def_zone_support` VARCHAR(10) NULL DEFAULT NULL,
  `def_dropdown` enum('yes','no') NOT NULL DEFAULT 'no',
  `def_max_parameters` int(3) NOT NULL DEFAULT '1',
  PRIMARY KEY (`def_id`),
  KEY `def_option` (`def_option`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 ;
TABLE;
    $table[] = <<<TABLE
CREATE TABLE IF NOT EXISTS {$database}.`fm_{$__FM_CONFIG[$module]['prefix']}keys` (
  `key_id` int(11) NOT NULL AUTO_INCREMENT,
  `account_id` int(11) NOT NULL DEFAULT '1',
  `key_name` varchar(255) NOT NULL,
  `key_algorithm` enum('hmac-md5',  'hmac-sha1',  'hmac-sha224',  'hmac-sha256', 'hmac-sha384',  'hmac-sha512') NOT NULL DEFAULT 'hmac-md5',
  `key_secret` varchar(255) NOT NULL,
  `key_view` int(11) NOT NULL DEFAULT '0',
  `key_comment` text,
  `key_status` enum('active','disabled','deleted') NOT NULL DEFAULT 'active',
  PRIMARY KEY (`key_id`)
) ENGINE = MYISAM DEFAULT CHARSET=utf8;
TABLE;
    $table[] = <<<TABLE
CREATE TABLE IF NOT EXISTS {$database}.`fm_{$__FM_CONFIG[$module]['prefix']}records` (
  `record_id` int(11) NOT NULL AUTO_INCREMENT,
  `account_id` int(11) NOT NULL DEFAULT '1',
  `domain_id` int(11) NOT NULL DEFAULT '0',
  `record_timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `record_name` varchar(255) DEFAULT '@',
  `record_value` text,
  `record_ttl` varchar(50) NOT NULL DEFAULT '',
  `record_class` enum('IN','CH','HS') NOT NULL DEFAULT 'IN',
  `record_type` ENUM( 'A',  'AAAA',  'CERT',  'CNAME',  'DNAME',  'DNSKEY', 'KEY',
\t'KX',  'MX',  'NS',  'PTR',  'RP',  'SRV',  'TXT', 'HINFO', 'SSHFP' ) NOT NULL DEFAULT  'A',
  `record_priority` int(4) DEFAULT NULL,
  `record_weight` int(4) DEFAULT NULL,
  `record_port` int(4) DEFAULT NULL,
  `record_os` varchar(255) DEFAULT NULL,
  `record_cert_type` tinyint(4) DEFAULT NULL,
  `record_key_tag` int(11) DEFAULT NULL,
  `record_algorithm` tinyint(4) DEFAULT NULL,
  `record_flags` enum('0','256','257') DEFAULT NULL,
  `record_text` varchar(255) DEFAULT NULL,
  `record_comment` varchar(200),
  `record_append` enum('yes','no') NOT NULL DEFAULT 'yes',
  `record_status` enum('active','disabled','deleted') NOT NULL DEFAULT 'active',
  PRIMARY KEY (`record_id`),
  KEY `domain_id` (`domain_id`)
) ENGINE=INNODB DEFAULT CHARSET=utf8 ;
TABLE;
    $table[] = <<<TABLE
CREATE TABLE IF NOT EXISTS {$database}.`fm_{$__FM_CONFIG[$module]['prefix']}records_skipped` (
  `skip_id` int(11) NOT NULL AUTO_INCREMENT,
  `account_id` int(11) NOT NULL,
  `domain_id` int(11) NOT NULL,
  `record_id` int(11) NOT NULL,
  `record_status` enum('active','deleted') NOT NULL DEFAULT 'active',
  PRIMARY KEY (`skip_id`),
  KEY `record_id` (`record_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
TABLE;
    $table[] = <<<TABLE
CREATE TABLE IF NOT EXISTS {$database}.`fm_{$__FM_CONFIG[$module]['prefix']}servers` (
  `server_id` int(11) NOT NULL AUTO_INCREMENT,
  `account_id` int(11) NOT NULL DEFAULT '1',
  `server_serial_no` int(10) NOT NULL,
  `server_name` varchar(255) NOT NULL,
  `server_os` varchar(50) DEFAULT NULL,
  `server_os_distro` varchar(50) DEFAULT NULL,
  `server_key` int(11) NOT NULL,
  `server_type` enum('bind9') NOT NULL DEFAULT 'bind9',
  `server_version` varchar(150) DEFAULT NULL,
  `server_run_as_predefined` enum('named','bind','daemon','as defined:') NOT NULL DEFAULT 'named',
  `server_run_as` varchar(50) DEFAULT NULL,
  `server_root_dir` varchar(255) NOT NULL,
  `server_chroot_dir` VARCHAR(255) NULL DEFAULT NULL,
  `server_zones_dir` varchar(255) NOT NULL,
  `server_config_file` varchar(255) NOT NULL DEFAULT '/etc/named.conf',
  `server_update_method` enum('http','https','cron','ssh') NOT NULL DEFAULT 'http',
  `server_update_port` int(5) NOT NULL DEFAULT '0',
  `server_build_config` enum('yes','no') NOT NULL DEFAULT 'no',
  `server_update_config` enum('yes','no','conf') NOT NULL DEFAULT 'no',
  `server_installed` enum('yes','no') NOT NULL DEFAULT 'no',
  `server_client_version` varchar(150) DEFAULT NULL,
  `server_status` enum('active','disabled','deleted') NOT NULL DEFAULT 'disabled',
  PRIMARY KEY (`server_id`),
  UNIQUE KEY `server_serial_no` (`server_serial_no`)
) ENGINE = MYISAM  DEFAULT CHARSET=utf8;
TABLE;
    $table[] = <<<TABLE
CREATE TABLE IF NOT EXISTS {$database}.`fm_{$__FM_CONFIG[$module]['prefix']}server_groups` (
  `group_id` int(11) NOT NULL AUTO_INCREMENT,
  `account_id` int(11) NOT NULL,
  `group_name` varchar(128) NOT NULL,
  `group_masters` text NOT NULL,
  `group_slaves` text NOT NULL,
  `group_status` enum('active','disabled','deleted') NOT NULL DEFAULT 'active',
  PRIMARY KEY (`group_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
TABLE;
    $table[] = <<<TABLE
CREATE TABLE IF NOT EXISTS {$database}.`fm_{$__FM_CONFIG[$module]['prefix']}soa` (
  `soa_id` int(11) NOT NULL AUTO_INCREMENT,
  `account_id` int(11) NOT NULL DEFAULT '1',
  `soa_template` ENUM(  'yes',  'no' ) NOT NULL DEFAULT  'no',
  `soa_default` ENUM(  'yes',  'no' ) NOT NULL DEFAULT  'no',
  `soa_name` varchar(255) DEFAULT NULL,
  `soa_master_server` varchar(50) NOT NULL DEFAULT '',
  `soa_append` enum('yes','no') NOT NULL DEFAULT 'yes',
  `soa_email_address` varchar(50) NOT NULL DEFAULT '',
  `soa_refresh` varchar(50) DEFAULT '21600',
  `soa_retry` varchar(50) DEFAULT '7200',
  `soa_expire` varchar(50) DEFAULT '604800',
  `soa_ttl` varchar(50) DEFAULT '1200',
  `soa_status` enum('active','disabled','deleted') NOT NULL DEFAULT 'active',
  PRIMARY KEY (`soa_id`)
) ENGINE=INNODB DEFAULT CHARSET=utf8 ;
TABLE;
    $table[] = <<<TABLE
CREATE TABLE IF NOT EXISTS {$database}.`fm_{$__FM_CONFIG[$module]['prefix']}track_builds` (
  `domain_id` int(11) NOT NULL,
  `server_serial_no` int(11) NOT NULL
) ENGINE=INNODB DEFAULT CHARSET=utf8;
TABLE;
    $table[] = <<<TABLE
CREATE TABLE IF NOT EXISTS {$database}.`fm_{$__FM_CONFIG[$module]['prefix']}track_reloads` (
  `domain_id` int(11) NOT NULL,
  `server_serial_no` int(11) NOT NULL
) ENGINE = INNODB DEFAULT CHARSET=utf8;
TABLE;
    $table[] = <<<TABLE
CREATE TABLE IF NOT EXISTS {$database}.`fm_{$__FM_CONFIG[$module]['prefix']}views` (
  `view_id` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  `account_id` int(11) NOT NULL DEFAULT '1',
  `server_serial_no` varchar(255) NOT NULL DEFAULT '0',
  `view_name` VARCHAR(255) NOT NULL ,
  `view_comment` text,
  `view_status` ENUM( 'active',  'disabled',  'deleted') NOT NULL DEFAULT  'active'
) ENGINE = MYISAM DEFAULT CHARSET=utf8;
TABLE;
    /** fm_prefix_config inserts */
    $inserts[] = <<<INSERT
INSERT INTO {$database}.`fm_{$__FM_CONFIG[$module]['prefix']}config` (account_id, cfg_parent, cfg_name, cfg_data, cfg_status) 
\tSELECT '0', '0', 'directory', '\$ROOT', 'hidden' FROM DUAL
WHERE NOT EXISTS
\t(SELECT * FROM {$database}.`fm_{$__FM_CONFIG[$module]['prefix']}config` WHERE account_id = '0');
INSERT;
    $inserts[] = <<<INSERT
INSERT INTO {$database}.`fm_{$__FM_CONFIG[$module]['prefix']}config` (account_id, cfg_parent, cfg_name, cfg_data, cfg_status) 
\tSELECT '1', '0', 'version', 'none', 'active' FROM DUAL
WHERE NOT EXISTS
\t(SELECT * FROM {$database}.`fm_{$__FM_CONFIG[$module]['prefix']}config` WHERE 
\taccount_id = '1' AND cfg_parent = '0' AND cfg_name = 'version' AND server_serial_no = '0'
\t);
INSERT;
    $inserts[] = <<<INSERT
INSERT INTO {$database}.`fm_{$__FM_CONFIG[$module]['prefix']}config` (account_id, cfg_parent, cfg_name, cfg_data, cfg_status) 
\tSELECT '1', '0', 'hostname', 'none', 'active' FROM DUAL
WHERE NOT EXISTS
\t(SELECT * FROM {$database}.`fm_{$__FM_CONFIG[$module]['prefix']}config` WHERE 
\taccount_id = '1' AND cfg_parent = '0' AND cfg_name = 'hostname' AND server_serial_no = '0'
\t);
INSERT;
    $inserts[] = <<<INSERT
INSERT INTO {$database}.`fm_{$__FM_CONFIG[$module]['prefix']}config` (account_id, cfg_parent, cfg_name, cfg_data, cfg_status) 
\tSELECT '1', '0', 'recursion', 'no', 'active' FROM DUAL
WHERE NOT EXISTS
\t(SELECT * FROM {$database}.`fm_{$__FM_CONFIG[$module]['prefix']}config` WHERE 
\taccount_id = '1' AND cfg_parent = '0' AND cfg_name = 'recursion' AND server_serial_no = '0'
\t);
INSERT;
    $inserts[] = <<<INSERT
INSERT INTO {$database}.`fm_{$__FM_CONFIG[$module]['prefix']}config` (account_id, cfg_parent, cfg_name, cfg_data, cfg_status) 
\tSELECT '1', '0', 'statistics-file', '"\$ROOT/named.stats"', 'active' FROM DUAL
WHERE NOT EXISTS
\t(SELECT * FROM {$database}.`fm_{$__FM_CONFIG[$module]['prefix']}config` WHERE 
\taccount_id = '1' AND cfg_parent = '0' AND cfg_name = 'statistics-file' AND server_serial_no = '0'
\t);
INSERT;
    $inserts[] = <<<INSERT
INSERT INTO {$database}.`fm_{$__FM_CONFIG[$module]['prefix']}config` (account_id, cfg_parent, cfg_name, cfg_data, cfg_status) 
\tSELECT '1', '0', 'zone-statistics', 'yes', 'active' FROM DUAL
WHERE NOT EXISTS
\t(SELECT * FROM {$database}.`fm_{$__FM_CONFIG[$module]['prefix']}config` WHERE 
\taccount_id = '1' AND cfg_parent = '0' AND cfg_name = 'zone-statistics' AND server_serial_no = '0'
\t);
INSERT;
    $inserts[] = <<<INSERT
INSERT INTO {$database}.`fm_{$__FM_CONFIG[$module]['prefix']}config` (account_id, cfg_parent, cfg_name, cfg_data, cfg_status) 
\tSELECT '1', '0', 'pid-file', '"\$ROOT/named.pid"', 'active' FROM DUAL
WHERE NOT EXISTS
\t(SELECT * FROM {$database}.`fm_{$__FM_CONFIG[$module]['prefix']}config` WHERE 
\taccount_id = '1' AND cfg_parent = '0' AND cfg_name = 'pid-file' AND server_serial_no = '0'
\t);
INSERT;
    $inserts[] = <<<INSERT
INSERT INTO {$database}.`fm_{$__FM_CONFIG[$module]['prefix']}config` (account_id, cfg_parent, cfg_name, cfg_data, cfg_status) 
\tSELECT '1', '0', 'dump-file', '"\$ROOT/named.dump"', 'active' FROM DUAL
WHERE NOT EXISTS
\t(SELECT * FROM {$database}.`fm_{$__FM_CONFIG[$module]['prefix']}config` WHERE 
\taccount_id = '1' AND cfg_parent = '0' AND cfg_name = 'dump-file' AND server_serial_no = '0'
\t);
INSERT;
    $inserts[] = <<<INSERT
INSERT INTO {$database}.`fm_{$__FM_CONFIG[$module]['prefix']}config` (account_id, cfg_parent, cfg_name, cfg_data, cfg_status) 
\tSELECT '1', '0', 'auth-nxdomain', 'no', 'active' FROM DUAL
WHERE NOT EXISTS
\t(SELECT * FROM {$database}.`fm_{$__FM_CONFIG[$module]['prefix']}config` WHERE 
\taccount_id = '1' AND cfg_parent = '0' AND cfg_name = 'auth-nxdomain' AND server_serial_no = '0'
\t);
INSERT;
    $inserts[] = <<<INSERT
INSERT INTO {$database}.`fm_{$__FM_CONFIG[$module]['prefix']}config` (account_id, cfg_parent, cfg_name, cfg_data, cfg_status) 
\tSELECT '1', '0', 'cleaning-interval', '120', 'active' FROM DUAL
WHERE NOT EXISTS
\t(SELECT * FROM {$database}.`fm_{$__FM_CONFIG[$module]['prefix']}config` WHERE 
\taccount_id = '1' AND cfg_parent = '0' AND cfg_name = 'cleaning-interval' AND server_serial_no = '0'
\t);
INSERT;
    $inserts[] = <<<INSERT
INSERT INTO {$database}.`fm_{$__FM_CONFIG[$module]['prefix']}config` (account_id, cfg_parent, cfg_name, cfg_data, cfg_status) 
\tSELECT '1', '0', 'interface-interval', '0', 'active' FROM DUAL
WHERE NOT EXISTS
\t(SELECT * FROM {$database}.`fm_{$__FM_CONFIG[$module]['prefix']}config` WHERE 
\taccount_id = '1' AND cfg_parent = '0' AND cfg_name = 'interface-interval' AND server_serial_no = '0'
\t);
INSERT;
    /** fm_prefix_functions inserts*/
    $inserts[] = <<<INSERT
INSERT IGNORE INTO  {$database}.`fm_{$__FM_CONFIG[$module]['prefix']}functions` (
`def_function` ,
`def_option` ,
`def_type` ,
`def_multiple_values` ,
`def_clause_support`,
`def_zone_support`,
`def_dropdown`
)
VALUES 
('key', 'algorithm', 'string', 'no', 'K', NULL, 'no'),
('key', 'secret', 'quoted_string', 'no', 'K', NULL, 'no'),
('options', 'acache-cleaning-interval', '( minutes )', 'no', 'OV', NULL, 'no'),
('options', 'acache-enable', '( yes | no )', 'no', 'OV', NULL, 'yes'),
('options', 'additional-from-auth', '( yes | no )', 'no', 'OV', NULL, 'yes'),
('options', 'additional-from-cache', '( yes | no )', 'no', 'OV', NULL, 'yes'),
('options', 'allow-notify', '( address_match_element )', 'yes', 'OVZ', 'S', 'no'),
('options', 'allow-query', '( address_match_element )', 'yes', 'OVZ', 'MS', 'no'),
('options', 'allow-query-cache', '( address_match_element )', 'yes', 'OV', NULL, 'no'),
('options', 'allow-query-cache-on', '( address_match_element )', 'yes', 'OV', NULL, 'no'),
('options', 'allow-query-on', '( address_match_element )', 'yes', 'OVZ', 'MS', 'no'),
('options', 'allow-recursion', '( address_match_element )', 'yes', 'OV', NULL, 'no'),
('options', 'allow-recursion-on', '( address_match_element )', 'yes', 'OV', NULL, 'no'),
('options', 'allow-transfer', '( address_match_element )', 'yes', 'OVZ', 'MS', 'no'),
('options', 'allow-update', '( address_match_element )', 'yes', 'OVZ', 'MS', 'no'),
('options', 'allow-update-forwarding', '( address_match_element )', 'yes', 'OVZ', 'MS', 'no'),
('options', 'also-notify', '( ipv4_address | ipv6_address ) [ port ( ip_port | * ) ]', 'yes', 'OVZ', 'M', 'no'),
('options', 'alt-transfer-source', '( ipv4_address | * ) [ port ( ip_port | * ) ]', 'no', 'OVZ', 'S', 'no'),
('options', 'alt-transfer-source-v6', '( ipv6_address | * ) [ port ( ip_port | * ) ]', 'no', 'OVZ', 'S', 'no'),
('options', 'attach-cache', '( quoted_string )', 'no', 'OV', NULL, 'no'),
('options', 'auth-nxdomain', '( yes | no )', 'no', 'OV', NULL, 'yes'),
('options', 'auto-dnssec', '( allow | maintain | create | off )', 'no', 'OVZ', 'MS', 'yes'),
('options', 'avoid-v4-udp-ports', '( ip_port )', 'yes', 'O', NULL, 'no'),
('options', 'avoid-v6-udp-ports', '( ip_port )', 'yes', 'O', NULL, 'no'),
('options', 'bindkeys-file', '( quoted_string )', 'no', 'O', NULL, 'no'),
('options', 'blackhole', '( address_match_element )', 'yes', 'O', NULL, 'no'),
('options', 'bogus', '( yes | no )', 'no', 'S', NULL, 'yes'),
('options', 'check-dup-records', '( fail | warn | ignore )', 'no', 'OVZ', 'MS', 'yes'),
('options', 'check-integrity', '( yes | no )', 'no', 'OVZ', 'MS', 'yes'),
('options', 'check-mx', '( fail | warn | ignore )', 'no', 'OVZ', 'MS', 'yes'),
('options', 'check-mx-cname', '( fail | warn | ignore )', 'no', 'OVZ', 'MS', 'yes'),
('options', 'check-names', '( warn | fail | ignore )', 'no', 'Z', 'MS', 'yes'),
('options', 'check-sibling', '( yes | no )', 'no', 'OVZ', 'MS', 'yes'),
('options', 'check-srv-cname', '( fail | warn | ignore )', 'no', 'OVZ', 'MS', 'yes'),
('options', 'check-wildcard', '( yes | no )', 'no', 'OVZ', 'MS', 'yes'),
('options', 'cleaning-interval', '( minutes )', 'no', 'OV', NULL, 'no'),
('options', 'clients-per-query', '( integer )', 'no', 'OV', NULL, 'no'),
('options', 'coresize', '( size_in_bytes )', 'no', 'O', NULL, 'no'),
('options', 'database', '( quoted_string )', 'no', 'Z', 'MS', 'no'),
('options', 'datasize', '( size_in_bytes )', 'no', 'O', NULL, 'no'),
('options', 'delegation-only', '( yes | no )', 'no', 'Z', 'MS', 'yes'),
('options', 'deny-answer-address', '( address_match_element ) [ except-from { ( address_match_element ) } ]', 'yes', 'OV', NULL, 'no'),
('options', 'deny-answer-aliases', '( quoted_string ) [ except-from { ( address_match_element ) } ]', 'yes', 'OV', NULL, 'no'),
('options', 'dialup', '( yes | no | notify | refresh | passive | notify-passive )', 'no', 'OVZ', 'MS', 'yes'),
('options', 'disable-algorithms', '( string )', 'yes', 'OV', NULL, 'no'),
('options', 'disable-empty-zone', '( quoted_string )', 'no', 'OV', NULL, 'no'),
('options', 'dnssec-accept-expired', '( yes | no )', 'no', 'OV', NULL, 'yes'),
('options', 'dnssec-dnskey-kskonly', '( yes | no )', 'no', 'OVZ', 'MS', 'yes'),
('options', 'dnssec-enable', '( yes | no )', 'no', 'OV', NULL, 'yes'),
('options', 'dnssec-lookaside', 'domain trust-anchor domain', 'no', 'OV', NULL, 'no'),
('options', 'dnssec-must-be-secure', 'domain ( yes | no )', 'no', 'OV', NULL, 'no'),
('options', 'dnssec-secure-to-insecure', '( yes | no )', 'no', 'OVZ', 'MS', 'yes'),
('options', 'dnssec-validation', '( yes | no )', 'no', 'OV', NULL, 'yes'),
('options', 'dual-stack-servers', '( quoted_string )', 'yes', 'OV', NULL, 'no'),
('options', 'dump-file', '( quoted_string )', 'no', 'O', NULL, 'no'),
('options', 'edns', '( yes | no )', 'no', 'S', NULL, 'yes'),
('options', 'edns-udp-size', '( size_in_bytes )', 'no', 'OSV', NULL, 'no'),
('options', 'empty-contact', '( string )', 'no', 'OV', NULL, 'no'),
('options', 'empty-server', '( string )', 'no', 'OV', NULL, 'no'),
('options', 'empty-zones-enable', '( yes | no )', 'no', 'OV', NULL, 'yes'),
('options', 'files', '( integer )', 'no', 'O', NULL, 'no'),
('options', 'flush-zones-on-shutdown', '( yes | no )', 'no', 'O', NULL, 'yes'),
('options', 'forward', '( first | only )', 'no', 'OVZ', 'F', 'yes'),
('options', 'forwarders', '[ port ( ip_port | * ) ] { ( ipv4_address | ipv6_address ) } [ port ( ip_port | * ) ]', 'yes', 'OVZ', 'F', 'no'),
('options', 'heartbeat-interval', '( minutes )', 'no', 'O', NULL, 'no'),
('options', 'hostname', '( quoted_string | none )', 'no', 'O', NULL, 'no'),
('options', 'interface-interval', '( minutes )', 'no', 'O', NULL, 'no'),
('options', 'ixfr-from-differences', '( yes | no )', 'no', 'Z', 'MS', 'yes'),
('options', 'journal', '( quoted_string )', 'no', 'Z', 'MS', 'no'),
('options', 'key-directory', '( quoted_string )', 'no', 'OVZ', 'MS', 'no'),
('options', 'lame-ttl', '( seconds )', 'no', 'OV', NULL, 'no'),
('options', 'listen-on', '[ port ( ip_port | * ) ] { ( ipv4_address ) }', 'yes', 'OR', NULL, 'no'),
('options', 'listen-on-v6', '[ port ( ip_port | * ) ] { ( ipv6_address ) }', 'yes', 'O', NULL, 'no'),
('options', 'managed-keys-directory', '( quoted_string )', 'no', 'O', NULL, 'no'),
('options', 'masterfile-format', '( text | raw )', 'no', 'OVZ', 'MS', 'yes'),
('options', 'masters', '( { ipv4_address | ipv6_address } )', 'yes', 'OVZ', 'S', 'no'),
('options', 'match-clients', '( address_match_element )', 'yes', 'V', NULL, 'no'),
('options', 'match-destinations', '( address_match_element )', 'yes', 'V', NULL, 'no'),
('options', 'match-mapped-addresses', '( yes | no )', 'no', 'O', NULL, 'yes'),
('options', 'match-recursive-only', '( yes | no )', 'no', 'V', NULL, 'yes'),
('options', 'max-acache-size', '( size_in_bytes )', 'no', 'OV', NULL, 'no'),
('options', 'max-cache-size', '( size_in_bytes )', 'no', 'OV', NULL, 'no'),
('options', 'max-cache-ttl', '( seconds )', 'no', 'OV', NULL, 'no'),
('options', 'max-clients-per-query', '( integer )', 'no', 'OV', NULL, 'no'),
('options', 'max-journal-size', '( size_in_bytes )', 'no', 'OVZ', 'MS', 'no'),
('options', 'max-ncache-ttl', '( seconds )', 'no', 'OV', NULL, 'no'),
('options', 'max-refresh-time', '( seconds )', 'no', 'OVZ', 'S', 'no'),
('options', 'max-retry-time', '( seconds )', 'no', 'OVZ', 'S', 'no'),
('options', 'max-transfer-idle-in', '( minutes )', 'no', 'OVZ', 'S', 'no'),
('options', 'max-transfer-idle-out', '( minutes )', 'no', 'OVZ', 'M', 'no'),
('options', 'max-transfer-time-in', '( minutes )', 'no', 'OVZ', 'S', 'no'),
('options', 'max-transfer-time-out', '( minutes )', 'no', 'OVZ', 'M', 'no'),
('options', 'max-udp-size', '( size_in_bytes )', 'no', 'OSV', NULL, 'no'),
('options', 'memstatistics', '( yes | no )', 'no', 'O', NULL, 'yes'),
('options', 'memstatistics-file', '( quoted_string )', 'no', 'O', NULL, 'no'),
('options', 'min-refresh-time', '( seconds )', 'no', 'OVZ', 'S', 'no'),
('options', 'min-retry-time', '( seconds )', 'no', 'OVZ', 'S', 'no'),
('options', 'minimal-responses', '( yes | no )', 'no', 'OV', NULL, 'yes'),
('options', 'multi-master', '( yes | no )', 'no', 'OVZ', 'S', 'yes'),
('options', 'ndots', '( integer )', 'no', 'R', NULL, 'no'),
('options', 'notify', '( yes | no | explicit )', 'no', 'OVZ', 'MS', 'yes'),
('options', 'notify-delay', '( seconds )', 'no', 'OVZ', 'MS', 'no'),
('options', 'notify-source', '( ipv4_address | * ) [ port ( ip_port | * ) ]', 'no', 'OSVZ', 'M', 'no'),
('options', 'notify-source-v6', '( ipv6_address | * ) [ port ( ip_port | * ) ]', 'no', 'OSVZ', 'M', 'no'),
('options', 'notify-to-soa', '( yes | no )', 'no', 'OVZ', 'MS', 'yes'),
('options', 'pid-file', '( quoted_string | none )', 'no', 'O', NULL, 'no'),
('options', 'port', '( ip_port )', 'no', 'O', NULL, 'no'),
('options', 'preferred-glue', '( A | AAAA )', 'no', 'OV', NULL, 'yes'),
('options', 'provide-ixfr', '( yes | no )', 'no', 'S', 'M', 'yes'),
('options', 'query-source', 'address ( ipv4_address | * ) [ port ( ip_port | * ) ]', 'no', 'OVZ', 'MS', 'no'),
('options', 'query-source-v6', 'address ( ipv6_address | * ) [ port ( ip_port | * ) ]', 'no', 'OVZ', 'MS', 'no'),
('options', 'querylog', '( yes | no )', 'no', 'O', NULL, 'yes'),
('options', 'random-device', '( quoted_string )', 'no', 'O', NULL, 'no'),
('options', 'recursing-file', '( quoted_string )', 'no', 'O', NULL, 'no'),
('options', 'recursion', '( yes | no )', 'no', 'OV', NULL, 'yes'),
('options', 'recursive-clients', '( integer )', 'no', 'O', NULL, 'no'),
('options', 'request-ixfr', '( yes | no )', 'no', 'OVZ', 'S', 'yes'),
('options', 'request-nsid', '( yes | no )', 'no', 'OV', NULL, 'yes'),
('options', 'reserved-sockets', '( integer )', 'no', 'O', NULL, 'no'),
('options', 'search', '( quoted_string )', 'yes', 'R', NULL, 'no'),
('options', 'secroots-file', '( quoted_string )', 'no', 'O', NULL, 'no'),
('options', 'serial-query-rate', '( integer )', 'no', 'O', NULL, 'no'),
('options', 'server-id', '( quoted_string | none | hostname )', 'no', 'O', NULL, 'no'),
('options', 'session-keyfile', '( quoted_string | none )', 'no', 'O', NULL, 'no'),
('options', 'session-keyname', '( quoted_string )', 'no', 'O', NULL, 'no'),
('options', 'session-keyalg', '( string )', 'no', 'O', NULL, 'no'),
('options', 'sig-signing-nodes', '( integer )', 'no', 'OVZ', 'MS', 'no'),
('options', 'sig-signing-signatures', '( integer )', 'no', 'OVZ', 'MS', 'no'),
('options', 'sig-signing-type', '( integer )', 'no', 'OVZ', 'MS', 'no'),
('options', 'sig-validity-interval', '( days )', 'no', 'OVZ', 'MS', 'no'),
('options', 'sortlist', '( address_match_element )', 'yes', 'OV', NULL, 'no'),
('options', 'stacksize', '( size_in_bytes )', 'no', 'O', NULL, 'no'),
('options', 'statistics-file', '( quoted_string )', 'no', 'O', NULL, 'no'),
('options', 'tcp-clients', '( integer )', 'no', 'O', NULL, 'no'),
('options', 'tcp-listen-queue', '( integer )', 'no', 'O', NULL, 'no'),
('options', 'tkey-dhkey', '( quoted_string integer )', 'no', 'O', NULL, 'no'),
('options', 'tkey-domain', '( quoted_string )', 'no', 'O', NULL, 'no'),
('options', 'tkey-gssapi-credential', '( quoted_string )', 'no', 'O', NULL, 'no'),
('options', 'transfer-format', '( many-answers | one-answer )', 'no', 'OSVZ', 'M', 'yes'),
('options', 'transfer-source', '( ipv4_address | * ) [ port ( ip_port | * ) ]', 'no', 'OSVZ', 'S', 'no'),
('options', 'transfer-source-v6', '( ipv6_address | * ) [ port ( ip_port | * ) ]', 'no', 'OSVZ', 'S', 'no'),
('options', 'transfers', '( integer )', 'no', 'S', NULL, 'no'),
('options', 'transfers-in', '( integer )', 'no', 'O', 'S', 'no'),
('options', 'transfers-out', '( integer )', 'no', 'O', 'M', 'no'),
('options', 'transfers-per-ns', '( integer )', 'no', 'O', 'S', 'no'),
('options', 'try-tcp-refresh', '( yes | no )', 'no', 'OVZ', NULL, 'yes'),
('options', 'update-check-ksk', '( yes | no )', 'no', 'OVZ', NULL, 'yes'),
('options', 'update-policy', '( local | { update-policy-rule } )', 'no', 'Z', 'MS', 'no'),
('options', 'use-alt-transfer-source', '( yes | no )', 'no', 'OVZ', 'MS', 'yes'),
('options', 'use-v4-udp-ports', '( range ip_port ip_port )', 'no', 'O', NULL, 'no'),
('options', 'use-v6-udp-ports', '( range ip_port ip_port )', 'no', 'O', NULL, 'no'),
('options', 'view', '( quoted_string )', 'no', 'R', NULL, 'no'),
('options', 'version', '( quoted_string | none )', 'no', 'O', NULL, 'no'),
('options', 'zero-no-soa-ttl', '( yes | no )', 'no', 'OVZ', 'MS', 'yes'),
('options', 'zero-no-soa-ttl-cache', '( yes | no )', 'no', 'OV', NULL, 'yes'),
('options', 'zone-statistics', '( yes | no )', 'no', 'OVZ', 'MS', 'yes')
;
INSERT;
    $inserts[] = <<<INSERT
INSERT IGNORE INTO  {$database}.`fm_{$__FM_CONFIG[$module]['prefix']}functions` (
`def_function` ,
`def_option_type`,
`def_option` ,
`def_type` ,
`def_multiple_values` ,
`def_clause_support`,
`def_dropdown`
)
VALUES 
('options', 'ratelimit', 'referrals-per-second', '( integer )', 'no', 'OV', 'no'),
('options', 'ratelimit', 'nodata-per-second', '( integer )', 'no', 'OV', 'no'),
('options', 'ratelimit', 'nxdomains-per-second', '( integer )', 'no', 'OV', 'no'),
('options', 'ratelimit', 'errors-per-second', '( integer )', 'no', 'OV', 'no'),
('options', 'ratelimit', 'all-per-second', '( integer )', 'no', 'OV', 'no'),
('options', 'ratelimit', 'window', '( integer )', 'no', 'OV', 'no'),
('options', 'ratelimit', 'log-only', '( yes | no )', 'no', 'OV', 'yes'),
('options', 'ratelimit', 'qps-scale', '( integer )', 'no', 'OV', 'no'),
('options', 'ratelimit', 'ipv4-prefix-length', '( integer )', 'no', 'OV', 'no'),
('options', 'ratelimit', 'ipv6-prefix-length', '( integer )', 'no', 'OV', 'no'),
('options', 'ratelimit', 'slip', '( integer )', 'no', 'OV', 'no'),
('options', 'ratelimit', 'exempt-clients', '( address_match_element )', 'yes', 'OV', 'no'),
('options', 'ratelimit', 'max-table-size', '( integer )', 'no', 'OV', 'no'),
('options', 'ratelimit', 'min-table-size', '( integer )', 'no', 'OV', 'no')
;
INSERT;
    $inserts[] = <<<INSERT
INSERT IGNORE INTO  {$database}.`fm_{$__FM_CONFIG[$module]['prefix']}functions` (
`def_function` ,
`def_option_type`,
`def_option` ,
`def_type` ,
`def_multiple_values` ,
`def_clause_support`,
`def_dropdown`,
`def_max_parameters`
)
VALUES 
('options', 'ratelimit', 'responses-per-second', '( [size integer] [ratio fixedpoint] integer )', 'no', 'OV', 'no', '5')
;
INSERT;
    /** fm_options inserts */
    $inserts[] = <<<INSERT
INSERT INTO {$database}.`fm_options` (option_name, option_value, module_name) 
\tSELECT 'version', '{$__FM_CONFIG[$module]['version']}', '{$module}' FROM DUAL
WHERE NOT EXISTS
\t(SELECT option_name FROM {$database}.`fm_options` WHERE option_name = 'version'
\t\tAND module_name='{$module}');
INSERT;
    $inserts[] = <<<INSERT
INSERT INTO {$database}.`fm_options` (option_name, option_value, module_name) 
\tSELECT 'client_version', '{$__FM_CONFIG[$module]['client_version']}', '{$module}' FROM DUAL
WHERE NOT EXISTS
\t(SELECT option_name FROM {$database}.`fm_options` WHERE option_name = 'client_version'
\t\tAND module_name='{$module}');
INSERT;
    $inserts[] = <<<INSERT
INSERT INTO {$database}.`fm_options` (option_name, option_value, module_name) 
\tSELECT 'clones_use_dnames', '{$__FM_CONFIG[$module]['default']['options']['clones_use_dnames']['default_value']}', '{$module}' FROM DUAL
WHERE NOT EXISTS
\t(SELECT option_name FROM {$database}.`fm_options` WHERE option_name = 'clones_use_dnames'
\t\tAND module_name='{$module}');
INSERT;
    /** localhost domain and records */
    $inserts[] = <<<INSERT
INSERT INTO {$database}.`fm_{$__FM_CONFIG[$module]['prefix']}domains` (`domain_name`, `domain_mapping`) VALUES 
\t('localhost', 'forward'), 
\t('0.0.127.in-addr.arpa', 'reverse'),
\t('0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa', 'reverse');
INSERT;
    $inserts[] = <<<INSERT
INSERT INTO {$database}.`fm_{$__FM_CONFIG[$module]['prefix']}records` (`domain_id`, `record_name`, `record_value`, `record_ttl`, `record_type`, `record_append`) VALUES 
\t(1, '@', '127.0.0.1', '', 'A', 'yes'),
\t(1, '@', '::1', '', 'AAAA', 'yes'),
\t(1, '@', '@', '', 'NS', 'no'),
\t(2, '1', 'localhost.', '', 'PTR', 'yes'),
\t(2, '@', 'localhost.', '', 'NS', 'no'),
\t(3, '1', 'localhost.', '', 'PTR', 'yes'),
\t(3, '@', 'localhost.', '', 'NS', 'no');
INSERT;
    /** Create table schema */
    foreach ($table as $schema) {
        if ($link) {
            $result = mysql_query($schema, $link);
            if (mysql_error($link)) {
                return function_exists('displayProgress') ? displayProgress($module, $result, $noisy, mysql_error($link)) : $result;
            }
        } else {
            global $fmdb;
            $result = $fmdb->query($schema);
            if ($fmdb->last_error) {
                return function_exists('displayProgress') ? displayProgress($module, $result, $noisy, $fmdb->last_error) : $result;
            }
        }
    }
    /** Insert site values if not already present */
    foreach ($inserts as $query) {
        if ($link) {
            $result = mysql_query($query, $link);
            if (mysql_error($link)) {
                return function_exists('displayProgress') ? displayProgress($module, $result, $noisy, mysql_error($link)) : $result;
            }
        } else {
            $result = $fmdb->query($query);
            if ($fmdb->last_error) {
                return function_exists('displayProgress') ? displayProgress($module, $result, $noisy, $fmdb->last_error) : $result;
            }
        }
    }
    if (function_exists('displayProgress')) {
        return displayProgress($module, $result, $noisy);
    } else {
        if ($result) {
            return 'Success';
        } else {
            return 'Failed';
        }
    }
}
function importFile()
{
    global $_FILES, $_POST, $psql_exec;
    extract($_POST);
    $OUTPUT = "<h3>Import Company</h3>";
    $v =& new Validate();
    if (!$v->isOk($compname, "string", 1, 250, "")) {
        return "<li class='err'>Invalid Company Name</li>" . selectFile();
    }
    // generate code
    $code = "aaaa";
    // make sure it 4 chars long by padding with a's
    $code = str_replace(" ", "", $code);
    $code = str_pad($code, 4, 'a', STR_PAD_RIGHT);
    while (1) {
        // check if the code exists
        db_con("cubit");
        $rslt = db_exec("SELECT * FROM companies WHERE code='{$code}'");
        // not exist! YAY!!
        if (pg_numrows($rslt) < 1 && !exists_compdb($code)) {
            break;
        }
        // increase
        $code[3] = chr(ord($code[3]) + 1);
        for ($i = 3; $i >= 0; $i--) {
            if (ord($code[$i]) > ord('z')) {
                $code[$i] = 'a';
                if ($i > 0) {
                    $code[$i - 1] = chr(ord($code[$i - 1]) + 1);
                }
                if (substr($code, 0, 3) == "zzz") {
                    $code = "aaaa";
                }
            }
        }
    }
    require_lib("progress");
    displayProgress("newtemplate.php");
    # Change code to lowercase
    $code = strtolower($code);
    // parse the import file
    if (PLATFORM == "windows") {
        $importfile = cfs::tempnam("cubitimport_");
    } else {
        $importfile = cfs::tempnam("cubitimport_");
    }
    if (!ucfs::valid("compfile")) {
        return "<li class='err'>" . ucfs::ferror("compfile") . "</li>";
    }
    $fd_in = ucfs::fopen("compfile", "r");
    $fd_out = cfs::fopen($importfile, "w", true);
    if ($fd_in === false) {
        return "<li class='err'>Unable to open import file.</li>";
    }
    if ($fd_out === false) {
        return "<li class='err'>Unable to open temporary file required to import company.</li>";
    }
    $company_ver = "";
    while (!cfs::feof($fd_in)) {
        $buf = cfs::fgets($fd_in, 4096);
        // get the version of imported company if on this line
        $pos = strpos($buf, "-- V'e'r's'i'o'n:");
        if ($pos !== false && $pos == 0) {
            $company_ver = trim(substr($buf, 17));
        }
        // check if it valid platform
        $pos = strpos($buf, "-- P'l'a't'f'o'r'm:");
        if ($pos !== false && $pos == 0) {
            $comp_platform = trim(substr($buf, 19));
            if (PLATFORM != $comp_platform) {
                $OUTPUT .= "You cannot import another platform's company!<br>\n\t\t\t\t\tOnly from Windows to Windows or Linux to Linux.<br><Br>\n\t\t\t\t\tYour platform: " . PLATFORM . "<Br>\n\t\t\t\t\tProposed Imported Company Platform: {$comp_platform}<br>";
                return $OUTPUT;
            }
        }
        // parse the create database code variable if on this line
        $pos = strpos($buf, "CREATE DATABASE");
        if ($pos !== false && strpos($buf, "%c'o'd'e%") > 0) {
            $buf = str_replace("%c'o'd'e%", $code, $buf);
        }
        // parse the company code variable if on this line
        $pos = strpos($buf, "\\c ");
        if ($pos !== false && strpos($buf, "%c'o'd'e%") > 0) {
            $buf = str_replace("%c'o'd'e%", $code, $buf);
        }
        fputs($fd_out, $buf);
    }
    fclose($fd_in);
    fclose($fd_out);
    // get the version of current cubit
    db_con("cubit");
    $cubit_ver = CUBIT_VERSION;
    // check if versions are the same (TEMPORARY HACK, ai tog)
    if ($cubit_ver != $company_ver) {
        return $OUTPUT . "Versions do not match:<br>\n\t\t\tProposed Imported Company version is \"{$company_ver}\"<br>\n\t\t\tYour Cubit version is \"{$cubit_ver}\"<br>\n\t\t\t<br>\n\t\t\tCheck for updates for your Cubit to support the functionality of importing non matching versions.";
    }
    // import
    exec("{$psql_exec}/" . PSQL_EXE . " -U postgres template1 < {$importfile}");
    // insert the company
    db_con("cubit");
    db_exec("INSERT INTO companies (code,name,ver,status) VALUES('{$code}', '{$compname}', '{$company_ver}', 'active')");
    // if only one company in list, we can safely assume this was the first company
    // and forward to the login screen
    $sql = "SELECT * FROM companies";
    $rslt = db_exec($sql);
    if (!isset($_SESSION["USER_ID"]) && $rslt && pg_num_rows($rslt) > 0) {
        $_SESSION["code"] = $code;
        $_SESSION["comp"] = $compname;
        $OUTPUT = "<script>top.document.location.href='doc-index.php';</script>";
        return $OUTPUT;
        header("Location: main.php");
        exit;
    }
    $OUTPUT .= "\n\tCompany has been imported successfully.<br>\n\tCompany Name: {$compname}<br>\n\tCompany Code: {$code}<br>";
    return $OUTPUT;
}
Esempio n. 8
0
/**
 * Check for the required PHP version, and the MySQL extension or a database drop-in.
 *
 * Dies if requirements are not met.
 *
 * @access private
 * @since 1.0
 */
function checkAppVersions($single_check = true)
{
    global $fm_name;
    require ABSPATH . 'fm-includes/version.php';
    $requirement_check = null;
    $error = false;
    /** PHP Version */
    if (version_compare(PHP_VERSION, $required_php_version, '<')) {
        $message = sprintf(_('Your server is running PHP version %1$s but %2$s %3$s requires at least %4$s.'), PHP_VERSION, $fm_name, $fm_version, $required_php_version);
        if ($single_check) {
            bailOut($message);
        } else {
            $requirement_check .= displayProgress("PHP >= {$required_php_version}", false, 'display', $message);
            $error = true;
        }
    } else {
        if (!$single_check) {
            $requirement_check .= displayProgress("PHP >= {$required_php_version}", true, 'display');
        }
    }
    /** PHP Extensions */
    $required_php_extensions = array('mysql', 'mysqli', 'curl', 'posix', 'filter', 'json');
    foreach ($required_php_extensions as $extension) {
        if (!extension_loaded($extension)) {
            $message = sprintf(_('Your PHP installation appears to be missing the %1s extension which is required by %2s.'), $extension, $fm_name);
            if ($single_check) {
                bailOut($message);
            } else {
                $requirement_check .= displayProgress(_(sprintf('PHP %1s Extension', $extension)), false, 'display', $message);
                $error = true;
            }
        } else {
            if (!$single_check) {
                $requirement_check .= displayProgress(_(sprintf('PHP %1s Extension', $extension)), true, 'display');
            }
        }
    }
    /** Apache mod_rewrite module */
    if (function_exists('apache_get_modules')) {
        if (!in_array('mod_rewrite', apache_get_modules())) {
            $message = sprintf(_('Your Apache installation appears to be missing the mod_rewrite module which is required by %1s.'), $fm_name);
            if ($single_check) {
                bailOut($message);
            } else {
                $requirement_check .= displayProgress(_('Apache mod_rewrite Loaded'), false, 'display', $message);
                $error = true;
            }
        } else {
            if (!$single_check) {
                $requirement_check .= displayProgress(_('Apache mod_rewrite Loaded'), true, 'display');
            }
        }
    }
    /** .htaccess file */
    if (!defined('FM_NO_HTACCESS')) {
        if (!file_exists(ABSPATH . '.htaccess')) {
            if (is_writeable(ABSPATH)) {
                file_put_contents(ABSPATH . '.htaccess', '<IfModule mod_headers.c>
	<FilesMatch "\\.(js|css|txt)$">
		Header set Cache-Control "max-age=7200"
	</FilesMatch>
	<FilesMatch "\\.(jpe?g|png|gif|ico)$">
		Header set Cache-Control "max-age=2592000"
	</FilesMatch>
</IfModule>

<IfModule mod_rewrite.c>
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>

');
            } else {
                if ($single_check) {
                    bailOut(sprintf(_('I cannot create the missing %1s.htaccess which is required by %2s so please create it with the following contents:'), ABSPATH, $fm_name) . '<textarea rows="8">&lt;IfModule mod_headers.c&gt;
	&lt;FilesMatch "\\.(js|css|txt)$"&gt;
		Header set Cache-Control "max-age=7200"
	&lt;/FilesMatch&gt;
	&lt;FilesMatch "\\.(jpe?g|png|gif|ico)$"&gt;
		Header set Cache-Control "max-age=2592000"
	&lt;/FilesMatch&gt;
&lt;/IfModule&gt;

&lt;IfModule mod_rewrite.c&gt;
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
&lt;/IfModule&gt;
</textarea>');
                } else {
                    $requirement_check .= displayProgress(_('.htaccess File Present'), false, 'display');
                    $error = true;
                }
            }
        } else {
            if (!$single_check) {
                $requirement_check .= displayProgress(_('.htaccess File Present'), true, 'display');
            }
        }
    }
    /** Test rewrites */
    if (!defined('INSTALL')) {
        if (dns_get_record($_SERVER['SERVER_NAME'], DNS_A + DNS_AAAA)) {
            $test_output = getPostData($GLOBALS['FM_URL'] . 'admin-accounts.php?verify', array('module_type' => 'CLIENT'));
            $test_output = isSerialized($test_output) ? unserialize($test_output) : $test_output;
            if (strpos($test_output, 'Account is not found.') === false) {
                $message = sprintf(_('The required .htaccess file appears to not work with your Apache configuration which is required by %1s.'), $fm_name);
                if ($single_check) {
                    bailOut($message);
                } else {
                    $requirement_check .= displayProgress(_('Test Rewrites'), false, 'display', $message);
                    $error = true;
                }
            } else {
                if (!$single_check) {
                    $requirement_check .= displayProgress(_('Test Rewrites'), true, 'display');
                }
            }
        }
    }
    if ($error) {
        $requirement_check = sprintf('
			<div id="window">
			<table class="form-table">%s</table>
			<p class="step"><a href="%s" class="button">%s</a></p></div>', $requirement_check, $_SERVER['PHP_SELF'], _('Try Again'));
    } else {
        $requirement_check = null;
    }
    return $requirement_check;
}
Esempio n. 9
0
function installSchema($link, $database)
{
    include ABSPATH . 'fm-includes/version.php';
    include ABSPATH . 'fm-modules/facileManager/variables.inc.php';
    $default_timezone = date_default_timezone_get() ? date_default_timezone_get() : 'America/Denver';
    $table[] = <<<TABLE
CREATE TABLE IF NOT EXISTS {$database}.`fm_accounts` (
  `account_id` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  `account_key` varchar(255) NOT NULL,
  `account_name` VARCHAR(255) NOT NULL ,
  `account_status` ENUM( 'active',  'disabled',  'deleted') NOT NULL DEFAULT  'active'
) ENGINE = MYISAM DEFAULT CHARSET=utf8;
TABLE;
    $table[] = <<<TABLE
CREATE TABLE IF NOT EXISTS {$database}.`fm_logs` (
  `log_id` int(11) NOT NULL AUTO_INCREMENT,
  `user_id` int(11) NOT NULL DEFAULT '0',
  `account_id` int(11) NOT NULL DEFAULT '1',
  `log_module` varchar(255) NOT NULL,
  `log_timestamp` int(10) NOT NULL DEFAULT '0',
  `log_data` text NOT NULL,
  PRIMARY KEY (`log_id`)
) ENGINE=INNODB DEFAULT CHARSET=utf8 ;
TABLE;
    $table[] = <<<TABLE
CREATE TABLE IF NOT EXISTS {$database}.`fm_options` (
  `option_id` int(11) NOT NULL AUTO_INCREMENT,
  `account_id` int(11) NOT NULL DEFAULT '0',
  `module_name` varchar(255) DEFAULT NULL,
  `option_name` varchar(50) NOT NULL,
  `option_value` text NOT NULL,
  PRIMARY KEY (`option_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 ;
TABLE;
    $table[] = <<<TABLE
CREATE TABLE IF NOT EXISTS {$database}.`fm_pwd_resets` (
  `pwd_id` varchar(255) NOT NULL,
  `pwd_login` int(11) NOT NULL,
  `pwd_timestamp` int(10) NOT NULL DEFAULT '0',
  PRIMARY KEY (`pwd_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
TABLE;
    $table[] = <<<TABLE
CREATE TABLE IF NOT EXISTS {$database}.`fm_users` (
  `user_id` int(11) NOT NULL AUTO_INCREMENT,
  `account_id` int(11) NOT NULL DEFAULT '1',
  `user_login` varchar(128) NOT NULL,
  `user_password` varchar(255) NOT NULL,
  `user_email` varchar(255) NOT NULL,
  `user_default_module` varchar(255) DEFAULT NULL,
  `user_auth_type` int(1) NOT NULL DEFAULT '1',
  `user_caps` text,
  `user_last_login` int(10) NOT NULL DEFAULT '0',
  `user_ipaddr` varchar(255) DEFAULT NULL,
  `user_force_pwd_change` enum('yes','no') NOT NULL DEFAULT 'no',
  `user_template_only` enum('yes','no') NOT NULL DEFAULT 'no',
  `user_status` enum('active','disabled','deleted') NOT NULL DEFAULT 'active',
  PRIMARY KEY (`user_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8;
TABLE;
    $inserts[] = <<<INSERT
INSERT IGNORE INTO  {$database}.`fm_accounts` (`account_id` ,`account_key`, `account_name` ,`account_status`) VALUES ('1' , 'default', 'Default Account',  'active');
INSERT;
    $inserts[] = <<<INSERT
INSERT INTO {$database}.`fm_options` (option_name, option_value) 
\tSELECT 'fm_db_version', '{$fm_db_version}' FROM DUAL
WHERE NOT EXISTS
\t(SELECT option_name FROM {$database}.`fm_options` WHERE option_name = 'fm_db_version');
INSERT;
    $inserts[] = <<<INSERT
INSERT INTO {$database}.`fm_options` (`option_name`, `option_value`) 
\tSELECT 'auth_method', '1' FROM DUAL
WHERE NOT EXISTS
\t(SELECT option_name FROM {$database}.`fm_options` WHERE option_name = 'auth_method');
INSERT;
    $inserts[] = <<<INSERT
INSERT INTO {$database}.`fm_options` (`option_name`, `option_value`) 
\tSELECT 'mail_enable', '1' FROM DUAL
WHERE NOT EXISTS
\t(SELECT option_name FROM {$database}.`fm_options` WHERE option_name = 'mail_enable');
INSERT;
    $inserts[] = <<<INSERT
INSERT INTO {$database}.`fm_options` (`option_name`, `option_value`) 
\tSELECT 'mail_smtp_host', 'localhost' FROM DUAL
WHERE NOT EXISTS
\t(SELECT option_name FROM {$database}.`fm_options` WHERE option_name = 'mail_smtp_host');
INSERT;
    $inserts[] = "\nINSERT INTO {$database}.`fm_options` (`option_name`, `option_value`) \n\tSELECT 'mail_from', 'noreply@" . php_uname('n') . "' FROM DUAL\nWHERE NOT EXISTS\n\t(SELECT option_name FROM {$database}.`fm_options` WHERE option_name = 'mail_from');\n";
    $inserts[] = <<<INSERT
INSERT INTO {$database}.`fm_options` (`option_name`, `option_value`) 
\tSELECT 'mail_smtp_tls', '0' FROM DUAL
WHERE NOT EXISTS
\t(SELECT option_name FROM {$database}.`fm_options` WHERE option_name = 'mail_smtp_tls');
INSERT;
    $inserts[] = <<<INSERT
INSERT INTO {$database}.`fm_options` (`account_id` ,`option_name`, `option_value`) 
\tSELECT 1, 'timezone', '{$default_timezone}' FROM DUAL
WHERE NOT EXISTS
\t(SELECT option_name FROM {$database}.`fm_options` WHERE option_name = 'timezone');
INSERT;
    $inserts[] = <<<INSERT
INSERT INTO {$database}.`fm_options` (`account_id` ,`option_name`, `option_value`) 
\tSELECT 1, 'date_format', 'D, d M Y' FROM DUAL
WHERE NOT EXISTS
\t(SELECT option_name FROM {$database}.`fm_options` WHERE option_name = 'date_format');
INSERT;
    $inserts[] = <<<INSERT
INSERT INTO {$database}.`fm_options` (`account_id` ,`option_name`, `option_value`) 
\tSELECT 1, 'time_format', 'H:i:s O' FROM DUAL
WHERE NOT EXISTS
\t(SELECT option_name FROM {$database}.`fm_options` WHERE option_name = 'time_format');
INSERT;
    $tmp = sys_get_temp_dir();
    $inserts[] = <<<INSERT
INSERT INTO {$database}.`fm_options` (`account_id` ,`option_name`, `option_value`) 
\tSELECT 0, 'fm_temp_directory', '{$tmp}' FROM DUAL
WHERE NOT EXISTS
\t(SELECT option_name FROM {$database}.`fm_options` WHERE option_name = 'fm_temp_directory');
INSERT;
    $inserts[] = <<<INSERT
INSERT INTO {$database}.`fm_options` (`account_id` ,`option_name`, `option_value`) 
\tSELECT 0, 'software_update', 1 FROM DUAL
WHERE NOT EXISTS
\t(SELECT option_name FROM {$database}.`fm_options` WHERE option_name = 'software_update');
INSERT;
    $inserts[] = <<<INSERT
INSERT INTO {$database}.`fm_options` (`account_id` ,`option_name`, `option_value`) 
\tSELECT 0, 'software_update_interval', 'week' FROM DUAL
WHERE NOT EXISTS
\t(SELECT option_name FROM {$database}.`fm_options` WHERE option_name = 'software_update_interval');
INSERT;
    $inserts[] = <<<INSERT
INSERT INTO {$database}.`fm_options` (`account_id` ,`option_name`, `option_value`) 
\tSELECT 0, 'client_auto_register', 1 FROM DUAL
WHERE NOT EXISTS
\t(SELECT option_name FROM {$database}.`fm_options` WHERE option_name = 'client_auto_register');
INSERT;
    $inserts[] = <<<INSERT
INSERT INTO {$database}.`fm_options` (`account_id` ,`option_name`, `option_value`) 
\tSELECT 0, 'ssh_user', 'fm_user' FROM DUAL
WHERE NOT EXISTS
\t(SELECT option_name FROM {$database}.`fm_options` WHERE option_name = 'ssh_user');
INSERT;
    /** Create table schema */
    foreach ($table as $schema) {
        $result = @mysql_query($schema, $link);
        if (mysql_error()) {
            return displayProgress(sprintf(_('Creating %s Schema'), $fm_name), $result, 'noisy', mysql_error());
        }
    }
    /** Insert site values if not already present */
    $query = "SELECT * FROM fm_options";
    $temp_result = mysql_query($query, $link);
    if (!@mysql_num_rows($temp_result)) {
        foreach ($inserts as $query) {
            $result = @mysql_query($query, $link);
            if (mysql_error()) {
                return displayProgress(sprintf(_('Creating %s Schema'), $fm_name), $result, 'noisy', mysql_error());
            }
        }
    }
    addLogEntry(sprintf(_('%s %s was born.'), $fm_name, $fm_version), $fm_name, $link);
    return displayProgress(sprintf(_('Creating %s Schema'), $fm_name), $result);
}