Skip to content

Commit

Permalink
Merge branch 'beta'
Browse files Browse the repository at this point in the history
  • Loading branch information
velocity23 committed Aug 27, 2021
2 parents 8bee6bc + 5668afd commit 1e1aabe
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 50 deletions.
10 changes: 2 additions & 8 deletions api.php
Original file line number Diff line number Diff line change
Expand Up @@ -445,10 +445,9 @@ function accessDenied()

// View All Events
Router::add('/events', function () {
global $user;
if (!VANet::isGold()) badReq(ErrorCode::VaNotGold);

$events = VANet::getEvents();
if ($events === null) internalError();

echo Json::encode([
"status" => ErrorCode::NoError,
"result" => $events,
Expand All @@ -457,8 +456,6 @@ function accessDenied()

// View Specific Event
Router::add('/events/' . $guid, function ($eventId) {
if (!VANet::isGold()) badReq(ErrorCode::VaNotGold);

$event = VANet::findEvent($eventId);
if ($event === FALSE) notFound();

Expand All @@ -474,7 +471,6 @@ function accessDenied()
if ($_authType == AuthType::ApiKey) {
accessDenied();
}
if (!VANet::isGold()) badReq(ErrorCode::VaNotGold);
if ($_apiUser->ifuserid == null) badReq(ErrorCode::NoIfUid);

$event = VANet::findEvent($eventId);
Expand Down Expand Up @@ -1105,8 +1101,6 @@ function accessDenied()

// Get Active ATC (Gold Only)
Router::add('/atc', function () {
if (!VANet::isGold()) accessDenied();

$res = VANet::getAtc(empty(Input::get('server')) ? 'expert' : Input::get('server'));
if (!$res) internalError();

Expand Down
5 changes: 3 additions & 2 deletions classes/app/Updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,14 @@ public static function releasesUrl()

/**
* @return string
* @param string $ref
*/
public static function downloadUrl()
public static function downloadUrl($ref)
{
$conf = Config::get('updater/raw_url');
if (!empty($conf)) return $conf;

return 'https://api.github.com/repos/va-net/flare/contents';
return 'https://raw.githubusercontent.com/va-net/flare/' . urlencode($ref) . '/';
}

/**
Expand Down
25 changes: 0 additions & 25 deletions core/docker_entrypoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,6 @@
}
});

$db = DB::getInstance();
$tables = array_map(function ($x) {
return ((array)$x)['Tables_in_' . Config::get('mysql/db')];
}, $db->query('SHOW TABLES')->results());
if (!in_array('pilots', $tables)) {
$branch = Updater::getVersion()['prerelease'] ? Updater::githubPrereleaseBranch() : Updater::githubDefaultBranch();
$dl = Updater::downloadUrl();
$auth = Updater::authentication();

$opts = array(
'http' => array(
'method' => "GET",
'header' => "User-Agent: va-net\r\n"
)
);
if (!empty($auth)) {
$opts['http']['header'] .= "Authorization: Basic " . base64_encode($auth) . "\r\n";
}
$context = stream_context_create($opts);

$res = Json::decode(file_get_contents("{$DL_URL}/install/db.sql?ref=" . urlencode($branch), false, $context));
$sql = base64_decode($res["content"]);
$db->query($sql);
}

if (file_exists(__DIR__ . '/config.new.php')) die();

$output = "<?php\n";
Expand Down
4 changes: 2 additions & 2 deletions install/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static function showTemplate($name)
public static function createConfig($data = array())
{

$template = file_get_contents(__DIR__ . '/templates/config.php');
$template = file_get_contents(__DIR__ . '/templates/config.new.php');
foreach ($data as $name => $val) {
$template = str_replace("'{$name}'", "'{$val}'", $template);
}
Expand All @@ -50,7 +50,7 @@ public static function setupDb()
{

$sql = file_get_contents(__DIR__ . '/db.sql');
$db = DB::getInstance();
$db = DB::newInstance();
if (!$db->query($sql)) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion install/install.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
break;
case 'db-setup-cont':
if (Input::get('submit')) {
sleep(8);
sleep(3);
if (!Installer::setupDb()) {
Session::flash('error', 'Hmm. Looks like there was an error setting up the database. Ensure you have entered the correct database details, and try again.');
Redirect::to('?page=db-setup');
Expand Down
31 changes: 20 additions & 11 deletions updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
Redirect::to('index.php');
}

if (!$user->hasPermission('opsmanage')) {
if (!$user->hasPermission('site')) {
die();
}

$RELEASES_URL = Updater::releasesUrl();
$DL_URL = Updater::downloadUrl();
$BRANCH = Updater::githubDefaultBranch();
$DL_URL = Updater::downloadUrl($BRANCH);

$current = Updater::getVersion();

Expand All @@ -41,6 +41,16 @@
$releases = array_filter(Json::decode(file_get_contents($RELEASES_URL, false, $context)), function ($release) {
return !$release['draft'];
});
usort($releases, function ($x, $y) {
if ($x['published_at'] == $y['published_at']) {
return 0;
}

$a = new DateTime($x['published_at']);
$b = new DateTime($y['published_at']);
$diff = $a->diff($b);
return $diff->invert ? -1 : 1;
});

// Find next applicable release
$currentFound = false;
Expand All @@ -52,6 +62,7 @@
if (Config::get('CHECK_PRERELEASE') == 1) {
$next = $r;
$BRANCH = Updater::githubPrereleaseBranch();
$DL_URL = Updater::downloadUrl($BRANCH);
break;
} elseif (!$r["prerelease"]) {
$next = $r;
Expand All @@ -71,16 +82,14 @@
}

// Get the updates.json file
$updateResponse = Json::decode(file_get_contents("{$DL_URL}/updates.json?ref=" . urlencode($BRANCH), false, $context));
$updateData = base64_decode($updateResponse["content"]);
$updateData = Json::decode(file_get_contents("{$DL_URL}/updates.json", false, $context));
// Check Release is Compatible
if ($updateData === FALSE) {
if (empty($updateData)) {
echo "This Version of Flare does not support the Updater.";
die();
}

// Process updates.json File
$updateData = Json::decode($updateData);
$nextUpdate = null;
foreach ($updateData as $upd) {
if ($upd["tag"] == $next["tag_name"]) {
Expand All @@ -101,6 +110,8 @@
die();
}

$DL_URL = Updater::downloadUrl($next['tag_name']);

// Run DB Queries
if (count($nextUpdate["queries"]) != 0 && !($current["prerelease"] && !$next["prerelease"])) {
$db = DB::getInstance();
Expand Down Expand Up @@ -145,18 +156,16 @@

// Update Files
foreach ($nextUpdate["files"] as $file) {
$fileInfo = Json::decode(file_get_contents($DL_URL . "/" . $file . '?ref=' . urlencode($next["tag_name"]), false, $context));
$fileData = base64_decode($fileInfo["content"]);
if ($fileData === FALSE || file_put_contents(__DIR__ . '/' . $file, $fileData) === FALSE) {
$fileData = file_get_contents($DL_URL . '/' . $file, false, $context);
if (empty($fileData) || file_put_contents(__DIR__ . '/' . $file, $fileData) === FALSE) {
echo "Error Updating File " . $file;
die();
}
}
echo "Updated Files Successfully<br />";

// Update Version File
$vInfo = Json::decode(file_get_contents($DL_URL . "/version.json?ref=" . urlencode($next["tag_name"]), false, $context));
$vData = base64_decode($vInfo["content"]);
$vData = file_get_contents($DL_URL . "/version.json", false, $context);
file_put_contents(__DIR__ . '/' . "version.json", $vData);
echo "Updated Version File<br />";

Expand Down
23 changes: 22 additions & 1 deletion updates.json
Original file line number Diff line number Diff line change
Expand Up @@ -851,10 +851,31 @@
"deletedFiles": [],
"newFolders": []
},
{
"tag": "v2.0.0-beta.14",
"name": "Version 2.0.0 Beta 14",
"date": "2021-08-26",
"notes": "Various bug fixes",
"prerelease": true,
"useUpdater": true,
"files": [
"classes/data/User.php",
"classes/controllers/admin/AdminEventsController.php",
"classes/controllers/PirepsController.php",
"themes/default/views/pireps_all.php",
"themes/tailwind/views/pireps_all.php",
"api.php",
"classes/app/Updater.php",
"updater.php"
],
"queries": [],
"deletedFiles": [],
"newFolders": []
},
{
"tag": "v2.0.0",
"name": "Version 2.0.0",
"date": "2021-08-25",
"date": "2021-08-27",
"notes": "See https://github.com/va-net/flare/releases/tag/v2.0.0",
"prerelease": false,
"useUpdater": true,
Expand Down

0 comments on commit 1e1aabe

Please sign in to comment.