|
|
<?php
|
|
|
namespace backend\controllers;
|
|
|
|
|
|
use Yii;
|
|
|
use app\models\SysConfig;
|
|
|
/**
|
|
|
* Site controller
|
|
|
*/
|
|
|
class SystemController extends BaseController
|
|
|
{
|
|
|
|
|
|
public function actionServers()
|
|
|
{
|
|
|
$key = 'servers';
|
|
|
if (Yii::$app->request->isPost && trim(Yii::$app->request->post('content'))) {
|
|
|
$content = Yii::$app->request->post('content');
|
|
|
$ip_arr = explode(",",trim($content));
|
|
|
$ip_arr = array_map(function($v){return trim($v);},$ip_arr);
|
|
|
|
|
|
$model = SysConfig::findOne(['conf_key'=>$key]);
|
|
|
$model->conf_value = json_encode($ip_arr);
|
|
|
if($model->save()){
|
|
|
Yii::$app->session->setFlash('success', '保存成功。');
|
|
|
}else{
|
|
|
Yii::$app->session->setFlash('error', '保存失败。');
|
|
|
}
|
|
|
$this->redirect('/system/servers');
|
|
|
}else{
|
|
|
$model = SysConfig::find()->where(['conf_key' => $key])->one();
|
|
|
$ips = json_decode($model->conf_value, true);
|
|
|
return $this->render('servers', ['ips' => $ips]);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public function actionServAddr()
|
|
|
{
|
|
|
$key = 'serv_addr';
|
|
|
if( Yii::$app->request->isPost && trim(Yii::$app->request->post('content')) ){
|
|
|
$save_arr = [];
|
|
|
$content = Yii::$app->request->post('content');
|
|
|
|
|
|
$val_arr = explode(",",trim($content));
|
|
|
$val_arr = array_map(function($v){return trim($v);},$val_arr);
|
|
|
/*foreach($val_arr as $k=>$v){
|
|
|
list($host,$port) = explode(':',$v);
|
|
|
$save_arr[$k]['host']=$host;
|
|
|
$save_arr[$k]['port']=$port;
|
|
|
}*/
|
|
|
// var_dump($val_arr);exit;
|
|
|
$model = SysConfig::findOne(['conf_key'=>$key]);
|
|
|
$model->conf_value = json_encode($val_arr);
|
|
|
if($model->save()){
|
|
|
Yii::$app->session->setFlash('success', '保存成功。');
|
|
|
}else{
|
|
|
Yii::$app->session->setFlash('error', '保存失败。');
|
|
|
}
|
|
|
$this->redirect('/system/serv-addr');
|
|
|
}else{
|
|
|
$model = SysConfig::find()->where(['conf_key'=>$key])->one();
|
|
|
$data = json_decode($model->conf_value,true);
|
|
|
return $this->render('serv-addr',['data'=>$data]);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
} |
...
|
...
|
|