Skip to content

Commit

Permalink
Adding auto updator
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Jul 4, 2018
1 parent b1e4ad6 commit b6c7f9b
Show file tree
Hide file tree
Showing 42 changed files with 1,305 additions and 122 deletions.
4 changes: 3 additions & 1 deletion app/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ class Category extends Model
public function isSub(){
return ($this->parent_id != null);
}

public function getProducts(){
return(\App\Product::where("category_id",$this->id)->get());
}
public function isParent(){
return (count(\App\Category::where('visible',1)->where('parent_id', $this->id)->get()) > 0);
}
Expand Down
5 changes: 5 additions & 0 deletions app/Http/Controllers/APIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,9 @@ function checkConnection(){
$server= \Request::get('server');
return(array("success"=>true,"name"=>$server->name));
}

function getCategory(){
$server= \Request::get('server');
return(array("success"=>true,"name"=>$server->name));
}
}
1 change: 1 addition & 0 deletions app/Http/Controllers/Admin/CategoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public function store(Request $request)
$category->short_desc = request("short_desc");
$category->visible = (request("visible") != null);
$category->featured = (request("featured") != null);

$category->parent_id = request("parent");

$category->save();
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Admin/Dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function showDashboard()
}

public function dd(){
$json_string = json_encode(Request("commands"), JSON_PRETTY_PRINT);
$json_string = json_encode(Request("commands"));
die($json_string);
}
}
26 changes: 15 additions & 11 deletions app/Http/Controllers/Admin/ProductController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function index()
*/
public function create()
{
return view('admin.pages.category.new');
return view('admin.pages.product.new');
}

/**
Expand All @@ -42,17 +42,21 @@ public function create()
*/
public function store(Request $request)
{
$category = new \App\Category;
$category->name = request("name");
$category->desc = request("desc");
$category->short_desc = request("short_desc");
$category->visible = (request("visible") != null);
$category->featured = (request("featured") != null);
$category->parent_id = request("parent");
$product = new \App\Product;

$category->save();
session()->flash('good', 'Category created');
return redirect()->route('admin.Categories');
$product->name = request("name");
$product->image = request("image");
$product->description = request("desc");
$product->price = request("price");
$product->category_id = request("parent");
$product->stock = 999999;
$product->sold = 0;
$product->commands = json_encode(Request("commands"));

$product->save();

session()->flash('good', 'Product created');
return redirect()->route('admin.products');
}

