Exemplo n.º 1
0
 public function __construct($resource)
 {
     //$this->webDownloads = intval($resource->webDownloads);
     //$this->ingameDownloads = intval($resource->ingameDownloads);
     //$this->updateDownloads = intval($resource->updateDownloads);
     //$this->downloads = $this->webDownloads + $this->ingameDownloads + $this->updateDownloads;
     //print_r($resource);
     $this->id = intval($resource->id);
     $this->board = intval($resource->board);
     $this->blid = intval($resource->blid);
     $this->name = $resource->name;
     $this->description = $resource->description;
     $this->approved = intval($resource->approved);
     //$this->rating = floatval($resource->rating);
     $this->version = $resource->version;
     $this->authorInfo = json_decode($resource->authorInfo);
     //$this->file = intval($resource->file);
     $this->filename = $resource->filename;
     $this->deleted = intval($resource->deleted);
     $this->reviewInfo = json_decode($resource->reviewInfo);
     $this->betaVersion = $resource->betaVersion;
     $this->rating = $resource->rating;
     $this->uploadDate = $resource->uploadDate;
     $this->url = "https://s3.amazonaws.com/" . urlencode(AWSFileManager::getBucket()) . "/addons/" . $this->id;
 }
Exemplo n.º 2
0
 public function __construct($resource)
 {
     $this->id = intval($resource->id);
     $this->blid = intval($resource->blid);
     $this->name = $resource->name;
     $this->bricks = intval($resource->bricks);
     $this->description = $resource->description;
     $this->filename = $resource->filename;
     $this->url = "https://s3.amazonaws.com/" . urlencode(AWSFileManager::getBucket()) . "/builds/" . $this->id;
 }
 public function __construct($resource)
 {
     $this->id = intval($resource->id);
     $this->blid = intval($resource->blid);
     $this->name = $resource->name;
     $this->filename = $resource->filename;
     $this->description = $resource->description;
     $this->url = "http://s3.amazonaws.com/" . urlencode(AWSFileManager::getBucket()) . "/screenshots/" . $this->id;
     $this->thumburl = "http://s3.amazonaws.com/" . urlencode(AWSFileManager::getBucket()) . "/screenshots/thumb/" . $this->id;
     $this->x = $resource->x;
     $this->y = $resource->y;
     $this->ext = @$resource->ext;
 }
 public function getDiff()
 {
     $fileNew = realpath($this->getFile());
     $fileOld = dirname(__DIR__) . '/../addons/files/local/' . $this->aid . '.zip';
     if (!is_file($fileOld)) {
         $path = realpath(dirname(__DIR__) . '/../addons/files/local/');
         $fh = fopen($path . '/' . $this->aid . '.zip', 'w');
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL, "http://" . AWSFileManager::getBucket() . "/addons/" . $this->aid . "_1");
         curl_setopt($ch, CURLOPT_FILE, $fh);
         curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
         // this will follow redirects
         curl_exec($ch);
         curl_close($ch);
         fclose($fh);
     }
     $fileOld = realpath(dirname(__DIR__) . '/../addons/files/local/' . $this->aid . '.zip');
     $zipNew = new ZipArchive();
     $zipOld = new ZipArchive();
     $resNew = $zipNew->open($fileNew);
     $resOld = $zipOld->open($fileOld);
     if ($resNew === TRUE && $resOld === TRUE) {
         $newFiles = array();
         for ($i = 0; $i < $zipNew->numFiles; $i++) {
             $newFiles[] = $zipNew->getNameIndex($i);
         }
         $oldFiles = [];
         for ($i = 0; $i < $zipOld->numFiles; $i++) {
             $oldFiles[] = $zipOld->getNameIndex($i);
         }
         $added = array_diff($newFiles, $oldFiles);
         $removed = array_diff($oldFiles, $newFiles, ["glass.json", "version.json"]);
         $commonFiles = array_intersect($newFiles, $oldFiles);
         $commonFiles = array_diff($commonFiles, ["glass.json", "version.json"]);
         $diff = [];
         foreach ($commonFiles as $fi) {
             if (strpos($fi, ".cs") == strlen($fi) - 3) {
                 $newStr = $zipNew->getFromName($fi);
                 $oldStr = $zipOld->getFromName($fi);
                 if (trim($newStr) != trim($oldStr)) {
                     $diff[$fi] = Diff::toTable(Diff::compare($oldStr, $newStr));
                 }
             }
         }
         $ret = ["added" => $added, "removed" => $removed, "changes" => $diff];
         return $ret;
     } else {
         return false;
     }
 }
