app.php 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. <?php
  2. /*
  3. [UCenter] (C)2001-2099 Comsenz Inc.
  4. This is NOT a freeware, use is subject to license terms
  5. $Id: app.php 1165 2014-10-31 06:58:43Z hypowang $
  6. */
  7. !defined('IN_UC') && exit('Access Denied');
  8. class control extends adminbase {
  9. function __construct() {
  10. $this->control();
  11. }
  12. function control() {
  13. parent::__construct();
  14. $this->check_priv();
  15. if(!$this->user['isfounder'] && !$this->user['allowadminapp']) {
  16. $this->message('no_permission_for_this_module');
  17. }
  18. $this->load('app');
  19. $this->load('misc');
  20. }
  21. function onls() {
  22. $status = $affectedrows = 0;
  23. if($this->submitcheck() && !empty($_POST['delete'])) {
  24. $affectedrows += $_ENV['app']->delete_apps($_POST['delete']);
  25. foreach($_POST['delete'] as $k => $appid) {
  26. $_ENV['app']->alter_app_table($appid, 'REMOVE');
  27. unset($_POST['name'][$k]);
  28. }
  29. $this->load('cache');
  30. $_ENV['cache']->updatedata();
  31. $this->writelog('app_delete', 'appid='.implode(',', $_POST['delete']));
  32. $status = 2;
  33. $this->_add_note_for_app();
  34. }
  35. $a = getgpc('a');
  36. $applist = $_ENV['app']->get_apps();
  37. $this->view->assign('status', $status);
  38. $this->view->assign('a', $a);
  39. $this->view->assign('applist', $applist);
  40. $this->view->display('admin_app');
  41. }
  42. function onadd() {
  43. if(!$this->submitcheck()) {
  44. $md5ucfounderpw = md5(UC_FOUNDERPW);
  45. $this->view->assign('md5ucfounderpw', $md5ucfounderpw);
  46. $a = getgpc('a');
  47. $this->view->assign('a', $a);
  48. $typelist = array('DISCUZX'=>'DiscuzX','UCHOME'=>'UCenter Home','XSPACE'=>'X-Space','DISCUZ'=>'Discuz!','SUPESITE'=>'SupeSite','SUPEV'=>'SupeV','ECSHOP'=>'ECShop','ECMALL'=>'ECMall','OTHER'=>$this->lang['other']);
  49. $this->view->assign('typelist', $typelist);
  50. $this->view->display('admin_app');
  51. } else {
  52. $type = getgpc('type', 'P');
  53. $name = getgpc('name', 'P');
  54. $url = getgpc('url', 'P');
  55. $ip = getgpc('ip', 'P');
  56. $viewprourl = getgpc('viewprourl', 'P');
  57. $authkey = getgpc('authkey', 'P');
  58. $authkey = $this->authcode($authkey, 'ENCODE', UC_MYKEY);
  59. $synlogin = getgpc('synlogin', 'P');
  60. $recvnote = getgpc('recvnote', 'P');
  61. $apifilename = trim(getgpc('apifilename', 'P'));
  62. $tagtemplates = array();
  63. $tagtemplates['template'] = getgpc('tagtemplates', 'P');
  64. $tagfields = explode("\n", getgpc('tagfields', 'P'));
  65. foreach($tagfields as $field) {
  66. $field = trim($field);
  67. list($k, $v) = explode(',', $field);
  68. if($k) {
  69. $tagtemplates['fields'][$k] = $v;
  70. }
  71. }
  72. $tagtemplates = $this->serialize($tagtemplates, 1);
  73. if(!$_ENV['misc']->check_url($_POST['url'])) {
  74. $this->message('app_add_url_invalid', 'BACK');
  75. }
  76. if(!empty($_POST['ip']) && !$_ENV['misc']->check_ip($_POST['ip'])) {
  77. $this->message('app_add_ip_invalid', 'BACK');
  78. }
  79. $app = $this->db->result_first("SELECT COUNT(*) FROM ".UC_DBTABLEPRE."applications WHERE name='$name'");
  80. if($app) {
  81. $this->message('app_add_name_invalid', 'BACK');
  82. } else {
  83. $extra = serialize(array('apppath'=> getgpc('apppath', 'P')));
  84. $this->db->query("INSERT INTO ".UC_DBTABLEPRE."applications SET name='$name', url='$url', ip='$ip',
  85. viewprourl='$viewprourl', apifilename='$apifilename', authkey='$authkey', synlogin='$synlogin',
  86. type='$type', recvnote='$recvnote', extra='$extra',
  87. tagtemplates='$tagtemplates'");
  88. $appid = $this->db->insert_id();
  89. }
  90. $this->_add_note_for_app();
  91. $this->load('cache');
  92. $_ENV['cache']->updatedata('apps');
  93. $_ENV['app']->alter_app_table($appid, 'ADD');
  94. $this->writelog('app_add', "appid=$appid; appname=$_POST[name]");
  95. header("location: admin.php?m=app&a=detail&appid=$appid&addapp=yes&sid=".$this->view->sid);
  96. }
  97. }
  98. function onping() {
  99. $ip = getgpc('ip');
  100. $url = getgpc('url');
  101. $appid = intval(getgpc('appid'));
  102. $app = $_ENV['app']->get_app_by_appid($appid);
  103. $status = '';
  104. if($app['extra']['apppath'] && @include $app['extra']['apppath'].'./api/'.$app['apifilename']) {
  105. $uc_note = new uc_note();
  106. $status = $uc_note->test($note['getdata'], $note['postdata']);
  107. } else {
  108. $this->load('note');
  109. $url = $_ENV['note']->get_url_code('test', '', $appid);
  110. $status = $_ENV['app']->test_api($url, $ip);
  111. }
  112. if($status == '1') {
  113. echo 'document.getElementById(\'status_'.$appid.'\').innerHTML = "<img src=\'images/correct.gif\' border=\'0\' class=\'statimg\' \/><span class=\'green\'>'.$this->lang['app_connent_ok'].'</span>";testlink();';
  114. } else {
  115. echo 'document.getElementById(\'status_'.$appid.'\').innerHTML = "<img src=\'images/error.gif\' border=\'0\' class=\'statimg\' \/><span class=\'red\'>'.$this->lang['app_connent_false'].'</span>";testlink();';
  116. }
  117. }
  118. function ondetail() {
  119. $appid = getgpc('appid');
  120. $updated = false;
  121. $app = $_ENV['app']->get_app_by_appid($appid);
  122. if($this->submitcheck()) {
  123. $type = getgpc('type', 'P');
  124. $name = getgpc('name', 'P');
  125. $url = getgpc('url', 'P');
  126. $ip = getgpc('ip', 'P');
  127. $viewprourl = getgpc('viewprourl', 'P');
  128. $apifilename = trim(getgpc('apifilename', 'P'));
  129. $authkey = getgpc('authkey', 'P');
  130. $authkey = $this->authcode($authkey, 'ENCODE', UC_MYKEY);
  131. $synlogin = getgpc('synlogin', 'P');
  132. $recvnote = getgpc('recvnote', 'P');
  133. $extraurl = getgpc('extraurl', 'P');
  134. if(getgpc('apppath', 'P')) {
  135. $app['extra']['apppath'] = $this->_realpath(getgpc('apppath', 'P'));
  136. if($app['extra']['apppath']) {
  137. $apifile = $app['extra']['apppath'].'./api/uc.php';
  138. if(!file_exists($apifile)) {
  139. $this->message('app_apifile_not_exists', 'BACK', 0, array('$apifile' => $apifile));
  140. }
  141. $s = file_get_contents($apifile);
  142. preg_match("/define\(\'UC_CLIENT_VERSION\'\, \'([^\']+?)\'\)/i", $s, $m);
  143. $uc_client_version = @$m[1];
  144. if(!$uc_client_version || $uc_client_version <= '1.0.0') {
  145. $this->message('app_apifile_too_low', 'BACK', 0, array('$apifile' => $apifile));
  146. }
  147. } else {
  148. $this->message('app_path_not_exists');
  149. }
  150. } else {
  151. $app['extra']['apppath'] = '';
  152. }
  153. $app['extra']['extraurl'] = array();
  154. if($extraurl) {
  155. foreach(explode("\n", $extraurl) as $val) {
  156. if(!$val = trim($val)) continue;
  157. $app['extra']['extraurl'][] = $val;
  158. }
  159. }
  160. $tagtemplates = array();
  161. $tagtemplates['template'] = MAGIC_QUOTES_GPC ? stripslashes(getgpc('tagtemplates', 'P')) : getgpc('tagtemplates', 'P');
  162. $tagfields = explode("\n", getgpc('tagfields', 'P'));
  163. foreach($tagfields as $field) {
  164. $field = trim($field);
  165. list($k, $v) = explode(',', $field);
  166. if($k) {
  167. $tagtemplates['fields'][$k] = $v;
  168. }
  169. }
  170. $tagtemplates = $this->serialize($tagtemplates, 1);
  171. $extra = addslashes(serialize($app['extra']));
  172. $this->db->query("UPDATE ".UC_DBTABLEPRE."applications SET appid='$appid', name='$name', url='$url',
  173. type='$type', ip='$ip', viewprourl='$viewprourl', apifilename='$apifilename', authkey='$authkey',
  174. synlogin='$synlogin', recvnote='$recvnote', extra='$extra',
  175. tagtemplates='$tagtemplates'
  176. WHERE appid='$appid'");
  177. $updated = true;
  178. $this->load('cache');
  179. $_ENV['cache']->updatedata('apps');
  180. $this->cache('settings');
  181. $this->writelog('app_edit', "appid=$appid");
  182. $this->_add_note_for_app();
  183. $app = $_ENV['app']->get_app_by_appid($appid);
  184. }
  185. $tagtemplates = $this->unserialize($app['tagtemplates']);
  186. $template = dhtmlspecialchars($tagtemplates['template']);
  187. $tmp = '';
  188. if(is_array($tagtemplates['fields'])) {
  189. foreach($tagtemplates['fields'] as $field => $memo) {
  190. $tmp .= $field.','.$memo."\n";
  191. }
  192. }
  193. $tagtemplates['fields'] = $tmp;
  194. $a = getgpc('a');
  195. $this->view->assign('a', $a);
  196. $app = $_ENV['app']->get_app_by_appid($appid);
  197. $this->view->assign('isfounder', $this->user['isfounder']);
  198. $this->view->assign('appid', $app['appid']);
  199. $this->view->assign('allowips', $app['allowips']);
  200. $this->view->assign('name', $app['name']);
  201. $this->view->assign('url', $app['url']);
  202. $this->view->assign('ip', $app['ip']);
  203. $this->view->assign('viewprourl', $app['viewprourl']);
  204. $this->view->assign('apifilename', $app['apifilename']);
  205. $this->view->assign('authkey', $app['authkey']);
  206. $synloginchecked = array($app['synlogin'] => 'checked="checked"');
  207. $recvnotechecked = array($app['recvnote'] => 'checked="checked"');
  208. $this->view->assign('synlogin', $synloginchecked);
  209. $this->view->assign('charset', $app['charset']);
  210. $this->view->assign('dbcharset', $app['dbcharset']);
  211. $this->view->assign('type', $app['type']);
  212. $this->view->assign('recvnotechecked', $recvnotechecked);
  213. $typelist = array('DISCUZX'=>'DiscuzX','UCHOME'=>'UCenter Home','XSPACE'=>'X-Space','DISCUZ'=>'Discuz!','SUPESITE'=>'SupeSite','SUPEV'=>'SupeV','ECSHOP'=>'ECShop','ECMALL'=>'ECMall','OTHER'=>$this->lang['other']);
  214. $this->view->assign('typelist', $typelist);
  215. $this->view->assign('updated', $updated);
  216. $addapp = getgpc('addapp');
  217. $this->view->assign('addapp', $addapp);
  218. $this->view->assign('extraurl', implode("\n", $app['extra']['extraurl']));
  219. $this->view->assign('apppath', $app['extra']['apppath']);
  220. $this->view->assign('tagtemplates', $tagtemplates);
  221. $this->view->display('admin_app');
  222. }
  223. function _add_note_for_app() {
  224. $this->load('note');
  225. $notedata = $this->db->fetch_all("SELECT appid, type, name, url, ip, viewprourl, apifilename, charset, synlogin, extra, recvnote FROM ".UC_DBTABLEPRE."applications");
  226. $notedata = $this->_format_notedata($notedata);
  227. $notedata['UC_API'] = UC_API;
  228. $_ENV['note']->add('updateapps', '', $this->serialize($notedata, 1));
  229. $_ENV['note']->send();
  230. }
  231. function _format_notedata($notedata) {
  232. $arr = array();
  233. foreach($notedata as $key => $note) {
  234. $note['extra'] = unserialize($note['extra']);
  235. $arr[$note['appid']] = $note;
  236. }
  237. return $arr;
  238. }
  239. function _realpath($path) {
  240. return realpath($path).'/';
  241. }
  242. }
  243. ?>