Beispiel #1
0
 public static function addStat()
 {
     if (isset($_POST["lobby"]["lid"]) && isset($_POST["lobby"]["version"])) {
         $sql = \Lobby\DB::getDBH()->prepare("INSERT INTO `lobby_api_access` (`lid`, `version`, `accessed`, `frequency`) VALUES (:lid, :version, UNIX_TIMESTAMP(), '1') ON DUPLICATE KEY UPDATE `accessed` = UNIX_TIMESTAMP(), `frequency` = `frequency` + 1, `version` = :version");
         $sql->execute(array("lid" => $_POST["lobby"]["lid"], "version" => $_POST["lobby"]["version"]));
     }
 }
Beispiel #2
0
 public static function __constructStatic()
 {
     /**
      * Default timezone of Lobby is UTC
      */
     date_default_timezone_set("UTC");
     if (DB::getType() === "mysql") {
         $sql = DB::getDBH()->prepare("SET time_zone = ?;");
         $sql->execute(array('+00:00'));
     }
     self::loadConfig();
 }
Beispiel #3
0
 /**
  * Install module
  * --------------
  * Create the `users` table
  */
 public function install()
 {
     if (DB::getOption("admin_installed") == null && \Lobby::$installed) {
         /**
          * Install Module
          */
         $salt = \Helper::randStr(15);
         $cookie = \Helper::randStr(15);
         DB::saveOption("admin_secure_salt", $salt);
         DB::saveOption("admin_secure_cookie", $cookie);
         $prefix = DB::getPrefix();
         /**
          * Create `users` TABLE
          */
         $sql = DB::getDBH()->prepare("CREATE TABLE IF NOT EXISTS `{$prefix}users` (\n        `id` int(11) NOT NULL AUTO_INCREMENT,\n        `username` varchar(10) NOT NULL,\n        `password` varchar(255) NOT NULL,\n        `name` varchar(30) NOT NULL,\n        `created` datetime NOT NULL,\n        `attempt` varchar(15) NOT NULL DEFAULT '0',\n        PRIMARY KEY (`id`)\n      ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;");
         if ($sql->execute() != 0) {
             DB::saveOption("admin_installed", "true");
         }
     }
 }
Beispiel #4
0
$App = new \Lobby\Apps("lobby-server");
$App->run();
require APPS_DIR . "/lobby-server/src/inc/LobbyGit.php";
/**
 * Argument 1 has the App ID
 */
if (isset($argv[1])) {
    $sql = \Lobby\DB::getDBH()->prepare("SELECT `id`, `git_url` FROM `apps` WHERE `id` = ?");
    $sql->execute(array($argv[1]));
    if ($sql->rowCount() !== 0) {
        $r = $sql->fetch(\PDO::FETCH_ASSOC);
        $LG = new \LobbyGit($r['id'], $r['git_url']);
        if ($LG->update()) {
            echo "{$r['id']} updated\r\n";
        } else {
            echo "{$r['id']} failed to update\r\n";
        }
    }
} else {
    $sql = \Lobby\DB::getDBH()->prepare("SELECT `id`, `git_url` FROM `apps` ORDER BY `downloads` DESC");
    $sql->execute();
    while ($r = $sql->fetch()) {
        echo "{$r['id']} updating...\n";
        /**
         * Constructing will update app if it hasn't been updated in a day
         */
        $LG = new \LobbyGit($r['id'], $r['git_url']);
        $LG->register();
        echo "{$r['id']} updated.\n";
    }
}
Beispiel #5
0
 public function prepare($query)
 {
     $obj = \Lobby\DB::getDBH()->prepare($query);
     return $obj;
 }
Beispiel #6
0
$this->setTitle("New App");
?>
<div class="contents">
  <h1>Add App</h1>
  <?php 
