XpressEngine Core  1.11.2
 All Classes Namespaces Files Functions Variables Pages
install.admin.controller.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) NAVER <http://www.navercorp.com> */
9 {
13  function init()
14  {
15  }
16 
21  {
22  $module_name = Context::get('module_name');
23  if(!$module_name) return new BaseObject(-1, 'invalid_request');
24 
25  $oInstallController = getController('install');
26  $oInstallController->installModule($module_name, './modules/'.$module_name);
27 
28  $this->setMessage('success_installed');
29  }
30 
35  {
36  @set_time_limit(0);
37  $module_name = Context::get('module_name');
38  if(!$module_name) return new BaseObject(-1, 'invalid_request');
39 
40  $oModule = getModule($module_name, 'class');
41  if($oModule) $output = $oModule->moduleUpdate();
42  else $output = new BaseObject(-1, 'invalid_request');
43 
44  return $output;
45  }
46 
51  {
52  $db_info = Context::getDBInfo();
53 
54  $admin_ip_list = Context::get('admin_ip_list');
55 
56  if($admin_ip_list)
57  {
58  $admin_ip_list = preg_replace("/[\r|\n|\r\n]+/",",",$admin_ip_list);
59  $admin_ip_list = preg_replace("/\s+/","",$admin_ip_list);
60  if(preg_match('/(<\?|<\?php|\?>)/xsm', $admin_ip_list))
61  {
62  $admin_ip_list = '';
63  }
64  $admin_ip_list .= ',127.0.0.1,' . $_SERVER['REMOTE_ADDR'];
65  $admin_ip_list = explode(',',trim($admin_ip_list, ','));
66  $admin_ip_list = array_unique($admin_ip_list);
67  if(!IpFilter::validate($admin_ip_list)) {
68  return new BaseObject(-1, 'msg_invalid_ip');
69  }
70  }
71 
72  $default_url = Context::get('default_url');
73  if($default_url && strncasecmp('http://', $default_url, 7) !== 0 && strncasecmp('https://', $default_url, 8) !== 0) $default_url = 'http://'.$default_url;
74  if($default_url && substr($default_url, -1) !== '/') $default_url = $default_url.'/';
75 
76  /* convert NON Alphabet URL to punycode URL - Alphabet URL will not be changed */
77  require_once(_XE_PATH_ . 'libs/idna_convert/idna_convert.class.php');
78  $IDN = new idna_convert(array('idn_version' => 2008));
79  $default_url = $IDN->encode($default_url);
80 
81  $use_ssl = Context::get('use_ssl');
82  if(!$use_ssl) $use_ssl = 'none';
83 
84  $http_port = Context::get('http_port');
85  $https_port = Context::get('https_port');
86 
87  $use_rewrite = Context::get('use_rewrite');
88  if($use_rewrite!='Y') $use_rewrite = 'N';
89 
90  $use_sso = Context::get('use_sso');
91  if($use_sso !='Y') $use_sso = 'N';
92 
93  $use_db_session = Context::get('use_db_session');
94  if($use_db_session!='Y') $use_db_session = 'N';
95 
96  $qmail_compatibility = Context::get('qmail_compatibility');
97  if($qmail_compatibility!='Y') $qmail_compatibility = 'N';
98 
99  $use_html5 = Context::get('use_html5');
100  if(!$use_html5) $use_html5 = 'N';
101 
102  $db_info->default_url = $default_url;
103  $db_info->qmail_compatibility = $qmail_compatibility;
104  $db_info->use_db_session = $use_db_session;
105  $db_info->use_rewrite = $use_rewrite;
106  $db_info->use_sso = $use_sso;
107  $db_info->use_ssl = $use_ssl;
108  $db_info->use_html5 = $use_html5;
109  $db_info->admin_ip_list = $admin_ip_list;
110 
111  if($http_port) $db_info->http_port = (int) $http_port;
112  else if($db_info->http_port) unset($db_info->http_port);
113 
114  if($https_port) $db_info->https_port = (int) $https_port;
115  else if($db_info->https_port) unset($db_info->https_port);
116 
117  unset($db_info->lang_type);
118 
119  $oInstallController = getController('install');
120  if(!$oInstallController->makeConfigFile())
121  {
122  return new BaseObject(-1, 'msg_invalid_request');
123  }
124  else
125  {
126  Context::setDBInfo($db_info);
127  if($default_url)
128  {
129  $site_args = new stdClass;
130  $site_args->site_srl = 0;
131  $site_args->domain = $default_url;
132  $oModuleController = getController('module');
133  $oModuleController->updateSite($site_args);
134  }
135  $this->setRedirectUrl(Context::get('error_return_url'));
136  }
137  }
138 
140  {
141  if(!Context::get('index_module_srl') || !Context::get('menu_item_srl'))
142  {
143  return new BaseObject(-1, 'msg_invalid_request');
144  }
145 
146  $site_args = new stdClass();
147  $site_args->site_srl = 0;
148  $site_args->index_module_srl = Context::get('index_module_srl');
149  $oModuleController = getController('module');
150  $oModuleController->updateSite($site_args);
151 
152  // get menu item info
153  $menuItemSrl = Context::get('menu_item_srl');
154  $oMenuAdminModel = getAdminModel('menu');
155  $output = $oMenuAdminModel->getMenuItemInfo($menuItemSrl);
156 
157  // update homeSitemap.php cache file
159  $homeMenuCacheFile = $oMenuAdminController->getHomeMenuCacheFile();
160  if(file_exists($homeMenuCacheFile))
161  {
162  include($homeMenuCacheFile);
163  }
164 
165  if(!$homeMenuSrl || $homeMenuSrl != $output->menu_srl)
166  {
167  $oMenuAdminController->makeHomemenuCacheFile($output->menu_srl);
168  }
169 
170  $this->setMessage('success_updated');
171  }
172 
174  {
175  $ftp_config_file = Context::getFTPConfigFile();
176  if(file_exists($ftp_config_file)) unlink($ftp_config_file);
177  if($_SESSION['ftp_password']) unset($_SESSION['ftp_password']);
178  $this->setMessage('success_deleted');
179  }
180 
182  {
183  $ftp_info = Context::getFTPInfo();
184  $ftp_info->ftp_user = Context::get('ftp_user');
185  $ftp_info->ftp_port = Context::get('ftp_port');
186  $ftp_info->ftp_host = Context::get('ftp_host');
187  $ftp_info->ftp_pasv = Context::get('ftp_pasv');
188  if(!$ftp_info->ftp_pasv) $ftp_info->ftp_pasv = "N";
189  $ftp_info->sftp = Context::get('sftp');
190 
191  $ftp_root_path = Context::get('ftp_root_path');
192  if(substr($ftp_root_path, strlen($ftp_root_path)-1) == "/")
193  {
194  $ftp_info->ftp_root_path = $ftp_root_path;
195  }
196  else
197  {
198  $ftp_info->ftp_root_path = $ftp_root_path.'/';
199  }
200 
201  if(ini_get('safe_mode'))
202  {
203  $ftp_info->ftp_password = Context::get('ftp_password');
204  }
205 
206  $buff = '<?php if(!defined("__XE__")) exit();'."\n\$ftp_info = new stdClass;\n";
207  foreach($ftp_info as $key => $val)
208  {
209  if(!$val) continue;
210  if(preg_match('/(<\?|<\?php|\?>|fputs|fopen|fwrite|fgets|fread|file_get_contents|file_put_contents|exec|proc_open|popen|passthru|show_source|phpinfo|system|\/\*|\*\/|chr\()/xsm', preg_replace('/\s/', '', $val)))
211  {
212  continue;
213  }
214  $buff .= sprintf("\$ftp_info->%s = '%s';\n", $key, str_replace("'","\\'",$val));
215  }
216  $buff .= "?>";
217  $config_file = Context::getFTPConfigFile();
218  FileHandler::WriteFile($config_file, $buff);
219  if($_SESSION['ftp_password']) unset($_SESSION['ftp_password']);
220 
221  $this->setMessage('success_updated');
222  $returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'module', 'admin', 'act', 'dispAdminConfigFtp');
223  $this->setRedirectUrl($returnUrl);
224  }
225 
227  {
228  $use_mobile_view = Context::get('use_mobile_view');
229  if($use_mobile_view!='Y') $use_mobile_view = 'N';
230 
231  $time_zone = Context::get('time_zone');
232 
233  $db_info = Context::getDBInfo();
234  $db_info->use_mobile_view = $use_mobile_view;
235  $db_info->time_zone = $time_zone;
236 
237  unset($db_info->lang_type);
238  Context::setDBInfo($db_info);
239  $oInstallController = getController('install');
240  if(!$oInstallController->makeConfigFile())
241  {
242  return new BaseObject(-1, 'msg_invalid_request');
243  }
244 
245  $site_args = new stdClass();
246  $site_args->site_srl = 0;
247  $site_args->index_module_srl = Context::get('index_module_srl');//
248  $site_args->default_language = Context::get('change_lang_type');//
249  $oModuleController = getController('module');
250  $oModuleController->updateSite($site_args);
251 
252  //언어 선택
253  $selected_lang = Context::get('selected_lang');
254  $this->saveLangSelected($selected_lang);
255 
256  //save icon images
257  $deleteFavicon = Context::get('is_delete_favicon');
258  $deleteMobicon = Context::get('is_delete_mobicon');
259 
260  $this->updateIcon('favicon.ico',$deleteFavicon);
261  $this->updateIcon('mobicon.png',$deleteMobicon);
262 
263  //모듈 설정 저장(썸네일, 풋터스크립트)
264  $config = new stdClass();
265  $config->thumbnail_type = Context::get('thumbnail_type');
266  $config->htmlFooter = Context::get('htmlFooter');
267  $config->siteTitle = Context::get('site_title');
268  $this->setModulesConfig($config);
269 
270  $this->setRedirectUrl(Context::get('error_return_url'));
271  }
272 
274  $this->setTemplatePath($this->module_path.'tpl');
275  $this->setTemplateFile("after_upload_config_image.html");
276 
277  $favicon = Context::get('favicon');
278  $mobicon = Context::get('mobicon');
279  if(!$favicon && !$mobicon) {
280  Context::set('msg', Context::getLang("msg_invalid_format"));
281  return;
282  }
283  if($favicon) {
284  $name = 'favicon';
285  $tmpFileName = $this->saveIconTmp($favicon,'favicon.ico');
286  } else {
287  $name = 'mobicon';
288  $tmpFileName = $this->saveIconTmp($mobicon,'mobicon.png');
289  }
290 
291  Context::set('name', $name);
292  Context::set('tmpFileName', $tmpFileName.'?'.$_SERVER['REQUEST_TIME']);
293  }
294 
298  function saveLangSelected($selected_lang)
299  {
300  $langs = $selected_lang;
301 
302  $lang_supported = Context::loadLangSupported();
303  $buff = null;
304  for($i=0;$i<count($langs);$i++)
305  {
306  $buff .= sprintf("%s,%s\n", $langs[$i], $lang_supported[$langs[$i]]);
307 
308  }
309  FileHandler::writeFile(_XE_PATH_.'files/config/lang_selected.info', trim($buff));
310  //$this->setMessage('success_updated');
311  }
312 
318  function setModulesConfig($config)
319  {
320  $documentConfig = getModel('document')->getDocumentConfig();
321 
322  if (!$config->thumbnail_type || $config->thumbnail_type != 'ratio')
323  {
324  $documentConfig->thumbnail_type = 'crop';
325  }
326  else
327  {
328  $documentConfig->thumbnail_type = 'ratio';
329  }
330 
331  $oModuleController = getController('module');
332  $oModuleController->insertModuleConfig('document',$documentConfig);
333 
334  $args = new stdClass;
335  $args->htmlFooter = $config->htmlFooter;
336  $args->siteTitle = $config->siteTitle;
337  $oModuleController->updateModuleConfig('module',$args);
338  }
339 
340  private function saveIconTmp($icon, $iconname)
341  {
342 
343  $site_info = Context::get('site_module_info');
344  $virtual_site = '';
345  if($site_info->site_srl)
346  {
347  $virtual_site = $site_info->site_srl . '/';
348  }
349 
350  $target_file = $icon['tmp_name'];
351  $type = $icon['type'];
352  $relative_filename = 'files/attach/xeicon/'.$virtual_site.'tmp/'.$iconname;
353  $target_filename = _XE_PATH_.$relative_filename;
354 
355  list($width, $height, $type_no, $attrs) = @getimagesize($target_file);
356  if($iconname == 'favicon.ico')
357  {
358  if(!preg_match('/^.*(x-icon|\.icon)$/i',$type)) {
359  Context::set('msg', '*.ico '.Context::getLang('msg_possible_only_file'));
360  return;
361  }
362  }
363  else if($iconname == 'mobicon.png')
364  {
365  if(!preg_match('/^.*(png).*$/',$type)) {
366  Context::set('msg', '*.png '.Context::getLang('msg_possible_only_file'));
367  return;
368  }
369  if(!(($height == '57' && $width == '57') || ($height == '114' && $width == '114'))) {
370  Context::set('msg', Context::getLang('msg_invalid_format').' (size : 57x57, 114x114)');
371  return;
372  }
373  }
374  else
375  {
376  Context::set('msg', Context::getLang('msg_invalid_format'));
377  return;
378  }
379 
380  $fitHeight = $fitWidth = $height;
381  //FileHandler::createImageFile($target_file, $target_filename, $fitHeight, $fitWidth, $ext);
382  FileHandler::copyFile($target_file, $target_filename);
383  return $relative_filename;
384  }
385 
386  private function updateIcon($iconname, $deleteIcon = false) {
387 
388  $site_info = Context::get('site_module_info');
389  $virtual_site = '';
390  if($site_info->site_srl)
391  {
392  $virtual_site = $site_info->site_srl . '/';
393  }
394 
395  $image_filepath = _XE_PATH_.'files/attach/xeicon/' . $virtual_site;
396 
397  if($deleteIcon) {
398  FileHandler::removeFile($image_filepath.$iconname);
399  return;
400  }
401 
402  $tmpicon_filepath = $image_filepath.'tmp/'.$iconname;
403  $icon_filepath = $image_filepath.$iconname;
404  if(file_exists($tmpicon_filepath))
405  {
406  FileHandler::moveFile($tmpicon_filepath, $icon_filepath);
407  }
408 
409  FileHandler::removeFile($tmpicon_filepath);
410  }
411 
412 
413 }
414 /* End of file install.admin.controller.php */
415 /* Location: ./modules/install/install.admin.controller.php */
setTemplateFile($filename)
$IDN
Definition: example.php:7
setMessage($message= 'success', $type=NULL)
getController($module_name)
Definition: func.inc.php:90
$oMenuAdminController
Definition: ko.install.php:7
removeFile($filename)
$output
Definition: ko.install.php:193
validate($ip_list=array())
set($key, $val, $set_to_get_vars=0)
getNotEncodedUrl()
Definition: func.inc.php:316
writeFile($filename, $buff, $mode="w")
moveFile($source, $target)
$args
Definition: ko.install.php:185
setRedirectUrl($url= './', $output=NULL)
$time_zone
Definition: func.inc.php:29
procInstallAdminSaveTimeZone()
Change settings.
getAdminModel($module_name)
Definition: func.inc.php:156
install module of the high class
saveLangSelected($selected_lang)
Supported languages (was procInstallAdminSaveLangSelected)
procInstallAdminInstall()
Install the module.
copyFile($source, $target, $force= 'Y')
loadLangSupported()
getLang($code)
const _XE_PATH_
Definition: config.inc.php:49
getModel($module_name)
Definition: func.inc.php:145
setDBInfo($db_info)
admin controller class of the install module
getAdminController($module_name)
Definition: func.inc.php:101
$oModuleController
Definition: ko.install.php:287
getModule($module_name, $type= 'view', $kind= '')
Definition: func.inc.php:79
procInstallAdminUpdate()
Upate the module.
$site_args
Definition: ko.install.php:296