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()})"); } }
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()}"); }
protected function makePackageArray(Package $pkg) { $tags = array(); foreach ($pkg->getTags() as $t) { $tags[] = $t->getName(); } return array('package_url' => mfwRequest::makeUrl("/package?id={$pkg->getId()}"), 'application_url' => mfwRequest::makeUrl("/app?id={$pkg->getAppId()}"), 'id' => $pkg->getId(), 'platform' => $pkg->getPlatform(), 'title' => $pkg->getTitle(), 'description' => $pkg->getDescription(), 'ios_identifier' => $pkg->getIOSIdentifier(), 'original_file_name' => $pkg->getOriginalFileName(), 'file_size' => $pkg->getFileSize(), 'created' => $pkg->getCreated(), 'tags' => $tags, 'install_count' => $pkg->getInstallCount()); }
public static function execute() { // PATH_INFO should be '/module/action'. The deefault is 'top/index'. $pathinfo = mfwRequest::getPathInfoArray(); $module = isset($pathinfo[0]) && !empty($pathinfo[0]) ? $pathinfo[0] : 'top'; $action = isset($pathinfo[1]) && !empty($pathinfo[1]) ? $pathinfo[1] : 'index'; return parent::executeAction($module, $action); }
public function executeDelete() { $appid = mfwRequest::param('id'); $instapp = InstallLog::getInstallApp($this->login_user, $appid); if ($instapp) { $instapp->delete(); } return $this->redirect('/myapps/installed'); }
protected function redirect($query, $params = array()) { $query = mfwHttp::composeUrl($query, $params); if (strpos($query, 'http') !== 0) { $query = mfwRequest::makeUrl($query); } $headers = array("Location: {$query}"); return array($headers, null); }
public function executeIndex() { // httpsが使えるならlogin画面はhttpsを強制 if (Config::get('enable_https')) { if (strpos(mfwRequest::url(), 'http://') === 0) { return $this->redirect(mfwrequest::makeUrl('/login', 'https')); } } return $this->build(); }
public function executeRepoSave() { $name = mfwRequest::get('name'); $project = mfwRequest::get('project'); if (!$name || !$project) { return $this->buildErrorPage("invalid argument (name={$name}, project={$project})", "/pulls/repoEdit?repo_id={$this->repo->getId()}", 'return'); } $this->repo->update($name, $project); return $this->redirect("/pulls/repoEdit?repo_id={$this->repo->getId()}"); }
protected function getAccessToken($code) { if (!$code) { return null; } $callback_url = mfwRequest::makeUrl('/login/google_callback'); $url_base = 'https://accounts.google.com/o/oauth2/token'; $query = array('code' => $code, 'client_id' => $this->config['google_app_id'], 'client_secret' => $this->config['google_app_secret'], 'redirect_uri' => $callback_url, 'grant_type' => 'authorization_code'); $response = mfwHttp::post($url_base, $query); return json_decode($response, true); }
public function executeAdd() { $name = mfwRequest::get('name'); $project = mfwRequest::get('project'); if (!$name || !$project) { return $this->buildErrorPage("invalid argument (name={$name}, project={$project})", "/pulls/add", 'return'); } $repo = new Repository(array('name' => $name, 'project' => $project)); $repo->save(); return $this->redirect("/pulls/index"); }
public function executeIndex() { $current_page = mfwRequest::param('page', 1); $app_count = ApplicationDb::selectCount(); $max_page = ceil($app_count / self::LINE_IN_PAGE); $offset = max(0, min($current_page, $max_page) - 1) * self::LINE_IN_PAGE; $apps = ApplicationDb::selectByUpdateOrderWithLimit($offset, self::LINE_IN_PAGE); $comments = CommentDb::selectCountsByAppIds($apps->getColumnArray('id')); $params = array('applications' => $apps, 'comments' => $comments, 'cur_page' => $current_page, 'max_page' => $max_page); return $this->build($params); }
protected function saveUrlBeforeLogin() { if (mfwRequest::method() === 'GET') { $url = mfwRequest::url(); if (Config::get('enable_https')) { $url = preg_replace('/^http:/', 'https:', $url); } mfwSession::set(self::SESKEY_URL_BEFORE_LOGIN, $url); } else { mfwSession::clear(self::SESKEY_URL_BEFORE_LOGIN); } }
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); }
/** * @param[in] string $sender 送信アドレス */ public function sendResetMail() { $data = array('mail' => $this->row['mail'], 'microtime' => microtime()); $key = sha1(json_encode($data)); mfwMemcache::set($key, $data, self::RESET_MAIL_EXPIRE); $url = mfwRequest::makeUrl("/login/password_reset?key={$key}"); $subject = 'Reset password'; $to = $data['mail']; $from = 'From: ' . Config::get('mail_sender'); $body = "EMLauncher password reset URL:\n{$url}\n"; if (!mb_send_mail($to, $subject, $body, $from)) { throw new RuntimeException("mb_send_mail faild (key:{$key} to:{$to})"); } }
public function executeSave() { $arr = array(); $fid = (int) mfwRequest::get('id'); if ($fid) { $arr['id'] = $fid; } $arr['enable'] = (bool) mfwRequest::get('enable', true); $arr['name'] = mfwRequest::get('name'); $arr['target'] = mfwRequest::get('target'); $arr['pattern'] = mfwRequest::get('pattern'); $filter = new Filter($arr); $filter->save(); return $this->redirect('/filters/index'); }
public function executePassword_commit() { $key = mfwRequest::param('key'); $pass = mfwRequest::param('password'); $data = mfwMemcache::get($key); $user_pass = null; if (isset($data['mail'])) { $user_pass = UserPassDb::selectByEmail($data['mail']); } if (!$user_pass) { return $this->buildErrorPage('invalid key'); } $user_pass->updatePasshash($pass); mfwMemcache::delete($key); return $this->build(); }
public function executeNotification_setting() { try { $app_id = mfwRequest::param('id'); $notify = mfwRequest::param('value', false); $instapp = InstallLog::getInstallApp($this->login_user, $app_id); if (!$instapp) { return $this->jsonResponse(self::HTTP_404_NOTFOUND, array('error' => 'installed application not found.')); } $instapp->updateNotifySetting($notify); } 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, $instapp->toArray()); }
public function executeInstall_plist() { $token = mfwRequest::param('t'); if (!$this->checkToken($token)) { return $this->buildErrorPage('Permission Denied', array(self::HTTP_403_FORBIDDEN)); } $pkg = $this->package; $app = $pkg->getApplication(); $ipa_url = $pkg->getFileUrl('+60 min'); $image_url = $app->getIconUrl(); $bundle_identifier = $pkg->getIOSIdentifier(); $pkg_title = $pkg->getTitle(); $app_title = $app->getTitle(); ob_start(); include APP_ROOT . '/data/templates/package/install_plist.php'; $plist = ob_get_clean(); $header = array('Content-Type: text/xml'); return array($header, $plist); }
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()}"); }
public function executeView() { $pullid = (int) mfwRequest::get('pull_id'); $pull = PullRequestDb::retrieveByPK($pullid); if (!$pull) { return $this->buildErrorPage("pull request no found (id={$pullid})"); } $repo = $this->repolist[$pull->getRepoId()]; $rawpull = Github::getSinglePullRequest($repo->getName(), $pull->getNumber()); $comments = Github::getPullRequestComments($repo->getName(), $pull->getNumber()); $files = Github::getPullRequestFiles($repo->getName(), $pull->getNumber()); $alerts = PullRequestAlertDb::selectByPullRequest($pull); $filters = FilterDb::selectAll(); $alert_filters = array(); foreach ($alerts as $a) { $alert_filters[$a->getFileName()][] = $filters[$a->getFilterId()]; } $params = array('rawpull' => $rawpull, 'comments' => $comments, 'files' => $files, 'pull' => $pull, 'repo' => $repo, 'alert_filters' => $alert_filters); return $this->build($params); }
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); }
public function executePreferences_update_owners() { $owners = mfwRequest::param('owners'); $owners = array_filter($owners, 'strlen'); // 自分自身は除外させない $owners[] = $this->login_user->getMail(); $owners = array_unique($owners); $con = mfwDBConnection::getPDO(); $con->beginTransaction(); try { $this->app = ApplicationDb::retrieveByPkForUpdate($this->app->getId(), $con); $this->app->setOwners($owners, $con); $con->commit(); } catch (Exception $e) { error_log(__METHOD__ . '(' . __LINE__ . '): ' . get_class($e) . ":{$e->getMessage()}"); $con->rollback(); throw $e; } return $this->redirect("/app/preferences?id={$this->app->getId()}#owners"); }
public function executeComment_post() { $message = mfwRequest::param('message'); $package_id = mfwRequest::param('package_id'); $con = mfwDBConnection::getPDO(); $con->beginTransaction(); try { $this->app = ApplicationDb::retrieveByPkForUpdate($this->app->getId()); $comment = CommentDb::post($this->login_user, $this->app, $package_id, $message); $this->app->updateLastCommented($comment->getCreated()); $con->commit(); } catch (Exception $e) { error_log(__METHOD__ . '(' . __LINE__ . '): ' . get_class($e) . ":{$e->getMessage()}"); $con->rollback(); throw $e; } $owners = $this->app->getOwners(); $owners->noticeNewComment($comment, $this->app); return $this->redirect('/app/comment', array('id' => $this->app->getId())); }
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 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 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); }
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)); }
<link type="text/css" rel="stylesheet" href="/vendor/syntaxhighlighter/styles/shCore.css"> <link type="text/css" rel="stylesheet" href="/vendor/syntaxhighlighter/styles/shCoreDefault.css"> <script type="text/javascript" src="/vendor/syntaxhighlighter/scripts/shCore.js"></script> <script type="text/javascript" src="/vendor/syntaxhighlighter/scripts/shBrushPhp.js"></script> <?php $returl = mfwRequest::getReturnUrl(); if (!$returl) { $returl = url('/pulls/index'); } ?> <h2>[<?php echo $repo->getProject(); ?> ] <?php echo $pull->getNumber(); ?> :<?php echo $pull->getTitle(); ?> </h2> <ul class="repolist"> <?php foreach ($repos as $r) { ?> <li><a href="<?php echo url("/pulls/repo?repo_id={$r->getId()}"); ?> "><?php echo $r->getProject(); ?>
</a></h3> <ul class="info"> <li><span class="tag">Login Name:</span> <?php echo $alert['pull']->getUser(); ?> </li> <li><span class="tag">Created At:</span> <?php echo $alert['pull']->getCreatedAt(); ?> </li> </ul> <div class="view_link">[<a href="/pulls/view?pull_id=<?php echo $alert['pull']->getId(); ?> &link_id=<?php echo mfwRequest::makeThisLinkId(); ?> ">詳細</a>]</div> </div> <div class="detail"> <ul class="alerts"> <?php foreach ($alert['alerts'] as $a) { ?> <li><?php echo $a->getName(); ?> </li> <?php } ?>