diff --git a/.env.example b/.env.example
index 3621e13..a755618 100644
--- a/.env.example
+++ b/.env.example
@@ -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
diff --git a/.gitignore b/.gitignore
index 20eef05..e57bb11 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,4 +4,5 @@
.env
/tests/logs
/packages
-composer.phar
\ No newline at end of file
+composer.phar
+INSTALLED
\ No newline at end of file
diff --git a/app/Http/Controllers/InstallerController.php b/app/Http/Controllers/InstallerController.php
index 9723012..76a4086 100644
--- a/app/Http/Controllers/InstallerController.php
+++ b/app/Http/Controllers/InstallerController.php
@@ -19,6 +19,7 @@
use App\Http\Requests;
use App\Http\Controllers\Controller;
+use Symfony\Component\Console\Output\StreamOutput;
use Illuminate\Http\Request;
@@ -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);
+
+ }
}
diff --git a/app/Http/Controllers/WebPanel/Store/VersionsController.php b/app/Http/Controllers/WebPanel/Store/VersionsController.php
index d3921d0..df306c2 100644
--- a/app/Http/Controllers/WebPanel/Store/VersionsController.php
+++ b/app/Http/Controllers/WebPanel/Store/VersionsController.php
@@ -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;
@@ -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'));
}
/**
@@ -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",
+ );
+ }
+ }
}
diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php
index 519b948..af1857f 100644
--- a/app/Http/Kernel.php
+++ b/app/Http/Kernel.php
@@ -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',
];
}
diff --git a/app/Http/Middleware/Installed.php b/app/Http/Middleware/Installed.php
new file mode 100644
index 0000000..25b78c5
--- /dev/null
+++ b/app/Http/Middleware/Installed.php
@@ -0,0 +1,26 @@
+ 'installer'], function () {
-// Route::get('', ['as' => 'installer.welcome.show', 'uses' => 'InstallerController@showWelcome']);
-// Route::post('', ['as' => 'installer.welcome.post', 'uses' => 'InstallerController@postWelcome']);
-// Route::get('settings', ['as' => 'installer.settings.show', 'uses' => 'InstallerController@showSettings']);
-// Route::post('settings', ['as' => 'installer.settings.post', 'uses' => 'InstallerController@postSettings']);
-// Route::get('users', ['as' => 'installer.users.show', 'uses' => 'InstallerController@showUsers']);
-// Route::post('users', ['as' => 'installer.users.post', 'uses' => 'InstallerController@postUsers']);
-// Route::get('finish', ['as' => 'installer.finish.show', 'uses' => 'InstallerController@showFinish']);
-//});
+Route::group(['prefix' => 'installer'], function () {
+ Route::get('', ['as' => 'installer.welcome.show', 'uses' => 'InstallerController@showWelcome','middleware' => 'notinstalled']);
+ Route::post('', ['as' => 'installer.welcome.post', 'uses' => 'InstallerController@postWelcome','middleware' => 'notinstalled']);
+ Route::get('settings', ['as' => 'installer.settings.show', 'uses' => 'InstallerController@showSettings','middleware' => 'notinstalled']);
+ Route::post('settings', ['as' => 'installer.settings.post', 'uses' => 'InstallerController@postSettings','middleware' => 'notinstalled']);
+ Route::get('fill_db', ['as' => 'installer.fill_db.show', 'uses' => 'InstallerController@showFillDb','middleware' => 'notinstalled']);
+ Route::post('fill_db', ['as' => 'installer.fill_db.post', 'uses' => 'InstallerController@postFillDb','middleware' => 'notinstalled']);
+ Route::get('finish', ['as' => 'installer.finish.show', 'uses' => 'InstallerController@showFinish']);
+});
//WebPanel Routes
Route::group(['middleware' => ['auth', 'authorize'], 'prefix' => 'webpanel'], function () {
@@ -64,6 +64,7 @@
Route::group(['prefix' => 'versions'], function () {
Route::get('', ['as' => 'webpanel.store.versions.index', 'uses' => 'WebPanel\Store\VersionsController@index']);
+ Route::get('update', ['as' => 'webpanel.store.versions.update', 'uses' => 'WebPanel\Store\VersionsController@update']);
Route::get('/{versions}', ['as' => 'webpanel.store.versions.show', 'uses' => 'WebPanel\Store\VersionsController@show']);
});
diff --git a/database/migrations/2015_05_02_100000_store_create_tables.php b/database/migrations/2015_05_02_100000_store_create_tables.php
index cf31242..acfa17a 100644
--- a/database/migrations/2015_05_02_100000_store_create_tables.php
+++ b/database/migrations/2015_05_02_100000_store_create_tables.php
@@ -130,11 +130,14 @@ public function up()
$table->string('mod_description',64)->nullable();
$table->string('mod_ver_convar',64)->nullable();
$table->string('mod_ver_number',64);
- $table->string('server_id',64);
+ $table->integer('server_id')->unsigned();
$table->timestamp('last_updated');
$table->timestamps();
$table->unique(['mod_ver_convar', 'server_id']);
+
+ $table->foreign('server_id')->references('id')->on('servers')
+ ->onUpdate('cascade')->onDelete('cascade');
});
// Create table for store servers
diff --git a/resources/views/templates/adminlte205/includes/cont-footer.blade.php b/resources/views/templates/adminlte205/includes/cont-footer.blade.php
index 65d3c9c..15bbc93 100644
--- a/resources/views/templates/adminlte205/includes/cont-footer.blade.php
+++ b/resources/views/templates/adminlte205/includes/cont-footer.blade.php
@@ -15,6 +15,6 @@
{{--You should have received a copy of the GNU Affero General Public License--}}
{{--along with this program. If not, see