$app_info = array("id" => \Request::get("app_id"), "name" => \Request::get("app_name"), "git_url" => \Request::get("app_download"), "requires" => \Request::get("app_requires"), "short_description" => \Request::get("app_short_description"), "description" => \Request::get("app_description"), "category" => \Request::get("app_category"), "sub_category" => \Request::get("app_sub_category"), "version" => \Request::get("app_version"), "page" => \Request::get("app_page"), "author_id" => \Request::get("author_id"));
if (isset($_POST['app_id']) && array_search(null, $app_info) === false && CSRF::check()) {
    $apps_sql = \Lobby\DB::getDBH()->prepare("SELECT COUNT(1) FROM `apps` WHERE `id` = ?");
    $apps_sql->execute(array($app_info['id']));
    if ($apps_sql->fetchColumn() != 0) {
        ser("App Exists", "Hmmm... Looks like the App ID you submitted already exists either on App Center Or in the App Queue. " . \Lobby::l("/apps/{$app_info['id']}", "See Existing App"));
    } else {
        $app_info["logo"] = isset($_POST["app_logo"]) ? "1" : "0";
        $lobby_web = isset($_POST['app_lobby_web']) ? 1 : 0;
        $sql = \Lobby\DB::getDBH()->prepare("INSERT INTO `apps` (`id`, `name`, `version`, `logo`, `requires`, `git_url`, `description`, `short_description`, `category`, `sub_category`, `app_page`, `author`, `lobby_web`, `updated`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, NOW());");
        $sql->execute(array($app_info['id'], $app_info['name'], $app_info['version'], $app_info['logo'], $app_info['requires'], $app_info['git_url'], $app_info['description'], $app_info['short_description'], $app_info['category'], $app_info['sub_category'], $app_info['page'], $app_info['author_id'], $lobby_web));
        require_once __DIR__ . "/../../inc/LobbyGit.php";
        $LG = new LobbyGit($app_info["id"], $app_info["git_url"]);
        $LG->register();
        sss("App Added", "App was added to the repository");
    }
}
?>
  <form action="<?php 
echo \Lobby::u();
?>
" method="POST">
    <label>
      <span>App ID</span>
      <input type="text" name="app_id" />
Beispiel #7
0
 public function getRepo()
 {
     if (file_exists($this->git_dir)) {
         $this->recursiveRemoveDirectory($this->git_dir);
     }
     $repo = Gitonomy\Git\Admin::cloneTo($this->git_dir, $this->git_url, false);
     $tags = $repo->getReferences()->getTags();
     /**
      * If no tags, use master
      */
     if (empty($tags)) {
         $commitHash = $repo->getReferences()->getBranch('master')->getCommitHash();
     } else {
         rsort($tags);
         $commitHash = $tags[0]->getCommitHash();
     }
     if ($commitHash === $this->info["last_commit"]) {
         // No need of update
         return true;
     }
     $sql = \Lobby\DB::getDBH()->prepare("UPDATE `git_cache` SET `last_commit` = ? WHERE `git_url` = ?");
     $sql->execute(array($commitHash, $this->git_url));
     $this->recursiveRemoveDirectory($this->git_dir . "/.git");
     /**
      * Get screenshots
      */
     $manifest = json_decode(file_get_contents($this->git_dir . "/manifest.json"), true);
     // Manifest file is invalid
     if (!is_array($manifest)) {
         return false;
     }
     if (isset($manifest["version"])) {
         $latestVersion = $manifest["version"];
     } else {
         return false;
     }
     if (isset($manifest->screenshots)) {
         $screenshots = array();
         foreach ($manifest["screenshots"] as $img) {
             $url = parse_url($img);
             if ($url["host"] === "i.imgur.com") {
                 $path = $url["path"];
                 // $path has slash at beginning
                 $headers = @get_headers("http://i.imgur.com{$path}", 1);
                 if ($headers[0] === "HTTP/1.1 200 OK") {
                     $screenshots[] = "//i.imgur.com{$path}";
                 }
             }
         }
         if (empty($screenshots)) {
             unset($screenshots);
         }
     }
     if (exec("cd {$this->git_dir};zip -r '{$this->git_dir}/app.zip' ./ -1 -q;") !== false) {
         $logo = true;
         if (file_exists($this->git_dir . "/src/image/logo.svg")) {
             $this->convertLogoToPNG();
         } else {
             if (file_exists($this->git_dir . "/src/image/logo.png")) {
                 copy($this->git_dir . "/src/image/logo.png", $this->git_dir . "/logo.png");
             } else {
                 $logo = false;
             }
         }
         $webdavPass = getenv("SKY_WEBDAV_PASS");
         $settings = array('baseUri' => "https://sky-phpgeek.rhcloud.com/remote.php/webdav/Apps/{$this->id}/", 'userName' => 'lobby-apps', 'password' => $webdavPass);
         $client = new Client($settings);
         /**
          * Create folder
          */
         $client->request('MKCOL');
         /**
          * Upload files
          */
         $client->request('PUT', "{$this->id}.zip", file_get_contents($this->git_dir . "/app.zip"));
         if ($logo) {
             $client->request('PUT', "logo.png", file_get_contents($this->git_dir . "/logo.png"));
         }
         $request = \Requests::post("https://sky-phpgeek.rhcloud.com/ocs/v1.php/apps/files_sharing/api/v1/shares?format=json", array("Content-Type" => "application/x-www-form-urlencoded"), array("path" => "Apps/{$this->id}", "shareType" => "3"), array("auth" => array("lobby-apps", $webdavPass)));
         $response = json_decode($request->body);
         $this->cloud_id = $response->ocs->data->token;
         $extraColumnData = array("short_description" => $manifest["short_description"]);
         if (isset($latestVersion)) {
             $extraColumnData["version"] = $latestVersion;
         }
         if (isset($screenshots)) {
             $extraColumnData["screenshots"] = implode("\n", $screenshots);
         }
         if (isset($manifest["require"]) && is_array($manifest["require"])) {
             $extraColumnData["requires"] = json_encode($manifest["require"]);
         }
         /**
          * Update Cloud ID and download file size
          */
         $appInfoUpdate = array(":cloudID" => $this->cloud_id, ":downloadSize" => filesize($this->git_dir . "/app.zip"), ":appID" => $this->id);
         $extraColumns = "";
         if (!empty($extraColumnData)) {
             foreach ($extraColumnData as $k => $v) {
                 $extraColumns .= ", {$k} = :{$k}";
                 $appInfoUpdate[":{$k}"] = $v;
             }
         }
         $sql = \Lobby\DB::getDBH()->prepare("UPDATE `apps` SET `cloud_id` = :cloudID, `download_size` = :downloadSize, `updated` = NOW() {$extraColumns} WHERE `id` = :appID");
         $sql->execute($appInfoUpdate);
         $this->recursiveRemoveDirectory($this->git_dir);
         return true;
     }
     return false;
 }
