cloud.mod.php 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468
  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. $_URLTYPE = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
  8. define('CLOUD_GATEWAY_URL', $_URLTYPE.$_SERVER['HTTP_HOST']);
  9. define('CLOUD_GATEWAY_URL_NORMAL', $_URLTYPE.$_SERVER['HTTP_HOST']);
  10. function cloud_client_define() {
  11. return array(
  12. '/framework/function/communication.func.php',
  13. '/framework/model/cloud.mod.php',
  14. '/web/source/cloud/upgrade.ctrl.php',
  15. '/web/source/cloud/process.ctrl.php',
  16. '/web/source/cloud/dock.ctrl.php',
  17. '/web/themes/default/cloud/upgrade.html',
  18. '/web/themes/default/cloud/process.html'
  19. );
  20. }
  21. function _cloud_build_params($must_authorization_host = true) {
  22. global $_W;
  23. $pars = array();
  24. $pars['host'] = strexists($_SERVER['HTTP_HOST'], ':') ? parse_url($_SERVER['HTTP_HOST'], PHP_URL_HOST) : $_SERVER['HTTP_HOST'];
  25. if (is_array($_W['setting']['site']) && !empty($_W['setting']['site']['url']) && !$must_authorization_host) {
  26. $pars['host'] = parse_url($_W['setting']['site']['url'], PHP_URL_HOST);
  27. }
  28. $pars['https'] = $_W['ishttps'] ? true : false;
  29. $pars['family'] = IMS_FAMILY;
  30. $pars['version'] = IMS_VERSION;
  31. $pars['php_version'] = PHP_VERSION;
  32. $pars['current_host'] = $_SERVER['HTTP_HOST'];
  33. $pars['release'] = IMS_RELEASE_DATE;
  34. if (!empty($_W['setting']['site'])) {
  35. $pars['key'] = $_W['setting']['site']['key'];
  36. $pars['password'] = md5($_W['setting']['site']['key'] . $_W['setting']['site']['token']);
  37. }
  38. $clients = cloud_client_define();
  39. $string = '';
  40. foreach($clients as $cli) {
  41. $string .= md5_file(IA_ROOT . $cli);
  42. }
  43. $pars['client'] = md5($string);
  44. return $pars;
  45. }
  46. function _cloud_shipping_parse($dat, $file) {
  47. if (is_error($dat)) {
  48. return error(-1, '网络传输错误, 请检查您的cURL是否可用, 或者服务器网络是否正常. ' . $dat['message']);
  49. }
  50. $tmp = iunserializer($dat['content']);
  51. if (is_array($tmp) && is_error($tmp)) {
  52. if ($tmp['errno'] == '-2') {
  53. $data = file_get_contents(IA_ROOT . '/framework/version.inc.php');
  54. file_put_contents(IA_ROOT . '/framework/version.inc.php', str_replace("'x'", "'v'", $data));
  55. }
  56. return $tmp;
  57. }
  58. if ($dat['content'] == 'patching') {
  59. return error(-1, '补丁程序正在更新中,请稍后再试!');
  60. }
  61. if ($dat['content'] == 'frequent') {
  62. return error(-1, '更新操作太频繁,请稍后再试!');
  63. }
  64. if ($dat['content'] == 'blacklist') {
  65. return error(-1, '抱歉,您的站点已被列入云服务黑名单,云服务一切业务已被禁止,请联系微擎客服!');
  66. }
  67. /*
  68. $content = json_decode($dat['content'], true);
  69. if (!empty($content['error'])) {
  70. return error(-1, $content['error']);
  71. }
  72. if (!empty($content) && is_array($content)) {
  73. return $content;
  74. }
  75. if (strlen($dat['content']) != 32) {
  76. $dat['content'] = iunserializer($dat['content']);
  77. if (is_array($dat['content']) && isset($dat['content']['files'])) {
  78. if (!empty($dat['content']['manifest'])) {
  79. $dat['content']['manifest'] = base64_decode($dat['content']['manifest']);
  80. }
  81. if (!empty($dat['content']['scripts'])) {
  82. $dat['content']['scripts'] = base64_decode($dat['content']['scripts']);
  83. }
  84. return $dat['content'];
  85. }
  86. return error(-1, '云服务平台向您的服务器传输数据过程中出现错误, 这个错误可能是由于您的通信密钥和云服务不一致, 请尝试诊断云服务参数(重置站点ID和通信密钥). 传输原始数据:' . $dat['meta']);
  87. }
  88. $data = @file_get_contents($file);
  89. if (empty($data)) {
  90. return error(-1, '没有接收到服务器的传输的数据.');
  91. }
  92. @unlink($file);
  93. $ret = @iunserializer($data);
  94. if (empty($data) || empty($ret) || $dat['content'] != $ret['secret']) {
  95. return error(-1, '云服务平台向您的服务器传输的数据校验失败, 可能是因为您的网络不稳定, 或网络不安全, 请稍后重试.');
  96. }
  97. $ret = iunserializer($ret['data']);
  98. if (is_array($ret) && is_error($ret)) {
  99. if ($ret['errno'] == '-2') {
  100. $data = file_get_contents(IA_ROOT . '/framework/version.inc.php');
  101. file_put_contents(IA_ROOT . '/framework/version.inc.php', str_replace("'x'", "'v'", $data));
  102. }
  103. if ($ret['errno'] == '-3') { return array(
  104. 'errno' => $ret['errno'],
  105. 'message' => $ret['message'],
  106. 'cloud_id' => $ret['data'],
  107. );
  108. }
  109. }
  110. if (!is_error($ret) && is_array($ret) && !empty($ret)) {
  111. if ($ret['state'] == 'fatal') {
  112. return error($ret['errorno'], '发生错误: ' . $ret['message']);
  113. }
  114. return $ret;
  115. } else {
  116. return error($ret['errno'], "发生错误: {$ret['message']}");
  117. }*/
  118. return array();
  119. }
  120. function cloud_request($url, $post = '', $extra = array(), $timeout = 60) {
  121. global $_W;
  122. load()->func('communication');
  123. if (!empty($_W['setting']['cloudip']['ip']) && empty($extra['ip'])) {
  124. // $extra['ip'] = $_W['setting']['cloudip']['ip'];
  125. $extra['ip'] = $_SERVER['HTTP_HOST'];
  126. }
  127. /* if (strexists($url, 's.we7.cc')) {
  128. $extra = array();
  129. }
  130. $response = ihttp_request($url, $post, $extra, $timeout);
  131. if (is_error($response)) {
  132. setting_save(array(), 'cloudip');
  133. }
  134. return $response;
  135. */
  136. return array();
  137. }
  138. function cloud_api($method, $data = array(), $extra = array(), $timeout = 60) {
  139. /* $cache_key = cache_system_key($method);
  140. $cache = cache_load($cache_key);
  141. if (!empty($cache) && $cache['expire'] > time() && $method != 'module/query') {
  142. return $cache;
  143. }
  144. $api_url = 'http://api.w7.cc/%s';
  145. $pars = _cloud_build_params();
  146. $pars['token'] = cloud_build_transtoken();
  147. $data = array_merge($pars, $data);
  148. if ($GLOBALS['_W']['config']['setting']['development'] == 3) {
  149. $extra['CURLOPT_USERAGENT'] = 'development';
  150. }
  151. $response = ihttp_request(sprintf($api_url, $method), $data, $extra, $timeout);
  152. $file = IA_ROOT . '/data/' . (!empty($data['method']) ? $data['method'] : $method);
  153. $ret = _cloud_shipping_parse($response, $file);
  154. cache_write($cache_key, $ret, 300);
  155. return $ret;
  156. */
  157. return null;
  158. }
  159. function cloud_api_request($method, $data = array(), $extra = array(), $timeout = 60) {
  160. load()->func('communication');
  161. // $api_url = 'http://api.w7.cc/%s';
  162. $api_url = CLOUD_GATEWAY_URL;
  163. $pars = _cloud_build_params();
  164. $data = array_merge($pars, $data);
  165. $response = ihttp_request(sprintf($api_url, $method), $data, $extra, $timeout);
  166. $result = _cloud_response_parse($response);
  167. return $result;
  168. }
  169. function cloud_prepare() {
  170. global $_W;
  171. setting_load();
  172. /* if(empty($_W['setting']['site']['key']) || empty($_W['setting']['site']['token'])) {
  173. return error('-1', '站点注册信息丢失, 请通过"重置站点ID和通信密钥"重新获取 !');
  174. }
  175. */
  176. return true;
  177. }
  178. function cloud_build(){
  179. /*
  180. $pars = _cloud_build_params();
  181. $pars['method'] = 'application.build4';
  182. $dat = cloud_request('http://api-upgrade.w7.cc/gateway.php', $pars);
  183. $file = IA_ROOT . '/data/application.build';
  184. $ret = _cloud_shipping_parse($dat, $file);
  185. if (is_error($ret)) {
  186. return $ret;
  187. }
  188. if($ret['state'] == 'warning') {
  189. $ret['files'] = cloud_client_define();
  190. unset($ret['schemas']);
  191. unset($ret['scripts']);
  192. } else {
  193. $patch_path = sprintf('%s/data/patch/upgrade/%s', IA_ROOT, date('Ymd'));
  194. if (!is_dir($patch_path)) {
  195. mkdirs($patch_path);
  196. }
  197. $files = $files_allowed = array();
  198. if(!empty($ret['files'])) {
  199. foreach($ret['files'] as $file) {
  200. $entry = IA_ROOT . $file['path'];
  201. if(!is_file($entry) || md5_file($entry) != $file['checksum']) {
  202. $files_allowed[] = $file['path'];
  203. }
  204. $entry = $patch_path . $file['path'];
  205. if (!is_file($entry)) {
  206. $entry = IA_ROOT . $file['path'];
  207. }
  208. if(!is_file($entry) || md5_file($entry) != $file['checksum']) {
  209. $files[] = $file['path'];
  210. }
  211. }
  212. }
  213. $ret['files'] = $files;
  214. if (!empty($ret['files'])) {
  215. cloud_bakup_files($ret['files']);
  216. } else {
  217. if (!empty($files_allowed)) {
  218. foreach ($files_allowed as $file) {
  219. $dir = pathinfo(IA_ROOT . $file, PATHINFO_DIRNAME);
  220. if (!is_dir($dir)) {
  221. mkdirs($dir);
  222. }
  223. file_put_contents(IA_ROOT . $file, file_get_contents($patch_path . $file));
  224. }
  225. rmdirs($patch_path);
  226. }
  227. }
  228. $schemas = array();
  229. if(!empty($ret['schemas'])) {
  230. load()->func('db');
  231. foreach($ret['schemas'] as $remote) {
  232. $name = substr($remote['tablename'], 4);
  233. $local = db_table_schema(pdo(), $name);
  234. unset($remote['increment']);
  235. unset($local['increment']);
  236. if(empty($local)) {
  237. $schemas[] = $remote;
  238. } else {
  239. $sqls = db_table_fix_sql($local, $remote);
  240. if(!empty($sqls)) {
  241. $schemas[] = $remote;
  242. }
  243. }
  244. }
  245. }
  246. $ret['schemas'] = $schemas;
  247. }
  248. if (IMS_FAMILY != $ret['family']) {
  249. $update_version_success = setting_upgrade_version($ret['family'], IMS_VERSION, IMS_RELEASE_DATE);
  250. if (empty($update_version_success)) {
  251. message('切换版本失败,请修改 /framework/version.inc.php 文件权限为 User 可写或是 777', 'refresh', 'error');
  252. } else {
  253. message('更新系统正在为您自动切换版本', 'refresh');
  254. }
  255. }
  256. $ret['upgrade'] = false;
  257. if(!empty($ret['files']) || !empty($ret['schemas']) || !empty($ret['scripts'])) {
  258. $ret['upgrade'] = true;
  259. }
  260. $upgrade = array();
  261. $upgrade['upgrade'] = $ret['upgrade'];
  262. $upgrade['data'] = $ret;
  263. $upgrade['lastupdate'] = TIMESTAMP;
  264. cache_write(cache_system_key('upgrade'), $upgrade);
  265. cache_write(cache_system_key('cloud_transtoken'), authcode($ret['token'], 'ENCODE'));
  266. return $ret;
  267. */
  268. return null;
  269. }
  270. function cloud_schema() {
  271. $pars = _cloud_build_params();
  272. $pars['method'] = 'application.schema';
  273. $_URLTYPE = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
  274. $dat = cloud_request($_URLTYPE.$_SERVER['HTTP_HOST'], $pars);
  275. $file = IA_ROOT . '/data/application.schema';
  276. $ret = _cloud_shipping_parse($dat, $file);
  277. if(!is_error($ret)) {
  278. $schemas = array();
  279. if(!empty($ret['schemas'])) {
  280. load()->func('db');
  281. foreach($ret['schemas'] as $remote) {
  282. $name = substr($remote['tablename'], 4);
  283. $local = db_table_schema(pdo(), $name);
  284. unset($remote['increment']);
  285. unset($local['increment']);
  286. if(empty($local)) {
  287. $schemas[] = $remote;
  288. } else {
  289. $diffs = db_schema_compare($local, $remote);
  290. if(!empty($diffs)) {
  291. $schemas[] = $remote;
  292. }
  293. }
  294. }
  295. }
  296. $ret['schemas'] = $schemas;
  297. }
  298. return $ret;
  299. }
  300. function cloud_download($path, $type = '') {
  301. global $_W;
  302. $pars = _cloud_build_params();
  303. $pars['method'] = 'application.shipping';
  304. $pars['path'] = $path;
  305. $pars['type'] = $type;
  306. $pars['gz'] = function_exists('gzcompress') && function_exists('gzuncompress') ? 'true' : 'false';
  307. $pars['download'] = 'true';
  308. $headers = array('content-type' => 'application/x-www-form-urlencoded');
  309. $_URLTYPE = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
  310. $dat = cloud_request($_URLTYPE.$_SERVER['HTTP_HOST'], $pars, $headers, 300);
  311. if(is_error($dat)) {
  312. return error(-1, '网络存在错误, 请稍后重试。' . $dat['message']);
  313. }
  314. if($dat['content'] == 'success') {
  315. return true;
  316. }
  317. $ret = @json_decode($dat['content'], true);
  318. if (isset($ret['error'])) {
  319. return error(1, $ret['error']);
  320. }
  321. if(is_error($ret)) {
  322. return $ret;
  323. } else {
  324. $post = $dat['content'];
  325. $data = base64_decode($post);
  326. if (base64_encode($data) !== $post) {
  327. $data = $post;
  328. }
  329. $ret = iunserializer($data);
  330. $gz = function_exists('gzcompress') && function_exists('gzuncompress');
  331. $file = base64_decode($ret['file']);
  332. if($gz) {
  333. $file = gzuncompress($file);
  334. }
  335. $_W['setting']['site']['token'] = authcode(cache_load(cache_system_key('cloud_transtoken')), 'DECODE');
  336. $string = (md5($file) . $ret['path'] . $_W['setting']['site']['token']);
  337. if(!empty($_W['setting']['site']['token']) && md5($string) === $ret['sign']) {
  338. $error_file_list = array();
  339. if (!cloud_file_permission_pass($error_file_list)) {
  340. return error(-1, '请修复下列文件读写权限 : ' . implode('; ', $error_file_list));
  341. }
  342. if ($type == 'module' || $type == 'theme') {
  343. $patch_path = IA_ROOT;
  344. } else {
  345. $patch_path = sprintf('%s/data/patch/upgrade/%s', IA_ROOT, date('Ymd'));
  346. }
  347. $path = $patch_path . $ret['path'];
  348. load()->func('file');
  349. @mkdirs(dirname($path));
  350. if (file_put_contents($path, $file)) {
  351. return true;
  352. } else {
  353. return error(-1, '写入失败');
  354. }
  355. }
  356. return error(-1, '写入失败');
  357. }
  358. }
  359. function cloud_m_prepare($name) {
  360. $pars['method'] = 'module.check';
  361. $pars['module'] = $name;
  362. $_URLTYPE = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
  363. $dat = cloud_request($_URLTYPE.$_SERVER['HTTP_HOST'], $pars);
  364. if (is_error($dat)) {
  365. return $dat;
  366. }
  367. if ($dat['content'] == 'install-module-protect') {
  368. // return error('-1', '此模块已设置版权保护,您只能通过云平台来安装。');
  369. }
  370. return true;
  371. }
  372. function cloud_m_build($modulename, $type = ''){
  373. /* $type = in_array($type, array('uninstall')) ? $type : '';
  374. if (empty($modulename)) {
  375. return array();
  376. }
  377. $module = table('modules')->getByName($modulename);
  378. $pars = _cloud_build_params();
  379. $pars['method'] = 'module.build';
  380. $pars['module'] = $modulename;
  381. $pars['type'] = $type;
  382. $pars['token'] = cloud_build_transtoken();
  383. if (!empty($module)) {
  384. $pars['module_version'] = $module['version'];
  385. }
  386. $_URLTYPE = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
  387. $dat = cloud_request($_URLTYPE.$_SERVER['HTTP_HOST'], $pars);
  388. $file = IA_ROOT . '/data/module.build';
  389. $ret = _cloud_shipping_parse($dat, $file);
  390. if (!is_error($ret)) {
  391. $dir = IA_ROOT . '/addons/' . $modulename;
  392. $files = array();
  393. if (!empty($ret['files'])) {
  394. foreach ($ret['files'] as $file) {
  395. $entry = $dir . $file['path'];
  396. if (!is_file($entry) || md5_file($entry) != $file['checksum']) {
  397. $files[] = '/' . $modulename . $file['path'];
  398. }
  399. }
  400. }
  401. $ret['files'] = $files;
  402. $schemas = array();
  403. if (!empty($ret['schemas'])) {
  404. load()->func('db');
  405. foreach ($ret['schemas'] as $remote) {
  406. $name = substr($remote['tablename'], 4);
  407. $local = db_table_schema(pdo() , $name);
  408. unset($remote['increment']);
  409. unset($local['increment']);
  410. if (empty($local)) {
  411. $schemas[] = $remote;
  412. } else {
  413. $diffs = db_table_fix_sql($local, $remote);
  414. if (!empty($diffs)) {
  415. $schemas[] = $remote;
  416. }
  417. }
  418. }
  419. }
  420. $ret['upgrade'] = true;
  421. $ret['type'] = 'module';
  422. $ret['schemas'] = $schemas;
  423. if (empty($module)) {
  424. $ret['install'] = 1;
  425. }
  426. cache_write(cache_system_key('cloud_transtoken'), authcode($ret['token'], 'ENCODE'));
  427. }
  428. return $ret;
  429. */
  430. return null;
  431. }
  432. function cloud_m_query($module = array(), $page = 0) {
  433. $pars['method'] = 'module.query';
  434. if (empty($module)) {
  435. $module = cloud_extra_module();
  436. }
  437. if (!is_array($module)) {
  438. $module = array($module);
  439. }
  440. if (intval($page) > 0) {
  441. $pars['page'] = $page;
  442. }
  443. $pars['module'] = base64_encode(iserializer($module));
  444. $ret = cloud_api('module/query/index', $pars);
  445. if (isset($ret['error'])) {
  446. return error(1, $ret['error']);
  447. }
  448. /* if (!is_error($ret)) {
  449. $pirate_apps = $ret['pirate_apps'];
  450. unset($ret['pirate_apps']);
  451. $support_names = array('app', 'wxapp', 'webapp', 'system_welcome', 'android', 'ios', 'xzapp', 'aliapp', 'baiduapp', 'toutiaoapp');
  452. foreach ($ret['data'] as $modulename => &$info) {
  453. foreach ($support_names as $support) {
  454. if (in_array($support, $info['site_branch']['bought']) && !empty($info['site_branch']["{$support}_support"]) && $info['site_branch']["{$support}_support"] == 2) {
  455. $info['site_branch']["{$support}_support"] = 2;
  456. } else {
  457. $info['site_branch']["{$support}_support"] = 1;
  458. }
  459. }
  460. }
  461. $ret['pirate_apps'] = $pirate_apps;
  462. }
  463. */
  464. return $ret;
  465. }
  466. function cloud_m_bought() {
  467. $pars = _cloud_build_params();
  468. $pars['method'] = 'module.bought';
  469. $_URLTYPE = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
  470. $dat = cloud_request($_URLTYPE.$_SERVER['HTTP_HOST'], $pars);
  471. $file = IA_ROOT . '/data/module.bought';
  472. $ret = _cloud_shipping_parse($dat, $file);
  473. return $ret;
  474. }
  475. function cloud_m_info($name) {
  476. $pars['method'] = 'module.info';
  477. $pars['module'] = $name;
  478. $ret = cloud_api('module/info/index', $pars);
  479. return $ret;
  480. }
  481. function cloud_m_upgradeinfo($modulename) {
  482. load()->model('module');
  483. $module = module_fetch($modulename);
  484. $pars = _cloud_build_params();
  485. $pars['method'] = 'module.info';
  486. $pars['module'] = $modulename;
  487. $pars['curversion'] = $module['version'];
  488. $pars['isupgrade'] = 1;
  489. $_URLTYPE = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
  490. $dat = cloud_request($_URLTYPE.$_SERVER['HTTP_HOST'], $pars);
  491. $file = IA_ROOT . '/data/module.info';
  492. $ret = _cloud_shipping_parse($dat, $file);
  493. if (empty($ret)) {
  494. return array();
  495. }
  496. if (is_error($ret)) {
  497. return $ret;
  498. }
  499. if (version_compare($ret['version']['version'], $module['version'], '>')) {
  500. $ret['upgrade'] = true;
  501. }
  502. $ret['site_branch'] = $ret['branches'][$ret['version']['branch_id']];
  503. $ret['from'] = 'cloud';
  504. foreach ($ret['branches'] as &$branch) {
  505. if ($branch['displayorder'] > $ret['site_branch']['displayorder'] || ($branch['displayorder'] == $ret['site_branch']['displayorder'] && $ret['site_branch']['id'] < intval($branch['id']))) {
  506. $ret['new_branch'] = true;
  507. }
  508. $branch['id'] = intval($branch['id']);
  509. $branch['version']['description'] = preg_replace('/\n/', '<br/>', $branch['version']['description']);
  510. $branch['displayorder'] = intval($branch['displayorder']);
  511. $branch['day'] = intval(date('d', $branch['version']['createtime']));
  512. $branch['month'] = date('Y.m', $branch['version']['createtime']);
  513. $branch['hour'] = date('H:i', $branch['version']['createtime']);
  514. }
  515. unset($branch);
  516. return $ret;
  517. }
  518. function cloud_t_prepare($name){
  519. /* $pars['method'] = 'theme.check';
  520. $pars['theme'] = $name;
  521. $dat = cloud_request('http://api-upgrade.w7.cc/gateway.php', $pars);
  522. if (is_error($dat)) {
  523. return $dat;
  524. }
  525. if ($dat['content'] == 'install-theme-protect') {
  526. return error('-1', '此模板已设置版权保护,您只能通过云平台来安装。');
  527. }
  528. */
  529. return true;
  530. }
  531. function cloud_t_query(){
  532. /* $pars = _cloud_build_params();
  533. $pars['method'] = 'theme.query';
  534. $pars['theme'] = cloud_extra_theme();
  535. $dat = cloud_request('http://api-upgrade.w7.cc/gateway.php', $pars);
  536. $file = IA_ROOT . '/data/theme.query';
  537. $ret = _cloud_shipping_parse($dat, $file);
  538. return $ret;
  539. */
  540. return null;
  541. }
  542. function cloud_t_info($name){
  543. /* $pars = _cloud_build_params();
  544. $pars['method'] = 'theme.info';
  545. $pars['theme'] = $name;
  546. $dat = cloud_request('http://api-upgrade.w7.cc/gateway.php', $pars);
  547. $file = IA_ROOT . '/data/theme.info';
  548. $ret = _cloud_shipping_parse($dat, $file);
  549. return $ret;
  550. */
  551. return null;
  552. }
  553. function cloud_t_build($name) {
  554. if (empty($name)) {
  555. return array();
  556. }
  557. $theme = table('site_templates')->getByName(trim($name));
  558. $pars = _cloud_build_params();
  559. $pars['method'] = 'theme.build';
  560. $pars['theme'] = $name;
  561. if(!empty($theme)) {
  562. $pars['themeversion'] = $theme['version'];
  563. }
  564. $_URLTYPE = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
  565. $dat = cloud_request($_URLTYPE.$_SERVER['HTTP_HOST'], $pars);
  566. $file = IA_ROOT . '/data/theme.build';
  567. $ret = _cloud_shipping_parse($dat, $file);
  568. if(!is_error($ret)) {
  569. $dir = IA_ROOT . '/app/themes/' . $name;
  570. $files = array();
  571. if(!empty($ret['files'])) {
  572. foreach($ret['files'] as $file) {
  573. $entry = $dir . $file['path'];
  574. if(!is_file($entry) || md5_file($entry) != $file['checksum']) {
  575. $files[] = '/'. $name . $file['path'];
  576. }
  577. }
  578. }
  579. $ret['files'] = $files;
  580. $ret['upgrade'] = true;
  581. $ret['type'] = 'theme';
  582. if(empty($theme)) {
  583. $ret['install'] = 1;
  584. }
  585. cache_write(cache_system_key('cloud_transtoken'), authcode($ret['token'], 'ENCODE'));
  586. }
  587. return $ret;
  588. }
  589. function cloud_t_upgradeinfo($name) {
  590. if (empty($name)) {
  591. return array();
  592. }
  593. $theme = table('site_templates')->getByName(trim($name));
  594. $pars = _cloud_build_params();
  595. $pars['method'] = 'theme.upgrade';
  596. $pars['theme'] = $theme['name'];
  597. $pars['version'] = $theme['version'];
  598. $pars['isupgrade'] = 1;
  599. $_URLTYPE = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
  600. $dat = cloud_request($_URLTYPE.$_SERVER['HTTP_HOST'], $pars);
  601. $file = IA_ROOT . '/data/module.info';
  602. $ret = _cloud_shipping_parse($dat, $file);
  603. return $ret;
  604. }
  605. function cloud_w_prepare($name) {
  606. $pars['method'] = 'webtheme.check';
  607. $pars['webtheme'] = $name;
  608. $_URLTYPE = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
  609. $dat = cloud_request($_URLTYPE.$_SERVER['HTTP_HOST'], $pars);
  610. if (is_error($dat)) {
  611. return $dat;
  612. }
  613. if ($dat['content'] == 'install-webtheme-protect') {
  614. return error('-1', '此后台皮肤已设置版权保护,您只能通过云平台来安装。');
  615. }
  616. return true;
  617. }
  618. function cloud_w_query() {
  619. $pars = _cloud_build_params();
  620. $pars['method'] = 'webtheme.query';
  621. $pars['webtheme'] = cloud_extra_webtheme();
  622. $_URLTYPE = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
  623. $dat = cloud_request($_URLTYPE.$_SERVER['HTTP_HOST'], $pars);
  624. $file = IA_ROOT . '/data/webtheme.query';
  625. $ret = _cloud_shipping_parse($dat, $file);
  626. return $ret;
  627. }
  628. function cloud_w_info($name) {
  629. $pars = _cloud_build_params();
  630. $pars['method'] = 'webtheme.info';
  631. $pars['webtheme'] = $name;
  632. $_URLTYPE = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
  633. $dat = cloud_request($_URLTYPE.$_SERVER['HTTP_HOST'], $pars);
  634. $file = IA_ROOT . '/data/webtheme.info';
  635. $ret = _cloud_shipping_parse($dat, $file);
  636. return $ret;
  637. }
  638. function cloud_w_build($name) {
  639. $sql = 'SELECT * FROM ' . tablename('webtheme_homepages') . ' WHERE `name`=:name';
  640. $webtheme = pdo_fetch($sql, array(':name' => $name));
  641. $pars = _cloud_build_params();
  642. $pars['method'] = 'webtheme.build';
  643. $pars['webtheme'] = $name;
  644. if(!empty($webtheme)) {
  645. $pars['webtheme_version'] = $webtheme['version'];
  646. }
  647. $_URLTYPE = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
  648. $dat = cloud_request($_URLTYPE.$_SERVER['HTTP_HOST'], $pars);
  649. $file = IA_ROOT . '/data/webtheme.build';
  650. $ret = _cloud_shipping_parse($dat, $file);
  651. if(!is_error($ret)) {
  652. $dir = IA_ROOT . '/web/themes/' . $name;
  653. $files = array();
  654. if(!empty($ret['files'])) {
  655. foreach($ret['files'] as $file) {
  656. $entry = $dir . $file['path'];
  657. if(!is_file($entry) || md5_file($entry) != $file['checksum']) {
  658. $files[] = '/'. $name . $file['path'];
  659. }
  660. }
  661. }
  662. $ret['files'] = $files;
  663. $ret['upgrade'] = true;
  664. $ret['type'] = 'webtheme';
  665. if(empty($webtheme)) {
  666. $ret['install'] = 1;
  667. }
  668. cache_write(cache_system_key('cloud_transtoken'), authcode($ret['token'], 'ENCODE'));
  669. }
  670. return $ret;
  671. }
  672. function cloud_w_upgradeinfo($name) {
  673. $sql = 'SELECT `name`, `version` FROM ' . tablename('webtheme_homepages') . ' WHERE `name` = :name';
  674. $webtheme = pdo_fetch($sql, array(':name' => $name));
  675. $pars = _cloud_build_params();
  676. $pars['method'] = 'webtheme.upgrade';
  677. $pars['webtheme'] = $webtheme['name'];
  678. $pars['version'] = $webtheme['version'];
  679. $pars['isupgrade'] = 1;
  680. $_URLTYPE = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
  681. $dat = cloud_request($_URLTYPE.$_SERVER['HTTP_HOST'], $pars);
  682. $file = IA_ROOT . '/data/webtheme.info';
  683. $ret = _cloud_shipping_parse($dat, $file);
  684. return $ret;
  685. }
  686. function cloud_sms_send($mobile, $content, $postdata = array(), $custom_sign = '', $use_system_balance = false) {
  687. global $_W;
  688. if(!preg_match('/^1\d{10}$/', $mobile) || empty($content)) {
  689. return error(1, '发送短信失败, 原因: 手机号错误或内容为空.');
  690. }
  691. $uniacid = empty($use_system_balance) ? $_W['uniacid'] : 0;
  692. if (empty($uniacid)) {
  693. $sms_info = cloud_sms_info();
  694. $balance = empty($sms_info['sms_count']) ? 0 : $sms_info['sms_count'];
  695. if (!empty($custom_sign)) {
  696. $sign = $custom_sign;
  697. }
  698. } else {
  699. $row = pdo_get('uni_settings' , array('uniacid' => $uniacid), array('notify'));
  700. $row['notify'] = @iunserializer($row['notify']);
  701. $config = $row['notify']['sms'];
  702. $balance = intval($config['balance']);
  703. $sign = empty($custom_sign) ? $config['signature'] : $custom_sign;
  704. $account_name = empty($_W['account']['type_name']) ? '' : $_W['account']['type_name'];
  705. $account_name .= empty($_W['account']['name']) ? '' : " [{$_W['account']['name']}] ";
  706. }
  707. if(empty($sign) || $sign == 'null') {
  708. $sign = '短信宝';
  709. }
  710. //判断剩余条数
  711. if($balance<1){
  712. return error(-1, '短信发送失败, 原因:余额不足');
  713. }
  714. //短信宝账号
  715. // $smsbao_info=pdo_get('uni_settings' , array('uniacid' => $_W['uniacid']), array('copyright'));
  716. //$smsbao_info=setting_load($key = 'copyright');
  717. $sms_param['u']=$_W['setting']['copyright']['sms_name'];
  718. $sms_param['p']=md5($_W['setting']['copyright']['sms_password']);
  719. $sms_param['m']=$mobile;
  720. $sms_param['c']='【'.$sign.'】'.$content;
  721. $response = file_get_contents("http://api.smsbao.com/sms?".http_build_query($sms_param));
  722. if (trim($response)!='0') {
  723. return error($response['errno'], '短信发送失败, 原因:'.$response['message']);
  724. }
  725. if (trim($response)=='0') {
  726. if (!empty($uniacid)) {
  727. $row['notify']['sms']['balance'] = $row['notify']['sms']['balance'] - 1;
  728. if ($row['notify']['sms']['balance'] < 0) {
  729. $row['notify']['sms']['balance'] = 0;
  730. }
  731. pdo_update('uni_settings', array('notify' => iserializer($row['notify'])), array('uniacid' => $uniacid));
  732. uni_setting_save('notify', $row['notify']);
  733. } else {
  734. $sms_info['sms_count'] = $sms_info['sms_count'] - 1;
  735. if ($sms_info['sms_count'] < 0) {
  736. $sms_info['sms_count'] = 0;
  737. }
  738. setting_save($sms_info, 'sms.info');
  739. }
  740. }
  741. return true;
  742. }
  743. function cloud_sms_info() {
  744. global $_W;
  745. $data=array();
  746. //返回短信的剩余条数以及签名
  747. $sms_name=$_W['setting']['copyright']['sms_name'];
  748. $sms_password=md5($_W['setting']['copyright']['sms_password']);
  749. $res=file_get_contents("http://api.smsbao.com/query?u={$sms_name}&p={$sms_password}");
  750. $retArr = explode("\n", $res);
  751. $balanceArr = explode(",", $retArr[1]);
  752. $data['sms_count']=$retArr[0] == 0 ? $balanceArr[1]:0;
  753. return $data;
  754. }
  755. function cloud_extra_account() {
  756. $data = array();
  757. $data['accounts'] = pdo_fetchall("SELECT name, account, original FROM ".tablename('account_wechats') . " GROUP BY account");
  758. return serialize($data);
  759. }
  760. function cloud_extra_module() {
  761. return table('modules')->getInstalled();
  762. }
  763. function cloud_extra_theme() {
  764. $sql = 'SELECT `name` FROM ' . tablename('site_templates') . ' WHERE `name` <> :name';
  765. $themes = pdo_fetchall($sql, array(':name' => 'default'), 'name');
  766. if (!empty($themes)) {
  767. return base64_encode(iserializer(array_keys($themes)));
  768. } else {
  769. return '';
  770. }
  771. }
  772. function cloud_extra_webtheme() {
  773. $sql = 'SELECT `name` FROM ' . tablename('webtheme_templates') . ' WHERE `name` <> :name';
  774. $themes = pdo_fetchall($sql, array(':name' => 'default'), 'name');
  775. if (!empty($themes)) {
  776. return base64_encode(iserializer(array_keys($themes)));
  777. } else {
  778. return '';
  779. }
  780. }
  781. function cloud_module_setting($acid, $module) {
  782. $pars = array(
  783. 'acid' => $acid,
  784. 'module_name' => $module['name'],
  785. 'module_version' => $module['version'],
  786. );
  787. return cloud_api('module/setting/index', $pars);
  788. }
  789. function cloud_module_setting_save($acid, $module_name, $setting) {
  790. $pars = array(
  791. 'acid' => $acid,
  792. 'module_name' => $module_name,
  793. 'setting' => $setting,
  794. );
  795. return cloud_api('module/setting/save', $pars);
  796. }
  797. function cloud_api_redirect($method, $params = array()) {
  798. $pars = array(
  799. 'method' => $method,
  800. 'params' => $params,
  801. );
  802. return cloud_api('util/api/index', $pars);
  803. }
  804. function cloud_cron_create($cron) {
  805. $pars = array(
  806. 'cron' => base64_encode(iserializer($cron)),
  807. );
  808. return cloud_api('site/cron/save', $pars);
  809. }
  810. function cloud_cron_update($cron) {
  811. return cloud_cron_create($cron); }
  812. function cloud_cron_get($cron_id) {
  813. $pars = array(
  814. 'cron_id' => $cron_id,
  815. );
  816. return cloud_api('site/cron/get', $pars);
  817. }
  818. function cloud_cron_change_status($cron_id, $status) {
  819. $pars = array(
  820. 'cron_id' => $cron_id,
  821. 'status' => $status,
  822. );
  823. return cloud_api('site/cron/status', $pars);
  824. }
  825. function cloud_cron_remove($cron_id) {
  826. $pars = array(
  827. 'cron_id' => $cron_id,
  828. );
  829. return cloud_api('site/cron/remove', $pars);
  830. }
  831. function _cloud_response_parse($result) {
  832. if (empty($result)) {
  833. return error(-1, '没有接收到服务器的传输的数据');
  834. }
  835. if ($result['content'] == 'blacklist') {
  836. return error(-1, '抱歉,您的站点已被列入云服务黑名单,云服务一切业务已被禁止,请联系微擎客服!');
  837. }
  838. $result = json_decode($result['content'], true);
  839. if (null === $result) {
  840. return error(-1, '云服务通讯发生错误,请稍后重新尝试!');
  841. }
  842. if (!empty($result['error'])) {
  843. return error(-1, $result['error']);
  844. }
  845. return $result;
  846. }
  847. function cloud_site_info() {
  848. return cloud_api('util/api/index', array('method' => 'license'));
  849. }
  850. function cloud_reset_siteinfo() {
  851. global $_W;
  852. return cloud_api('site/register/profile', array('url' => $_W['siteroot']));
  853. }
  854. function cloud_auth_url($forward, $data = array()){
  855. global $_W;
  856. if (!empty($_W['setting']['site']['url']) && !strexists($_W['siteroot'], $_W['setting']['site']['url'])) {
  857. $url = $_W['setting']['site']['url'];
  858. } else {
  859. $url = rtrim($_W['siteroot'], '/');
  860. }
  861. $auth = array();
  862. $auth['key'] = '';
  863. $auth['password'] = '';
  864. $auth['url'] = $url;
  865. $auth['referrer'] = intval($_W['config']['setting']['referrer']);
  866. $auth['version'] = IMS_VERSION;
  867. $auth['forward'] = $forward;
  868. $auth['family'] = IMS_FAMILY;
  869. if(!empty($_W['setting']['site']['key']) && !empty($_W['setting']['site']['token'])) {
  870. $auth['key'] = $_W['setting']['site']['key'];
  871. $auth['password'] = md5($_W['setting']['site']['key'] . $_W['setting']['site']['token']);
  872. }
  873. if ($data && is_array($data)) {
  874. $auth = array_merge($auth, $data);
  875. }
  876. $query = base64_encode(json_encode($auth));
  877. $_URLTYPE = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
  878. $auth_url = $_URLTYPE.$_SERVER['HTTP_HOST'] . $query;
  879. return $auth_url;
  880. }
  881. function cloud_module_setting_prepare($module, $binding) {
  882. global $_W;
  883. $auth = _cloud_build_params();
  884. $auth['arguments'] = array(
  885. 'binding' => $binding,
  886. 'acid' => $_W['uniacid'],
  887. 'type' => 'module',
  888. 'module' => $module,
  889. );
  890. $iframe_auth_url = cloud_auth_url('module', $auth);
  891. return $iframe_auth_url;
  892. }
  893. function cloud_resource_to_local($uniacid, $type, $url){
  894. global $_W;
  895. load()->func('file');
  896. $setting = $_W['setting']['upload'][$type];
  897. if (substr($url, 0, 2) == '//') {
  898. $url = 'http:' . $url;
  899. }
  900. if (!file_is_image($url)) {
  901. return error(1, '远程图片后缀非法,请重新上传');
  902. }
  903. $pathinfo = pathinfo($url);
  904. $extension = $pathinfo['extension'];
  905. if ($uniacid == 0) {
  906. $setting['folder'] = "{$type}s/global/".date('Y/m/');
  907. } else {
  908. $setting['folder'] = "{$type}s/{$uniacid}/".date('Y/m/');
  909. }
  910. $originname = pathinfo($url, PATHINFO_BASENAME);
  911. $filename = file_random_name(ATTACHMENT_ROOT .'/'. $setting['folder'], $extension);
  912. $pathname = $setting['folder'] . $filename;
  913. $fullname = ATTACHMENT_ROOT . $pathname;
  914. mkdirs(dirname($fullname));
  915. load()->func('communication');
  916. $response = ihttp_get($url);
  917. if (is_error($response)) {
  918. return error(1, $response['message']);
  919. }
  920. if (file_put_contents($fullname, $response['content']) == false) {
  921. return error(1, '提取文件失败');
  922. }
  923. if (!empty($_W['setting']['remote']['type'])) {
  924. $remotestatus = file_remote_upload($pathname);
  925. if (is_error($remotestatus)) {
  926. return error(1, '远程附件上传失败,请检查配置并重新上传');
  927. } else {
  928. file_delete($pathname);
  929. }
  930. }
  931. $data = array(
  932. 'uniacid' => $uniacid,
  933. 'uid' => intval($_W['uid']),
  934. 'filename' => $originname,
  935. 'attachment' => $pathname,
  936. 'type' => $type == 'image' ? 1 : 2,
  937. 'createtime' => TIMESTAMP,
  938. );
  939. pdo_insert('core_attachment', $data);
  940. $data['url'] = tomedia($pathname);
  941. $data['id'] = pdo_insertid();
  942. return $data;
  943. }
  944. function cloud_bakup_files($files) {
  945. global $_W;
  946. if (empty($files)) {
  947. return false;
  948. }
  949. $map = json_encode($files);
  950. $hash = md5($map.$_W['config']['setting']['authkey']);
  951. if ($handle = opendir(IA_ROOT . '/data/patch/backup/' . date('Ymd'))) {
  952. while (false !== ($patchpath = readdir($handle))) {
  953. if ($patchpath != '.' && $patchpath != '..') {
  954. if (strexists($patchpath, $hash)) {
  955. return false;
  956. }
  957. }
  958. }
  959. }
  960. $path = IA_ROOT . '/data/patch/backup/' . date('Ymd') . '/' . date('Hi') . '_' . $hash;
  961. load()->func('file');
  962. if (!is_dir($path) && mkdirs($path)) {
  963. foreach ($files as $file) {
  964. if (file_exists(IA_ROOT . $file)) {
  965. mkdirs($path . '/' . dirname($file));
  966. file_put_contents($path . '/' . $file, file_get_contents(IA_ROOT . $file));
  967. }
  968. }
  969. file_put_contents($path . '/' . 'map.json', $map);
  970. }
  971. return false;
  972. }
  973. function cloud_flow_master_post($flow_master) {
  974. $pars = _cloud_build_params();
  975. $pars['method'] = 'flow.master_post';
  976. $pars['flow_master'] = array(
  977. 'linkman' => $flow_master['linkman'],
  978. 'mobile' => $flow_master['mobile'],
  979. 'address' => $flow_master['address'],
  980. 'id_card_photo' => $flow_master['id_card_photo'], 'business_licence_photo' => $flow_master['business_licence_photo'], );
  981. $_URLTYPE = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
  982. $dat = cloud_request($_URLTYPE.$_SERVER['HTTP_HOST'], $pars, array(), 300);
  983. if(is_error($dat)) {
  984. return error(-1, '网络存在错误, 请稍后重试。' . $dat['message']);
  985. }
  986. cache_delete(cache_system_key('cloud_flow_master'));
  987. $ret = @json_decode($dat['content'], true);
  988. return $ret;
  989. }
  990. function cloud_flow_master_get() {
  991. $cachekey = cache_system_key('cloud_flow_master');
  992. $cache = cache_load($cachekey);
  993. if(!empty($cache) && $cache['expire'] > TIMESTAMP) {
  994. return $cache['setting'];
  995. }
  996. $pars = _cloud_build_params();
  997. $pars['method'] = 'flow.master_get';
  998. $_URLTYPE = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
  999. $dat = cloud_request($_URLTYPE.$_SERVER['HTTP_HOST'], $pars, array(), 300);
  1000. if(is_error($dat)) {
  1001. return error(-1, '网络存在错误, 请稍后重试。' . $dat['message']);
  1002. }
  1003. $ret = @json_decode($dat['content'], true);
  1004. if ($ret['status'] == '3') {
  1005. cache_write($cachekey, array('expire' => TIMESTAMP + 300, 'setting' => $ret));
  1006. } else if ($ret['status'] == '4') {
  1007. cache_write($cachekey, array('expire' => TIMESTAMP + 12 * 3600, 'setting' => $ret));
  1008. }
  1009. return $ret;
  1010. }
  1011. function cloud_flow_uniaccount_post($uniaccount) {
  1012. $pars = _cloud_build_params();
  1013. $pars['method'] = 'flow.uniaccount_post';
  1014. $pars['uniaccount'] = array(
  1015. 'uniacid' => $uniaccount['uniacid'],
  1016. );
  1017. isset($uniaccount['title']) && $pars['uniaccount']['title'] = $uniaccount['title'];
  1018. isset($uniaccount['original']) && $pars['uniaccount']['original'] = $uniaccount['original'];
  1019. isset($uniaccount['gh_type']) && $pars['uniaccount']['gh_type'] = $uniaccount['gh_type'];
  1020. isset($uniaccount['ad_tags']) && $pars['uniaccount']['ad_tags'] = $uniaccount['ad_tags'];
  1021. isset($uniaccount['enable']) && $pars['uniaccount']['enable'] = $uniaccount['enable'];
  1022. $_URLTYPE = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
  1023. $dat = cloud_request($_URLTYPE.$_SERVER['HTTP_HOST'], $pars, array(), 300);
  1024. if(is_error($dat)) {
  1025. return error(-1, '网络存在错误, 请稍后重试。' . $dat['message']);
  1026. }
  1027. cache_delete(cache_system_key('cloud_ad_uniaccount', array('uniacid' => $uniaccount['uniacid'])));
  1028. cache_delete(cache_system_key('cloud_ad_uniaccount_list'));
  1029. $ret = @json_decode($dat['content'], true);
  1030. return $ret;
  1031. }
  1032. function cloud_flow_uniaccount_get($uniacid) {
  1033. $cachekey = cache_system_key('cloud_ad_uniaccount', array('uniacid' => $uniacid));
  1034. $cache = cache_load($cachekey);
  1035. if(!empty($cache) && $cache['expire'] > TIMESTAMP) {
  1036. return $cache['setting'];
  1037. }
  1038. $pars = _cloud_build_params();
  1039. $pars['method'] = 'flow.uniaccount_get';
  1040. $pars['uniaccount'] = array(
  1041. 'uniacid' => $uniacid,
  1042. );
  1043. $pars['md5'] = md5(base64_encode(serialize($pars['uniaccount'])));
  1044. $_URLTYPE = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
  1045. $dat = cloud_request($_URLTYPE.$_SERVER['HTTP_HOST'], $pars, array(), 300);
  1046. if(is_error($dat)) {
  1047. return error(-1, '网络存在错误, 请稍后重试。' . $dat['message']);
  1048. }
  1049. $ret = @json_decode($dat['content'], true);
  1050. cache_write($cachekey, array('expire' => TIMESTAMP + 600, 'setting' => $ret));
  1051. return $ret;
  1052. }
  1053. function cloud_flow_uniaccount_list_get() {
  1054. $cachekey = cache_system_key('cloud_ad_uniaccount_list');
  1055. $cache = cache_load($cachekey);
  1056. if(!empty($cache) && $cache['expire'] > TIMESTAMP) {
  1057. return $cache['setting'];
  1058. }
  1059. $pars = _cloud_build_params();
  1060. $pars['method'] = 'flow.uniaccount_list_get';
  1061. $_URLTYPE = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
  1062. $dat = cloud_request($_URLTYPE.$_SERVER['HTTP_HOST'], $pars, array(), 300);
  1063. if(is_error($dat)) {
  1064. return error(-1, '网络存在错误, 请稍后重试。' . $dat['message']);
  1065. }
  1066. $ret = @json_decode($dat['content'], true);
  1067. cache_write($cachekey, array('expire' => TIMESTAMP + 600, 'setting' => $ret));
  1068. return $ret;
  1069. }
  1070. function cloud_flow_ad_tag_list() {
  1071. $cachekey = cache_system_key('cloud_ad_tags');
  1072. $cache = cache_load($cachekey);
  1073. if(!empty($cache) && $cache['expire'] > TIMESTAMP) {
  1074. return $cache['items'];
  1075. }
  1076. $pars = _cloud_build_params();
  1077. $pars['method'] = 'flow.ad_tag_list';
  1078. $_URLTYPE = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
  1079. $dat = cloud_request($_URLTYPE.$_SERVER['HTTP_HOST'], $pars, array(), 300);
  1080. if(is_error($dat)) {
  1081. return error(-1, '网络存在错误, 请稍后重试。' . $dat['message']);
  1082. }
  1083. $ret = @json_decode($dat['content'], true);
  1084. cache_write($cachekey, array('expire' => TIMESTAMP + 6 * 3600, 'items' => $ret));
  1085. return $ret;
  1086. }
  1087. function cloud_flow_ad_type_list() {
  1088. $cachekey = cache_system_key('cloud_ad_type_list');
  1089. $cache = cache_load($cachekey);
  1090. if(!empty($cache) && $cache['expire'] > TIMESTAMP) {
  1091. return $cache['items'];
  1092. }
  1093. $pars = _cloud_build_params();
  1094. $pars['method'] = 'flow.ad_type_list';
  1095. $_URLTYPE = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
  1096. $dat = cloud_request($_URLTYPE.$_SERVER['HTTP_HOST'], $pars, array(), 300);
  1097. if(is_error($dat)) {
  1098. return error(-1, '网络存在错误, 请稍后重试。' . $dat['message']);
  1099. }
  1100. $ret = @json_decode($dat['content'], true);
  1101. cache_write($cachekey, array('expire' => TIMESTAMP + 3600, 'items' => $ret));
  1102. return $ret;
  1103. }
  1104. function cloud_flow_app_post($uniacid, $module_name, $enable = 0, $ad_types = null) {
  1105. $pars = _cloud_build_params();
  1106. $pars['method'] = 'flow.app_post';
  1107. $pars['uniaccount_app'] = array(
  1108. 'uniacid' => $uniacid,
  1109. 'module' => $module_name,
  1110. );
  1111. if (!empty($enable)) {
  1112. $pars['uniaccount_app']['enable'] = $enable; }
  1113. if (is_array($ad_types)) {
  1114. $pars['uniaccount_app']['ad_types'] = $ad_types; }
  1115. $_URLTYPE = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
  1116. $dat = cloud_request($_URLTYPE.$_SERVER['HTTP_HOST'], $pars, array(), 300);
  1117. if(is_error($dat)) {
  1118. return error(-1, '网络存在错误, 请稍后重试。' . $dat['message']);
  1119. }
  1120. cache_delete(cache_system_key('cloud_ad_app_list', array('uniacid' => $uniacid)));
  1121. $ret = @json_decode($dat['content'], true);
  1122. return $ret;
  1123. }
  1124. function cloud_flow_app_list_get($uniacid) {
  1125. $cachekey = cache_system_key('cloud_ad_app_list', array('uniacid' => $uniacid));
  1126. $cache = cache_load($cachekey);
  1127. if(!empty($cache) && $cache['expire'] > TIMESTAMP) {
  1128. return $cache['setting'];
  1129. }
  1130. $pars = _cloud_build_params();
  1131. $pars['method'] = 'flow.app_list_get';
  1132. $pars['uniaccount'] = array(
  1133. 'uniacid' => $uniacid,
  1134. );
  1135. $_URLTYPE = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
  1136. $dat = cloud_request($_URLTYPE.$_SERVER['HTTP_HOST'], $pars, array(), 300);
  1137. if(is_error($dat)) {
  1138. return error(-1, '网络存在错误, 请稍后重试。' . $dat['message']);
  1139. }
  1140. $ret = @json_decode($dat['content'], true);
  1141. cache_write($cachekey, array('expire' => TIMESTAMP + 300, 'setting' => $ret));
  1142. return $ret;
  1143. }
  1144. function cloud_flow_app_support_list($module_names) {
  1145. if (empty($module_names)) {
  1146. return array();
  1147. }
  1148. $cachekey = cache_system_key('cloud_ad_app_support_list');
  1149. $cache = cache_load($cachekey);
  1150. if(!empty($cache) && $cache['expire'] > TIMESTAMP) {
  1151. return $cache['setting'];
  1152. }
  1153. $pars = _cloud_build_params();
  1154. $pars['method'] = 'flow.app_support_list';
  1155. $pars['modules'] = $module_names;
  1156. $_URLTYPE = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
  1157. $dat = cloud_request($_URLTYPE.$_SERVER['HTTP_HOST'], $pars, array(), 300);
  1158. if(is_error($dat)) {
  1159. return error(-1, '网络存在错误, 请稍后重试。' . $dat['message']);
  1160. }
  1161. $ret = @json_decode($dat['content'], true);
  1162. cache_write($cachekey, array('expire' => TIMESTAMP + 300, 'setting' => $ret));
  1163. return $ret;
  1164. }
  1165. function cloud_flow_site_stat_day($condition) {
  1166. $cachekey = cache_system_key('cloud_ad_site_finance');
  1167. $cache = cache_load($cachekey);
  1168. if(!empty($cache) && $cache['expire'] > TIMESTAMP) {
  1169. return $cache['info'];
  1170. }
  1171. $pars = _cloud_build_params();
  1172. $pars['method'] = 'flow.site_stat_day';
  1173. $pars['condition'] = array();
  1174. $pars['condition']['starttime'] = $condition['starttime'];
  1175. $pars['condition']['endtime'] = $condition['endtime'];
  1176. $pars['condition']['page'] = $condition['page'];
  1177. $pars['condition']['size'] = $condition['size'];
  1178. $_URLTYPE = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
  1179. $dat = cloud_request($_URLTYPE.$_SERVER['HTTP_HOST'], $pars, array(), 300);
  1180. if(is_error($dat)) {
  1181. return error(-1, '网络存在错误, 请稍后重试。' . $dat['message']);
  1182. }
  1183. $ret = @json_decode($dat['content'], true);
  1184. cache_write($cachekey, array('expire' => TIMESTAMP + 300, 'info' => $ret));
  1185. return $ret;
  1186. }
  1187. function cloud_build_transtoken() {
  1188. $pars = _cloud_build_params();
  1189. $pars['method'] = 'application.token';
  1190. $dat = cloud_request(CLOUD_GATEWAY_URL_NORMAL, $pars);
  1191. $file = IA_ROOT . '/data/application.build';
  1192. $ret = _cloud_shipping_parse($dat, $file);
  1193. cache_write(cache_system_key('cloud_transtoken'), authcode($ret['token'], 'ENCODE'));
  1194. return $ret['token'];
  1195. }
  1196. function cloud_build_schemas($schemas) {
  1197. $database = array();
  1198. if (empty($schemas) || !is_array($schemas)) {
  1199. return $database;
  1200. }
  1201. foreach ($schemas as $remote) {
  1202. $row = array();
  1203. $row['tablename'] = $remote['tablename'];
  1204. $name = substr($remote['tablename'], 4);
  1205. $local = db_table_schema(pdo(), $name);
  1206. unset($remote['increment']);
  1207. unset($local['increment']);
  1208. if (empty($local)) {
  1209. $row['new'] = true;
  1210. } else {
  1211. $row['new'] = false;
  1212. $row['fields'] = array();
  1213. $row['indexes'] = array();
  1214. $diffs = db_schema_compare($local, $remote);
  1215. if (!empty($diffs['fields']['less'])) {
  1216. $row['fields'] = array_merge($row['fields'], $diffs['fields']['less']);
  1217. }
  1218. if (!empty($diffs['fields']['diff'])) {
  1219. $row['fields'] = array_merge($row['fields'], $diffs['fields']['diff']);
  1220. }
  1221. if (!empty($diffs['indexes']['less'])) {
  1222. $row['indexes'] = array_merge($row['indexes'], $diffs['indexes']['less']);
  1223. }
  1224. if (!empty($diffs['indexes']['diff'])) {
  1225. $row['indexes'] = array_merge($row['indexes'], $diffs['indexes']['diff']);
  1226. }
  1227. $row['fields'] = implode($row['fields'], ' ');
  1228. $row['indexes'] = implode($row['indexes'], ' ');
  1229. }
  1230. $database[] = $row;
  1231. }
  1232. return $database;
  1233. }
  1234. function cloud_file_permission_pass(&$error_file_list = array()) {
  1235. $check_path = array(
  1236. '/app/common',
  1237. '/app/source',
  1238. '/app/themes/default',
  1239. '/web/common',
  1240. '/web/source',
  1241. '/web/themes/default',
  1242. '/web/themes/black',
  1243. '/web/themes/classical',
  1244. '/web/themes/2.0',
  1245. '/framework/class',
  1246. '/framework/model',
  1247. '/framework/function',
  1248. '/framework/table',
  1249. '/framework/library/agent',
  1250. );
  1251. $check_file = array(
  1252. '/web/index.php',
  1253. '/framework/bootstrap.inc.php',
  1254. '/framework/version.inc.php',
  1255. '/framework/const.inc.php',
  1256. );
  1257. $sub_paths = array();
  1258. foreach ($check_path as $path) {
  1259. $file_list = cloud_file_tree(IA_ROOT . $path);
  1260. if (!empty($file_list)) {
  1261. foreach ($file_list as $file) {
  1262. if (is_file($file)) {
  1263. $sub_path = pathinfo($file, PATHINFO_DIRNAME);
  1264. if (empty($sub_paths[$sub_path])) {
  1265. if (!cloud_path_is_writable($sub_path)) {
  1266. $error_file_list[] = str_replace(IA_ROOT, '', $sub_path);
  1267. }
  1268. $sub_paths[$sub_path] = $sub_path;
  1269. }
  1270. }
  1271. if (!is_writable($file)) {
  1272. $error_file_list[] = str_replace(IA_ROOT, '', $file);
  1273. }
  1274. }
  1275. }
  1276. }
  1277. foreach ($check_file as $file) {
  1278. if (!is_writable(IA_ROOT . $file)) {
  1279. $error_file_list[] = str_replace(IA_ROOT, '', $file);
  1280. }
  1281. }
  1282. return empty($error_file_list) ? true : false;
  1283. }
  1284. function cloud_file_tree($path, $include = array()) {
  1285. $files = array();
  1286. if (!empty($include)) {
  1287. $ds = glob($path . '/{' . implode(',', $include) . '}', GLOB_BRACE);
  1288. } else {
  1289. $ds = glob($path . '/*');
  1290. }
  1291. if (is_array($ds)) {
  1292. foreach ($ds as $entry) {
  1293. if (is_file($entry)) {
  1294. $files[] = $entry;
  1295. }
  1296. if (is_dir($entry)) {
  1297. $rs = cloud_file_tree($entry);
  1298. foreach ($rs as $f) {
  1299. $files[] = $f;
  1300. }
  1301. }
  1302. }
  1303. }
  1304. return $files;
  1305. }
  1306. function cloud_path_is_writable($dir) {
  1307. $writeable = false;
  1308. if (!is_dir($dir)) {
  1309. @mkdir($dir, 0755);
  1310. }
  1311. if (is_dir($dir)) {
  1312. if($fp = fopen("$dir/test.txt", 'w')) {
  1313. fclose($fp);
  1314. unlink("$dir/test.txt");
  1315. $writeable = true;
  1316. } else {
  1317. $writeable = false;
  1318. }
  1319. }
  1320. return $writeable;
  1321. }
  1322. function cloud_get_store_notice() {
  1323. load()->classs('cloudapi');
  1324. $api = new CloudApi();
  1325. $result = $api->get('store', 'official_dynamics');
  1326. return $result;
  1327. }
  1328. function cloud_v_to_xs($url) {
  1329. if (empty($url)) {
  1330. return false;
  1331. }
  1332. /*$pars = _cloud_build_params();
  1333. $pars['method'] = 'module.query';
  1334. $pars['url'] = urlencode($url);
  1335. cloud_request('http://api.w7.cc/site/pirate/index', $pars);
  1336. */
  1337. return true;
  1338. }
  1339. function cloud_workorder() {
  1340. $result = cloud_api('work-order/status/index');
  1341. return $result;
  1342. }