Exemplo n.º 5
0
$authorDat[] = $author;
$branchId["stable"] = 1;
$branchId["unstable"] = 2;
$branchId["development"] = 3;
$file["stable"] = $res->file_stable;
$versionData = array();
foreach ($file as $branch => $fid) {
    if ($fid != 0) {
        $version = new stdClass();
        $fileRes = $mysql->query("SELECT * FROM `addon_files` WHERE `id`='" . $fid . "'");
        $hash = $fileRes->fetch_object()->hash;
        $oldfile = $dir . $hash . ".zip";
        $bid = $branchId[$branch];
        echo "Uploading {$oldfile} to AWS as {$res->id}_{$bid}.zip";
        //AWSFileManager::upload("addons/{$res->id}_{$bid}", $oldfile);
        AWSFileManager::uploadNewAddon($res->id, $bid, $res->filename, $oldfile);
        $updateRes = $mysql->query("SELECT *\nFROM  `addon_updates`\nWHERE  `aid` = '" . $aid . "'\nAND  `branch`='" . $bid . "' ORDER BY  `time` DESC\nLIMIT 0 , 1");
        if ($updateRes->num_rows == 0) {
            $version->version = "0.0.0";
            $version->restart = "0.0.0";
        } else {
            $obj = $updateRes->fetch_object();
            $version->version = $obj->version;
            $version->restart = $obj->version;
            //not worth it
        }
        $versionData[$branch] = $version;
    }
}
$db->query($sql = "INSERT INTO `addon_addons` (`id`, `board`, `blid`, `name`, `filename`, `description`, `version`, `authorInfo`, `reviewInfo`, `deleted`, `approved`, `uploadDate`) VALUES " . "('" . $db->sanitize($res->id) . "'," . "NULL," . "'" . $db->sanitize($res->author) . "'," . "'" . $db->sanitize($res->name) . "'," . "'" . $db->sanitize($res->filename) . "'," . "'" . $db->sanitize($res->description) . "'," . "'" . $db->sanitize($versionData['stable']->version) . "'," . "'" . $db->sanitize(json_encode($authorDat)) . "'," . "''," . "'0'," . "'0'," . "CURRENT_TIMESTAMP);");
echo $db->error();
Exemplo n.º 6
0
 public static function approveUpdate($update)
 {
     $database = new DatabaseManager();
     AddonManager::verifyTable($database);
     $id = $update->getId();
     if ($update->status !== null) {
         throw new Exception("Attempted to approve already approved update");
     }
     $update->status = true;
     $database->query("UPDATE `addon_updates` SET `approved` = b'1' WHERE `id` = '" . $database->sanitize($id) . "'");
     $database->query("UPDATE `addon_addons` SET `version` = '" . $database->sanitize($update->version) . "' WHERE `id` = '" . $database->sanitize($update->aid) . "'");
     AddonFileHandler::injectGlassFile($update->aid, $update->getFile());
     AddonFileHandler::injectVersionInfo($update->aid, 1, $update->getFile());
     AWSFileManager::uploadNewAddon($update->aid, 1, $update->getAddon()->getFilename(), $update->getFile());
     $params = new stdClass();
     $addon = new stdClass();
     $addon->type = "addon";
     $addon->id = $update->getAddon()->getId();
     $params->vars[] = $addon;
     NotificationManager::createNotification($manager, 'Your update to $1 was approved', $params);
     @unlink($update->getFile());
 }