/**
Expand Down
37 changes: 24 additions & 13 deletions app/Http/Controllers/Admin/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ public function save(){
return redirect()->back();
}

public function saveToS(){
\Setting::set("tos_title", Request("title"));
\Setting::set("tos_desc", Request("desc"));
\Setting::save();
session()->flash('good', 'Settings saved');
return redirect()->back();
}

public function showPterodactyl(){
return view('admin.pages.settings.pterodactyl.index');
}
Expand All @@ -44,14 +52,15 @@ public function savePterodactyl(){

if(Request("ptero_link")!= null){
\Setting::set("pterodactyl_link", Request("ptero_link"));
\Setting::save();
}
if(Request("ptero_key")!= null){
\Setting::set("pterodactyl_appkey", Request("ptero_key"));
}
if(Request("ptero_appkey")!= null){
\Setting::set("pterodactyl_appkey", Request("ptero_appkey"));
\Setting::set("pterodactyl_key", Request("ptero_key"));
\Setting::save();

}
// \Setting::save();

//
session()->flash('good', 'Your settings have been saved');
return redirect()->back();
}
Expand Down Expand Up @@ -102,8 +111,8 @@ public function magicPterodactyl(){

// id = $server["attributes"];
// name = $server["name"];
$link = \Setting::get("pterodactyl_link")."application/servers";
$authorization= "Authorization: Bearer ".\Setting::get('pterodactyl_appkey');
$link = \Setting::get("pterodactyl_link")."client";
$authorization= "Authorization: Bearer ".\Setting::get('pterodactyl_key');

$opts = array(
'http'=>array(
Expand All @@ -117,12 +126,14 @@ public function magicPterodactyl(){
$result = file_get_contents($link, false, $context);

foreach(json_decode($result,true)["data"] as $server){
$srv = new \App\Server;
$srv->name = $server["attributes"]["name"];
$srv->ptero_id = $server["attributes"]["identifier"];
$srv->type="pterodactyl";
$srv->api_key= sha1(\Hash::make($server["attributes"]["name"]));
$srv->save();
if( $server["object"] == "server" ){
$srv = new \App\Server;
$srv->name = $server["attributes"]["name"];
$srv->ptero_id = $server["attributes"]["identifier"];
$srv->type="pterodactyl";
$srv->api_key= sha1(\Hash::make($server["attributes"]["name"]));
$srv->save();
}
}
session()->flash('good', 'MinePoS found '.count(\App\Server::all()).' servers they have been added to your store');
return redirect()->back();
Expand Down
88 changes: 75 additions & 13 deletions app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use Illuminate\Http\Request;
use App\Category;
use App\Order;
use Log;

class HomeController extends Controller
{
Expand Down Expand Up @@ -42,20 +44,80 @@ public function logout(){
public function showCategory(Category $category){
return view('category')->with(['category'=>$category]);
}

public function paymentDone(){
// $item_name = $_POST['item_name'];
// $item_number = $_POST['item_number'];
// $payment_status = $_POST['payment_status'];
// $payment_amount = $_POST['mc_gross'];
// $payment_currency = $_POST['mc_currency'];
// $txn_id = $_POST['txn_id'];
// $receiver_email = $_POST['receiver_email'];
// $payer_email = $_POST['payer_email'];
// $order = \App\Order::find($item_number);
// if($order == null){
// abort(404);
// return;
// }
return view('paymentDone');
}

public function addProduct(\App\Product $product){
\Cart::add($product->id, $product->name, 1, $product->price);
return redirect()->route('store.index');
}
public function viewCart(){
// dd(\Cart::content());
return view('cart');
}
public function clearCart(){
\Cart::destroy();
return redirect()->route('store.viewcart');
}

public function checkout(){

$commands = array();
foreach(\Cart::content() as $item){
$product = \App\Product::find($item->id);
$commandTmp = $product->commands;
$commandTmp = str_replace("{username}", \Store::username(), $commandTmp);
$commandTmp = json_decode($commandTmp, true);

$i = 0;
while($i != $item->qty){
foreach($commandTmp as $cmdIndex => $cmdValue){
if(!(isset($commands[$cmdIndex]))){
$commands[$cmdIndex] = array();
}
foreach($cmdValue as $cmd){
array_push($commands[$cmdIndex] , $cmd);

}
}
$i++;
}
}
$commands = json_encode($commands,true);

if(\Request("tos") == null ){
return redirect()->back();
}
if(\Request("gateway") == null ){
return redirect()->back();
}
$gateway = Request("gateway");
if($gateway == "paypal"){
$order = new Order;
$order->username = \Store::username();
$order->commands = $commands;
//die($commands);
$order->total = \Cart::subtotal();
$order->save();

Log::info("Sending to paypal");
\Cart::destroy();
return view("SendToPayPal")->with('order',$order);
}else{
return redirect()->back();
}

}

public function viewCheckout(){
if(\Cart::count() == 0){
return redirect()->route('store.viewcart');
}
return view('checkout');
}
public function testPoint(){

}
}
12 changes: 11 additions & 1 deletion app/Http/Controllers/PayPalTestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,17 @@ public function paypalIpn()
$order->status = "payment_received";
$commands = json_decode($order->commands,true);
foreach($commands as $cmdIndex => $cmdValue){
\App\Server::find($cmdIndex)->runCommands($cmdValue);
if($cmdIndex == -1){
foreach(\App\Server::all() as $srv){
$srv->runCommands($cmdValue);
}
}else{
$srv = \App\Server::find($cmdIndex);
if($srv != null){
$srv->runCommands($cmdValue);
}
}

}
$order->postdata = json_encode($ipn->getPostData());
$order->status = "processed";
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Middleware/ServerAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function handle($request, Closure $next)
}
$server = \App\Server::where('api_key', $key)->first();
if($server == null || $server->enabled == false){
return response()->json(array("error"=>"server not found"));
return response()->json(array("success"=>false,"error"=>"server not found"));
}
$current_time = \Carbon\Carbon::now()->toDateTimeString();
$server->last_used = $current_time;
Expand Down
4 changes: 4 additions & 0 deletions app/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ public static function last($num)
{
return \App\Order::orderBy('created_at', 'desc')->take($num)->get();
}
public static function lastProcessed($num)
{
return \App\Order::where("status","processed")->orderBy('created_at', 'desc')->take($num)->get();
}

public static function lastDays($days)
{
Expand Down
8 changes: 7 additions & 1 deletion app/Providers/EventServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ class EventServiceProvider extends ServiceProvider
'App\Events\Event' => ['App\Listeners\EventListener',],
'Illuminate\Auth\Events\Login' => ['App\Listeners\UserEventListener@onUserLogin'],
'Illuminate\Auth\Events\Logout' => ['App\Listeners\UserEventListener@onUserLogout'],
'Illuminate\Auth\Events\Failed' => ['App\Listeners\UserEventListener@onUserFailed']
'Illuminate\Auth\Events\Failed' => ['App\Listeners\UserEventListener@onUserFailed'],
\Codedge\Updater\Events\UpdateAvailable::class => [
\Codedge\Updater\Listeners\SendUpdateAvailableNotification::class
],
\Codedge\Updater\Events\UpdateSucceeded::class => [
\Codedge\Updater\Listeners\SendUpdateSucceededNotification::class
],
];

/**
Expand Down
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@
"andrew-a/laravel5-paypal-ipn": "dev-master",
"andrew-a/laravel5-paypal-ipn-new": "dev-master",
"anlutro/l4-settings": "^0.6.0",
"codedge/laravel-selfupdater": "^1.4",
"creativeorange/gravatar": "~1.0",
"fedeisas/laravel-mail-css-inliner": "@dev",
"fideloper/proxy": "~4.0",
"gloudemans/shoppingcart": "^2.5",
"igaster/laravel-theme": "^2.0",
"laravel/framework": "5.6.*",
"laravel/tinker": "~1.0",
Expand All @@ -19,8 +22,7 @@
"paypal/rest-api-sdk-php": "*",
"spatie/laravel-permission": "^2.9",
"ujjwal/currency-converter": "^2.3",
"xpaw/php-minecraft-query": "^2.0",
"fedeisas/laravel-mail-css-inliner": "@dev"
"xpaw/php-minecraft-query": "^2.0"
},
"require-dev": {
"filp/whoops": "~2.0",
Expand Down
Loading

0 comments on commit b6c7f9b

Please sign in to comment.