system.mod.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  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 $w7_system_menu;
  9. require_once IA_ROOT . '/web/common/frames.inc.php';
  10. return $w7_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 = $_W['isadmin'];
  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. }
  45. return $shortcut_menu;
  46. }
  47. function system_menu_permission_list($role = '') {
  48. global $_W;
  49. $system_menu = cache_load(cache_system_key('system_frame', array('uniacid' => $_W['uniacid'])));
  50. if (empty($system_menu)) {
  51. cache_build_frame_menu();
  52. $system_menu = cache_load(cache_system_key('system_frame', array('uniacid' => $_W['uniacid'])));
  53. }
  54. if ($role == ACCOUNT_MANAGE_NAME_OPERATOR) {
  55. unset($system_menu['appmarket']);
  56. unset($system_menu['system']);
  57. }
  58. return $system_menu;
  59. }
  60. function system_database_backup() {
  61. $path = IA_ROOT . '/data/backup/';
  62. load()->func('file');
  63. $reduction = array();
  64. if (!is_dir($path)) {
  65. return array();
  66. }
  67. if ($handle = opendir($path)) {
  68. while (false !== ($bakdir = readdir($handle))) {
  69. if ($bakdir == '.' || $bakdir == '..') {
  70. continue;
  71. }
  72. $times[$bakdir] = date("Y-m-d H:i:s", filemtime($path . $bakdir));
  73. if (preg_match('/^(?P<time>\d{10})_[a-z\d]{8}$/i', $bakdir, $match)) {
  74. $time = $match['time'];
  75. $volume_prefix = '';
  76. if ($handle1 = opendir($path . $bakdir)) {
  77. while (false !== ($filename = readdir($handle1))) {
  78. if ($filename == '.' || $filename == '..') {
  79. continue;
  80. }
  81. if (preg_match('/^volume-(?P<prefix>[a-z\d]{32})-\d{1,}\.sql$/i', $filename, $match1)) {
  82. $volume_prefix = $match1['prefix'];
  83. if (!empty($volume_prefix)) {
  84. break;
  85. }
  86. }
  87. }
  88. }
  89. $volume_list = array();
  90. for ($i = 1;;) {
  91. $last = $path . $bakdir . "/volume-{$volume_prefix}-{$i}.sql";
  92. array_push($volume_list, $last);
  93. $i++;
  94. $next = $path . $bakdir . "/volume-{$volume_prefix}-{$i}.sql";
  95. if (!is_file($next)) {
  96. break;
  97. }
  98. }
  99. if (is_file($last)) {
  100. $fp = fopen($last, 'r');
  101. fseek($fp, -27, SEEK_END);
  102. $end = fgets($fp);
  103. fclose($fp);
  104. if ($end == '----WeEngine MySQL Dump End') {
  105. $row = array(
  106. 'bakdir' => $bakdir,
  107. 'time' => $time,
  108. 'volume' => $i - 1,
  109. 'volume_list' => $volume_list,
  110. );
  111. $reduction[$bakdir] = $row;
  112. continue;
  113. }
  114. }
  115. }
  116. rmdirs($path . $bakdir);
  117. }
  118. closedir($handle);
  119. }
  120. if (!empty($times)) {
  121. array_multisort($times, SORT_DESC, SORT_STRING, $reduction);
  122. }
  123. return $reduction;
  124. }
  125. function system_database_volume_next($volume_name) {
  126. $next_volume_name = '';
  127. if (!empty($volume_name) && preg_match('/^([^\s]*volume-(?P<prefix>[a-z\d]{10})-)(\d{1,})\.sql$/i', $volume_name, $match)) {
  128. $next_volume_name = $match[1] . ($match[3] + 1) . ".sql";
  129. }
  130. return $next_volume_name;
  131. }
  132. function system_database_volume_restore($volume_name) {
  133. if (empty($volume_name) || !is_file($volume_name)) {
  134. return false;
  135. }
  136. $sql = file_get_contents($volume_name);
  137. pdo_run($sql);
  138. return true;
  139. }
  140. function system_database_backup_delete($delete_dirname) {
  141. $path = IA_ROOT . '/data/backup/';
  142. $dir = $path . $delete_dirname;
  143. if (empty($delete_dirname) || !is_dir($dir)) {
  144. return false;
  145. }
  146. return rmdirs($dir);
  147. }
  148. function system_template_ch_name() {
  149. $result = array(
  150. 'default' => '白色',
  151. 'black' => '黑色',
  152. 'classical' => '经典',
  153. '2.0' => '2.0',
  154. );
  155. return $result;
  156. }
  157. function system_login_template_ch_name() {
  158. $result = array(
  159. 'half-auto' => '兼容版',
  160. 'big' => '大图版',
  161. 'half' => '半屏图版',
  162. 'base' => '基础版'
  163. );
  164. return $result;
  165. }
  166. function system_check_statcode($statcode) {
  167. $allowed_stats = array(
  168. 'baidu' => array(
  169. 'enabled' => true,
  170. 'reg' => '/(http[s]?\:)?\/\/hm\.baidu\.com\/hm\.js\?/'
  171. ),
  172. 'qq' => array(
  173. 'enabled' => true,
  174. 'reg' => '/(http[s]?\:)?\/\/tajs\.qq\.com/'
  175. ),
  176. );
  177. foreach ($allowed_stats as $key => $item) {
  178. $preg = preg_match($item['reg'], $statcode);
  179. if (!$preg && !$item['enabled']) {
  180. continue;
  181. } else {
  182. return htmlspecialchars_decode($statcode);
  183. }
  184. return safe_gpc_html(htmlspecialchars_decode($statcode, ENT_QUOTES));
  185. }
  186. }
  187. function system_check_items() {
  188. return array(
  189. 'mbstring' => array(
  190. 'operate' => 'system_check_php_ext',
  191. 'description' => 'mbstring 扩展',
  192. 'error_message' => '不支持库',
  193. 'solution' => '安装 mbstring 扩展',
  194. 'handle' => 'http://s.w7.cc/wo/problem/46'
  195. ),
  196. 'mcrypt' => array(
  197. 'operate' => 'system_check_php_ext',
  198. 'description' => 'mcrypt 扩展',
  199. 'error_message' => '不支持库',
  200. 'solution' => '安装 mcrypt 扩展',
  201. 'handle' => 'http://s.w7.cc/wo/problem/46'
  202. ),
  203. 'zip' => array(
  204. 'operate' => 'system_check_php_ext',
  205. 'description' => 'zip 扩展',
  206. 'error_message' => '不支持库',
  207. 'solution' => '安装 zip 扩展',
  208. 'handle' => 'http://s.w7.cc/wo/problem/46'
  209. ),
  210. 'openssl' => array(
  211. 'operate' => 'system_check_php_ext',
  212. 'description' => 'openssl 扩展',
  213. 'error_message' => '不支持库',
  214. 'solution' => '安装 openssl 扩展',
  215. 'handle' => 'http://s.w7.cc/wo/problem/46'
  216. ),
  217. 'system_template' => array(
  218. 'operate' => 'system_check_template',
  219. 'description' => '是否系统皮肤',
  220. 'error_message' => '不是系统皮肤',
  221. 'solution' => '更换系统默认皮肤',
  222. 'handle' => 'https://bbs.w7.cc/thread-33162-1-1.html'
  223. ),
  224. 'max_allowed_packet' => array(
  225. 'operate' => 'system_check_mysql_params',
  226. 'description' => 'mysql max_allowed_packet 值',
  227. 'error_message' => 'max_allowed_packet 小于 20M',
  228. 'solution' => '修改 mysql max_allowed_packet 值',
  229. 'handle' => 'https://bbs.w7.cc/thread-33415-1-1.html'
  230. ),
  231. 'always_populate_raw_post_data' => array(
  232. 'operate' => 'system_check_php_raw_post_data',
  233. 'description' => 'php always_populate_raw_post_data 配置',
  234. 'error_message' => '配置有误',
  235. 'solution' => '修改 php always_populate_raw_post_data 配置为 -1',
  236. 'handle' => 'https://s.w7.cc/wo/problem/134'
  237. ),
  238. 'https' => array(
  239. 'operate' => 'system_check_site_https',
  240. 'description' => '授权域名是否https',
  241. 'error_message' => '授权域名非https',
  242. 'solution' => '联系微擎客服更改',
  243. 'handle' => 'https://task.w7.com/taskrelease?type_id=10&team_id=1'
  244. ),
  245. );
  246. }
  247. function system_check_site_https() {
  248. global $_W;
  249. return 0 === strpos($_W['setting']['site']['url'], 'https');
  250. }
  251. function system_check_php_ext($extension) {
  252. return extension_loaded($extension) ? true : false;
  253. }
  254. function system_check_mysql_params($param) {
  255. $check_result = pdo_fetchall("SHOW GLOBAL VARIABLES LIKE '{$param}'");
  256. return $check_result[0]['Value'] < 1024 * 1024 * 20 ? false : true;
  257. }
  258. function system_check_template() {
  259. global $_W;
  260. $current_template = $_W['template'];
  261. $template_ch_name = system_template_ch_name();
  262. return in_array($current_template, array_keys($template_ch_name)) ? true : false;
  263. }
  264. function system_check_php_raw_post_data() {
  265. if (version_compare(PHP_VERSION, '7.0.0') == -1 && version_compare(PHP_VERSION, '5.6.0') >= 0) {
  266. return @ini_get('always_populate_raw_post_data') == '-1';
  267. }
  268. return true;
  269. }
  270. function system_setting_items() {
  271. return array(
  272. 'bind',
  273. 'icp',
  274. 'policeicp',
  275. 'login_type',
  276. 'log_status',
  277. 'mobile_status',
  278. 'reason',
  279. 'status',
  280. 'old_user_guide_status',
  281. 'welcome_link',
  282. 'blogo',
  283. 'background_img',
  284. 'company',
  285. 'description',
  286. 'footerleft',
  287. 'footerright',
  288. 'flogo',
  289. 'keywords',
  290. 'leftmenufixed',
  291. 'oauth_bind',
  292. 'statcode',
  293. 'sitename',
  294. 'template',
  295. 'login_template',
  296. 'url',
  297. 'verifycode',
  298. );
  299. }
  300. function system_scrap_file() {
  301. $scrap_file = array(
  302. '/framework/builtin/basic/template/display.html',
  303. '/framework/builtin/basic/module.php',
  304. '/framework/builtin/chats/template/display.html',
  305. '/framework/builtin/custom/template/display.html',
  306. '/framework/builtin/custom/module.php',
  307. '/framework/builtin/images/template/form.html',
  308. '/framework/builtin/images/template/modules.css',
  309. '/framework/builtin/images/module.php',
  310. '/framework/builtin/music/template/form.html',
  311. '/framework/builtin/music/template/modules.css',
  312. '/framework/builtin/music/module.php',
  313. '/framework/builtin/news/template/display.html',
  314. '/framework/builtin/news/module.php',
  315. '/framework/builtin/video/template/form.html',
  316. '/framework/builtin/video/template/modules.css',
  317. '/framework/builtin/video/module.php',
  318. '/framework/builtin/voice/template/form.html',
  319. '/framework/builtin/voice/template/modules.css',
  320. '/framework/builtin/voice/module.php',
  321. '/framework/class/account.class.php',
  322. '/framework/class/agent.class.php',
  323. '/framework/class/ali.pay.class.php',
  324. '/framework/class/webapp.account.class.php',
  325. '/framework/class/weixin.account.class.php',
  326. '/framework/class/weixin.nativepay.php',
  327. '/framework/class/weixin.platform.class.php',
  328. '/framework/class/weixin.pay.class.php',
  329. '/framework/class/wxapp.account.class.php',
  330. '/framework/class/yixin.account.class.php',
  331. '/framework/class/pay.class.php',
  332. '/framework/table/account.table.php',
  333. '/framework/table/job.table.php',
  334. '/framework/table/menu.table.php',
  335. '/framework/module/app.mod.php',
  336. '/framework/module/frame.mod.php',
  337. '/framework/module/platform.mod.php',
  338. '/web/source/phoneapp/version.ctrl.php',
  339. '/web/source/system/template.ctrl.php',
  340. '/web/themes/2.0/common/footer-base.html',
  341. '/web/themes/black/common/footer-base.html',
  342. '/web/themes/black/common/footer.html',
  343. '/web/themes/classical/common/footer-base.html',
  344. '/web/themes/default/account/manage-sms-wxapp.html',
  345. '/web/themes/default/account/manage-base-aliapp.html',
  346. '/web/themes/default/account/manage-base-baiduapp.html',
  347. '/web/themes/default/account/manage-base-phoneapp.html',
  348. '/web/themes/default/account/manage-base-toutiaoapp.html',
  349. '/web/themes/default/account/manage-base-webapp.html',
  350. '/web/themes/default/account/manage-base-wxapp.html',
  351. '/web/themes/default/phoneapp/version-home.html',
  352. );
  353. return $scrap_file;
  354. }
  355. function system_star_menu() {
  356. global $_W;
  357. $result = array(
  358. 'platform' => array(
  359. 'title' => '所有平台',
  360. 'icon' => 'wi wi-platform',
  361. 'apiurl' => url('account/display/list', array('type' => 'all')),
  362. 'one_page' => 0,
  363. 'hide_sort' => 0,
  364. ),
  365. 'modules' => array(
  366. 'title' => '所有应用',
  367. 'icon' => 'wi wi-apply',
  368. 'apiurl' => url('module/display/own'),
  369. 'one_page' => 0,
  370. 'hide_sort' => 1,
  371. ),
  372. 'system_welcome_modules' => array(
  373. 'title' => '首页应用',
  374. 'icon' => 'wi wi-apply',
  375. 'apiurl' => url('module/display/system_welcome'),
  376. 'one_page' => 0,
  377. 'hide_sort' => 1,
  378. ),
  379. 'platform_children' => array(
  380. 'title' => '平台分类',
  381. 'menu' => array(),
  382. ),
  383. );
  384. if (!in_array(IMS_FAMILY, array('s', 'x'))) {
  385. unset($result['system_welcome_modules']);
  386. }
  387. $account_all = table('account')->searchAccountList();
  388. $result['platform']['num'] = max(0, count($account_all));
  389. if ($result['platform']['num'] == 0) {
  390. unset($result['platform']['num']);
  391. }
  392. foreach (uni_account_type_sign() as $type_sign => $type_sign_info) {
  393. $account_num = uni_user_accounts($_W['uid'], $type_sign);
  394. $result['platform_children']['menu'][$type_sign] = array(
  395. 'title' => $type_sign_info['title'],
  396. 'icon' => $type_sign_info['icon'],
  397. 'num' => max(0, count($account_num)),
  398. 'apiurl' => url('account/display/list', array('type' => $type_sign)),
  399. 'one_page' => 0,
  400. 'hide_sort' => 0,
  401. );
  402. }
  403. return $result;
  404. }