Exemplo n.º 7
0
$repo = new stdClass();
$repo->name = "Blockland Glass Generated Repo";
$ao = 'add-ons';
$repo->{$ao} = array();
foreach ($addonIds as $id) {
    $obj = AddonManager::getFromId($id);
    if (!is_object($obj)) {
        $addon = new stdClass();
        $addon->id = $id;
        $addon->error = "Unable to create object";
        array_push($repo->{$ao}, $addon);
        continue;
    }
    //$webUrl = "api.blocklandglass.com";
    $webUrl = "api.blocklandglass.com";
    $cdnUrl = AWSFileManager::getBucket();
    $addon = new stdClass();
    $addon->name = substr($obj->getFilename(), 0, strlen($obj->getFilename()) - 4);
    //$addon->description = str_replace("\r\n", "<br>", $obj->getDescription());
    $chanObj = new stdClass();
    $chanObj->name = "stable";
    $chanObj->version = $obj->getVersion();
    $chanObj->restartRequired = $obj->getRestartVersion();
    $chanObj->file = "http://" . $webUrl . "/api/2/download.php?type=addon_update&id=" . $obj->getId() . "&branch=1";
    $chanObj->changelog = "http://" . $webUrl . "/api/2/changelog.php?id=" . $obj->getId() . "&branch=1";
    if (isset($_REQUEST['legacy']) && $_REQUEST['legacy'] == 1 && $id != 11) {
        $chanObj->name = "*";
    }
    if ($id == 193) {
        $chanObj->name = "*";
    }
Exemplo n.º 8
0
echo $_GET['id'];
?>
">Click here!</a>
		</div>
	</div>
	<hr />
	<div style="text-align:center"><img src="/img/rtb_logo.gif"></div>
	<hr />
	<?php 
if ($addonData->glass_id == 0 || $addonData->approved != 1) {
    ?>
	<div style="text-align: center">
		<?php 
    $id = "RTB";
    $class = "red";
    echo '<a href="http://' . AWSFileManager::getBucket() . '/rtb/' . $addonData->filename . '" class="btn dlbtn ' . $class . '"><b>' . ucfirst($id) . '</b><span style="font-size:9pt"><br />Imported Archive</span></a>';
    ?>
	</div>
	<?php 
} else {
    $addon = AddonManager::getFromId($addonData->glass_id);
    ?>
		<p style="text-align:center">This add-on has been imported to <a href="/addons/addon.php?id=<?php 
    echo $addon->getId();
    ?>
"><?php 
    echo $addon->getName();
    ?>
</a></p>
	<?php 
}
 public static function injectVersionInfo($aid, $branchId, $file)
 {
     $addonObject = AddonManager::getFromID($aid);
     $branchName[1] = "stable";
     $branchName[2] = "beta";
     if ($branchId == 1) {
         $v = $addonObject->getVersion();
     } else {
         $v = $addonObject->getBetaVersion();
     }
     $versionData = new stdClass();
     $versionData->version = $v;
     $versionData->channel = $branchName[$branchId];
     $mainRepo = new stdClass();
     $mainRepo->url = "http://api.blocklandglass.com/api/2/repository.php";
     $mainRepo->format = "JSON";
     $mainRepo->id = $aid;
     $backupRepo = new stdClass();
     $backupRepo->url = "http://" . AWSFileManager::getBucket() . "/repository.txt";
     $backupRepo->format = "JSON";
     $backupRepo->id = $aid;
     $versionData->repositories = [$mainRepo, $backupRepo];
     $workingDir = dirname(dirname(__DIR__)) . "/addons/upload/files/";
     $tempFile = $workingDir . "temp/" . $addonObject->getId() . "version.json";
     if (!is_dir($workingDir . "temp")) {
         mkdir($workingDir . "temp", 0777, true);
     }
     $res = file_put_contents($tempFile, json_encode($versionData));
     if ($res === false) {
         return false;
     }
     $zip = new ZipArchive();
     $res = $zip->open($file);
     if ($res === TRUE) {
         $zip->addFile($tempFile, 'version.json');
         $zip->close();
         unlink($tempFile);
     } else {
         return false;
     }
 }
Exemplo n.º 10
0
 /**
  *  Upload a build with contents as an array of strings
  */
 public static function uploadBuild($blid, $buildName, $fileName, $contents, $tempPath, $description = false)
 {
     //to do, generate a random name for storage?, and allow the build name to contain any characters and be not unique - done - check
     //if(!preg_match("/^[a-zA-Z0-9\-\_\ \'\!]{1,56}\.bls$/", $fileName)) {
     if (!BuildManager::validateFileName($fileName)) {
         $response = ["message" => "Invalid File Name - You may use up to 56 characters followed by '.bls' and include letters, numbers, spaces, and the following symbols: -, ', _, and !"];
         return $response;
     }
     //if(!preg_match("/^.{1,60}$/", $buildName)) {
     if (!BuildManager::validateTitle($buildName)) {
         $response = ["message" => "Your Build Title can only contain up to 60 characters and cannot contain line breaks"];
         return $response;
     }
     //temporary file storage for now
     //$targetPath = dirname(__DIR__) . "/../builds/uploads/" . $buildName . ".bls";
     $check = BuildManager::validateBLSContents($contents);
     //to do:
     //actual file saving - check
     //create database entries - check
     //start stat tracking - check?
     //redirect user to manage page - check
     //event logging
     if (!$check['ok']) {
         $response = ["message" => $check['message']];
         return $response;
     }
     if ($description === false) {
         $description = $check['description'];
     }
     //it's go time
     $database = new DatabaseManager();
     BuildManager::verifyTable($database);
     if (!$database->query("INSERT INTO `build_builds` (`blid`, `name`, `filename`, `bricks`, `description`) VALUES ('" . $database->sanitize($blid) . "', '" . $database->sanitize($buildName) . "', '" . $database->sanitize($fileName) . "', '" . $database->sanitize($check['brickcount']) . "', '" . $database->sanitize($description) . "')")) {
         throw new Exception("Database error: " . $database->error());
     }
     $id = $database->fetchMysqli()->insert_id;
     require_once realpath(dirname(__FILE__) . '/AWSFileManager.php');
     AWSFileManager::uploadNewBuild($id, $fileName, $tempPath);
     require_once realpath(dirname(__FILE__) . '/StatManager.php');
     StatManager::addStatsToBuild($id);
     $response = ["redirect" => "/builds/manage.php?id=" . $id];
     return $response;
 }
Exemplo n.º 11
0
 public static function uploadScreenshotForBuild($build, $ext, $tempPath)
 {
     $blid = $build->getBLID();
     $tempThumb = ScreenshotManager::createTempThumbnail($tempPath);
     $database = new DatabaseManager();
     ScreenshotManager::verifyTable($database);
     if (!$database->query("INSERT INTO `screenshots` (`blid`) VALUES ('" . $database->sanitize($blid) . "')")) {
         throw new Exception("Database error: " . $database->error());
     }
     $sid = $database->fetchMysqli()->insert_id;
     require_once realpath(dirname(__FILE__) . '/AWSFileManager.php');
     AWSFileManager::uploadNewScreenshot($sid, "screenshot." . $ext, $tempPath, $tempThumb);
     apc_delete('userScreenshots_' . $blid);
     if (ScreenshotManager::buildHasPrimaryScreenshot($build->getID())) {
         return ScreenshotManager::addScreenshotToBuild($sid, $build->getID());
     } else {
         return ScreenshotManager::setBuildPrimaryScreenshot($sid, $build->getID());
     }
 }
Exemplo n.º 12
0
 public static function getBucket()
 {
     $keyData = AWSFileManager::getCredentials();
     return $keyData->aws_bucket;
 }
Exemplo n.º 13
0
    }
    if ($type == "addon_update") {
        StatManager::downloadAddonID($id, "update");
    } else {
        StatManager::downloadAddonID($id, "ingame");
    }
    $head = 'Location: http://' . AWSFileManager::getBucket() . '/addons/' . $id . '_' . $branch;
    if ($debug) {
        echo $head;
    } else {
        header($head);
    }
    $ao = AddonManager::getFromID($id);
    /*
    //ideal code? need to review how stats work and are kept
    //(object, type[0=web, 1=ingame, 2=update], increment)
    AddonManager::incrementDailyDownloads($ao, 1 ,1);
    AddonManager::incrementWeeklyDownloads($ao, 1, 1);
    AddonManager::incrementTotalDownloads($ao, 1, 1);
    */
} else {
    if ($type == "rtb") {
        $filename = $_REQUEST['fn'];
        $head = 'Location: http://' . AWSFileManager::getBucket() . '/rtb/' . $filename;
        if ($debug) {
            echo $head;
        } else {
            header($head);
        }
    }
}
Exemplo n.º 14
0
<?php

require_once realpath(dirname(__DIR__) . "/private/class/AddonManager.php");
require_once realpath(dirname(__DIR__) . "/private/class/AWSFileManager.php");
require_once realpath(dirname(__DIR__) . "/private/class/StatManager.php");
$id = $_REQUEST['id'];
$addonObject = AddonManager::getFromId($id);
if ($addonObject !== false) {
    StatManager::downloadAddon($addonObject);
    if (isset($_REQUEST['beta'])) {
        $bid = $_REQUEST['beta'] == 1 ? 2 : 1;
    } else {
        $bid = 1;
    }
    //echo 'Location: http://' . AWSFileManager::getBucket() . '/addons/' . $id . "_" . $bid;
    header('Location: http://' . AWSFileManager::getBucket() . '/addons/' . $id . "_" . $bid);
} else {
    header('Status: 404');
    header('Location: /error.php');
}