diff --git a/lib/ztcloud/ztcloud.class.php b/lib/ztcloud/ztcloud.class.php new file mode 100644 index 0000000000..0a9f7491d2 --- /dev/null +++ b/lib/ztcloud/ztcloud.class.php @@ -0,0 +1,199 @@ +from = $from; + $this->fromName = empty($fromName) ? $from : $fromName; + } + + /** + * Add an address + * + * @param string $kind + * @param string $address + * @param string $name + * @access public + * @return bool + */ + public function addAnAddress($kind, $address, $name = '') + { + $kind = strtolower($kind); + if(!preg_match('/^(to|cc|bcc|replyto)$/', $kind)) + { + $error = 'Invalid recipient array: ' . $kind; + throw new Exception($error); + echo $error; + return false; + } + + $address = trim($address); + if(empty($address)) return true; + + $key = $kind . 'List'; + $this->$key .= $address . ';'; + return true; + } + + /** + * Send mail + * + * @access public + * @return bool + */ + public function send() + { + if(!empty($this->Subject) and empty($this->subject)) $this->subject = $this->Subject; + + $param['account'] = $this->account; + $param['from'] = $this->from; + $param['fromName'] = $this->fromName; + $param['toList'] = $this->toList; + $param['ccList'] = $this->ccList; + $param['subject'] = $this->subject; + $param['body'] = $this->body; + + $result = $this->queryZtcloud($this->url, $param); + if($result->result == 'fail') + { + throw new Exception($result->message . "(code:{$result->code})"); + return false; + } + } + + /** + * Query Ztcloud + * + * @param string $url + * @param array $param + * @access public + * @return object + */ + public function queryZtcloud($url, $param) + { + if(!isset($param['signature'])) $param['signature'] = $this->getSignature($param); + + $data = http_build_query($param); + $options['http'] = array( + 'method' => 'POST', + 'header' => 'Content-Type: application/x-www-form-urlencoded', + 'content' => $data + ); + $context = stream_context_create($options); + $result = file_get_contents($url, FILE_TEXT, $context); + return json_decode($result); + } + + /** + * Compute Signature. + * + * @param array $param + * @access public + * @return string + */ + public function getSignature($param) + { + ksort($param); + $data = ''; + foreach($param as $key => $value) $data .= $key . '=' . $value . '&'; + return md5($this->secretKey . '&' . $data . $this->secretKey); + } + + /** + * Add address + * + * @param string $address + * @param string $name + * @access public + * @return bool + */ + public function addAddress($address, $name = '') + { + return $this->addAnAddress('to', $address, $name); + } + + /** + * Add cc. + * + * @param string $address + * @param string $name + * @access public + * @return bool + */ + public function addCC($address, $name = '') + { + return $this->addAnAddress('cc', $address, $name); + } + + /** + * MsgHtml + * + * @param string $html + * @access public + * @return void + */ + public function msgHtml($html) + { + $this->body = $html; + } + + /** + * Clear all recipients. + * + * @access public + * @return void + */ + public function clearAllRecipients() + { + $this->toList = ''; + } + + /** + * Clear attachments. + * + * @access public + * @return void + */ + public function clearAttachments() + { + $this->subject = ''; + $this->html = ''; + $this->files = ''; + $this->headers = ''; + $this->Subject = ''; + } + + /** + * Set language. + * + * @param string $langcode + * @param string $lang_path + * @access public + * @return bool + */ + public function setLanguage($langcode = 'en', $lang_path = '../phpmailer/language/') + { + return true; + } +} diff --git a/module/admin/control.php b/module/admin/control.php index 45668c622e..bd0bb4a55f 100644 --- a/module/admin/control.php +++ b/module/admin/control.php @@ -47,7 +47,10 @@ class admin extends control */ public function ignore() { - $this->loadModel('setting')->setItem('system.common.global.community', 'na'); + $this->loadModel('setting'); + $this->setting->deleteItems('owner=system&module=common§ion=global&key=community'); + $this->setting->deleteItems('owner=system&module=common§ion=global&key=ztPrivateKey'); + $this->setting->setItem('system.common.global.community', 'na'); die(js::locate(inlink('index'), 'parent')); } @@ -57,16 +60,26 @@ class admin extends control * @access public * @return void */ - public function register() + public function register($from = 'admin') { if($_POST) { $response = $this->admin->registerByAPI(); - if($response == 'success') + $response = json_decode($response); + if($response->result == 'success') { - $this->loadModel('setting')->setItem('system.common.global.community', $this->post->account); + $user = json_decode($response->data); + $data['community'] = $user->account; + $data['ztPrivateKey'] = $user->privateKey; + + $this->loadModel('setting'); + $this->setting->deleteItems('owner=system&module=common§ion=global&key=community'); + $this->setting->deleteItems('owner=system&module=common§ion=global&key=ztPrivateKey'); + $this->setting->setItems('system.common.global', $data); + echo js::alert($this->lang->admin->register->success); - die(js::locate(inlink('index'), 'parent')); + if($from == 'admin') die(js::locate(inlink('index'), 'parent')); + if($from == 'mail') die(js::locate($this->createLink('mail', 'ztcloud'), 'parent')); } die($response); } @@ -75,6 +88,7 @@ class admin extends control $this->view->position[] = $this->lang->admin->register->caption; $this->view->register = $this->admin->getRegisterInfo(); $this->view->sn = $this->config->global->sn; + $this->view->from = $from; $this->display(); } @@ -84,7 +98,7 @@ class admin extends control * @access public * @return void */ - public function bind() + public function bind($from = 'admin') { if($_POST) { @@ -92,9 +106,18 @@ class admin extends control $response = json_decode($response); if($response->result == 'success') { - $this->loadModel('setting')->setItem('system.common.global.community', $this->post->account); + $user = $response->data; + $data['community'] = $user->account; + $data['ztPrivateKey'] = $user->privateKey; + + $this->loadModel('setting'); + $this->setting->deleteItems('owner=system&module=common§ion=global&key=community'); + $this->setting->deleteItems('owner=system&module=common§ion=global&key=ztPrivateKey'); + $this->setting->setItems('system.common.global', $data); + echo js::alert($this->lang->admin->bind->success); - die(js::locate(inlink('index'), 'parent')); + if($from == 'admin') die(js::locate(inlink('index'), 'parent')); + if($from == 'mail') die(js::locate($this->createLink('mail', 'ztcloud'), 'parent')); } else { @@ -105,6 +128,7 @@ class admin extends control $this->view->title = $this->lang->admin->bind->caption; $this->view->position[] = $this->lang->admin->bind->caption; $this->view->sn = $this->config->global->sn; + $this->view->from = $from; $this->display(); } @@ -192,4 +216,64 @@ class admin extends control $this->view->code = isset($this->config->sso->code) ? $this->config->sso->code : ''; $this->display(); } + + public function certifyZtEmail($email = '') + { + if($_POST) + { + $this->admin->certifyByAPI('mail'); + die(js::locate($this->createLink('mail', 'ztCloud'), 'parent')); + } + + $this->view->title = $this->lang->admin->certifyEmail; + $this->view->position[] = $this->lang->admin->certifyEmail; + + $this->view->email = helper::safe64Decode($email); + $this->display(); + } + + public function certifyZtMobile($mobile = '') + { + if($_POST) + { + $this->admin->certifyByAPI('mobile'); + die(js::locate($this->createLink('mail', 'ztCloud'), 'parent')); + } + + $this->view->title = $this->lang->admin->certifyMobile; + $this->view->position[] = $this->lang->admin->certifyMobile; + + $this->view->mobile = helper::safe64Decode($mobile); + $this->display(); + } + + public function ajaxSendCode($type) + { + die($this->admin->sendCodeByAPI($type)); + } + + public function sendmail() + { + $url = 'http://api.sendcloud.net/apiv2/mail/send'; + $params['apiUser'] = 'zentao_chunsheng'; + $params['apiKey'] = 'I70rz0E5Org4N3jU'; + $params['from'] = '876333172@qq.com'; + $params['fromName'] = 'QQ'; + $params['to'] = 'wyd621@163.com'; + $params['subject'] = 'test'; + $params['html'] = 'test'; + + $data = http_build_query($params); + + $options['http'] = array( + 'method' => 'POST', + 'header' => 'Content-Type: application/x-www-form-urlencoded', + 'content' => $data + ); + $context = stream_context_create($options); + $result = file_get_contents($url, FILE_TEXT, $context); + + a($result); + + } } diff --git a/module/admin/lang/zh-cn.php b/module/admin/lang/zh-cn.php index a0b7106c37..011cab4d09 100644 --- a/module/admin/lang/zh-cn.php +++ b/module/admin/lang/zh-cn.php @@ -9,12 +9,16 @@ * @version $Id: zh-cn.php 4767 2013-05-05 06:10:13Z wwccss $ * @link http://www.zentao.net */ -$lang->admin->common = '后台管理'; -$lang->admin->index = '后台管理首页'; -$lang->admin->checkDB = '检查数据库'; -$lang->admin->sso = '然之集成'; -$lang->admin->safeIndex = '安全'; -$lang->admin->checkWeak = '弱口令检查'; +$lang->admin->common = '后台管理'; +$lang->admin->index = '后台管理首页'; +$lang->admin->checkDB = '检查数据库'; +$lang->admin->sso = '然之集成'; +$lang->admin->safeIndex = '安全'; +$lang->admin->checkWeak = '弱口令检查'; +$lang->admin->certifyMobile = '认证手机'; +$lang->admin->certifyEmail = '认证邮箱'; +$lang->admin->captcha = '验证码'; +$lang->admin->getCaptcha = '获取验证码'; $lang->admin->info = new stdclass(); $lang->admin->info->version = '当前系统的版本是%s,'; diff --git a/module/admin/model.php b/module/admin/model.php index f22847fd5d..1406c3cfce 100644 --- a/module/admin/model.php +++ b/module/admin/model.php @@ -125,6 +125,55 @@ class adminModel extends model return $this->postAPI($apiURL, $_POST); } + public function getSecretKey() + { + //$apiURL = "http://www.zentao.net/user-secretKey.json"; + $apiURL = "http://www.zentao.cn/user-secretKey.json"; + $params['account'] = $this->config->global->community; + $params['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'; + $params['signature'] = $this->getSignature($params); + $this->agent->cookies['lang'] = $this->cookie->lang; + $this->agent->fetch($apiURL . '?' . http_build_query($params)); + $result = $this->agent->results; + $result = json_decode($result); + return $result; + } + + public function sendCodeByAPI($type) + { + $module = $type == 'mobile' ? 'sms' : 'mail'; +// $apiURL = "http://www.zentao.net/{$module}-apiSendCode.json"; + $apiURL = "http://www.zentao.cn/{$module}-apiSendCode.json"; + $params['account'] = $this->config->global->community; + $params['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'; + $params['signature'] = $this->getSignature($params); + + $param = http_build_query($params); + return $this->postAPI($apiURL . '?' . $param, $_POST); + } + + public function certifyByAPI($type) + { + $module = $type == 'mobile' ? 'sms' : 'mail'; +// $apiURL = "http://www.zentao.net/{$module}-apiCertify.json"; + $apiURL = "http://www.zentao.cn/{$module}-apiCertify.json"; + $params['account'] = $this->config->global->community; + $params['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'; + $params['signature'] = $this->getSignature($params); + + $param = http_build_query($params); + return $this->postAPI($apiURL . '?' . $param, $_POST); + } + + public function getSignature($params) + { + ksort($params); + $data = ''; + foreach($params as $key => $value) $data .= $key . '=' . $value . '&'; + $privateKey = $this->config->global->ztPrivateKey; + return md5($privateKey . '&' . $data . $privateKey); + } + /** * Get register information. * diff --git a/module/admin/view/bind.html.php b/module/admin/view/bind.html.php index 0674133ec3..5d928b2d7c 100644 --- a/module/admin/view/bind.html.php +++ b/module/admin/view/bind.html.php @@ -22,7 +22,11 @@
| user->account;?> | -+ global, 'community', ''); + if($account == 'na') $account = ''; + ?> + | ||
|---|---|---|---|
| user->password;?> | diff --git a/module/admin/view/certifyztemail.html.php b/module/admin/view/certifyztemail.html.php new file mode 100644 index 0000000000..4a9cdb479e --- /dev/null +++ b/module/admin/view/certifyztemail.html.php @@ -0,0 +1,62 @@ + + * @package admin + * @version $Id$ + * @link http://www.zentao.net + */ +?> + +|||
| user->phone;?> | -+ | user->mobile;?> | +|
| user->email;?> | diff --git a/module/mail/control.php b/module/mail/control.php index 2df6cb4464..7fa06c7670 100755 --- a/module/mail/control.php +++ b/module/mail/control.php @@ -40,6 +40,7 @@ class mail extends control if($this->config->mail->turnon) { if($this->config->mail->mta == 'sendcloud') $this->locate(inlink('sendcloud')); + if($this->config->mail->mta == 'ztcloud') $this->locate(inlink('ztcloud')); if($this->config->mail->mta == 'smtp') $this->locate(inlink('edit')); } $this->view->title = $this->lang->mail->common . $this->lang->colon . $this->lang->mail->index; @@ -452,4 +453,79 @@ class mail extends control $this->view->users = $this->loadModel('user')->getList(); $this->display(); } + + public function ztCloud() + { + if($_POST) + { + $mailConfig = new stdclass(); + $mailConfig->sendcloud = new stdclass(); + + $mailConfig->turnon = $this->post->turnon; + $mailConfig->mta = 'ztcloud'; + $mailConfig->async = $this->post->async; + $mailConfig->fromAddress = $this->post->fromAddress; + $mailConfig->fromName = $this->post->fromName; + $mailConfig->domain = trim($this->post->domain); + + if(empty($mailConfig->fromName)) die(js::alert(sprintf($this->lang->error->notempty, $this->lang->mail->fromName))); + + $this->loadModel('setting')->setItems('system.mail', $mailConfig); + die(js::reload('parent')); + } + + $this->view->title = $this->lang->mail->ztCloud; + $this->view->position[] = html::a(inlink('index'), $this->lang->mail->common); + $this->view->position[] = $this->lang->mail->ztCloud; + if(!empty($this->config->mail->ztcloud->secretKey)) + { + $mailConfig = new stdclass(); + $mailConfig->fromAddress = $this->config->mail->fromAddress; + $mailConfig->fromName = $this->config->mail->fromName; + $mailConfig->turnon = $this->config->mail->turnon; + $mailConfig->domain = isset($this->config->mail->domain) ? $this->config->mail->domain : common::getSysURL(); + $mailConfig->async = isset($this->config->mail->async) ? $this->config->mail->async : 0; + + $this->view->mailExist = $this->mail->mailExist(); + $this->view->mailConfig = $mailConfig; + $this->view->step = 'config'; + die($this->display()); + } + + if($this->cookie->ztCloudLicense != 'yes') + { + $this->view->step = 'license'; + die($this->display()); + } + if(empty($this->config->global->ztPrivateKey) or $this->config->global->community == 'na' or empty($this->config->global->community)) + { + if(!empty($this->config->global->community) and $this->config->global->community != 'na') die(js::locate($this->createLink('admin', 'bind', 'from=mail'))); + die(js::locate($this->createLink('admin', 'register', 'from=mail'))); + } + $result = $this->loadModel('admin')->getSecretKey(); + $data = $result->data; + if($result->result == 'fail' and empty($data->emailCertified)) + { + die(js::locate($this->createLink('admin', 'certifyZtEmail', 'email=' . helper::safe64Encode($data->email)))); + } + if($result->result == 'fail' and (empty($data->mobileCertified) or $data->mobileCertified != $data->mobile)) + { + die(js::locate($this->createLink('admin', 'certifyZtMobile', 'mobile=' . helper::safe64Encode($data->mobile)))); + } + if($result->result == 'success') + { + $this->loadModel('setting')->setItem('system.mail.ztcloud.secretKey', $data->secretKey); + $this->setting->setItem('system.mail.fromAddress', $data->email); + + $mailConfig = new stdclass(); + $mailConfig->turnon = true; + $mailConfig->fromAddress = $data->email; + $mailConfig->fromName = $this->config->mail->fromName; + $mailConfig->domain = isset($this->config->mail->domain) ? $this->config->mail->domain : common::getSysURL(); + + $this->view->mailConfig = $mailConfig; + $this->view->step = 'config'; + die($this->display()); + } + } } diff --git a/module/mail/js/ztcloud.js b/module/mail/js/ztcloud.js new file mode 100644 index 0000000000..0f8756fc0b --- /dev/null +++ b/module/mail/js/ztcloud.js @@ -0,0 +1,5 @@ +function agreeLicense() +{ + $.cookie('ztCloudLicense', 'yes', {expires:config.cookieLife, path:config.webRoot}); + self.location.href=self.location.href; +} diff --git a/module/mail/lang/zh-cn.php b/module/mail/lang/zh-cn.php index ea81b4c20d..0519fac1ab 100755 --- a/module/mail/lang/zh-cn.php +++ b/module/mail/lang/zh-cn.php @@ -8,9 +8,12 @@ $lang->mail->test = '测试发信'; $lang->mail->reset = '重置'; $lang->mail->browse = '邮件列表'; $lang->mail->delete = '删除邮件'; -$lang->mail->sendCloud = 'SendCloud发信'; +$lang->mail->ztCloud = 'SendCloud发信'; +$lang->mail->sendCloud = 'Notice发信'; $lang->mail->batchDelete = '批量删除'; $lang->mail->sendcloudUser = '同步联系人'; +$lang->mail->agreeLicense = '同意'; +$lang->mail->disagree = '不同意'; $lang->mail->turnon = '是否打开'; $lang->mail->async = '异步发送'; @@ -27,6 +30,7 @@ $lang->mail->debug = '调试级别'; $lang->mail->charset = '编码'; $lang->mail->accessKey = 'accessKey'; $lang->mail->secretKey = 'secretKey'; +$lang->mail->license = 'Sendcloud发信须知'; $lang->mail->selectMTA = '请选择发信方式:'; $lang->mail->smtp = 'SMTP发信'; @@ -85,6 +89,12 @@ EOD; $lang->mail->sendCloudSuccess = '操作成功'; $lang->mail->closeSendCloud = '关闭SendCloud'; $lang->mail->addressWhiteList = '为防止邮件被屏蔽,请在邮件服务器里面将发信邮箱设为白名单'; +$lang->mail->ztCloudNotice = <<mail->test); - echo html::linkButton($lang->mail->edit, inLink($config->mail->mta == 'sendcloud' ? 'sendcloud' : 'edit')); + $mta = $config->mail->mta; + echo html::linkButton($lang->mail->edit, inlink(($mta == 'sendcloud' or $mta == 'ztcloud') ? $mta : 'edit')); ?> | diff --git a/module/mail/view/ztcloud.html.php b/module/mail/view/ztcloud.html.php new file mode 100644 index 0000000000..98808908c5 --- /dev/null +++ b/module/mail/view/ztcloud.html.php @@ -0,0 +1,77 @@ + + * @package mail + * @version $Id$ + * @link http://www.zentao.net + */ +?> + +