Esempio n. 1
0
 public function executeDelete()
 {
     $token = mfwRequest::param('token', null, 'POST');
     if ($token !== mfwSession::get(self::SESKEY_TOKEN)) {
         return $this->buildErrorPage('Bad Request', array(self::HTTP_400_BADREQUEST));
     }
     mfwSession::clear(self::SESKEY_TOKEN);
     $con = mfwDBConnection::getPDO();
     $con->beginTransaction();
     try {
         $this->app = ApplicationDb::retrieveByPKForUpdate($this->app->getId());
         $this->package->delete($con);
         if ($this->app->getLastUpload() == $this->package->getCreated()) {
             // 最終アップデート時刻を前のものに戻す
             $pkg = PackageDb::selectNewestOneByAppId($this->app->getId());
             $lastupload = $pkg ? $pkg->getCreated() : null;
             $this->app->updateLastUpload($lastupload, $con);
         }
         $con->commit();
     } catch (Exception $e) {
         $con->rollback();
         error_log(__METHOD__ . '(' . __LINE__ . '): ' . get_class($e) . ":{$e->getMessage()}");
         throw $e;
     }
     apache_log('app_id', $this->app->getId());
     apache_log('pkg_id', $this->package->getId());
     apache_log('platform', $this->package->getPlatform());
     try {
         $this->package->deleteFile();
     } catch (Exception $e) {
         // S3から削除出来なくてもDBからは消えているので許容する
     }
     return $this->redirect("/app?id={$this->app->getId()}");
 }
Esempio n. 2
0
 public function executeIndex()
 {
     static $pf = array('android' => Package::PF_ANDROID, 'ios' => Package::PF_IOS, 'all' => null);
     $platform = mfwRequest::param('pf');
     if (!in_array($platform, array('android', 'ios', 'all'))) {
         $ua = mfwRequest::userAgent();
         if ($ua->isAndroid()) {
             $platform = 'android';
         } elseif ($ua->isIOS()) {
             $platform = 'ios';
         } else {
             $platform = 'all';
         }
     }
     $tags = mfwRequest::param('tags') ? explode(' ', mfwRequest::param('tags')) : array();
     $current_page = mfwRequest::param('page', 1);
     $offset = ($current_page - 1) * self::LINE_IN_PAGE;
     $pkgs = PackageDb::selectByAppIdPfTagsWithLimit($this->app->getId(), $pf[$platform], $tags, $offset, self::LINE_IN_PAGE + 1);
     $has_next_page = false;
     if ($pkgs->count() > self::LINE_IN_PAGE) {
         $pkgs = $pkgs->slice(0, self::LINE_IN_PAGE);
         $has_next_page = true;
     }
     $comment_count = CommentDb::selectCountByAppId($this->app->getId());
     $top_comments = CommentDb::selectByAppId($this->app->getId(), 2);
     $commented_package = PackageDb::retrieveByPKs($top_comments->getColumnArray('package_id'));
     $params = array('pf' => $platform, 'is_owner' => $this->app->isOwner($this->login_user), 'packages' => $pkgs, 'active_tags' => $tags, 'current_page' => $current_page, 'has_next_page' => $has_next_page, 'filter_open' => mfwRequest::param('filter_open'), 'top_comments' => $top_comments, 'comment_count' => $comment_count, 'commented_package' => $commented_package);
     return $this->build($params);
 }