Beispiel #8
0
                <div>Version : <?php 
            echo $app['version'];
            ?>
</div>
              </div>
            </div>
          </div>
        <?php 
        }
    }
    ?>
    </div>
  </div>
<?php 
} else {
    $sql = \Lobby\DB::getDBH()->prepare("SELECT * FROM `apps` WHERE `id` = ?");
    $sql->execute(array($node));
    if ($sql->rowCount() == "0") {
        ser();
    } else {
        $this->addStyle("app.css");
        $appInfo = $sql->fetch(\PDO::FETCH_ASSOC);
        \Response::setTitle($appInfo['name'] . " | Store");
        require_once $this->dir . "/src/inc/Parsedown.php";
        $Parsedown = new Parsedown();
        ?>
    <div class="contents">
      <?php 
        $no_header = 1;
        require_once $this->dir . "/src/inc/views/top.apps.php";
        ?>
Beispiel #9
0
 public function clearData()
 {
     $sql = \Lobby\DB::getDBH()->prepare("DELETE FROM `" . \Lobby\DB::getPrefix() . "data` WHERE `app` = ?");
     $sql->execute(array($this->app));
     return true;
 }
Beispiel #10
0
 function getAuthorName($id = 1)
 {
     $sql = \Lobby\DB::getDBH()->prepare("SELECT `name` FROM `users` WHERE `id` = ?");
     $sql->execute(array($id));
     return $sql->fetchColumn();
 }
Beispiel #11
0
                         if ($app_edit != true && ($queue_sql->fetchColumn() != 0 || $apps_sql->fetchColumn() != 0)) {
                             ser("App Exists", "Hmmm... Looks like the App ID you submitted already exists either on App Center Or in the App Queue. " . \Lobby::l("/apps/{$app_info['id']}", "See Existing App"));
                         } else {
                             if ($app_edit != true && preg_match("/\\b(?:(?:https?|ftp):\\/\\/|www\\.)[-a-z0-9+&@#\\/%?=~_|!:,.;]*[-a-z0-9+&@#\\/%=~_|]/i", $app_info['git_url']) == 0) {
                                 ser("Invalid URL", "The app's source code URL you provided was invalid.");
                             } else {
                                 if ($app_edit != true) {
                                     $sql = \Lobby\DB::getDBH()->prepare("INSERT INTO `apps_queue` (`id`, `name`, `src`, `description`, `category`, `sub_category`, `app_page`, `author`, `updated`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, NOW());");
                                     $sql->execute(array($app_info['id'], $app_info['name'], $app_info['git_url'], $app_info['description'], $app_info['category'], $app_info['sub_category'], $app_info['app_page'], \Fr\LS2::$user));
                                     $admin_access_token = \Fr\LS2::getUser("username", 1);
                                     require_once $this->dir . "/src/inc/open.auth.php";
                                     $Opth = new OpenAuth("EAtGbLfgxiCJxhwWfsLsyxA0p8Zj4oUyOd4POaVc", "80d23edfa535caf4cc44b91e16c55c0f09e3bed927fecff96b092df0f517f410");
                                     $Opth->action("email", array("subject" => "Lobby App Review", "body" => "Dude, a person requested to review her/his app ({$app_info['id']}). Please go and check it. http://lobby.subinsb.com"), $admin_access_token);
                                     sss("App Submitted", "Your app was added to the review queue. You will be notified by email about your app's review status.");
                                 } else {
                                     $sql = \Lobby\DB::getDBH()->prepare("UPDATE `apps` SET `name` = ?, `logo` = ?, `description` = ?, `category` = ?, `sub_category` = ?, `app_page` = ?, `lobby_web` = ?, `updated` = NOW() WHERE `id` = ? AND `author` = ?");
                                     $sql->execute(array($app_info['name'], $app_info['logo'], $app_info['description'], $app_info['category'], $app_info['sub_category'], $app_info['app_page'], $app_info['lobby_web'], $app_info['id'], \Fr\LS2::$user));
                                     sss("Updated", "Your app was successfully updated.");
                                 }
                             }
                         }
                     }
                     if ($app_edit) {
                         \Response::setTitle("Edit App " . $app_info['name'] . " | Me");
                     } else {
                         \Response::setTitle("New App | Me");
                     }
                     ?>
 <h1><?php 
                     echo $app_edit == true ? $app_info['name'] : "New App";
                     ?>
Beispiel #12
0
  <div class="contents">
    <h1><?php 
    echo $u['display_name'];
    ?>
</h1>
    <p>Real Name : <?php 
    echo $u['name'];
    ?>
</p>
    <p>Member of Lobby since <?php 
    echo date("d F Y", $u['registered']);
    ?>
</p>
    <h2>Apps</h2>
    <?php 
    $sql = \Lobby\DB::getDBH()->prepare("SELECT `id`, `name`, `short_description`, `downloads` FROM `apps` WHERE `author` = ?");
    $sql->execute(array($user));
    if ($sql->rowCount() != 0) {
        echo "<table>";
        echo "<thead><tr><td>App</td><td>Description</td><td>Downloads</td></tr></thead>";
        echo "<tbody>";
        while ($r = $sql->fetch()) {
            echo "<tr>\n              <td><a target='_blank' href='/apps/{$r['id']}'>{$r['name']}</a></td>\n              <td>{$r['short_description']}</td>\n              <td>{$r['downloads']}</td>\n            </tr>";
        }
        echo "</tbody>";
        echo "</table>";
    } else {
        echo "User haven't created any apps";
    }
    ?>
  </div>
Beispiel #13
0
<?php

$this->setTitle("Admin");
?>
<div class="contents">
  <h1>Lobby Admin</h1>
  <?php 
echo \Lobby::l("/admin/app/lobby-server/new-app", "New App", "class='btn green' clear");
echo \Lobby::l("/admin/app/lobby-server/downloads", "Download Stats", "class='btn' clear");
echo \Lobby::l("https://lobby-subins.rhcloud.com/phpmyadmin", "Database", "class='btn red' clear target='_blank'");
echo \Lobby::l("/admin/app/lobby-server?clear-git-cache" . \CSRF::getParam(), "Clear Git Cache", "class='btn orange' clear");
if (isset($_GET["clear-git-cache"]) && \CSRF::check()) {
    \Lobby\DB::getDBH()->exec("TRUNCATE TABLE `git_cache`");
    echo "<h2>cleared</h2>";
}
?>
</div>
Beispiel #14
0
  <table>
    <thead>
      <colgroup>
         <col span="1" style="width: 15%;">
         <col span="1" style="width: 15%;">
         <col span="2" style="width: 55%;">
         <col span="1" style="width: 15%;">
      </colgroup>
      <tr>
        <th>Lobby Version</th>
        <th>Frequency</th>
        <th>Last Accessed</th>
        <th>Public ID</th>
      </tr>
    </thead>
    <tbody>
      <?php 
$sql = \Lobby\DB::getDBH()->query("SELECT * FROM `lobby_api_access` ORDER BY `accessed` DESC");
while ($r = $sql->fetch(\PDO::FETCH_ASSOC)) {
    echo "<tr>";
    echo "<td>{$r['version']}</td>";
    echo "<td>{$r['frequency']}</td>";
    echo "<td>" . Lobby\Time::date(date("Y-m-d H:i:s", $r['accessed']), "Y-m-d H:i:s") . "</td>";
    echo "<td><div style='width: 300px;'>{$r['lid']}</div></td>";
    echo "</tr>";
}
?>
    </tbody>
  </table>
</div>