Example #1
0
 public function noticePackageUploaded(Package $pkg)
 {
     $app = $this->app;
     $package_url = mfwRequest::makeURL("/package?id={$pkg->getId()}");
     ob_start();
     include APP_ROOT . '/data/notice_mail_template.php';
     $body = ob_get_clean();
     $addresses = array();
     foreach ($this->rows as $r) {
         if ($r['notify']) {
             $addresses[] = $r['mail'];
         }
     }
     if (empty($addresses)) {
         return;
     }
     $subject = "New Package Uploaded to {$app->getTitle()}";
     $sender = Config::get('mail_sender');
     $to = $sender;
     $header = "From: {$sender}" . "\nBcc: " . implode(', ', $addresses);
     mb_language('uni');
     mb_internal_encoding('UTF-8');
     if (!mb_send_mail($to, $subject, $body, $header)) {
         throw new RuntimeException("mb_send_mail faild (pkg={$pkg->getId()}, {$pkg->getTitle()})");
     }
 }
Example #2
0
 public function executeCreate_token()
 {
     $token_expire = '+1 hours';
     $expire_time = strtotime($token_expire);
     $mc_expire = $expire_time - time();
     $tokendata = array('mail' => $this->login_user->getMail(), 'package_id' => $this->package->getId(), 'expire' => date('Y-m-d H:i:s', $expire_time));
     $token = Random::string(32);
     mfwMemcache::set(self::INSTALL_TOKEN_PREFIX . $token, json_encode($tokendata), $mc_expire);
     apache_log('token', $token);
     apache_log('token_data', $tokendata);
     $params = array('token' => $token, 'expire' => $tokendata['expire'], 'token_url' => mfwRequest::makeURL("/package/install?token={$token}"));
     return $this->build($params);
 }
Example #3
0
 public function executeCreate_token()
 {
     try {
         $api_key = mfwRequest::param('api_key');
         $pkg_id = mfwRequest::param('id');
         $mail = mfwRequest::param('mail');
         $expire_hour = mfwRequest::param('expire_hour');
         // api_key check
         $app = ApplicationDb::selectByApiKey($api_key);
         if (!$app) {
             return $this->jsonResponse(self::HTTP_400_BADREQUEST, array('error' => 'Invalid api_key'));
         }
         // id check
         $pkg = PackageDb::retrieveByPK($pkg_id);
         if (!$pkg || $app->getId() !== $pkg->getAppId()) {
             return $this->jsonResponse(self::HTTP_400_BADREQUEST, array('error' => 'Invalid package id'));
         }
         // mail check
         $owner_mails = $app->getOwners()->getMailArray();
         if (!in_array($mail, $owner_mails)) {
             return $this->jsonResponse(self::HTTP_400_BADREQUEST, array('error' => 'Invalid mail address'));
         }
         // create install token
         $expire_hour = empty($expire_hour) ? 1 : $expire_hour;
         $token_expire = sprintf('+%s hours', $expire_hour);
         $expire_time = strtotime($token_expire);
         $mc_expire = $expire_time - time();
         $tokendata = array('mail' => $mail, 'package_id' => $pkg_id, 'expire' => date('Y-m-d H:i:s', $expire_time));
         $token = Random::string(32);
         mfwMemcache::set(self::INSTALL_TOKEN_PREFIX . $token, json_encode($tokendata), $mc_expire);
         apache_log('token', $token);
         apache_log('token_data', $tokendata);
         $ret = $this->makePackageArray($pkg);
         $ret['install_url'] = mfwRequest::makeURL("/package/install?token={$token}");
     } catch (Exception $e) {
         error_log(__METHOD__ . '(' . __LINE__ . '): ' . get_class($e) . ":{$e->getMessage()}");
         return $this->jsonResponse(self::HTTP_500_INTERNALSERVERERROR, array('error' => $e->getMessage(), 'exception' => get_class($e)));
     }
     apache_log('app_id', $app->getId());
     return $this->jsonResponse(self::HTTP_200_OK, $ret);
 }
Example #4
0
 public function noticeNewComment(Comment $comment, Application $app)
 {
     $pkg = null;
     if ($comment->getPackageId()) {
         $pkg = PackageDb::retrieveByPK($comment->getPackageId());
     }
     $page_url = mfwRequest::makeURL("/app/comment?id={$app->getId()}#comment-{$comment->getNumber()}");
     ob_start();
     include APP_ROOT . '/data/notice_comment_mail_template.php';
     $body = ob_get_clean();
     $addresses = $this->getColumnArray('owner_mail');
     if (empty($addresses)) {
         return;
     }
     $subject = "New Comment to {$app->getTitle()}";
     $sender = Config::get('mail_sender');
     $to = implode(', ', $addresses);
     $header = "From: {$sender}";
     mb_language('uni');
     mb_internal_encoding('UTF-8');
     return !mb_send_mail($to, $subject, $body, $header);
 }