app.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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 1102 2011-05-30 09:40:42Z svn_project_zhangjie $
  6. */
  7. !defined('IN_UC') && exit('Access Denied');
  8. class appcontrol extends base {
  9. function __construct() {
  10. $this->appcontrol();
  11. }
  12. function appcontrol() {
  13. parent::__construct();
  14. $this->load('app');
  15. }
  16. function onls() {
  17. $this->init_input();
  18. $applist = $_ENV['app']->get_apps('appid, type, name, url, tagtemplates, viewprourl, synlogin');
  19. $applist2 = array();
  20. foreach($applist as $key => $app) {
  21. $app['tagtemplates'] = $this->unserialize($app['tagtemplates']);
  22. $applist2[$app['appid']] = $app;
  23. }
  24. return $applist2;
  25. }
  26. function onadd() {
  27. $ucfounderpw = getgpc('ucfounderpw', 'P');
  28. $apptype = getgpc('apptype', 'P');
  29. $appname = getgpc('appname', 'P');
  30. $appurl = getgpc('appurl', 'P');
  31. $appip = getgpc('appip', 'P');
  32. $apifilename = trim(getgpc('apifilename', 'P'));
  33. $viewprourl = getgpc('viewprourl', 'P');
  34. $appcharset = getgpc('appcharset', 'P');
  35. $appdbcharset = getgpc('appdbcharset', 'P');
  36. $apptagtemplates = getgpc('apptagtemplates', 'P');
  37. $appallowips = getgpc('allowips', 'P');
  38. $apifilename = $apifilename ? $apifilename : 'uc.php';
  39. if(md5(md5($ucfounderpw).UC_FOUNDERSALT) == UC_FOUNDERPW || (strlen($ucfounderpw) == 32 && $ucfounderpw == md5(UC_FOUNDERPW))) {
  40. @ob_start();
  41. $return = '';
  42. $app = $this->db->fetch_first("SELECT * FROM ".UC_DBTABLEPRE."applications WHERE url='$appurl' AND type='$apptype'");
  43. if(empty($app)) {
  44. $authkey = $this->_generate_key();
  45. $apptagtemplates = $this->serialize($apptagtemplates, 1);
  46. $this->db->query("INSERT INTO ".UC_DBTABLEPRE."applications SET
  47. name='$appname',
  48. url='$appurl',
  49. ip='$appip',
  50. apifilename='$apifilename',
  51. authkey='$authkey',
  52. viewprourl='$viewprourl',
  53. synlogin='1',
  54. charset='$appcharset',
  55. dbcharset='$appdbcharset',
  56. type='$apptype',
  57. recvnote='1',
  58. tagtemplates='$apptagtemplates',
  59. allowips='$appallowips'
  60. ");
  61. $appid = $this->db->insert_id();
  62. $_ENV['app']->alter_app_table($appid, 'ADD');
  63. $return = "$authkey|$appid|".UC_DBHOST.'|'.UC_DBNAME.'|'.UC_DBUSER.'|'.UC_DBPW.'|'.UC_DBCHARSET.'|'.UC_DBTABLEPRE.'|'.UC_CHARSET;
  64. $this->load('cache');
  65. $_ENV['cache']->updatedata('apps');
  66. $this->load('note');
  67. $notedata = $this->db->fetch_all("SELECT appid, type, name, url, ip, charset, synlogin, extra FROM ".UC_DBTABLEPRE."applications");
  68. $notedata = $this->_format_notedata($notedata);
  69. $notedata['UC_API'] = UC_API;
  70. $_ENV['note']->add('updateapps', '', $this->serialize($notedata, 1));
  71. $_ENV['note']->send();
  72. } else {
  73. $return = "$app[authkey]|$app[appid]|".UC_DBHOST.'|'.UC_DBNAME.'|'.UC_DBUSER.'|'.UC_DBPW.'|'.UC_DBCHARSET.'|'.UC_DBTABLEPRE.'|'.UC_CHARSET;
  74. }
  75. @ob_end_clean();
  76. exit($return);
  77. } else {
  78. exit('-1');
  79. }
  80. }
  81. function onucinfo() {
  82. $arrapptypes = $this->db->fetch_all("SELECT DISTINCT type FROM ".UC_DBTABLEPRE."applications");
  83. $apptypes = $tab = '';
  84. foreach($arrapptypes as $apptype) {
  85. $apptypes .= $tab.$apptype['type'];
  86. $tab = "\t";
  87. }
  88. exit("UC_STATUS_OK|".UC_SERVER_VERSION."|".UC_SERVER_RELEASE."|".UC_CHARSET."|".UC_DBCHARSET."|".$apptypes);
  89. }
  90. function _random($length, $numeric = 0) {
  91. PHP_VERSION < '4.2.0' && mt_srand((double)microtime() * 1000000);
  92. if($numeric) {
  93. $hash = sprintf('%0'.$length.'d', mt_rand(0, pow(10, $length) - 1));
  94. } else {
  95. $hash = '';
  96. $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz';
  97. $max = strlen($chars) - 1;
  98. for($i = 0; $i < $length; $i++) {
  99. $hash .= $chars[mt_rand(0, $max)];
  100. }
  101. }
  102. return $hash;
  103. }
  104. function _generate_key() {
  105. $random = $this->_random(32);
  106. $info = md5($_SERVER['SERVER_SOFTWARE'].$_SERVER['SERVER_NAME'].$_SERVER['SERVER_ADDR'].$_SERVER['SERVER_PORT'].$_SERVER['HTTP_USER_AGENT'].time());
  107. $return = array();
  108. for($i=0; $i<32; $i++) {
  109. $return[$i] = $random[$i].$info[$i];
  110. }
  111. return implode('', $return);
  112. }
  113. function _format_notedata($notedata) {
  114. $arr = array();
  115. foreach($notedata as $key => $note) {
  116. $arr[$note['appid']] = $note;
  117. }
  118. return $arr;
  119. }
  120. }
  121. ?>