Ejemplo n.º 1
0
/**
 * Gets and prepares the template part for services ports
 *
 * This function is used for generation of both pages (show page and error page)
 *
 * @param iMSCP_pTemplate $tpl iMSCP_pTemplate instance
 * @return void;
 */
function admin_showServices($tpl)
{
    /** @var $cfg iMSCP_Config_Handler_File */
    $cfg = iMSCP_Registry::get('config');
    if (isset($_SESSION['error_on_updt'])) {
        $values = new iMSCP_Config_Handler($_SESSION['error_on_updt']);
        unset($_SESSION['error_on_updt']);
        $services = array_keys($values->toArray());
    } else {
        $values = iMSCP_Registry::get('dbConfig');
        // Gets list of services port names
        $services = array_filter(array_keys($values->toArray()), function ($name) {
            return strlen($name) > 5 && substr($name, 0, 5) == 'PORT_';
        });
        if (isset($_SESSION['errorOnAdd'])) {
            $errorOnAdd = new iMSCP_Config_Handler($_SESSION['errorOnAdd']);
            unset($_SESSION['errorOnAdd']);
        }
    }
    if (empty($services)) {
        $tpl->assign('SERVICE_PORTS', '');
        set_page_message(tr('You have not service ports defined.'), 'static_info');
    } else {
        sort($services);
        foreach ($services as $index => $service) {
            list($port, $protocol, $name, $status, $ip) = explode(';', $values->{$service});
            $htmlSelected = $cfg->HTML_SELECTED;
            $selectedUdp = $protocol == 'udp' ? $htmlSelected : '';
            $selectedTcp = $protocol == 'udp' ? '' : $htmlSelected;
            $selectedOn = $status == '1' ? $htmlSelected : '';
            $selectedOff = $status == '1' ? '' : $htmlSelected;
            $tpl->assign(array('SERVICE' => '<input name="name[]" type="text" id="name' . $index . '" value="' . tohtml($name) . '" class="textinput" maxlength="25" />', 'NAME' => tohtml($name), 'DISABLED' => '', 'TR_DELETE' => tr('Delete'), 'URL_DELETE' => "?delete={$service}", 'NUM' => $index));
            $tpl->parse('PORT_DELETE_LINK', 'port_delete_link');
            $tpl->assign(array('VAR_NAME' => tohtml($service), 'IP' => $ip == 'localhost' ? '127.0.0.1' : (!$ip ? '0.0.0.0' : tohtml($ip)), 'PORT' => tohtml($port), 'SELECTED_UDP' => $selectedUdp, 'SELECTED_TCP' => $selectedTcp, 'SELECTED_ON' => $selectedOn, 'SELECTED_OFF' => $selectedOff));
            $tpl->parse('SERVICE_PORTS', '.service_ports');
        }
        // Add fields
        $tpl->assign(isset($errorOnAdd) ? array('VAL_FOR_NAME_NEW' => $errorOnAdd['name_new'], 'VAL_FOR_IP_NEW' => $errorOnAdd['ip_new'], 'VAL_FOR_PORT_NEW' => $errorOnAdd['port_new']) : array('VAL_FOR_NAME_NEW' => '', 'VAL_FOR_IP_NEW' => '', 'VAL_FOR_PORT_NEW' => ''));
        // Error fields ids
        $tpl->assign('ERROR_FIELDS_IDS', isset($_SESSION['errorFieldsIds']) ? $_SESSION['errorFieldsIds'] : '[]');
        unset($_SESSION['errorFieldsIds']);
    }
}
Ejemplo n.º 2
0
 /**
  * Replaces all parameters of this object with parameters from another
  *
  * This method replace the parameters values of this object with the same values from another
  * {@link iMSCP_Config_Handler} object.
  *
  * If a key from this object exists in the second object, its value will be replaced by the value from the second
  * object. If the key exists in the second object, and not in the first, it will be created in the first object.
  * All keys in this object that don't exist in the second object will be left untouched.
  *
  * <b>Note:</b> This method is not recursive.
  *
  * @param iMSCP_Config_Handler $config iMSCP_Config_Handler object
  * @return bool TRUE on success, FALSE otherwise
  */
 public function merge(iMSCP_Config_Handler $config)
 {
     try {
         $this->_db->beginTransaction();
         parent::merge($config);
         $this->_db->commit();
     } catch (PDOException $e) {
         $this->_db->rollBack();
         return false;
     }
     return true;
 }