/** * インストールトークンを使って初期化. * parentのinitializeは呼ばず、ここで認証と初期化を済ませる. */ public function initializeByInstallToken($token) { $tokendata = $this->getTokenData($token); apache_log('token_data', $tokendata); if (!$tokendata) { error_log("invalid install token: {$token}"); return $this->response(self::HTTP_403_FORBIDDEN, 'invalid token'); } $this->package = PackageDb::retrieveByPK($tokendata['package_id']); if (!$this->package) { return $this->response(self::HTTP_404_NOTFOUND, ''); } $this->app = $this->package->getApplication(); $this->login_user = new User($tokendata['mail']); return null; }
public function executeDelete() { $con = null; try { $api_key = mfwRequest::param('api_key'); $pkg_id = mfwRequest::param('id'); $app = ApplicationDb::selectByApiKey($api_key); if (!$app) { return $this->jsonResponse(self::HTTP_400_BADREQUEST, array('error' => 'Invalid api_key')); } $pkg = PackageDb::retrieveByPK($pkg_id); if (!$pkg || $app->getId() !== $pkg->getAppId()) { return $this->jsonResponse(self::HTTP_400_BADREQUEST, array('error' => 'Invalid package id')); } $con = mfwDBConnection::getPDO(); $con->beginTransaction(); $app = ApplicationDb::retrieveByPKForUpdate($app->getId(), $con); $pkg->delete($con); if ($app->getLastUpload() == $pkg->getCreated()) { // 最終アップデート時刻を前のものに戻す $pkg = PackageDb::selectNewestOneByAppId($app->getId()); $lastupload = $pkg ? $pkg->getCreated() : null; $app->updateLastUpload($lastupload, $con); } $con->commit(); } catch (Exception $e) { if ($con) { $con->rollback(); } error_log(__METHOD__ . '(' . __LINE__ . '): ' . get_class($e) . ":{$e->getMessage()}"); return $this->jsonResponse(self::HTTP_500_INTERNALSERVERERROR, array('error' => $e->getMessage(), 'exception' => get_class($e))); } try { $pkg->deleteFile(); } catch (Exception $e) { // S3から削除出来なくてもDBからは消えているので許容する } apache_log('app_id', $app->getId()); apache_log('pkg_id', $pkg->getId()); return $this->jsonResponse(self::HTTP_200_OK, $this->makePackageArray($pkg)); }
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); }
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); }