Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add auto updates #130

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ password: Ss123456
Please note that changes are reverted every hour.

### I noticed there is a new release. How do I update?
Updating server status is fairly straightforward. Download your config.php from the server. Delete all files. Upload the new release with config.php you downloaded earlier. You need to manually run install scripts. For that head to your domain and run create-server-config.php deleting it afterwards.
If you don't want to allow php to access your files or you have permission issues, use the following instructions.
In the admin panel, check for updates. If a version is available you can click to update.
#### Updating server config
Follow the instructions for installation without giving the app write access. Keep in mind that you will need to re-apply any modifications you made.

Expand Down
53 changes: 53 additions & 0 deletions SkyfallenCodeLib/UpdatesConsoleConnector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php


namespace SkyfallenCodeLibrary;


class UpdatesConsoleConnector
{
public static function getLatestVersion($appid,$seed,$remoteauthority){
$vajson = file_get_contents($remoteauthority."/updatecheck/?appid=".$appid."&seed=".$seed);
$va_array = json_decode($vajson,true);
return $va_array["version"];
}
public static function getLatestVersionData($appid,$seed,$remoteauthority){
$vajson = file_get_contents($remoteauthority."/updatecheck/?appid=".$appid."&seed=".$seed);
$va_array = json_decode($vajson,true);
return $va_array;
}
public static function downloadLatestVersion($appid,$seed,$remoteauthority,$rootpath = "../"){
$vajson = file_get_contents($remoteauthority."/updatecheck/?appid=".$appid."&seed=".$seed);
$va_array = json_decode($vajson,true);
$pkgloc = $va_array["downloadpath"];

$file_name = basename($pkgloc);

if(file_put_contents( $rootpath.$file_name,file_get_contents($pkgloc))) {
$arr["path"] = $rootpath.$file_name;
$arr["success"] = true;
return $arr;
}
else {
$arr["success"] = false;
return $arr;
}
}

public static function installUpdate($file,$rootpath = "../"){
$zip = new \ZipArchive;
$res = $zip->open($file);
if ($res === TRUE) {
$zip->extractTo($rootpath);
$zip->close();
return true;
} else {
return false;
}
}
public static function getProviderData($providerurl){
$vajson = file_get_contents($providerurl."/provider/");
$prv_array = json_decode($vajson,true);
return $prv_array;
}
}
9 changes: 9 additions & 0 deletions config.php.template
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,12 @@ if ($mysqli->connect_errno) {
}

$mysqli->set_charset("utf8");

include "SkyfallenCodeLib/UpdatesConsoleConnector.php";

define("UPDATES_PROVIDER_URL","https://swupdate.theskyfallen.com");
define("UPDATES_PROVIDER_APP_ID","6d84a0d1b6cc05e071c0199a8d8894c4");
define("UPDATE_SEED","STABLE");

include_once "updater.php";
include "thisversion.php";
2 changes: 2 additions & 0 deletions onupdate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
// This code will be executed when Server Status is updated to a specific package and then be deleted.
4 changes: 4 additions & 0 deletions thisversion.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

<?php
define("THIS_VERSION","SFR-000000");
define("VERSION_PROVIDER","Server Status Project");
53 changes: 53 additions & 0 deletions updater.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

require_once "config.php";

session_start();

if(!$_SESSION["loggedin"]){
header("Location: /");
}

function rrmdir($dir,$rmitself = true) {
if (is_dir($dir)) {
$objects = scandir($dir);
foreach ($objects as $object) {
if ($object != "." && $object != "..") {
if (is_dir($dir. DIRECTORY_SEPARATOR .$object) && !is_link($dir."/".$object))
rrmdir($dir. DIRECTORY_SEPARATOR .$object);
else
if($object != "config.php" and $object != "updater.php") {
unlink($dir . DIRECTORY_SEPARATOR . $object);
}
}
}
if($rmitself) {
rmdir($dir);
}
}
}

if(isset($_SESSION["UPDATE_AUTHORIZED"]) and $_SESSION["UPDATE_AUTHORIZED"]) {
include_once "SkyfallenCodeLib/UpdatesConsoleConnector.php";
rrmdir(getcwd(),false);
$ret = \SkyfallenCodeLibrary\UpdatesConsoleConnector::downloadLatestVersion(UPDATES_PROVIDER_APP_ID,UPDATE_SEED,UPDATES_PROVIDER_URL,"");
if($ret["success"]) {
if(\SkyfallenCodeLibrary\UpdatesConsoleConnector::installUpdate($ret["path"],getcwd())){
echo "Updated Successfully";
unlink($ret["path"]);
$_SESSION["UPDATE_AUTHORIZED"] = false;
if(file_exists("onupdate.php")){
include_once "onupdate.php";
unlink("onupdate.php");
}
header("location: /");
}else
{
ob_end_flush();
echo "Failed to unpack update.";
}
}else {
ob_end_flush();
echo "Failed to download update from the server.";
}
}