system.mod.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  1. <?php
  2. /**
  3. * [WeEngine System] Copyright (c) 2014 WE7.CC
  4. * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
  5. */
  6. defined('IN_IA') or exit('Access Denied');
  7. function system_menu() {
  8. global $we7_system_menu;
  9. require_once IA_ROOT . '/web/common/frames.inc.php';
  10. return $we7_system_menu;
  11. }
  12. function system_shortcut_menu() {
  13. global $_W;
  14. static $shortcut_menu;
  15. load()->model('user');
  16. if (empty($shortcut_menu)) {
  17. $shortcut_menu = array();
  18. $system_menu = system_menu();
  19. $is_main_founder = user_is_founder($_W['uid'], true);
  20. $is_vice_founder = user_is_vice_founder();
  21. $hidden_menu = array_keys((array) pdo_getall('core_menu', array('is_display' => 0), array('id', 'permission_name'), 'permission_name'));
  22. foreach (array('system', 'site') as $top_menu) {
  23. if (!empty($system_menu[$top_menu]['founder']) && !$is_main_founder) {
  24. continue;
  25. }
  26. if (in_array($top_menu, $hidden_menu)) {
  27. continue;
  28. }
  29. $shortcut_menu[$top_menu] = $system_menu[$top_menu];
  30. foreach ($shortcut_menu[$top_menu]['section'] as $section_key => &$section) {
  31. if (!empty($section['founder']) && !$is_main_founder) {
  32. unset($shortcut_menu[$top_menu]['section'][$section_key]);
  33. }
  34. foreach ($section['menu'] as $i => $menu) {
  35. if (!isset($menu['is_display'])) {
  36. $section['menu'][$i]['is_display'] = 1;
  37. }
  38. if (in_array($menu['permission_name'], $hidden_menu)) {
  39. $section['menu'][$i]['is_display'] = 0;
  40. }
  41. }
  42. }
  43. }
  44. $store_setting = $_W['setting']['store'];
  45. if (!in_array('store', $hidden_menu) && ($is_main_founder || empty($store_setting['status']))) {
  46. if (!$is_main_founder && !empty($_W['username']) && !empty($store_setting['permission_status']) && empty($store_setting['permission_status']['close'])) {
  47. if (!in_array($_W['username'], (array)$store_setting['whitelist']) && !empty($store_setting['permission_status']['whitelist'])
  48. || in_array($_W['username'], (array)$store_setting['blacklist']) && !empty($store_setting['permission_status']['blacklist'])
  49. ) {
  50. $system_menu['store'] = array();
  51. }
  52. }
  53. if (!empty($system_menu['store']['section'])) {
  54. $shortcut_menu['store'] = $system_menu['store'];
  55. foreach ($shortcut_menu['store']['section'] as $key => &$section) {
  56. if ($key == 'store_wish_goods' && $_W['setting']['store']['wish_module_status'] == 0) {
  57. $section['is_display'] = 0;
  58. }
  59. if (in_array($key, array('store_manage', 'store_payments', 'store_cash_manage')) && !$is_main_founder) {
  60. $section['is_display'] = 0;
  61. continue;
  62. }
  63. if ($key == 'store_cash' && (!$is_vice_founder || empty($store_setting['cash_status']))) {
  64. $section['is_display'] = 0;
  65. continue;
  66. }
  67. foreach ($section['menu'] as $menu_key => &$menu) {
  68. $menu['is_display'] = 1;
  69. if (in_array($menu_key, $hidden_menu)) {
  70. $menu['is_display'] = 0;
  71. }
  72. if ($key == 'store_goods' && !empty($store_setting[$menu_key])) {
  73. $menu['is_display'] = 0;
  74. }
  75. if ($menu_key == 'store_goods_users_package' && $is_vice_founder) {
  76. $menu['is_display'] = 0;
  77. }
  78. if ($menu_key == 'store_cash_orders' && (!$is_vice_founder || empty($store_setting['cash_status']))) {
  79. $menu['is_display'] = 0;
  80. }
  81. if ($menu_key == 'store_check_cash' && empty($store_setting['cash_status'])) {
  82. $menu['is_display'] = 0;
  83. }
  84. }
  85. }
  86. }
  87. }
  88. }
  89. return $shortcut_menu;
  90. }
  91. function system_menu_permission_list($role = '') {
  92. global $_W;
  93. $system_menu = cache_load(cache_system_key('system_frame', array('uniacid' => $_W['uniacid'])));
  94. if(empty($system_menu)) {
  95. cache_build_frame_menu();
  96. $system_menu = cache_load(cache_system_key('system_frame', array('uniacid' => $_W['uniacid'])));
  97. }
  98. if ($role == ACCOUNT_MANAGE_NAME_OPERATOR) {
  99. unset($system_menu['appmarket']);
  100. unset($system_menu['advertisement']);
  101. unset($system_menu['system']);
  102. }
  103. return $system_menu;
  104. }
  105. function system_database_backup() {
  106. $path = IA_ROOT . '/data/backup/';
  107. load()->func('file');
  108. $reduction = array();
  109. if (!is_dir($path)) {
  110. return array();
  111. }
  112. if ($handle = opendir($path)) {
  113. while (false !== ($bakdir = readdir($handle))) {
  114. if ($bakdir == '.' || $bakdir == '..') {
  115. continue;
  116. }
  117. $times[] = date("Y-m-d H:i:s", filemtime($path.$bakdir));
  118. if (preg_match('/^(?P<time>\d{10})_[a-z\d]{8}$/i', $bakdir, $match)) {
  119. $time = $match['time'];
  120. if ($handle1= opendir($path . $bakdir)) {
  121. while (false !== ($filename = readdir($handle1))) {
  122. if ($filename == '.' || $filename == '..') {
  123. continue;
  124. }
  125. if (preg_match('/^volume-(?P<prefix>[a-z\d]{10})-\d{1,}\.sql$/i', $filename, $match1)) {
  126. $volume_prefix = $match1['prefix'];
  127. if (!empty($volume_prefix)) {
  128. break;
  129. }
  130. }
  131. }
  132. }
  133. $volume_list = array();
  134. for ($i = 1;;) {
  135. $last = $path . $bakdir . "/volume-{$volume_prefix}-{$i}.sql";
  136. array_push($volume_list, $last);
  137. $i++;
  138. $next = $path . $bakdir . "/volume-{$volume_prefix}-{$i}.sql";
  139. if (!is_file($next)) {
  140. break;
  141. }
  142. }
  143. if (is_file($last)) {
  144. $fp = fopen($last, 'r');
  145. fseek($fp, -27, SEEK_END);
  146. $end = fgets($fp);
  147. fclose($fp);
  148. if ($end == '----WeEngine MySQL Dump End') {
  149. $row = array(
  150. 'bakdir' => $bakdir,
  151. 'time' => $time,
  152. 'volume' => $i - 1,
  153. 'volume_list' => $volume_list,
  154. );
  155. $reduction[$bakdir] = $row;
  156. continue;
  157. }
  158. }
  159. }
  160. rmdirs($path . $bakdir);
  161. }
  162. closedir($handle);
  163. }
  164. if (!empty($times)) {
  165. array_multisort($times, SORT_DESC, SORT_STRING, $reduction);
  166. }
  167. return $reduction;
  168. }
  169. function system_database_volume_next($volume_name) {
  170. $next_volume_name = '';
  171. if (!empty($volume_name) && preg_match('/^([^\s]*volume-(?P<prefix>[a-z\d]{10})-)(\d{1,})\.sql$/i', $volume_name, $match)) {
  172. $next_volume_name = $match[1] . ($match[3] + 1) . ".sql";
  173. }
  174. return $next_volume_name;
  175. }
  176. function system_database_volume_restore($volume_name) {
  177. if (empty($volume_name) || !is_file($volume_name)) {
  178. return false;
  179. }
  180. $sql = file_get_contents($volume_name);
  181. pdo_run($sql);
  182. return true;
  183. }
  184. function system_database_backup_delete($delete_dirname) {
  185. $path = IA_ROOT . '/data/backup/';
  186. $dir = $path . $delete_dirname;
  187. if (empty($delete_dirname) || !is_dir($dir)) {
  188. return false;
  189. }
  190. return rmdirs($dir);
  191. }
  192. function system_template_ch_name() {
  193. $result = array(
  194. 'default' => '白色',
  195. 'black' => '黑色',
  196. 'classical' => '经典',
  197. '2.0' => '2.0',
  198. );
  199. return $result;
  200. }
  201. function system_site_info() {
  202. load()->classs('cloudapi');
  203. $api = new CloudApi();
  204. $site_info = $api->get('site', 'info');
  205. return $site_info;
  206. }
  207. function system_check_statcode($statcode) {
  208. $allowed_stats = array(
  209. 'baidu' => array(
  210. 'enabled' => true,
  211. 'reg' => '/(http[s]?\:)?\/\/hm\.baidu\.com\/hm\.js\?/'
  212. ),
  213. 'qq' => array(
  214. 'enabled' => true,
  215. 'reg' => '/(http[s]?\:)?\/\/tajs\.qq\.com/'
  216. ),
  217. );
  218. foreach($allowed_stats as $key => $item) {
  219. $preg = preg_match($item['reg'], $statcode);
  220. if (!$preg && !$item['enabled']) {
  221. continue;
  222. } else {
  223. return htmlspecialchars_decode($statcode);
  224. }
  225. return safe_gpc_html(htmlspecialchars_decode($statcode));
  226. }
  227. }
  228. function system_check_items() {
  229. return array(
  230. 'mbstring' => array(
  231. 'operate' => 'system_check_php_ext',
  232. 'description' => 'mbstring 扩展',
  233. 'error_message' => '不支持库',
  234. 'solution' => '安装 mbstring 扩展',
  235. 'handle' => 'https://bbs.w7.cc/thread-33156-1-1.html'
  236. ),
  237. 'mcrypt' => array(
  238. 'operate' => 'system_check_php_ext',
  239. 'description' => 'mcrypt 扩展',
  240. 'error_message' => '不支持库',
  241. 'solution' => '安装 mcrypt 扩展',
  242. 'handle' => 'https://bbs.w7.cc/thread-33159-1-1.html'
  243. ),
  244. 'openssl' => array(
  245. 'operate' => 'system_check_php_ext',
  246. 'description' => 'openssl 扩展',
  247. 'error_message' => '不支持库',
  248. 'solution' => '安装 openssl 扩展',
  249. 'handle' => 'https://bbs.w7.cc/thread-33160-1-1.html'
  250. ),
  251. 'system_template' => array(
  252. 'operate' => 'system_check_template',
  253. 'description' => '是否系统皮肤',
  254. 'error_message' => '不是系统皮肤',
  255. 'solution' => '更换系统默认皮肤',
  256. 'handle' => 'https://bbs.w7.cc/thread-33162-1-1.html'
  257. ),
  258. 'max_allowed_packet' => array(
  259. 'operate' => 'system_check_mysql_params',
  260. 'description' => 'mysql max_allowed_packet 值',
  261. 'error_message' => 'max_allowed_packet 小于 20M',
  262. 'solution' => '修改 mysql max_allowed_packet 值',
  263. 'handle' => 'https://bbs.w7.cc/thread-33415-1-1.html'
  264. ),
  265. 'always_populate_raw_post_data' => array(
  266. 'operate' => 'system_check_php_raw_post_data',
  267. 'description' => 'php always_populate_raw_post_data 配置',
  268. 'error_message' => '配置有误',
  269. 'solution' => '修改 php always_populate_raw_post_data 配置为 -1',
  270. 'handle' => 'https://bbs.w7.cc/thread-33148-1-1.html'
  271. ),
  272. );
  273. }
  274. function system_check_php_ext($extension) {
  275. return extension_loaded($extension) ? true : false;
  276. }
  277. function system_check_mysql_params($param) {
  278. $check_result = pdo_fetchall("SHOW GLOBAL VARIABLES LIKE '{$param}'");
  279. return $check_result[0]['Value'] < 1024*1024*20 ? false : true;
  280. }
  281. function system_check_template() {
  282. global $_W;
  283. $current_template = $_W['template'];
  284. $template_ch_name = system_template_ch_name();
  285. return in_array($current_template, array_keys($template_ch_name)) ? true : false;
  286. }
  287. function system_check_php_raw_post_data() {
  288. if (version_compare(PHP_VERSION, '7.0.0') == -1 && version_compare(PHP_VERSION, '5.6.0') >= 0) {
  289. return @ini_get('always_populate_raw_post_data') == '-1';
  290. }
  291. return true;
  292. }
  293. function system_setting_items() {
  294. $items = array(
  295. 'bind',
  296. 'develop_status',
  297. 'icp',
  298. 'login_type',
  299. 'log_status',
  300. 'mobile_status',
  301. 'reason',
  302. 'status',
  303. 'welcome_link',
  304. );
  305. $more_items = array(
  306. 'address',
  307. 'blogo',
  308. 'baidumap',
  309. 'background_img',
  310. 'company',
  311. 'companyprofile',
  312. 'description',
  313. 'email',
  314. 'footerleft',
  315. 'footerright',
  316. 'flogo',
  317. 'icon',
  318. 'keywords',
  319. 'leftmenufixed',
  320. 'notice',
  321. 'oauth_bind',
  322. 'phone',
  323. 'person',
  324. 'qq',
  325. 'statcode',
  326. 'slides',
  327. 'showhomepage',
  328. 'sitename',
  329. 'template',
  330. 'url',
  331. 'verifycode',
  332. 'slide_logo',
  333. 'sms_name',
  334. 'sms_password',
  335. 'sms_sign',
  336. );
  337. $items = array_merge($items, $more_items);
  338. return $items;
  339. }
  340. function system_scrap_file() {
  341. $scrap_file = array(
  342. '/framework/builtin/basic/template/display.html',
  343. '/framework/builtin/basic/module.php',
  344. '/framework/builtin/chats/template/display.html',
  345. '/framework/builtin/custom/template/display.html',
  346. '/framework/builtin/custom/module.php',
  347. '/framework/builtin/images/template/form.html',
  348. '/framework/builtin/images/template/modules.css',
  349. '/framework/builtin/images/module.php',
  350. '/framework/builtin/music/template/form.html',
  351. '/framework/builtin/music/template/modules.css',
  352. '/framework/builtin/music/module.php',
  353. '/framework/builtin/news/template/display.html',
  354. '/framework/builtin/news/module.php',
  355. '/framework/builtin/video/template/form.html',
  356. '/framework/builtin/video/template/modules.css',
  357. '/framework/builtin/video/module.php',
  358. '/framework/builtin/voice/template/form.html',
  359. '/framework/builtin/voice/template/modules.css',
  360. '/framework/builtin/voice/module.php',
  361. '/framework/class/account.class.php',
  362. '/framework/class/agent.class.php',
  363. '/framework/class/ali.pay.class.php',
  364. '/framework/class/webapp.account.class.php',
  365. '/framework/class/weixin.account.class.php',
  366. '/framework/class/weixin.nativepay.php',
  367. '/framework/class/weixin.platform.class.php',
  368. '/framework/class/weixin.pay.class.php',
  369. '/framework/class/wxapp.account.class.php',
  370. '/framework/class/yixin.account.class.php',
  371. '/framework/class/pay.class.php',
  372. '/framework/module/frame.mod.php',
  373. '/framework/module/platform.mod.php',
  374. '/web/source/phoneapp/version.ctrl.php',
  375. '/web/themes/2.0/common/footer-base.html',
  376. '/web/themes/black/common/footer-base.html',
  377. '/web/themes/black/common/footer.html',
  378. '/web/themes/classical/common/footer-base.html',
  379. '/web/themes/default/account/manage-sms-wxapp.html',
  380. '/web/themes/default/phoneapp/version-home.html',
  381. );
  382. return $scrap_file;
  383. }