PageRenderTime 53ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 1ms

/control/app.php

https://github.com/alin40404/UCenter
PHP | 138 lines | 113 code | 17 blank | 8 comment | 15 complexity | 81fb8c7e08931d5a60aab30504ee4cd4 MD5 | raw file
  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 1059 2011-03-01 07:25:09Z monkey $
  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. $viewprourl = getgpc('viewprourl', 'P');
  33. $appcharset = getgpc('appcharset', 'P');
  34. $appdbcharset = getgpc('appdbcharset', 'P');
  35. $apptagtemplates = getgpc('apptagtemplates', 'P');
  36. $appallowips = getgpc('allowips', 'P');
  37. if(md5(md5($ucfounderpw).UC_FOUNDERSALT) == UC_FOUNDERPW || (strlen($ucfounderpw) == 32 && $ucfounderpw == md5(UC_FOUNDERPW))) {
  38. @ob_start();
  39. $return = '';
  40. $app = $this->db->fetch_first("SELECT * FROM ".UC_DBTABLEPRE."applications WHERE url='$appurl' AND type='$apptype'");
  41. if(empty($app)) {
  42. $authkey = $this->_generate_key();
  43. $apptagtemplates = $this->serialize($apptagtemplates, 1);
  44. $this->db->query("INSERT INTO ".UC_DBTABLEPRE."applications SET
  45. name='$appname',
  46. url='$appurl',
  47. ip='$appip',
  48. authkey='$authkey',
  49. viewprourl='$viewprourl',
  50. synlogin='1',
  51. charset='$appcharset',
  52. dbcharset='$appdbcharset',
  53. type='$apptype',
  54. recvnote='1',
  55. tagtemplates='$apptagtemplates',
  56. allowips='$appallowips'
  57. ");
  58. $appid = $this->db->insert_id();
  59. $_ENV['app']->alter_app_table($appid, 'ADD');
  60. //$return = "UC_STATUS_OK|$authkey|$appid|".UC_DBHOST.'|'.UC_DBNAME.'|'.UC_DBUSER.'|'.UC_DBPW.'|'.UC_DBCHARSET.'|'.UC_DBTABLEPRE.'|'.UC_CHARSET;
  61. $return = "$authkey|$appid|".UC_DBHOST.'|'.UC_DBNAME.'|'.UC_DBUSER.'|'.UC_DBPW.'|'.UC_DBCHARSET.'|'.UC_DBTABLEPRE.'|'.UC_CHARSET;
  62. $this->load('cache');
  63. $_ENV['cache']->updatedata('apps');
  64. $this->load('note');
  65. $notedata = $this->db->fetch_all("SELECT appid, type, name, url, ip, charset, synlogin, extra FROM ".UC_DBTABLEPRE."applications");
  66. $notedata = $this->_format_notedata($notedata);
  67. $notedata['UC_API'] = UC_API;
  68. $_ENV['note']->add('updateapps', '', $this->serialize($notedata, 1));
  69. $_ENV['note']->send();
  70. } else {
  71. //$return = "UC_STATUS_OK|$app[authkey]|$app[appid]|".UC_DBHOST.'|'.UC_DBNAME.'|'.UC_DBUSER.'|'.UC_DBPW.'|'.UC_DBCHARSET.'|'.UC_DBTABLEPRE.'|'.UC_CHARSET;
  72. $return = "$app[authkey]|$app[appid]|".UC_DBHOST.'|'.UC_DBNAME.'|'.UC_DBUSER.'|'.UC_DBPW.'|'.UC_DBCHARSET.'|'.UC_DBTABLEPRE.'|'.UC_CHARSET;
  73. }
  74. @ob_end_clean();
  75. exit($return);
  76. } else {
  77. exit('-1');
  78. }
  79. }
  80. function onucinfo() {
  81. $arrapptypes = $this->db->fetch_all("SELECT DISTINCT type FROM ".UC_DBTABLEPRE."applications");
  82. $apptypes = $tab = '';
  83. foreach($arrapptypes as $apptype) {
  84. $apptypes .= $tab.$apptype['type'];
  85. $tab = "\t";
  86. }
  87. exit("UC_STATUS_OK|".UC_SERVER_VERSION."|".UC_SERVER_RELEASE."|".UC_CHARSET."|".UC_DBCHARSET."|".$apptypes);
  88. }
  89. function _random($length, $numeric = 0) {
  90. PHP_VERSION < '4.2.0' && mt_srand((double)microtime() * 1000000);
  91. if($numeric) {
  92. $hash = sprintf('%0'.$length.'d', mt_rand(0, pow(10, $length) - 1));
  93. } else {
  94. $hash = '';
  95. $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz';
  96. $max = strlen($chars) - 1;
  97. for($i = 0; $i < $length; $i++) {
  98. $hash .= $chars[mt_rand(0, $max)];
  99. }
  100. }
  101. return $hash;
  102. }
  103. function _generate_key() {
  104. $random = $this->_random(32);
  105. $info = md5($_SERVER['SERVER_SOFTWARE'].$_SERVER['SERVER_NAME'].$_SERVER['SERVER_ADDR'].$_SERVER['SERVER_PORT'].$_SERVER['HTTP_USER_AGENT'].time());
  106. $return = array();
  107. for($i=0; $i<32; $i++) {
  108. $return[$i] = $random[$i].$info[$i];
  109. }
  110. return implode('', $return);
  111. }
  112. function _format_notedata($notedata) {
  113. $arr = array();
  114. foreach($notedata as $key => $note) {
  115. $arr[$note['appid']] = $note;
  116. }
  117. return $arr;
  118. }
  119. }
  120. ?>