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