Skip to content

Commit

Permalink
Merge branch 'release/2.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Arrow768 committed Jan 19, 2016
2 parents d13359b + e796640 commit 45dcc7c
Show file tree
Hide file tree
Showing 19 changed files with 799 additions and 387 deletions.
4 changes: 2 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
APP_ENV=local
APP_DEBUG=true
APP_KEY=SomeRandomString
APP_URL=http://LINK_TO_YOUR_PANEL
APP_KEY=32CharKey
APP_URL=

DB_HOST_PANEL=localhost
DB_DATABASE_PANEL=store
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
.env
/tests/logs
/packages
composer.phar
composer.phar
INSTALLED
87 changes: 78 additions & 9 deletions app/Http/Controllers/InstallerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

use App\Http\Requests;
use App\Http\Controllers\Controller;
use Symfony\Component\Console\Output\StreamOutput;

use Illuminate\Http\Request;

Expand All @@ -30,34 +31,102 @@ public function showWelcome()
return view('templates.installer.welcome');
}

public function postWelcome()
{

}

public function showSettings()
{
return view('templates.installer.settings');
}

public function postSettings()
public function postSettings(Request $request)
{
$settings = array();

$settings["APP_ENV"] = "local";
$settings["APP_DEBUG"] = "true";
$settings["APP_KEY"] = "";
$settings["APP_URL"] = "";

$settings["DB_HOST_PANEL"] = $request->input("db_host_panel");
$settings["DB_DATABASE_PANEL"] = $request->input("db_database_panel");
$settings["DB_USERNAME_PANEL"] = $request->input("db_username_panel");
$settings["DB_PASSWORD_PANEL"] = $request->input("db_password_panel");
$settings["DB_PREFIX_PANEL"] = $request->input("db_prefix_panel");

$settings["DB_HOST_STORE"] = $request->input("db_host_store");
$settings["DB_DATABASE_STORE"] = $request->input("db_database_store");
$settings["DB_USERNAME_STORE"] = $request->input("db_username_store");
$settings["DB_PASSWORD_STORE"] = $request->input("db_password_store");
$settings["DB_PREFIX_STORE"] = $request->input("db_prefix_store");

$settings["CACHE_DRIVER"] = $request->input("cache_driver");
$settings["SESSION_DRIVER"] = $request->input("session_driver");
$settings["QUEUE_DRIVER"] = $request->input("queue_driver");

$settings["MAIL_DRIVER"] = $request->input("mail_driver");
$settings["MAIL_HOST"] = $request->input("mail_host");
$settings["MAIL_PORT"] = $request->input("mail_port");
$settings["MAIL_USERNAME"] = $request->input("mail_username");
$settings["MAIL_PASSWORD"] = $request->input("mail_password");
$settings["MAIL_FROM_ADR"] = $request->input("mail_from_adr");
$settings["MAIL_FROM_NAME"] = $request->input("mail_from_name");

$settings["UP_SERVERLOGIN_IGNORE_IPMISMATCH"] = "true";
$settings["UP_ITEMS_REFUNDFEE"] = "0.8";

//Generate a new app key and add it to the config array
\Artisan::call('key:generate');
$output = \Artisan::output();
$start = strpos($output,"[");
$end = strpos($output,"]");
$key = substr($output,$start+1,$end-$start-1);
$settings["APP_KEY"] = $key;

//Write the settings to file
$this->writeEnvFile($settings);

//Redirect to next page
return redirect()->route('installer.fill_db.show');
}

public function showUsers()
public function showFillDb()
{
return view('templates.installer.user');
return view('templates.installer.fill');
}

public function postUsers()
public function postFillDb()
{
//Migrate DB
\Artisan::call('migrate', array());
$output = \Artisan::output();

return view('templates.installer.fillresult',compact("output"));
}

public function showFinish()
{
//Write installed file
$instfile = fopen("../INSTALLED","w");
fwrite($instfile,"INSTALLED");
fclose($instfile);

return view('templates.installer.finish');
}

