Files
EasySoft-ZenTaoPMS/module/system/model.php
T
2023-12-27 19:06:04 +08:00

138 lines
4.7 KiB
PHP

<?php
/**
* The model file of system module of ZenTaoPMS.
*
* @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.cnezsoft.com)
* @license ZPL (http://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
* @author Jianhua Wang <wangjianhua@easycorp.ltd>
* @package system
* @version $Id$
* @link https://www.zentao.net
*/
class systemModel extends model
{
/**
* Construct function: load setting model.
*
* @access public
* @return mixed
*/
public function __construct()
{
parent::__construct();
$this->loadModel('setting');
}
/**
* Get customized domain settings. *
* @access public
* @return object
*/
public function getDomainSettings()
{
$settings = new stdclass;
$settings->customDomain = $this->setting->getItem('owner=system&module=common&section=domain&key=customDomain');
$settings->https = $this->setting->getItem('owner=system&module=common&section=domain&key=https');
$settings->certPem = ''; //
$settings->certKey = ''; //
return $settings;
}
/**
* Save customized somain settings.
*
* @access public
* @return void
*/
public function saveDomainSettings()
{
$settings = fixer::input('post')
->setDefault('customDomain', '')
->setDefault('https', 'false')
->setIf(is_array($this->post->https) && in_array('true', $this->post->https), 'https', 'true')
->setDefault('certPem', '')
->setDefault('certKey', '')
->get();
$this->dao->from('system')->data($settings)
->check('customDomain', 'notempty')
->checkIf($settings->https == 'true', 'certPem', 'notempty')
->checkIf($settings->https == 'true', 'certKey', 'notempty');
if(dao::isError()) return;
if(!validater::checkREG($settings->customDomain, '/^((?!-)[a-z0-9-]{1,63}(?<!-)\\.)+[a-z]{2,6}$/'))
{
dao::$errors[] = $this->lang->system->errors->invalidDomain;
return;
}
/* Upload Certificate to CNE. */
if($settings->https == 'true')
{
$cert = new stdclass;
$cert->name = 'tls-' . str_replace('.', '-', $settings->customDomain);
$cert->certificate_pem = $settings->certPem;
$cert->private_key_pem = $settings->certKey;
$certResult = $this->loadModel('cne')->uploadCert($cert);
if($certResult->code != 200)
{
dao::$errors[] = $certResult->message;
return;
}
}
$oldSettings = $this->getDomainSettings();
if($settings->customDomain == $oldSettings->customDomain)
{
dao::$errors[] = $this->lang->system->errors->newDomainIsSameWithOld;
return;
}
if(stripos($settings->customDomain, 'haogs.cn') !== false)
{
dao::$errors[] = $this->lang->system->errors->forbiddenOriginalDomain;
return;
}
$expiredDomain = $this->setting->getItem('owner=system&module=common&section=domain&key=expiredDomain');
$expiredDomain = empty($expiredDomain ) ? array(getenv('APP_DOMAIN')) : json_decode($expiredDomain, true);
$expiredDomain[] = zget($settings, 'customDomain', '');
$this->setting->setItem('system.common.domain.expiredDomain', json_encode($expiredDomain));
$this->setting->setItem('system.common.domain.customDomain', zget($settings, 'customDomain', ''));
$this->setting->setItem('system.common.domain.https', zget($settings, 'https', 'false'));
$this->loadModel('instance')->updateInstancesDomain();
$this->updateMinioDomain();
}
/**
* Update minio domain.
*
* @access public
* @return void
*/
public function updateMinioDomain()
{
$this->loadModel('cne');
$sysDomain = $this->cne->sysDomain();
$minioInstance = new stdclass;
$minioInstance->k8name = 'cne-operator';
$minioInstance->chart = 'cne-operator';
$minioInstance->spaceData = new stdclass;
$minioInstance->spaceData->k8space = $this->config->k8space;
$settings = new stdclass;
$settings->settings_map = new stdclass;
$settings->settings_map->minio = new stdclass;
$settings->settings_map->minio->ingress = new stdclass;
$settings->settings_map->minio->ingress->enabled = true;
$settings->settings_map->minio->ingress->host = 's3.' . $sysDomain;
$this->cne->updateConfig($minioInstance, $settings);
}
}