public static function __constructStatic() { /** * Get DB config */ $config = \Lobby::config(true); if (is_array($config)) { /** * Make DB credentials variables from the config.php file */ self::$prefix = $config['prefix']; self::$type = $config['type']; $options = array(\PDO::ATTR_PERSISTENT => true, \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION); try { if ($config['type'] === 'mysql') { self::$dbh = new \PDO("mysql:dbname={$config['dbname']};host={$config['host']};port={$config['port']};charset=utf8;", $config['username'], $config['password'], $options); /** * Check if Lobby tables exist */ $notable = false; $tables = array("options", "data"); // The Tables of Lobby foreach ($tables as $tableName) { $results = self::$dbh->prepare("SHOW TABLES LIKE ?"); $results->execute(array(self::$prefix . $tableName)); if ($results->rowCount() == 0) { $notable = true; } } } else { if ($config['type'] === 'sqlite') { self::$dbh = new \PDO("sqlite:" . \Lobby\FS::loc($config['path']), "", "", $options); /** * Enable Multithreading Read/Write */ self::$dbh->exec("PRAGMA journal_mode=WAL;"); /** * Check if Lobby tables exist */ $sql = self::$dbh->query("SELECT COUNT(1) FROM `sqlite_master` WHERE `type` = 'table' AND (`name` = 'l_data' OR `name` = 'l_options')"); $notable = $sql->fetchColumn() === "2" ? false : true; } } if ($notable === false) { /* There are database tables */ parent::$installed = true; } else { parent::log(array("fatal", "Tables required by Lobby was not found in the database. Check your <b>config.php</b> and database to fix the error. Or Install again by removing <b>config.php</b>.")); } } catch (\PDOException $e) { parent::$installed = false; $error = $e->getMessage(); parent::log(array("fatal", "Unable to connect to database server. Is the database credentials given in <b>config.php</b> correct ? <blockquote>{$error}</blockquote>")); } } else { self::$installed = false; } }
/** * Lobby Store functions */ public static function Store($data) { /** * Response is in JSON */ $response = \Lobby::loadURL(L_SERVER . "/apps", $data, "POST"); if ($response == "false") { return false; } else { $arr = json_decode($response, true); /** * Make sure the response was valid. */ if (!is_array($arr)) { \Lobby::log("Lobby Server Replied : {$response}"); return false; } else { return $arr; } } }
/** * Get updates */ public static function check() { $url = self::$apiURL . "/lobby/updates"; $apps = Apps::getApps(); try { $response = \Requests::post($url, array(), self::makeData(array("apps" => implode(",", $apps))))->body; } catch (\Requests_Exception $error) { \Lobby::log("Checkup with server failed ({$url}) : {$error}"); $response = false; } if ($response) { $response = json_decode($response, true); if (is_array($response)) { DB::saveOption("lobby_latest_version", $response['version']); DB::saveOption("lobby_latest_version_release", $response['released']); DB::saveOption("lobby_latest_version_release_notes", $response['release_notes']); if (isset($response['apps']) && count($response['apps']) != 0) { $AppUpdates = array(); foreach ($response['apps'] as $appID => $version) { $App = new \Lobby\Apps($appID); if ($App->hasUpdate($version)) { $AppUpdates[$appID] = $version; } } DB::saveOption("app_updates", json_encode($AppUpdates)); } if (isset($response["notify"])) { foreach ($response["notify"]["items"] as $itemID => $item) { if (isset($item["href"])) { $item["href"] = \Lobby::u($item["href"]); } Panel::addNotifyItem("lobby_server_msg_" . $itemID, $item); } foreach ($response["notify"]["remove_items"] as $itemID) { Panel::removeNotifyItem("lobby_server_msg_" . $itemID); } } } } }
public static function log($m) { return \Lobby::log($m, "app.sige.log"); // Log writing will only happen in the debugging is enabled in config.php }
/** * Write messages to log file */ public function log($msg) { \Lobby::log($msg, "apps.log"); }
/** * Write messages to log file */ public function log($msg) { \Lobby::log($msg, "app." . $this->id . ".log"); }
/** * Write messages to log file */ public function log($msg) { \Lobby::log($msg, "themes.log"); }
* Call __constructStatic() on each classes with params for some classes */ $loader = new ConstructStatic\Loader($composer); $loader->setClassParameters("Lobby\\Apps", array(APPS_DIR, APPS_URL)); $loader->setClassParameters("Lobby\\UI\\Themes", array(THEMES_DIR, THEMES_URL)); $loader->processLoadedClasses(); /** * Set constants & Load Modules */ require_once L_DIR . "/includes/extra.php"; /** * These classes are not loaded by default by Composer */ $loader->loadClass("Lobby\\Require"); } catch (\Exception $e) { \Lobby::log(array("fatal", $e->getMessage())); } /** * Run not on CDN files serving */ if (!\Lobby::status("lobby.assets-serve")) { /** * Init the page setup */ require_once L_DIR . "/includes/init.php"; /** * Is Lobby Installed ? */ if (!\Lobby::$installed && !\Lobby::status("lobby.install")) { \Response::redirect("/admin/install.php"); }
/** * If the $appID is in the queue, then give the download status of it * If the updated value is less than 20 seconds ago, then restart the download */ if (isset($appInstallQueue[$appID]) && $appInstallQueue[$appID]["updated"] > strtotime("-20 seconds")) { echo json_encode(array("statusID" => $appInstallQueue[$appID]["statusID"], "status" => $appInstallQueue[$appID]["status"])); } else { $appInfo = \Lobby\Server::store(array("get" => "app", "id" => $appID)); /** * App doesn't exist on Lobby Store */ if ($appInfo === "false") { echo json_encode(array("status" => "error", "error" => "App Doesn't Exist")); } else { $appName = $appInfo["name"]; $Process = new Process(Process::getPHPExecutable(), array("arguments" => array(L_DIR . "/admin/ajax/install-app-bg.php", \Lobby::getLID(), base64_encode(serialize($_SERVER)), $appID))); /** * Get the command used to execute install-app-bg.php */ $command = $Process->start(function () use($appID) { /** * This callback will close the connection between browser and server, * http://stackoverflow.com/q/36968552/1372424 */ echo json_encode(array("statusID" => "download_intro", "status" => "Downloading <b>{$appID}</b>...")); }); \Lobby::log("To install app '{$appID}', this command was executed : {$command}"); } } } }
/** * Only 1 File is present */ $files = array($f); } /* Loop through files and */ foreach ($files as $file) { $file = str_replace(L_URL, "", $file); if ($file == "/includes/lib/jquery/jquery-ui.js" || $file == "/includes/lib/jquery/jquery.js" || $file == "/includes/lib/core/JS/main.js" || $file == "/includes/lib/core/JS/app.js") { $extraContent .= \Lobby\FS::get($file); } else { if (\Lobby\FS::exists($file)) { $content .= \Lobby\FS::get($file); } else { $type_of_file = isset($js) ? "JavaScript" : "CSS"; \Lobby::log("{$type_of_file} file was not found in location given : {$file}"); } } if (isset($css)) { $to_replace = array("<?L_URL?>" => L_URL, "<?THEME_URL?>" => THEME_URL); if (isset($_GET['APP_URL'])) { $to_replace["<?APP_URL?>"] = htmlspecialchars(urldecode($_GET['APP_URL'])); $to_replace["<?APP_SRC?>"] = htmlspecialchars(urldecode($_GET['APP_SRC'])); } foreach ($to_replace as $from => $to) { $content = str_replace($from, $to, $content); } } } if (isset($js)) { $content = "lobby.url='" . L_URL . "';lobby.csrf_token = '" . H::csrf("s") . "';" . $content;
/** * Update the App with the given ID */ public static function app($id) { if ($id == "") { ser("Error", "No App Mentioned to update."); } \Lobby::log("Installing Latest Version of App {$id}"); $url = \Lobby\Server::download("app", $id); $zipFile = L_DIR . "/contents/update/{$id}.zip"; self::zipFile($url, $zipFile); // Un Zip the file $zip = new \ZipArchive(); if ($zip->open($zipFile) != "true") { \Lobby::log("Unable to open Downloaded App ({$id}) File : {$zipFile}"); ser("Error", "Unable to open Downloaded App File."); } else { /** * Extract App */ $zip->extractTo(APPS_DIR); $zip->close(); \Lobby\FS::remove($zipFile); \Lobby::log("Installed App {$id}"); return true; } }