/**
* @param $settings Settings to write to the Env File
*/
private function writeEnvFile($settings)
{
$envcontent = "";

foreach($settings as $setting=>$value)
{
$envcontent .= $setting."=".$value.PHP_EOL;
}
//dd($envcontent);

$envfile = fopen("../.env","w");
fwrite($envfile, $envcontent);
fclose($envfile);

}
}
200 changes: 198 additions & 2 deletions app/Http/Controllers/WebPanel/Store/VersionsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
use App\Models\StoreVersion;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Storage;
use Carbon\Carbon;

use Illuminate\Http\Request;

Expand All @@ -33,9 +35,76 @@ class VersionsController extends Controller
*/
public function index()
{
$versions = StoreVersion::all();
//If the user us using private plugins
$private_plugins = false;

return view('templates.' . \Config::get('webpanel.template') . 'webpanel.store.versions.index', compact('versions'));
//Check if the Versions are cached
if(!Storage::exists('/versions/master.json'))
{
$this->do_update();
}

$master_json = Storage::get('/versions/master.json');
$master_array = json_decode($master_json,true);
$master_version = $master_array['format-version'];

//Verify that the master_version is correct
if($master_version != '0.0.3')
{
$versions = array();
return view('templates.' . \Config::get('webpanel.template') . 'webpanel.store.versions.index', compact('versions'))
->with("flash_notification",array("message"=>"Master Version Mismatch", "level"=>"error"));
}

//Get days since the last update
$update_date = Storage::lastModified('/versions/master.json');
$update_date = Carbon::createFromTimestamp($update_date);
$current_date = Carbon::today();
$date_diff = $update_date->diffInDays($current_date);

//Get the installed modules from the db
$plugins = StoreVersion::all();

//dd($plugins);
$plugin_versions = array();
foreach($plugins as $plugin)
{
if(Storage::exists('/versions/'.$plugin->mod_ver_convar.'.json'))
{
//Populate the default fields
$plugin_versions[$plugin->id]["mod_id"] = $plugin->id;
$plugin_versions[$plugin->id]["mod_name"] = $plugin->mod_name;
$plugin_versions[$plugin->id]["mod_description"] = $plugin->mod_description;
$plugin_versions[$plugin->id]["mod_ver_convar"] = $plugin->mod_ver_convar;
$plugin_versions[$plugin->id]["mod_ver_number"] = $plugin->mod_ver_number;
$plugin_versions[$plugin->id]["mod_last_updated"] = $plugin->last_updated;
$plugin_versions[$plugin->id]["server_id"] = $plugin->server_id;

//Get the online data for the plugin
$plugin_data =json_decode(Storage::get('/versions/'.$plugin->mod_ver_convar.'.json'),true);

//Add the online data to the plugin
$plugin_versions[$plugin->id]["name"] = $plugin_data["name"];
$plugin_versions[$plugin->id]["display-name"] = $plugin_data["display-name"];
$plugin_versions[$plugin->id]["description"] = $plugin_data["description"];
$plugin_versions[$plugin->id]["author"] = $plugin_data["author"];
$plugin_versions[$plugin->id]["current-version"] = $plugin_data["current-version"];
$plugin_versions[$plugin->id]["min-store-version"] = $plugin_data["min-store-version"];
$plugin_versions[$plugin->id]["max-store-version"] = $plugin_data["max-store-version"];
$plugin_versions[$plugin->id]["link"] = $plugin_data["link"];
$plugin_versions[$plugin->id]["tags"] = $plugin_data["tags"];

//Check if its up2date
$u2d = $this->check_if_up2date($plugin->mod_ver_number, $plugin_data["current-version"]);
$plugin_versions[$plugin->id]["version"] = $u2d;
}
else
{
$private_plugins = true;
}
}

return view('templates.' . \Config::get('webpanel.template') . 'webpanel.store.versions.index', compact('date_diff','plugin_versions','private_plugins'));
}