Esempio n. 3
0
 /**
  * インストールトークンを使って初期化.
  * 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;
 }
Esempio n. 4
0
 public function executeComment()
 {
     $app_id = $this->app->getId();
     $comment_count = CommentDb::selectCountByAppId($app_id);
     $current_page = mfwRequest::param('page', 1);
     $max_page = ceil($comment_count / self::COMMENTS_IN_PAGE);
     $offset = max(0, min($current_page, $max_page) - 1) * self::COMMENTS_IN_PAGE;
     $comments = CommentDb::selectByAppId($app_id, self::COMMENTS_IN_PAGE, $offset);
     $commented_package = PackageDb::retrieveByPKs($comments->getColumnArray('package_id'));
     $install_packages = $this->login_user->getInstallPackages($app_id);
     $install_packages->sort(function ($a, $b) {
         return $a['id'] < $b['id'];
     });
     $params = array('comments_in_page' => self::COMMENTS_IN_PAGE, 'comment_count' => $comment_count, 'comments' => $comments, 'commented_package' => $commented_package, 'cur_page' => $current_page, 'max_page' => $max_page, 'install_packages' => $install_packages);
     return $this->build($params);
 }
Esempio n. 5
0
 public function executeUpload_post()
 {
     $temp_name = mfwRequest::param('temp_name');
     $platform = mfwRequest::param('platform');
     $title = mfwRequest::param('title');
     $description = mfwRequest::param('description');
     $tag_names = mfwRequest::param('tags');
     $ios_identifier = mfwRequest::param('ios_identifier');
     $notify = mfwRequest::param('notify');
     $org_filename = mfwRequest::param('file_name');
     $filesize = mfwRequest::param('file_size');
     if (!$temp_name || !$title) {
         error_log(__METHOD__ . '(' . __LINE__ . "): bad request: {$temp_name}, {$title}");
         return $this->response(self::HTTP_400_BADREQUEST);
     }
     $ext = pathinfo($temp_name, PATHINFO_EXTENSION);
     $con = mfwDBConnection::getPDO();
     $con->beginTransaction();
     try {
         $app = ApplicationDb::retrieveByPKForUpdate($this->app->getId(), $con);
         $tags = $app->getTagsByName($tag_names, $con);
         $pkg = PackageDb::insertNewPackage($this->app->getId(), $platform, $ext, $title, $description, $ios_identifier, $org_filename, $filesize, $tags, $con);
         $pkg->renameTempFile($temp_name);
         $app->updateLastUpload($pkg->getCreated(), $con);
         $con->commit();
     } catch (Exception $e) {
         error_log(__METHOD__ . '(' . __LINE__ . '): ' . get_class($e) . ":{$e->getMessage()}");
         $con->rollback();
         throw $e;
     }
     if ($notify) {
         try {
             $users = $app->getInstallUsers();
             $users->noticePackageUploaded($pkg);
         } catch (Exception $e) {
             // アップロード通知が送れなくても許容する
             error_log(__METHOD__ . '(' . __LINE__ . '): ' . get_class($e) . ":{$e->getMessage()}");
         }
     }
     apache_log('app_id', $app->getId());
     apache_log('pkg_id', $pkg->getId());
     return $this->redirect("/package?id={$pkg->getId()}");
 }
Esempio n. 6
0
 public function executePackage_list()
 {
     try {
         $api_key = mfwRequest::param('api_key');
         $app = ApplicationDb::selectByApiKey($api_key);
         if (!$app) {
             return $this->jsonResponse(self::HTTP_400_BADREQUEST, array('error' => 'Invalid api_key'));
         }
         $pkgs = PackageDb::selectByAppId($app->getId());
         $ret = array();
         foreach ($pkgs as $pkg) {
             $ret[] = $this->makePackageArray($pkg);
         }
     } 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);
 }
Esempio n. 7
0
 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));
 }
Esempio n. 8
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);
 }
Esempio n. 9
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);
 }
Esempio n. 10
0
 public function executeEdit_commit()
 {
     $title = mfwRequest::param('title');
     $description = mfwRequest::param('description');
     $tag_names = mfwRequest::param('tags');
     if (!$title) {
         error_log(__METHOD__ . '(' . __LINE__ . "): bad request: {$temp_name}, {$title}");
         return $this->response(self::HTTP_400_BADREQUEST);
     }
     $con = mfwDBConnection::getPDO();
     $con->beginTransaction();
     try {
         $app = ApplicationDb::retrieveByPKForUpdate($this->app->getId(), $con);
         $tags = $app->getTagsByName($tag_names, $con);
         $pkg = PackageDb::retrieveByPKForUpdate($this->package->getId(), $con);
         $pkg->updateInfo($title, $description, $tags);
         $con->commit();
     } catch (Exception $e) {
         $con->rollback();
         throw $e;
     }
     return $this->redirect("/package?id={$this->package->getId()}");
 }
 public function executeUpload_package_temporary()
 {
     try {
         $file_info = mfwRequest::param('file');
         if (!$file_info || !isset($file_info['error']) || $file_info['error'] != UPLOAD_ERR_OK) {
             error_log(__METHOD__ . '(' . __LINE__ . '): upload file error: $_FILES[file]=' . json_encode($file_info));
             return $this->jsonResponse(self::HTTP_400_BADREQUEST, array('error' => 'upload_file error: $_FILES[file]=' . json_encode($file_info)));
         }
         $file_name = $file_info['name'];
         $file_path = $file_info['tmp_name'];
         $file_type = $file_info['type'];
         list($platform, $ext, $mime) = PackageDb::getPackageInfo($file_name, $file_path, $file_type);
         $temp_name = Package::uploadTempFile($file_path, $ext, $mime);
         $ios_identifier = null;
         if ($platform === Package::PF_IOS) {
             $plist = IPAFile::parseInfoPlist($file_path);
             $ios_identifier = $plist['CFBundleIdentifier'];
         }
     } 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)));
     }
     return $this->jsonResponse(self::HTTP_200_OK, array('file_name' => $file_name, 'temp_name' => $temp_name, 'platform' => $platform, 'ios_identifier' => $ios_identifier));
 }
Esempio n. 12
0
 public function getInstallPackages($app_id)
 {
     $pkg_ids = InstallLog::getInstallPackageIds($this, $app_id);
     return PackageDb::retrieveByPKs($pkg_ids);
 }
Esempio n. 13
0
 public function executeUpload()
 {
     $con = null;
     try {
         if (mfwRequest::method() !== 'POST') {
             return $this->jsonResponse(self::HTTP_405_METHODNOTALLOWED, array('error' => 'Method Not Allowed'));
         }
         $api_key = mfwRequest::param('api_key');
         $file_info = mfwRequest::param('file');
         $title = mfwRequest::param('title');
         $description = mfwRequest::param('description');
         $notify = mfwRequest::param('notify');
         $tag_names = explode(',', mfwRequest::param('tags'));
         if (!$api_key || !$file_info || !$title) {
             return $this->jsonResponse(self::HTTP_400_BADREQUEST, array('error' => 'A required field is not present.'));
         }
         if (!isset($file_info['error']) || $file_info['error'] !== UPLOAD_ERR_OK) {
             error_log(__METHOD__ . '(' . __LINE__ . '): upload file error: $_FILES[file]=' . json_encode($file_info));
             return $this->jsonResponse(self::HTTP_400_BADREQUEST, array('error' => 'upload file error: $_FILES[file]=' . json_encode($file_info)));
         }
         $app = ApplicationDb::selectByApiKey($api_key);
         if (!$app) {
             return $this->jsonResponse(self::HTTP_400_BADREQUEST, array('error' => 'Invalid api_key'));
         }
         apache_log('app_id', $app->getId());
         // ファイルフォーマット確認, 情報抽出
         list($platform, $ext, $mime) = PackageDb::getPackageInfo($file_info['name'], $file_info['tmp_name'], $file_info['type']);
         $ios_identifier = null;
         if ($platform === Package::PF_IOS) {
             $plist = IPAFile::parseInfoPlist($file_info['tmp_name']);
             $ios_identifier = $plist['CFBundleIdentifier'];
         }
         // DBへ保存
         $con = mfwDBConnection::getPDO();
         $con->beginTransaction();
         $app = ApplicationDb::retrieveByPKForUpdate($app->getId());
         $tags = $app->getTagsByName($tag_names, $con);
         $pkg = PackageDb::insertNewPackage($app->getId(), $platform, $ext, $title, $description, $ios_identifier, $file_info['name'], $file_info['size'], $tags, $con);
         apache_log('pkg_id', $pkg->getId());
         // S3へアップロード
         $pkg->uploadFile($file_info['tmp_name'], $mime);
         $app->updateLastUpload($pkg->getCreated(), $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)));
     }
     if ($notify) {
         try {
             $users = $app->getInstallUsers();
             $users->noticePackageUploaded($pkg);
         } catch (Exception $e) {
             // アップロード通知が送れなくても許容する
             error_log(__METHOD__ . '(' . __LINE__ . '): ' . get_class($e) . ":{$e->getMessage()}");
         }
     }
     return $this->jsonResponse(self::HTTP_200_OK, $this->makePackageArray($pkg));
 }