/**
Expand All @@ -47,4 +116,131 @@ public function show($version)
{
dd($version);
}


/**
* Updates the Cached Versions
*/
public function update()
{
$this->do_update();
return redirect()->route('webpanel.store.versions.index');
}

/**
* Perform the Update
*/
private function do_update()
{
//Delete the current files
$files = Storage::allFiles('/versions');
Storage::delete($files);

//Download the main file
$master_version = file_get_contents('https://raw.githubusercontent.com/SourceMod-Store/Module-Versions/master/modules.json');
Storage::put('/versions/master.json',$master_version);

$master_version = json_decode($master_version,true);
//Download additional files
foreach($master_version['modules-links'] as $module=>$version_link)
{
Storage::put('/versions/'.$module.'.json',file_get_contents($version_link));
}
}

/**
* Check if the store plugin is up2date
*/
private function check_if_up2date($plugin_version,$online_version)
{
//Return
/**
* txt_short = Short Message to the User
* txt_long = Long Message
* description = A description of the available update
* code = a return code that describes what happened
* * 0 -> up2date
* * 11 -> major version outofdate
* * 12 -> minor version outofdate
* * 13 -> patchlevel outofdate
* * 91 -> Problem when checking major version
* * 92 -> Problem when checking minor version
* * 93 -> Problem when checking patchlevel
*/

$plg_ver_array = explode(".",$plugin_version);
$onl_ver_array = explode(".",$online_version);

//Compare Major Version, then Minor and then Patchlevel
if($plg_ver_array[0] < $onl_ver_array[0])
{
return array(
"txt_short"=>"Out Of Date",
"txt_long"=>"Major Version is out of date",
"description" => "A Major Release is available",
"code"=>"11",
);
}
elseif($plg_ver_array[0] == $onl_ver_array[0])
{
//Compare Minor Versions
if($plg_ver_array[1] < $onl_ver_array[1])
{
return array(
"txt_short"=>"Out Of Date",
"txt_long"=>"Minor Version is out of date",
"description" => "A feature update is available",
"code"=>"12",
);
}
elseif($plg_ver_array[1] == $onl_ver_array[1])
{
if($plg_ver_array[2] < $onl_ver_array[2])
{
return array(
"txt_short"=>"Out Of Date",
"txt_long"=>"Patchlevel is out of date",
"description" => "A patch is available",
"code"=>"13",
);
}
elseif($plg_ver_array[2] == $onl_ver_array[2])
{
return array(
"txt_short"=>"Up2Date",
"txt_long"=>"The version is up to date",
"description" => "There is no update available",
"code"=>"0",
);
}
else
{
return array(
"txt_short"=>"Error",
"txt_long"=>"Error during version check",
"description" => "There has been an error while checking the patchlevel",
"code"=>"93",
);
}
}
else
{
return array(
"txt_short"=>"Error",
"txt_long"=>"Error during version check",
"description" => "There has been an error while checking minor version",
"code"=>"92",
);
}
}
else
{
return array(
"txt_short"=>"Error",
"txt_long"=>"Error during version check",
"description" => "There has been an error while checking the major version",
"code"=>"91",
);
}
}
}
2 changes: 2 additions & 0 deletions app/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class Kernel extends HttpKernel
'guest' => 'App\Http\Middleware\RedirectIfAuthenticated',
'authorize' => 'App\Http\Middleware\Authorize',
'storeuserauth' => 'App\Http\Middleware\StoreUserAuth',
'installed' => 'App\Http\Middleware\Installed',
'notinstalled' => 'App\Http\Middleware\NotInstalled',
];

}
26 changes: 26 additions & 0 deletions app/Http/Middleware/Installed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace App\Http\Middleware;

use Closure;

class Installed
{
/**
* Only allow Access if the application IS installed
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if(!file_exists("../INSTALLED"))
{
abort(403,'Application not installed');
die();
}

return $next($request);
}
}
Loading

0 comments on commit 45dcc7c

Please sign in to comment.