Cachet is now a Laravel 5 app
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
<?php namespace CachetHQ\Cachet\Commands;
|
||||
|
||||
abstract class Command
|
||||
{
|
||||
//
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Composers;
|
||||
|
||||
use CachetHQ\Cachet\Models\Component;
|
||||
use CachetHQ\Cachet\Models\Incident;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class DashboardComposer
|
||||
{
|
||||
/**
|
||||
* Bind data to the view.
|
||||
*
|
||||
* @param \Illuminate\View\View $view
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function compose(View $view)
|
||||
{
|
||||
$view->with('incidentCount', Incident::notScheduled()->count());
|
||||
$view->with('componentCount', Component::all()->count());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Composers;
|
||||
|
||||
use CachetHQ\Cachet\Models\Component;
|
||||
use CachetHQ\Cachet\Models\Incident;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class IndexComposer
|
||||
{
|
||||
/**
|
||||
* Index page view composer.
|
||||
*
|
||||
* @param \Illuminate\View\View $view
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function compose(View $view)
|
||||
{
|
||||
// Default data
|
||||
$withData = [
|
||||
'systemStatus' => 'danger',
|
||||
'systemMessage' => trans('cachet.service.bad'),
|
||||
];
|
||||
|
||||
if (Component::notStatus(1)->count() === 0) {
|
||||
// If all our components are ok, do we have any non-fixed incidents?
|
||||
$incidents = Incident::notScheduled()->orderBy('created_at', 'desc')->get();
|
||||
$incidentCount = $incidents->count();
|
||||
|
||||
if ($incidentCount === 0 || ($incidentCount >= 1 && (int) $incidents->first()->status === 4)) {
|
||||
$withData = [
|
||||
'systemStatus' => 'success',
|
||||
'systemMessage' => trans('cachet.service.good'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$view->with($withData);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Composers;
|
||||
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class LoggedUserComposer
|
||||
{
|
||||
/**
|
||||
* Bind data to the view.
|
||||
*
|
||||
* @param \Illuminate\View\View $view
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function compose(View $view)
|
||||
{
|
||||
$view->with('loggedUser', Auth::user());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Composers;
|
||||
|
||||
use DateTime;
|
||||
use DateTimeZone;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class TimezoneLocaleComposer
|
||||
{
|
||||
/**
|
||||
* Timezones and Locales composer.
|
||||
*
|
||||
* @param \Illuminate\View\View $view
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function compose(View $view)
|
||||
{
|
||||
$enabledLangs = Config::get('langs');
|
||||
|
||||
$langs = array_map(function ($lang) use ($enabledLangs) {
|
||||
$locale = basename($lang);
|
||||
|
||||
return [$locale => $enabledLangs[$locale]];
|
||||
}, glob(base_path('resources/lang').'/*'));
|
||||
|
||||
$langs = call_user_func_array('array_merge', $langs);
|
||||
|
||||
$regions = [
|
||||
'Africa' => DateTimeZone::AFRICA,
|
||||
'America' => DateTimeZone::AMERICA,
|
||||
'Antarctica' => DateTimeZone::ANTARCTICA,
|
||||
'Asia' => DateTimeZone::ASIA,
|
||||
'Atlantic' => DateTimeZone::ATLANTIC,
|
||||
'Australia' => DateTimeZone::AUSTRALIA,
|
||||
'Europe' => DateTimeZone::EUROPE,
|
||||
'Indian' => DateTimeZone::INDIAN,
|
||||
'Pacific' => DateTimeZone::PACIFIC,
|
||||
];
|
||||
|
||||
$timezones = [];
|
||||
|
||||
foreach ($regions as $name => $mask) {
|
||||
$zones = DateTimeZone::listIdentifiers($mask);
|
||||
|
||||
foreach ($zones as $timezone) {
|
||||
// Lets sample the time there right now
|
||||
$time = new DateTime(null, new DateTimeZone($timezone));
|
||||
|
||||
$ampm = $time->format('H') > 12 ? ' ('.$time->format('g:i a').')' : '';
|
||||
|
||||
// Remove region name and add a sample time
|
||||
$timezones[$name][$timezone] = substr($timezone, strlen($name) + 1).' - '.$time->format('H:i').$ampm;
|
||||
|
||||
$timezones[$name] = str_replace('_', ' ', $timezones[$name]);
|
||||
}
|
||||
}
|
||||
|
||||
$view->with([
|
||||
'timezones' => $timezones,
|
||||
'langs' => $langs,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Config;
|
||||
|
||||
use CachetHQ\Cachet\Models\Setting;
|
||||
|
||||
class Repository
|
||||
{
|
||||
/**
|
||||
* The eloquent model instance.
|
||||
*
|
||||
* @var \CachetHQ\Cachet\Models\Setting
|
||||
*/
|
||||
protected $model;
|
||||
|
||||
/**
|
||||
* Cache of the settings.
|
||||
*
|
||||
* @var array|null
|
||||
*/
|
||||
protected $settings;
|
||||
|
||||
/**
|
||||
* Create a new settings service instance.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\Setting $model
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Setting $model)
|
||||
{
|
||||
$this->model = $model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a setting from the database.
|
||||
*
|
||||
* @param string $name
|
||||
* @param bool $checkEnv
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function get($name, $checkEnv = true)
|
||||
{
|
||||
// if we've not loaded the settings, load them now
|
||||
if (!$this->settings) {
|
||||
$this->settings = $this->model->all()->lists('value', 'name');
|
||||
}
|
||||
|
||||
// if the setting exists, return it
|
||||
if (isset($this->settings[$name])) {
|
||||
return $this->settings[$name];
|
||||
}
|
||||
|
||||
// fallback to getenv if allowed to
|
||||
if ($checkEnv) {
|
||||
return $this->settings[$name] = getenv(strtoupper($name));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates or updates a setting value.
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $value
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function set($name, $value)
|
||||
{
|
||||
// save the change to the db
|
||||
$this->model->updateOrCreate(compact('name'), compact('value'));
|
||||
|
||||
// if we've loaded the settings, persist this change
|
||||
if ($this->settings) {
|
||||
$this->settings[$name] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Console\Commands;
|
||||
|
||||
use DirectoryIterator;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class FixPermissionsCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'cachet:chmod';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Fixes file and directory permissions. Ensures SQLite database is writeable.';
|
||||
|
||||
/**
|
||||
* Path to the storage directory.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $storageDirectory;
|
||||
|
||||
/**
|
||||
* Path of the database directory.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $databaseDirectory;
|
||||
|
||||
/**
|
||||
* Path of the SQLite database file.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $databasePath;
|
||||
|
||||
/**
|
||||
* Which database connection are we using?
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $databaseDefault;
|
||||
|
||||
/**
|
||||
* Create a new fix permissions command instance.
|
||||
*
|
||||
* @param string $storageDirectory
|
||||
* @param string $databaseDirectory
|
||||
* @param string $databasePath
|
||||
* @param string $databaseDefault
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($storageDirectory, $databaseDirectory, $databasePath, $databaseDefault)
|
||||
{
|
||||
$this->storageDirectory = $storageDirectory;
|
||||
$this->databaseDirectory = $databaseDirectory;
|
||||
$this->databasePath = $databasePath;
|
||||
$this->databaseDefault = $databaseDefault;
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function fire()
|
||||
{
|
||||
$this->recursiveChmod($this->storageDirectory);
|
||||
|
||||
if ($this->databaseDefault === 'sqlite') {
|
||||
chmod($this->databaseDirectory, 755);
|
||||
chmod($this->databasePath, 755);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively sets a paths file permissions.
|
||||
*
|
||||
* @param string $path
|
||||
* @param string $mode
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function recursiveChmod($path, $mode = '0755')
|
||||
{
|
||||
$dir = new DirectoryIterator($path);
|
||||
foreach ($dir as $item) {
|
||||
if (!$item->isDot()) {
|
||||
chmod($item->getPathname(), $mode);
|
||||
}
|
||||
|
||||
if ($item->isDir() && !$item->isDot()) {
|
||||
$this->recursiveChmod($item->getPathname());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
class OneClickDeployCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'cachet:one-click-deploy';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Installs CachetHQ on one click supported services';
|
||||
|
||||
/**
|
||||
* Should we run the migrations?
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $migrate;
|
||||
|
||||
/**
|
||||
* Create a new one click deploy command instance.
|
||||
*
|
||||
* @param bool $migrate
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($migrate)
|
||||
{
|
||||
$this->migrate = $migrate;
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int|null
|
||||
*/
|
||||
public function fire()
|
||||
{
|
||||
if ($this->migrate) {
|
||||
$migrations = $this->runMigrations();
|
||||
|
||||
segment_track('Installation', [
|
||||
'event' => 'Heroku Deployment',
|
||||
]);
|
||||
|
||||
return $migrations;
|
||||
}
|
||||
|
||||
$this->info('Please run "php artisan migrate" to finish the installation.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
protected function runMigrations()
|
||||
{
|
||||
$options = [
|
||||
'--database' => $this->input->getOption('database'),
|
||||
'--force' => $this->input->getOption('force'),
|
||||
'--seed' => $this->input->getOption('seed'),
|
||||
];
|
||||
|
||||
return $this->call('migrate', $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command options.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getOptions()
|
||||
{
|
||||
return [
|
||||
['database', null, InputOption::VALUE_OPTIONAL, 'The database connection to use.'],
|
||||
['force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production.'],
|
||||
['seed', null, InputOption::VALUE_NONE, 'Indicates if the seed task should be re-run.'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Console;
|
||||
|
||||
use Illuminate\Console\Scheduling\Schedule;
|
||||
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
||||
|
||||
class Kernel extends ConsoleKernel
|
||||
{
|
||||
/**
|
||||
* The Artisan commands provided by your application.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $commands = [
|
||||
'CachetHQ\Cachet\Console\Commands\FixPermissionsCommand',
|
||||
'CachetHQ\Cachet\Console\Commands\OneClickDeployCommand',
|
||||
];
|
||||
|
||||
/**
|
||||
* Define the application's command schedule.
|
||||
*
|
||||
* @param \Illuminate\Console\Scheduling\Schedule $schedule
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function schedule(Schedule $schedule)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
<?php namespace CachetHQ\Cachet\Events;
|
||||
|
||||
abstract class Event
|
||||
{
|
||||
//
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php namespace CachetHQ\Cachet\Exceptions;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
||||
use Illuminate\Support\Facades\Response;
|
||||
|
||||
class Handler extends ExceptionHandler
|
||||
{
|
||||
/**
|
||||
* A list of the exception types that should not be reported.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $dontReport = [
|
||||
'Symfony\Component\HttpKernel\Exception\HttpException',
|
||||
];
|
||||
|
||||
/**
|
||||
* Report or log an exception.
|
||||
*
|
||||
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
|
||||
*
|
||||
* @param \Exception $e
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function report(Exception $e)
|
||||
{
|
||||
return parent::report($e);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render an exception into an HTTP response.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Exception $e
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function render($request, Exception $e)
|
||||
{
|
||||
if ($request->is('api*')) {
|
||||
if ($e instanceof \CachetHQ\Cachet\Repositories\InvalidModelValidationException) {
|
||||
return Response::make(['status_code' => 400, 'message' => 'Bad Request'], 400);
|
||||
}
|
||||
|
||||
if ($e instanceof \Illuminate\Database\Eloquent\ModelNotFoundException) {
|
||||
return Response::make(['status_code' => 404, 'error' => 'Resource not found'], 404);
|
||||
}
|
||||
}
|
||||
|
||||
return parent::render($request, $e);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Facades;
|
||||
|
||||
use Illuminate\Support\Facades\Facade;
|
||||
|
||||
/**
|
||||
* @see \CachetHQ\Cachet\Services\SettingsService
|
||||
*/
|
||||
class Setting extends Facade
|
||||
{
|
||||
/**
|
||||
* Get the registered name of the component.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected static function getFacadeAccessor()
|
||||
{
|
||||
return 'setting';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Controllers;
|
||||
|
||||
use Illuminate\Foundation\Bus\DispatchesCommands;
|
||||
use Illuminate\Foundation\Validation\ValidatesRequests;
|
||||
use Illuminate\Routing\Controller as BaseController;
|
||||
|
||||
abstract class AbstractController extends BaseController
|
||||
{
|
||||
use DispatchesCommands, ValidatesRequests;
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Controllers\Admin;
|
||||
|
||||
use CachetHQ\Cachet\Models\Component;
|
||||
use CachetHQ\Cachet\Models\IncidentTemplate;
|
||||
use Exception;
|
||||
use GrahamCampbell\Binput\Facades\Binput;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Illuminate\Routing\Controller;
|
||||
|
||||
class ApiController extends Controller
|
||||
{
|
||||
/**
|
||||
* Updates a component with the entered info.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\Component $component
|
||||
*
|
||||
* @throws \Exception
|
||||
*
|
||||
* @return \CachetHQ\Cachet\Models\Component
|
||||
*/
|
||||
public function postUpdateComponent(Component $component)
|
||||
{
|
||||
if (!$component->update(Binput::except(['_token']))) {
|
||||
throw new Exception(trans('dashboard.components.edit.failure'));
|
||||
}
|
||||
|
||||
return $component;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a components ordering.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function postUpdateComponentOrder()
|
||||
{
|
||||
$componentData = Binput::all();
|
||||
unset($componentData['component'][0]); // Remove random 0 index.
|
||||
|
||||
foreach ($componentData['component'] as $componentId => $order) {
|
||||
$component = Component::find($componentId);
|
||||
$component->update(['order' => $order]);
|
||||
}
|
||||
|
||||
return $componentData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a template by slug.
|
||||
*
|
||||
* @throws \Illuminate\Database\Eloquent\ModelNotFoundException
|
||||
*
|
||||
* @return \CachetHQ\Cachet\Models\IncidentTemplate
|
||||
*/
|
||||
public function getIncidentTemplate()
|
||||
{
|
||||
$templateSlug = Binput::get('slug');
|
||||
|
||||
$template = IncidentTemplate::where('slug', $templateSlug)->first();
|
||||
|
||||
if ($template) {
|
||||
return $template;
|
||||
}
|
||||
|
||||
throw new ModelNotFoundException('Incident template for '.$templateSlug.' could not be found.');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,373 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Controllers\Admin;
|
||||
|
||||
use CachetHQ\Cachet\Models\Component;
|
||||
use CachetHQ\Cachet\Models\ComponentGroup;
|
||||
use CachetHQ\Cachet\Models\Tag;
|
||||
use GrahamCampbell\Binput\Facades\Binput;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
use Illuminate\Support\Facades\View;
|
||||
|
||||
class ComponentController extends Controller
|
||||
{
|
||||
protected $subMenu = [];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->subMenu = [
|
||||
'components' => [
|
||||
'title' => trans('dashboard.components.components'),
|
||||
'url' => route('dashboard.components'),
|
||||
'icon' => 'ion-outlet',
|
||||
'active' => false,
|
||||
],
|
||||
'groups' => [
|
||||
'title' => trans_choice('dashboard.components.groups.groups', 2),
|
||||
'url' => route('dashboard.components.groups'),
|
||||
'icon' => 'ion-folder',
|
||||
'active' => false,
|
||||
],
|
||||
];
|
||||
|
||||
View::share([
|
||||
'subMenu' => $this->subMenu,
|
||||
'subTitle' => trans_choice('dashboard.components.components', 2),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the components view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showComponents()
|
||||
{
|
||||
$components = Component::orderBy('order')->orderBy('created_at')->get();
|
||||
|
||||
$this->subMenu['components']['active'] = true;
|
||||
|
||||
return View::make('dashboard.components.index')->with([
|
||||
'pageTitle' => trans_choice('dashboard.components.components', 2).' - '.trans('dashboard.dashboard'),
|
||||
'components' => $components,
|
||||
'subMenu' => $this->subMenu,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the component groups view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showComponentGroups()
|
||||
{
|
||||
$this->subMenu['groups']['active'] = true;
|
||||
|
||||
return View::make('dashboard.components.groups.index')->with([
|
||||
'pageTitle' => trans_choice('dashboard.components.groups.groups', 2).' - '.trans('dashboard.dashboard'),
|
||||
'groups' => ComponentGroup::all(),
|
||||
'subMenu' => $this->subMenu,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the edit component view.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\Component $component
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showEditComponent(Component $component)
|
||||
{
|
||||
$groups = ComponentGroup::all();
|
||||
|
||||
$pageTitle = sprintf(
|
||||
'"%s" - %s - %s',
|
||||
$component->name,
|
||||
trans('dashboard.components.edit.title'),
|
||||
trans('dashboard.dashboard')
|
||||
);
|
||||
|
||||
return View::make('dashboard.components.edit')->with([
|
||||
'pageTitle' => $pageTitle,
|
||||
'component' => $component,
|
||||
'groups' => $groups,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a component.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\Component $component
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function updateComponentAction(Component $component)
|
||||
{
|
||||
$_component = Binput::get('component');
|
||||
$_component['user_id'] = Auth::user()->id;
|
||||
$tags = array_pull($_component, 'tags');
|
||||
|
||||
$component->update($_component);
|
||||
|
||||
if (! $component->isValid()) {
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Edit Component',
|
||||
'success' => false,
|
||||
]);
|
||||
|
||||
return Redirect::back()->withInput(Binput::all())
|
||||
->with('title', sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.whoops'),
|
||||
trans('dashboard.components.edit.failure')
|
||||
))
|
||||
->with('errors', $component->getErrors());
|
||||
}
|
||||
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Edit Component',
|
||||
'success' => true,
|
||||
]);
|
||||
|
||||
// The component was added successfully, so now let's deal with the tags.
|
||||
$tags = preg_split('/ ?, ?/', $tags);
|
||||
|
||||
// For every tag, do we need to create it?
|
||||
$componentTags = array_map(function ($taggable) use ($component) {
|
||||
return Tag::firstOrCreate([
|
||||
'name' => $taggable,
|
||||
])->id;
|
||||
}, $tags);
|
||||
|
||||
$component->tags()->sync($componentTags);
|
||||
|
||||
$successMsg = sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.awesome'),
|
||||
trans('dashboard.components.edit.success')
|
||||
);
|
||||
|
||||
return Redirect::back()->with('success', $successMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the add component view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showAddComponent()
|
||||
{
|
||||
$groups = ComponentGroup::all();
|
||||
|
||||
return View::make('dashboard.components.add')->with([
|
||||
'pageTitle' => trans('dashboard.components.add.title').' - '.trans('dashboard.dashboard'),
|
||||
'groups' => $groups,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new component.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function createComponentAction()
|
||||
{
|
||||
$_component = Binput::get('component');
|
||||
$_component['user_id'] = Auth::user()->id;
|
||||
// We deal with tags separately.
|
||||
$tags = array_pull($_component, 'tags');
|
||||
|
||||
$component = Component::create($_component);
|
||||
|
||||
if (! $component->isValid()) {
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Created Component',
|
||||
'success' => false,
|
||||
]);
|
||||
|
||||
return Redirect::back()->withInput(Binput::all())
|
||||
->with('title', sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.whoops'),
|
||||
trans('dashboard.components.add.failure')
|
||||
))
|
||||
->with('errors', $component->getErrors());
|
||||
}
|
||||
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Created Component',
|
||||
'success' => true,
|
||||
]);
|
||||
|
||||
// The component was added successfully, so now let's deal with the tags.
|
||||
$tags = preg_split('/ ?, ?/', $tags);
|
||||
|
||||
// For every tag, do we need to create it?
|
||||
$componentTags = array_map(function ($taggable) use ($component) {
|
||||
return Tag::firstOrCreate([
|
||||
'name' => $taggable,
|
||||
])->id;
|
||||
}, $tags);
|
||||
|
||||
$component->tags()->sync($componentTags);
|
||||
|
||||
$successMsg = sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.awesome'),
|
||||
trans('dashboard.components.add.success')
|
||||
);
|
||||
|
||||
return Redirect::back()->with('success', $successMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a given component.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\Component $component
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function deleteComponentAction(Component $component)
|
||||
{
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Deleted Component',
|
||||
]);
|
||||
|
||||
$component->delete();
|
||||
|
||||
return Redirect::back();
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a given component group.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\ComponentGroup $group
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function deleteComponentGroupAction(ComponentGroup $group)
|
||||
{
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Deleted Component Group',
|
||||
]);
|
||||
|
||||
$group->components->map(function ($component) {
|
||||
$component->update([
|
||||
'group_id' => 0,
|
||||
]);
|
||||
});
|
||||
|
||||
$group->delete();
|
||||
|
||||
return Redirect::back();
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the add component group view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showAddComponentGroup()
|
||||
{
|
||||
return View::make('dashboard.components.groups.add')->with([
|
||||
'pageTitle' => trans('dashboard.components.groups.add.title').' - '.trans('dashboard.dashboard'),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the edit component group view.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\ComponentGroup $group
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showEditComponentGroup(ComponentGroup $group)
|
||||
{
|
||||
return View::make('dashboard.components.groups.edit')->with([
|
||||
'pageTitle' => trans('dashboard.components.groups.edit.title').' - '.trans('dashboard.dashboard'),
|
||||
'group' => $group,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new component.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function postAddComponentGroup()
|
||||
{
|
||||
$group = ComponentGroup::create(Binput::get('group'));
|
||||
|
||||
if (! $group->isValid()) {
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Created Component Group',
|
||||
'success' => false,
|
||||
]);
|
||||
|
||||
return Redirect::back()->withInput(Binput::all())
|
||||
->with('title', sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.whoops'),
|
||||
trans('dashboard.components.groups.add.failure')
|
||||
))
|
||||
->with('errors', $group->getErrors());
|
||||
}
|
||||
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Created Component Group',
|
||||
'success' => true,
|
||||
]);
|
||||
|
||||
$successMsg = sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.awesome'),
|
||||
trans('dashboard.components.groups.add.success')
|
||||
);
|
||||
|
||||
return Redirect::back()->with('success', $successMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a component group.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\ComponentGroup $group
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function updateComponentGroupAction(ComponentGroup $group)
|
||||
{
|
||||
$groupData = Binput::get('group');
|
||||
$group->update($groupData);
|
||||
|
||||
if (! $group->isValid()) {
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Edit Component Group',
|
||||
'success' => false,
|
||||
]);
|
||||
|
||||
return Redirect::back()->withInput(Binput::all())
|
||||
->with('title', sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.whoops'),
|
||||
trans('dashboard.components.groups.edit.failure')
|
||||
))
|
||||
->with('errors', $group->getErrors());
|
||||
}
|
||||
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Edit Component Group',
|
||||
'success' => true,
|
||||
]);
|
||||
|
||||
$successMsg = sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.awesome'),
|
||||
trans('dashboard.components.groups.edit.success')
|
||||
);
|
||||
|
||||
return Redirect::back()->with('success', $successMsg);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Controllers\Admin;
|
||||
|
||||
use CachetHQ\Cachet\Models\Component;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Facades\View;
|
||||
|
||||
class DashboardController extends Controller
|
||||
{
|
||||
/**
|
||||
* Shows the dashboard view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showDashboard()
|
||||
{
|
||||
$components = Component::all();
|
||||
|
||||
return View::make('dashboard.index')->with([
|
||||
'components' => $components,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the notifications view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showNotifications()
|
||||
{
|
||||
return View::make('dashboard.notifications.index')->with([
|
||||
'pageTitle' => trans('dashboard.notifications.notifications').' - '.trans('dashboard.dashboard'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,317 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Controllers\Admin;
|
||||
|
||||
use CachetHQ\Cachet\Models\Component;
|
||||
use CachetHQ\Cachet\Models\Incident;
|
||||
use CachetHQ\Cachet\Models\IncidentTemplate;
|
||||
use GrahamCampbell\Binput\Facades\Binput;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
use Illuminate\Support\Facades\View;
|
||||
|
||||
class IncidentController extends Controller
|
||||
{
|
||||
/**
|
||||
* Stores the sub-sidebar tree list.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $subMenu = [];
|
||||
|
||||
/**
|
||||
* Creates a new DashIncidentController instance.
|
||||
*
|
||||
* @return \CachetHQ\Cachet\Http\Controllers\DashScheduleController
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->subMenu = [
|
||||
'incidents' => [
|
||||
'title' => trans('dashboard.incidents.incidents'),
|
||||
'url' => route('dashboard.incidents'),
|
||||
'icon' => 'ion-android-checkmark-circle',
|
||||
'active' => true,
|
||||
],
|
||||
'schedule' => [
|
||||
'title' => trans('dashboard.schedule.schedule'),
|
||||
'url' => route('dashboard.schedule'),
|
||||
'icon' => 'ion-android-calendar',
|
||||
'active' => false,
|
||||
],
|
||||
];
|
||||
|
||||
View::share('subMenu', $this->subMenu);
|
||||
View::share('subTitle', trans('dashboard.incidents.title'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the incidents view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showIncidents()
|
||||
{
|
||||
$incidents = Incident::notScheduled()->orderBy('created_at', 'desc')->get();
|
||||
|
||||
return View::make('dashboard.incidents.index')->with([
|
||||
'pageTitle' => trans('dashboard.incidents.incidents').' - '.trans('dashboard.dashboard'),
|
||||
'incidents' => $incidents,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the add incident view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showAddIncident()
|
||||
{
|
||||
return View::make('dashboard.incidents.add')->with([
|
||||
'pageTitle' => trans('dashboard.incidents.add.title').' - '.trans('dashboard.dashboard'),
|
||||
'components' => Component::all(),
|
||||
'incidentTemplates' => IncidentTemplate::all(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the incident templates.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showTemplates()
|
||||
{
|
||||
return View::make('dashboard.incidents.templates.index')->with([
|
||||
'pageTitle' => trans('dashboard.incidents.templates.title').' - '.trans('dashboard.dashboard'),
|
||||
'incidentTemplates' => IncidentTemplate::all(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new incident.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function createIncidentAction()
|
||||
{
|
||||
$incidentData = Binput::get('incident');
|
||||
$incidentData['user_id'] = Auth::user()->id;
|
||||
$componentStatus = array_pull($incidentData, 'component_status');
|
||||
|
||||
$incident = Incident::create($incidentData);
|
||||
|
||||
if (! $incident->isValid()) {
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Created Incident',
|
||||
'success' => false,
|
||||
]);
|
||||
|
||||
return Redirect::back()->withInput(Binput::all())
|
||||
->with('title', sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.whoops'),
|
||||
trans('dashboard.incidents.add.failure')
|
||||
))
|
||||
->with('errors', $incident->getErrors());
|
||||
}
|
||||
|
||||
// Update the component.
|
||||
if (isset($incidentData['component_id']) && (int) $incidentData['component_id'] > 0) {
|
||||
Component::find($incidentData['component_id'])->update([
|
||||
'status' => $componentStatus,
|
||||
]);
|
||||
}
|
||||
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Created Incident',
|
||||
'success' => true,
|
||||
]);
|
||||
|
||||
$successMsg = sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.awesome'),
|
||||
trans('dashboard.incidents.add.success')
|
||||
);
|
||||
|
||||
return Redirect::back()->with('success', $successMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the add incident template view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showAddIncidentTemplate()
|
||||
{
|
||||
return View::make('dashboard.incidents.templates.add')->with([
|
||||
'pageTitle' => trans('dashboard.incidents.templates.add.title').' - '.trans('dashboard.dashboard'),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the edit incident template view.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\IncidentTemplate $template
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showEditTemplateAction(IncidentTemplate $template)
|
||||
{
|
||||
return View::make('dashboard.incidents.templates.edit')->with([
|
||||
'pageTitle' => trans('dashboard.incidents.templates.edit.title').' - '.trans('dashboard.dashboard'),
|
||||
'template' => $template,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes an incident template.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\IncidentTemplate $template
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function deleteTemplateAction(IncidentTemplate $template)
|
||||
{
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Deleted Incident Template',
|
||||
]);
|
||||
|
||||
$template->delete();
|
||||
|
||||
return Redirect::back();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new incident template.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function createIncidentTemplateAction()
|
||||
{
|
||||
$_template = Binput::get('template');
|
||||
$template = IncidentTemplate::create($_template);
|
||||
|
||||
if (! $template->isValid()) {
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Created Incident Template',
|
||||
'success' => false,
|
||||
]);
|
||||
|
||||
return Redirect::back()->withInput(Binput::all())
|
||||
->with('title', sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.awesome'),
|
||||
trans('dashboard.incidents.templates.add.failure')
|
||||
))
|
||||
->with('errors', $template->getErrors());
|
||||
}
|
||||
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Created Incident Template',
|
||||
'success' => true,
|
||||
]);
|
||||
|
||||
$successMsg = sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.awesome'),
|
||||
trans('dashboard.incidents.templates.add.success')
|
||||
);
|
||||
|
||||
return Redirect::back()->with('success', $successMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a given incident.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\Incident $incident
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function deleteIncidentAction(Incident $incident)
|
||||
{
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Deleted Incident',
|
||||
]);
|
||||
|
||||
$incident->delete();
|
||||
|
||||
return Redirect::back();
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the edit incident view.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\Incident $incident
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showEditIncidentAction(Incident $incident)
|
||||
{
|
||||
return View::make('dashboard.incidents.edit')->with([
|
||||
'pageTitle' => trans('dashboard.incidents.edit.title').' - '.trans('dashboard.dashboard'),
|
||||
'incident' => $incident,
|
||||
'components' => Component::all(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit an incident.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\Incident $incident
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function editIncidentAction(Incident $incident)
|
||||
{
|
||||
$incidentData = Binput::get('incident');
|
||||
$incidentData['user_id'] = Auth::user()->id;
|
||||
$incident->update($incidentData);
|
||||
|
||||
if (! $incident->isValid()) {
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Edited Incident',
|
||||
'success' => false,
|
||||
]);
|
||||
|
||||
return Redirect::back()->withInput(Binput::all())
|
||||
->with('title', sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.awesome'),
|
||||
trans('dashboard.incidents.templates.edit.failure')
|
||||
))
|
||||
->with('errors', $incident->getErrors());
|
||||
}
|
||||
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Edited Incident',
|
||||
'success' => true,
|
||||
]);
|
||||
|
||||
$successMsg = sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.awesome'),
|
||||
trans('dashboard.incidents.edit.success')
|
||||
);
|
||||
|
||||
return Redirect::to('dashboard/incidents')->with('success', $successMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit an incident template.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\IncidentTemplate $template
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function editTemplateAction(IncidentTemplate $template)
|
||||
{
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Edited Incident Template',
|
||||
]);
|
||||
|
||||
$template->update(Binput::get('template'));
|
||||
|
||||
return Redirect::back()->with('updatedTemplate', $template);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,203 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Controllers\Admin;
|
||||
|
||||
use CachetHQ\Cachet\Models\Metric;
|
||||
use CachetHQ\Cachet\Models\MetricPoint;
|
||||
use GrahamCampbell\Binput\Facades\Binput;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
use Illuminate\Support\Facades\View;
|
||||
|
||||
class MetricController extends Controller
|
||||
{
|
||||
/**
|
||||
* Shows the metrics view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showMetrics()
|
||||
{
|
||||
$metrics = Metric::orderBy('created_at', 'desc')->get();
|
||||
|
||||
return View::make('dashboard.metrics.index')->with([
|
||||
'pageTitle' => trans('dashboard.metrics.metrics').' - '.trans('dashboard.dashboard'),
|
||||
'metrics' => $metrics,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the add metric view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showAddMetric()
|
||||
{
|
||||
return View::make('dashboard.metrics.add')->with([
|
||||
'pageTitle' => trans('dashboard.metrics.add.title').' - '.trans('dashboard.dashboard'),
|
||||
'metricMetricPoints' => MetricPoint::all(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the metric points.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showMetricPoints()
|
||||
{
|
||||
return View::make('dashboard.metrics.points.index')->with([
|
||||
'pageTitle' => trans('dashboard.metrics.points.title').' - '.trans('dashboard.dashboard'),
|
||||
'metricMetricPoints' => MetricPoint::all(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new metric.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function createMetricAction()
|
||||
{
|
||||
$metricData = Binput::get('metric');
|
||||
$metric = Metric::create($metricData);
|
||||
|
||||
if (! $metric->isValid()) {
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Created Metric',
|
||||
'success' => false,
|
||||
]);
|
||||
|
||||
return Redirect::back()->withInput(Binput::all())
|
||||
->with('title', sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.whoops'),
|
||||
trans('dashboard.metrics.add.failure')
|
||||
))
|
||||
->with('errors', $metric->getErrors());
|
||||
}
|
||||
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Created Metric',
|
||||
'success' => true,
|
||||
]);
|
||||
|
||||
$successMsg = sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.awesome'),
|
||||
trans('dashboard.metrics.add.success')
|
||||
);
|
||||
|
||||
return Redirect::back()->with('success', $successMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the add metric point view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showAddMetricPoint()
|
||||
{
|
||||
return View::make('dashboard.metrics.points.add')->with([
|
||||
'pageTitle' => trans('dashboard.metrics.points.add.title').' - '.trans('dashboard.dashboard'),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new metric point.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function createMetricPointAction()
|
||||
{
|
||||
$_point = Binput::get('point');
|
||||
$point = MetricPoint::create($_point);
|
||||
|
||||
if (! $point->isValid()) {
|
||||
return Redirect::back()->withInput(Binput::all())
|
||||
->with('title', sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.awesome'),
|
||||
trans('dashboard.metrics.points.add.failure')
|
||||
))
|
||||
->with('errors', $point->getErrors());
|
||||
}
|
||||
|
||||
$successMsg = sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.awesome'),
|
||||
trans('dashboard.metrics.points.add.success')
|
||||
);
|
||||
|
||||
return Redirect::back()->with('success', $successMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a given metric.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\Metric $metric
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function deleteMetricAction(Metric $metric)
|
||||
{
|
||||
$metric->delete();
|
||||
|
||||
return Redirect::back();
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the edit metric view.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\Metric $metric
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showEditMetricAction(Metric $metric)
|
||||
{
|
||||
return View::make('dashboard.metrics.edit')->with([
|
||||
'pageTitle' => trans('dashboard.metrics.edit.title').' - '.trans('dashboard.dashboard'),
|
||||
'metric' => $metric,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit an metric.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\Metric $metric
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function editMetricAction(Metric $metric)
|
||||
{
|
||||
$_metric = Binput::get('metric');
|
||||
$metric->update($_metric);
|
||||
|
||||
if (! $metric->isValid()) {
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Edited Metric',
|
||||
'success' => false,
|
||||
]);
|
||||
|
||||
return Redirect::back()->withInput(Binput::all())
|
||||
->with('title', sprintf(
|
||||
'<strong>%s</strong>',
|
||||
trans('dashboard.notifications.awesome')
|
||||
))
|
||||
->with('errors', $metric->getErrors());
|
||||
}
|
||||
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Edited Metric',
|
||||
'success' => true,
|
||||
]);
|
||||
|
||||
$successMsg = sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.awesome'),
|
||||
trans('dashboard.metrics.edit.success')
|
||||
);
|
||||
|
||||
return Redirect::to('dashboard/metrics')->with('success', $successMsg);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,233 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Controllers\Admin;
|
||||
|
||||
use CachetHQ\Cachet\Facades\Setting;
|
||||
use CachetHQ\Cachet\Models\Incident;
|
||||
use CachetHQ\Cachet\Models\IncidentTemplate;
|
||||
use GrahamCampbell\Binput\Facades\Binput;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
use Illuminate\Support\Facades\View;
|
||||
use Illuminate\Support\MessageBag;
|
||||
use Jenssegers\Date\Date;
|
||||
|
||||
class ScheduleController extends Controller
|
||||
{
|
||||
/**
|
||||
* Stores the sub-sidebar tree list.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $subMenu = [];
|
||||
|
||||
/**
|
||||
* Creates a new DashScheduleController instance.
|
||||
*
|
||||
* @return \CachetHQ\Cachet\Http\Controllers\DashScheduleController
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
// TODO: Remove this from DashIncidentController, so it's shared?
|
||||
$this->subMenu = [
|
||||
'incidents' => [
|
||||
'title' => trans('dashboard.incidents.incidents'),
|
||||
'url' => route('dashboard.incidents'),
|
||||
'icon' => 'ion-android-checkmark-circle',
|
||||
'active' => false,
|
||||
],
|
||||
'schedule' => [
|
||||
'title' => trans('dashboard.schedule.schedule'),
|
||||
'url' => route('dashboard.schedule'),
|
||||
'icon' => 'ion-android-calendar',
|
||||
'active' => true,
|
||||
],
|
||||
];
|
||||
|
||||
View::share('subMenu', $this->subMenu);
|
||||
View::share('subTitle', trans('dashboard.incidents.title'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists all scheduled maintenance.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showIndex()
|
||||
{
|
||||
$schedule = Incident::scheduled()->orderBy('created_at')->get();
|
||||
|
||||
return View::make('dashboard.schedule.index')->withSchedule($schedule);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the add schedule maintenance form.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showAddSchedule()
|
||||
{
|
||||
$incidentTemplates = IncidentTemplate::all();
|
||||
|
||||
return View::make('dashboard.schedule.add')->with([
|
||||
'incidentTemplates' => $incidentTemplates,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new scheduled maintenance "incident".
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function addScheduleAction()
|
||||
{
|
||||
$scheduleData = Binput::get('incident');
|
||||
$scheduleData['user_id'] = Auth::user()->id;
|
||||
// Parse the schedule date.
|
||||
$scheduledAt = Date::createFromFormat('d/m/Y H:i', $scheduleData['scheduled_at'], Setting::get('app_timezone'))
|
||||
->setTimezone(Config::get('app.timezone'));
|
||||
|
||||
if ($scheduledAt->isPast()) {
|
||||
$messageBag = new MessageBag();
|
||||
$messageBag->add('scheduled_at', trans('validation.date', [
|
||||
'attribute' => 'scheduled time you supplied',
|
||||
]));
|
||||
|
||||
return Redirect::back()->withErrors($messageBag);
|
||||
}
|
||||
|
||||
$scheduleData['scheduled_at'] = $scheduledAt;
|
||||
// Bypass the incident.status field.
|
||||
$scheduleData['status'] = 0;
|
||||
|
||||
$incident = Incident::create($scheduleData);
|
||||
|
||||
if (! $incident->isValid()) {
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Created Scheduled Maintenance',
|
||||
'success' => false,
|
||||
]);
|
||||
|
||||
return Redirect::back()->withInput(Binput::all())
|
||||
->with('success', sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.whoops'),
|
||||
trans('dashboard.schedule.add.failure')
|
||||
))
|
||||
->with('errors', $incident->getErrors());
|
||||
}
|
||||
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Created Scheduled Maintenance',
|
||||
'success' => true,
|
||||
]);
|
||||
|
||||
$successMsg = sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.awesome'),
|
||||
trans('dashboard.schedule.add.success')
|
||||
);
|
||||
|
||||
return Redirect::back()->with('success', $successMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the edit schedule maintenance form.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\Incident $schedule
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showEditSchedule(Incident $schedule)
|
||||
{
|
||||
$incidentTemplates = IncidentTemplate::all();
|
||||
|
||||
return View::make('dashboard.schedule.edit')->with([
|
||||
'incidentTemplates' => $incidentTemplates,
|
||||
'schedule' => $schedule,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the given incident.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\Incident $schedule
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function editScheduleAction(Incident $schedule)
|
||||
{
|
||||
$scheduleData = Binput::get('incident');
|
||||
$scheduleData['user_id'] = Auth::user()->id;
|
||||
// Parse the schedule date.
|
||||
$scheduledAt = Date::createFromFormat('d/m/Y H:i', $scheduleData['scheduled_at'], Setting::get('app_timezone'))
|
||||
->setTimezone(Config::get('app.timezone'));
|
||||
|
||||
if ($scheduledAt->isPast()) {
|
||||
$messageBag = new MessageBag();
|
||||
$messageBag->add('scheduled_at', trans('validation.date', [
|
||||
'attribute' => 'scheduled time you supplied',
|
||||
]));
|
||||
|
||||
return Redirect::back()->withErrors($messageBag);
|
||||
}
|
||||
|
||||
$scheduleData['scheduled_at'] = $scheduledAt;
|
||||
// Bypass the incident.status field.
|
||||
$scheduleData['status'] = 0;
|
||||
|
||||
$schedule->update($scheduleData);
|
||||
|
||||
if (! $schedule->isValid()) {
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Edited Schedule',
|
||||
'success' => false,
|
||||
]);
|
||||
|
||||
return Redirect::back()->withInput(Binput::all())
|
||||
->with('title', sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.awesome'),
|
||||
trans('dashboard.schedule.edit.failure')
|
||||
))
|
||||
->with('errors', $schedule->getErrors());
|
||||
}
|
||||
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Edited Schedule',
|
||||
'success' => true,
|
||||
]);
|
||||
|
||||
$successMsg = sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.awesome'),
|
||||
trans('dashboard.schedule.edit.success')
|
||||
);
|
||||
|
||||
return Redirect::to('dashboard/schedule')->with('success', $successMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a given schedule.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\Incident $schedule
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function deleteScheduleAction(Incident $schedule)
|
||||
{
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Deleted Schedule',
|
||||
]);
|
||||
|
||||
$schedule->delete();
|
||||
|
||||
return Redirect::back()->with('warning', sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.whoops'),
|
||||
trans('dashboard.schedule.delete.failure')
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,180 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Controllers\Admin;
|
||||
|
||||
use CachetHQ\Cachet\Models\Setting;
|
||||
use CachetHQ\Cachet\Models\User;
|
||||
use Exception;
|
||||
use GrahamCampbell\Binput\Facades\Binput;
|
||||
use CachetHQ\Cachet\Controllers\AbstractController;
|
||||
use Illuminate\Support\Facades\Lang;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
use Illuminate\Support\Facades\View;
|
||||
|
||||
class SettingsController extends AbstractController
|
||||
{
|
||||
protected $subMenu = [];
|
||||
protected $subTitle = 'Settings';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->subMenu = [
|
||||
'setup' => [
|
||||
'title' => trans('dashboard.settings.app-setup.app-setup'),
|
||||
'url' => '/dashboard/settings/setup',
|
||||
'icon' => 'ion-gear-b',
|
||||
'active' => false,
|
||||
],
|
||||
'security' => [
|
||||
'title' => trans('dashboard.settings.security.security'),
|
||||
'url' => '/dashboard/settings/security',
|
||||
'icon' => 'ion-lock-combination',
|
||||
'active' => false,
|
||||
],
|
||||
'theme' => [
|
||||
'title' => trans('dashboard.settings.theme.theme'),
|
||||
'url' => '/dashboard/settings/theme',
|
||||
'icon' => 'ion-paintbrush',
|
||||
'active' => false,
|
||||
],
|
||||
'stylesheet' => [
|
||||
'title' => trans('dashboard.settings.stylesheet.stylesheet'),
|
||||
'url' => '/dashboard/settings/stylesheet',
|
||||
'icon' => 'ion-paintbucket',
|
||||
'active' => false,
|
||||
],
|
||||
];
|
||||
|
||||
View::share('subTitle', $this->subTitle);
|
||||
|
||||
View::share('subMenu', $this->subMenu);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the settings setup view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showSetupView()
|
||||
{
|
||||
$this->subMenu['setup']['active'] = true;
|
||||
|
||||
return View::make('dashboard.settings.app-setup')->with([
|
||||
'pageTitle' => 'Application Setup - Dashboard',
|
||||
'subMenu' => $this->subMenu,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the settings theme view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showThemeView()
|
||||
{
|
||||
$this->subMenu['theme']['active'] = true;
|
||||
|
||||
return View::make('dashboard.settings.theme')->with([
|
||||
'pageTitle' => 'Theme - Dashboard',
|
||||
'subMenu' => $this->subMenu,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the settings security view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showSecurityView()
|
||||
{
|
||||
$this->subMenu['security']['active'] = true;
|
||||
|
||||
$unsecureUsers = User::whereNull('google_2fa_secret')->orWhere('google_2fa_secret', '')->get();
|
||||
|
||||
return View::make('dashboard.settings.security')->with([
|
||||
'pageTitle' => 'Security - Dashboard',
|
||||
'subMenu' => $this->subMenu,
|
||||
'unsecureUsers' => $unsecureUsers,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the settings stylesheet view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showStylesheetView()
|
||||
{
|
||||
$this->subMenu['stylesheet']['active'] = true;
|
||||
|
||||
return View::make('dashboard.settings.stylesheet')->with([
|
||||
'pageTitle' => 'Stylesheet - Dashboard',
|
||||
'subMenu' => $this->subMenu,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the status page settings.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function postSettings()
|
||||
{
|
||||
if (Binput::get('remove_banner') === '1') {
|
||||
$setting = Setting::where('name', 'app_banner');
|
||||
$setting->delete();
|
||||
}
|
||||
|
||||
if (Binput::hasFile('app_banner')) {
|
||||
$file = Binput::file('app_banner');
|
||||
|
||||
// Image Validation.
|
||||
// Image size in bytes.
|
||||
$maxSize = $file->getMaxFilesize();
|
||||
|
||||
if ($file->getSize() > $maxSize) {
|
||||
return Redirect::back()->withErrors(trans('dashboard.settings.app-setup.too-big', [
|
||||
'size' => $maxSize,
|
||||
]));
|
||||
}
|
||||
|
||||
if (!$file->isValid() || $file->getError()) {
|
||||
return Redirect::back()->withErrors($file->getErrorMessage());
|
||||
}
|
||||
|
||||
if (strpos($file->getMimeType(), 'image/') !== 0) {
|
||||
return Redirect::back()->withErrors(trans('dashboard.settings.app-setup.images-only'));
|
||||
}
|
||||
|
||||
// Store the banner.
|
||||
Setting::firstOrCreate([
|
||||
'name' => 'app_banner',
|
||||
])->update([
|
||||
'value' => base64_encode(file_get_contents($file->getRealPath())),
|
||||
]);
|
||||
|
||||
// Store the banner type
|
||||
Setting::firstOrCreate([
|
||||
'name' => 'app_banner_type',
|
||||
])->update([
|
||||
'value' => $file->getMimeType(),
|
||||
]);
|
||||
}
|
||||
|
||||
try {
|
||||
foreach (Binput::except(['app_banner', 'remove_banner']) as $settingName => $settingValue) {
|
||||
Setting::firstOrCreate([
|
||||
'name' => $settingName,
|
||||
])->update([
|
||||
'value' => $settingValue,
|
||||
]);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
return Redirect::back()->with('errors', trans('dashboard.settings.edit.failure'));
|
||||
}
|
||||
|
||||
Lang::setLocale(Binput::get('app_locale'));
|
||||
|
||||
return Redirect::back()->with('success', trans('dashboard.settings.edit.success'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Controllers\Admin;
|
||||
|
||||
use CachetHQ\Cachet\Models\User;
|
||||
use GrahamCampbell\Binput\Facades\Binput;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
use Illuminate\Support\Facades\View;
|
||||
|
||||
class TeamController extends Controller
|
||||
{
|
||||
/**
|
||||
* Shows the team members view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showTeamView()
|
||||
{
|
||||
$team = User::all();
|
||||
|
||||
return View::make('dashboard.team.index')->with([
|
||||
'pageTitle' => trans('dashboard.team.team').' - '.trans('dashboard.dashboard'),
|
||||
'teamMembers' => $team,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the edit team member view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showTeamMemberView(User $user)
|
||||
{
|
||||
return View::make('dashboard.team.edit')->with([
|
||||
'pageTitle' => trans('dashboard.team.edit.title').' - '.trans('dashboard.dashboard'),
|
||||
'user' => $user,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the add team member view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showAddTeamMemberView()
|
||||
{
|
||||
return View::make('dashboard.team.add')->with([
|
||||
'pageTitle' => trans('dashboard.team.add.title').' - '.trans('dashboard.dashboard'),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new team member.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function postAddUser()
|
||||
{
|
||||
$user = User::create(Binput::all());
|
||||
|
||||
if (! $user->isValid()) {
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Added User',
|
||||
'success' => false,
|
||||
]);
|
||||
|
||||
return Redirect::back()->withInput(Binput::except('password'))
|
||||
->with('title', sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.whoops'),
|
||||
trans('dashboard.team.add.failure')
|
||||
))
|
||||
->with('errors', $user->getErrors());
|
||||
}
|
||||
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Added User',
|
||||
'success' => true,
|
||||
]);
|
||||
|
||||
$successMsg = sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.awesome'),
|
||||
trans('dashboard.team.add.success')
|
||||
);
|
||||
|
||||
return Redirect::back()->with('success', $successMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a user.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\User $user
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function postUpdateUser(User $user)
|
||||
{
|
||||
$items = Binput::all();
|
||||
|
||||
$passwordChange = array_get($items, 'password');
|
||||
|
||||
if (trim($passwordChange) === '') {
|
||||
unset($items['password']);
|
||||
}
|
||||
|
||||
$user->update($items);
|
||||
|
||||
if (! $user->isValid()) {
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Updated User',
|
||||
'success' => false,
|
||||
]);
|
||||
|
||||
return Redirect::back()->withInput(Binput::except('password'))
|
||||
->with('title', sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.whoops'),
|
||||
trans('dashboard.team.edit.failure')
|
||||
))
|
||||
->with('errors', $user->getErrors());
|
||||
}
|
||||
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Updated User',
|
||||
'success' => true,
|
||||
]);
|
||||
|
||||
$successMsg = sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.awesome'),
|
||||
trans('dashboard.team.edit.success')
|
||||
);
|
||||
|
||||
return Redirect::back()->with('success', $successMsg);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Controllers\Admin;
|
||||
|
||||
use CachetHQ\Cachet\Models\User;
|
||||
use GrahamCampbell\Binput\Facades\Binput;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
use Illuminate\Support\Facades\View;
|
||||
use PragmaRX\Google2FA\Vendor\Laravel\Facade as Google2FA;
|
||||
|
||||
class UserController extends Controller
|
||||
{
|
||||
/**
|
||||
* Shows the user view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showUser()
|
||||
{
|
||||
return View::make('dashboard.user.index')->with([
|
||||
'pageTitle' => trans('dashboard.team.profile').' - '.trans('dashboard.dashboard'),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the current user.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function postUser()
|
||||
{
|
||||
$items = Binput::all();
|
||||
|
||||
$passwordChange = array_get($items, 'password');
|
||||
$enable2FA = (bool) array_pull($items, 'google2fa');
|
||||
|
||||
// Let's enable/disable auth
|
||||
if ($enable2FA && ! Auth::user()->hasTwoFactor) {
|
||||
$items['google_2fa_secret'] = Google2FA::generateSecretKey();
|
||||
|
||||
segment_track('User Management', [
|
||||
'event' => 'enabled_two_factor',
|
||||
'value' => true,
|
||||
]);
|
||||
} elseif (! $enable2FA) {
|
||||
$items['google_2fa_secret'] = '';
|
||||
|
||||
segment_track('User Management', [
|
||||
'event' => 'enabled_two_factor',
|
||||
'value' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
if (trim($passwordChange) === '') {
|
||||
unset($items['password']);
|
||||
}
|
||||
|
||||
$user = Auth::user();
|
||||
$user->update($items);
|
||||
|
||||
if (! $user->isValid()) {
|
||||
return Redirect::back()->withInput(Binput::except('password'))
|
||||
->with('title', sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.whoops'),
|
||||
trans('dashboard.team.edit.failure')
|
||||
))
|
||||
->with('errors', $user->getErrors());
|
||||
}
|
||||
|
||||
$successMsg = sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.awesome'),
|
||||
trans('dashboard.team.edit.success')
|
||||
);
|
||||
|
||||
return Redirect::back()->with('success', $successMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Regenerates the users API key.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function regenerateApiKey(User $user)
|
||||
{
|
||||
segment_track('User Management', [
|
||||
'event' => 'regenrated_api_token',
|
||||
]);
|
||||
|
||||
$user->api_key = User::generateApiKey();
|
||||
$user->save();
|
||||
|
||||
return Redirect::back();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Controllers\Api;
|
||||
|
||||
use CachetHQ\Cachet\Http\Controllers\AbstractController as BaseController;
|
||||
use Illuminate\Contracts\Pagination\Paginator;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Response;
|
||||
|
||||
abstract class AbstractApiController extends BaseController
|
||||
{
|
||||
/**
|
||||
* The HTTP response headers.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $headers = [];
|
||||
|
||||
/**
|
||||
* The HTTP response meta data.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $meta = [];
|
||||
|
||||
/**
|
||||
* The HTTP response data.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $data = [];
|
||||
|
||||
/**
|
||||
* The HTTP response status code.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $statusCode = 200;
|
||||
|
||||
/**
|
||||
* Set the response headers.
|
||||
*
|
||||
* @param array $headers
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
protected function setHeaders(array $headers)
|
||||
{
|
||||
$this->headers = $headers;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the response meta data.
|
||||
*
|
||||
* @param array $meta
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
protected function setMetaData(array $meta)
|
||||
{
|
||||
$this->meta = $meta;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the response meta data.
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
protected function setData(array $data)
|
||||
{
|
||||
$this->data = $data;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the response status code.
|
||||
*
|
||||
* @param int $statusCode
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
protected function setStatusCode($satusCode)
|
||||
{
|
||||
$this->satusCode = $satusCode;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Respond with a pagination response.
|
||||
*
|
||||
* @param \Illuminate\Pagination\Paginator $paginator
|
||||
* @param \Illuminate\Http\Request $request
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
protected function paginator(Paginator $paginator, Request $request)
|
||||
{
|
||||
foreach ($request->query as $key => $value) {
|
||||
if ($key != 'page') {
|
||||
$paginator->addQuery($key, $value);
|
||||
}
|
||||
}
|
||||
|
||||
$pagination = [
|
||||
'pagination' => [
|
||||
'total' => $paginator->total(),
|
||||
'count' => count($paginator->items()),
|
||||
'per_page' => $paginator->perPage(),
|
||||
'current_page' => $paginator->currentPage(),
|
||||
'total_pages' => $paginator->lastPage(),
|
||||
'links' => [
|
||||
'next_page' => $paginator->nextPageUrl(),
|
||||
'previous_page' => $paginator->previousPageUrl(),
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
return $this->setMetaData($pagination)->setData($paginator->items())->respond();
|
||||
}
|
||||
|
||||
/**
|
||||
* Respond with a no content response.
|
||||
*
|
||||
* @param string $message
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
protected function noContent()
|
||||
{
|
||||
return $this->setStatusCode(204)->respond();
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the response.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
protected function respond()
|
||||
{
|
||||
if (! empty($this->meta)) {
|
||||
$response['meta'] = $this->meta;
|
||||
}
|
||||
|
||||
$response['data'] = $this->data;
|
||||
|
||||
if ($this->data instanceof Arrayable) {
|
||||
$response['data'] = $this->data->toArray();
|
||||
}
|
||||
|
||||
return Response::json($response, $this->statusCode, $this->headers);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Controllers\Api;
|
||||
|
||||
use CachetHQ\Cachet\Models\Tag;
|
||||
use CachetHQ\Cachet\Repositories\Component\ComponentRepository;
|
||||
use GrahamCampbell\Binput\Facades\Binput;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ComponentController extends AbstractApiController
|
||||
{
|
||||
/**
|
||||
* The component repository instance.
|
||||
*
|
||||
* @var \CachetHQ\Cachet\Repositories\Component\ComponentRepository
|
||||
*/
|
||||
protected $component;
|
||||
|
||||
/**
|
||||
* Create a new component controller instance.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Repositories\Component\ComponentRepository $component
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(ComponentRepository $component)
|
||||
{
|
||||
$this->component = $component;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all components.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Collection
|
||||
*/
|
||||
public function getComponents(Request $request)
|
||||
{
|
||||
$components = $this->component->paginate(Binput::get('per_page', 20));
|
||||
|
||||
return $this->paginator($components, $request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a single component.
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return \CachetHQ\Cachet\Models\Component
|
||||
*/
|
||||
public function getComponent($id)
|
||||
{
|
||||
return $this->component->findOrFail($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new component.
|
||||
*
|
||||
* @return \CachetHQ\Cachet\Models\Component
|
||||
*/
|
||||
public function postComponents()
|
||||
{
|
||||
$component = $this->component->create(
|
||||
$this->auth->user()->id,
|
||||
Binput::except('tags')
|
||||
);
|
||||
|
||||
if (Binput::has('tags')) {
|
||||
// The component was added successfully, so now let's deal with the tags.
|
||||
$tags = preg_split('/ ?, ?/', Binput::get('tags'));
|
||||
|
||||
// For every tag, do we need to create it?
|
||||
$componentTags = array_map(function ($taggable) use ($component) {
|
||||
return Tag::firstOrCreate([
|
||||
'name' => $taggable,
|
||||
])->id;
|
||||
}, $tags);
|
||||
|
||||
$component->tags()->sync($componentTags);
|
||||
}
|
||||
|
||||
return $component;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update an existing component.
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return \CachetHQ\Cachet\Models\Component
|
||||
*/
|
||||
public function putComponent($id)
|
||||
{
|
||||
$component = $this->component->update($id, Binput::except('tags'));
|
||||
|
||||
if (Binput::has('tags')) {
|
||||
$tags = preg_split('/ ?, ?/', Binput::get('tags'));
|
||||
|
||||
// For every tag, do we need to create it?
|
||||
$componentTags = array_map(function ($taggable) use ($component) {
|
||||
return Tag::firstOrCreate([
|
||||
'name' => $taggable,
|
||||
])->id;
|
||||
}, $tags);
|
||||
|
||||
$component->tags()->sync($componentTags);
|
||||
}
|
||||
|
||||
return $component;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an existing component.
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function deleteComponent($id)
|
||||
{
|
||||
$this->component->destroy($id);
|
||||
|
||||
return $this->noContent();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Controllers\Api;
|
||||
|
||||
use CachetHQ\Cachet\Repositories\Incident\IncidentRepository;
|
||||
use GrahamCampbell\Binput\Facades\Binput;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class IncidentController extends AbstractApiController
|
||||
{
|
||||
/**
|
||||
* The incident repository instance.
|
||||
*
|
||||
* @var \CachetHQ\Cachet\Repositories\Incident\IncidentRepository
|
||||
*/
|
||||
protected $incident;
|
||||
|
||||
/**
|
||||
* Create a new incident controller instance.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Repositories\Incident\IncidentRepository $incident
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(IncidentRepository $incident)
|
||||
{
|
||||
$this->incident = $incident;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all incidents.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Collection
|
||||
*/
|
||||
public function getIncidents(Request $request)
|
||||
{
|
||||
$incidents = $this->incident->paginate(Binput::get('per_page', 20));
|
||||
|
||||
return $this->paginator($incidents, $request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a single incident.
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return \CachetHQ\Cachet\Models\Incident
|
||||
*/
|
||||
public function getIncident($id)
|
||||
{
|
||||
return $this->incident->findOrFail($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new incident.
|
||||
*
|
||||
* @return \CachetHQ\Cachet\Models\Incident
|
||||
*/
|
||||
public function postIncidents()
|
||||
{
|
||||
return $this->incident->create($this->auth->user()->id, Binput::all());
|
||||
}
|
||||
|
||||
/**
|
||||
* Update an existing incident.
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return \CachetHQ\Cachet\Models\Incident
|
||||
*/
|
||||
public function putIncident($id)
|
||||
{
|
||||
return $this->incident->update($id, Binput::all());
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an existing incident.
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function deleteIncident($id)
|
||||
{
|
||||
$this->incident->destroy($id);
|
||||
|
||||
return $this->noContent();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Controllers\Api;
|
||||
|
||||
use CachetHQ\Cachet\Repositories\Metric\MetricRepository;
|
||||
use GrahamCampbell\Binput\Facades\Binput;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class MetricController extends AbstractApiController
|
||||
{
|
||||
/**
|
||||
* The metric repository instance.
|
||||
*
|
||||
* @var \CachetHQ\Cachet\Repositories\Metric\MetricRepository
|
||||
*/
|
||||
protected $metric;
|
||||
|
||||
/**
|
||||
* Create a new metric controller instance.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Repositories\Metric\MetricRepository $metric
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(MetricRepository $metric)
|
||||
{
|
||||
$this->metric = $metric;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all metrics.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Collection
|
||||
*/
|
||||
public function getMetrics(Request $request)
|
||||
{
|
||||
$metrics = $this->metric->paginate(Binput::get('per_page', 20));
|
||||
|
||||
return $this->paginator($metrics, $request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a single metric.
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return \CachetHQ\Cachet\Models\Metric
|
||||
*/
|
||||
public function getMetric($id)
|
||||
{
|
||||
return $this->metric->findOrFail($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all metric points.
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Collection
|
||||
*/
|
||||
public function getMetricPoints($id)
|
||||
{
|
||||
return $this->metric->points($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new metric.
|
||||
*
|
||||
* @return \CachetHQ\Cachet\Models\Metric
|
||||
*/
|
||||
public function postMetrics()
|
||||
{
|
||||
return $this->metric->create(Binput::all());
|
||||
}
|
||||
|
||||
/**
|
||||
* Update an existing metric.
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return \CachetHQ\Cachet\Models\Metric
|
||||
*/
|
||||
public function putMetric($id)
|
||||
{
|
||||
return $this->metric->update($id, Binput::all());
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an existing metric.
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function deleteMetric($id)
|
||||
{
|
||||
$this->metric->destroy($id);
|
||||
|
||||
return $this->noContent();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Controllers\Api;
|
||||
|
||||
use CachetHQ\Cachet\Repositories\MetricPoint\MetricPointRepository;
|
||||
use GrahamCampbell\Binput\Facades\Binput;
|
||||
|
||||
class MetricPointController extends AbstractApiController
|
||||
{
|
||||
/**
|
||||
* The metric point repository instance.
|
||||
*
|
||||
* @var \CachetHQ\Cachet\Repositories\MetricPoint\MetricPointRepository
|
||||
*/
|
||||
protected $metricPoint;
|
||||
|
||||
/**
|
||||
* Create a new metric point controller instance.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Repositories\MetricPoint\MetricPointRepository $metricPoint
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(MetricPointRepository $metricPoint)
|
||||
{
|
||||
$this->metricPoint = $metricPoint;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a single metric point.
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return \CachetHQ\Cachet\Models\MetricPoint
|
||||
*/
|
||||
public function getMetricPoints($id)
|
||||
{
|
||||
return $this->metricPoint->findOrFail($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new metric point.
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return \CachetHQ\Cachet\Models\MetricPoint
|
||||
*/
|
||||
public function postMetricPoints($id)
|
||||
{
|
||||
return $this->metricPoint->create($id, Binput::all());
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a metric point.
|
||||
*
|
||||
* @param int $metricId
|
||||
* @param int $pointId
|
||||
*
|
||||
* @return \CachetHQ\Cachet\Models\MetricPoint
|
||||
*/
|
||||
public function putMetricPoint($metricId, $pointId)
|
||||
{
|
||||
$metricPoint = $this->metricPoint->findOrFail($pointId);
|
||||
$metricPoint->update(Binput::all());
|
||||
|
||||
return $metricPoint;
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroys a metric point.
|
||||
*
|
||||
* @param int $metricId
|
||||
* @param int $pointId
|
||||
*
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function deleteMetricPoint($metricId, $pointId)
|
||||
{
|
||||
$this->metricPoint->destroy($pointId);
|
||||
|
||||
return $this->noContent();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Controllers;
|
||||
|
||||
use CachetHQ\Cachet\Facades\Setting;
|
||||
use CachetHQ\Cachet\Models\Incident;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Facades\Response;
|
||||
use Roumen\Feed\Facades\Feed;
|
||||
|
||||
class AtomController extends Controller
|
||||
{
|
||||
/**
|
||||
* Generates an Atom feed of all incidents.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function feedAction()
|
||||
{
|
||||
$feed = Feed::make();
|
||||
$feed->title = Setting::get('app_name');
|
||||
$feed->description = trans('cachet.feed');
|
||||
$feed->link = Setting::get('app_domain');
|
||||
|
||||
$feed->setDateFormat('datetime');
|
||||
|
||||
Incident::all()->map(function ($incident) use ($feed) {
|
||||
if ($incident->component) {
|
||||
$componentName = $incident->component->name;
|
||||
} else {
|
||||
$componentName = null;
|
||||
}
|
||||
|
||||
$feed->add(
|
||||
$incident->name,
|
||||
Setting::get('app_name'),
|
||||
Setting::get('app_domain'),
|
||||
$incident->created_at,
|
||||
($componentName === null ? $incident->humanStatus : $componentName.' '.$incident->humanStatus),
|
||||
$incident->message
|
||||
);
|
||||
});
|
||||
|
||||
return $feed->render('atom');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php namespace CachetHQ\Cachet\Http\Controllers\Auth;
|
||||
|
||||
use CachetHQ\Cachet\Http\Controllers\Controller;
|
||||
use Illuminate\Contracts\Auth\Guard;
|
||||
use Illuminate\Contracts\Auth\Registrar;
|
||||
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
|
||||
|
||||
class AuthController extends Controller
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Registration & Login Controller
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This controller handles the registration of new users, as well as the
|
||||
| authentication of existing users. By default, this controller uses
|
||||
| a simple trait to add these behaviors. Why don't you explore it?
|
||||
|
|
||||
*/
|
||||
|
||||
use AuthenticatesAndRegistersUsers;
|
||||
|
||||
/**
|
||||
* Create a new authentication controller instance.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Auth\Guard $auth
|
||||
* @param \Illuminate\Contracts\Auth\Registrar $registrar
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Guard $auth, Registrar $registrar)
|
||||
{
|
||||
$this->auth = $auth;
|
||||
$this->registrar = $registrar;
|
||||
|
||||
$this->middleware('guest', ['except' => 'getLogout']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php namespace CachetHQ\Cachet\Http\Controllers\Auth;
|
||||
|
||||
use CachetHQ\Cachet\Http\Controllers\Controller;
|
||||
use Illuminate\Contracts\Auth\Guard;
|
||||
use Illuminate\Contracts\Auth\PasswordBroker;
|
||||
use Illuminate\Foundation\Auth\ResetsPasswords;
|
||||
|
||||
class PasswordController extends Controller
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Password Reset Controller
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This controller is responsible for handling password reset requests
|
||||
| and uses a simple trait to include this behavior. You're free to
|
||||
| explore this trait and override any methods you wish to tweak.
|
||||
|
|
||||
*/
|
||||
|
||||
use ResetsPasswords;
|
||||
|
||||
/**
|
||||
* Create a new password controller instance.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Auth\Guard $auth
|
||||
* @param \Illuminate\Contracts\Auth\PasswordBroker $passwords
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Guard $auth, PasswordBroker $passwords)
|
||||
{
|
||||
$this->auth = $auth;
|
||||
$this->passwords = $passwords;
|
||||
|
||||
$this->middleware('guest');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Controllers;
|
||||
|
||||
use GrahamCampbell\Binput\Facades\Binput;
|
||||
use GrahamCampbell\Throttle\Facades\Throttle;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
use Illuminate\Support\Facades\Request;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
use Illuminate\Support\Facades\View;
|
||||
use PragmaRX\Google2FA\Vendor\Laravel\Facade as Google2FA;
|
||||
|
||||
/**
|
||||
* Logs users into their account.
|
||||
*/
|
||||
class AuthController extends Controller
|
||||
{
|
||||
/**
|
||||
* Shows the login view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showLogin()
|
||||
{
|
||||
return View::make('auth.login');
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs the user in.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function postLogin()
|
||||
{
|
||||
$loginData = Binput::only(['email', 'password']);
|
||||
// Validate login credentials.
|
||||
if (Auth::validate($loginData)) {
|
||||
// Log the user in for one request.
|
||||
Auth::once($loginData);
|
||||
// Do we have Two Factor Auth enabled?
|
||||
if (Auth::user()->hasTwoFactor) {
|
||||
// Temporarily store the user.
|
||||
Session::put('2fa_id', Auth::user()->id);
|
||||
|
||||
return Redirect::route('two-factor');
|
||||
}
|
||||
|
||||
// We probably wan't to add support for "Remember me" here.
|
||||
Auth::attempt(Binput::only(['email', 'password']));
|
||||
|
||||
return Redirect::intended('dashboard');
|
||||
}
|
||||
|
||||
Throttle::hit(Request::instance(), 10, 10);
|
||||
|
||||
return Redirect::back()
|
||||
->withInput(Binput::except('password'))
|
||||
->with('error', trans('forms.login.invalid'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the two-factor-auth view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showTwoFactorAuth()
|
||||
{
|
||||
return View::make('auth.two-factor-auth');
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the Two Factor token.
|
||||
*
|
||||
* This feels very hacky, but we have to juggle authentication and codes.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function postTwoFactor()
|
||||
{
|
||||
// Check that we have a session.
|
||||
if ($userId = Session::pull('2fa_id')) {
|
||||
$code = Binput::get('code');
|
||||
|
||||
// Maybe a temp login here.
|
||||
Auth::loginUsingId($userId);
|
||||
|
||||
$valid = Google2FA::verifyKey(Auth::user()->google_2fa_secret, $code);
|
||||
|
||||
if ($valid) {
|
||||
return Redirect::intended('dashboard');
|
||||
} else {
|
||||
// Failed login, log back out.
|
||||
Auth::logout();
|
||||
|
||||
return Redirect::route('login')->with('error', trans('forms.login.invalid-token'));
|
||||
}
|
||||
}
|
||||
|
||||
return Redirect::route('login')->with('error', trans('forms.login.invalid-token'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs the user out, deleting their session etc.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function logoutAction()
|
||||
{
|
||||
Auth::logout();
|
||||
|
||||
return Redirect::to('/');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Controllers;
|
||||
|
||||
use CachetHQ\Cachet\Facades\Setting;
|
||||
use CachetHQ\Cachet\Models\Component;
|
||||
use CachetHQ\Cachet\Models\ComponentGroup;
|
||||
use CachetHQ\Cachet\Models\Incident;
|
||||
use CachetHQ\Cachet\Models\Metric;
|
||||
use Carbon\Carbon;
|
||||
use Exception;
|
||||
use GrahamCampbell\Binput\Facades\Binput;
|
||||
use GrahamCampbell\Markdown\Facades\Markdown;
|
||||
use Illuminate\Support\Facades\View;
|
||||
use Jenssegers\Date\Date;
|
||||
|
||||
class HomeController extends AbstractController
|
||||
{
|
||||
/**
|
||||
* Returns the rendered Blade templates.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showIndex()
|
||||
{
|
||||
$today = Carbon::now();
|
||||
$startDate = Carbon::now();
|
||||
|
||||
segment_track('Status Page', [
|
||||
'event' => 'Landed',
|
||||
]);
|
||||
|
||||
// Check if we have another starting date
|
||||
if (Binput::has('start_date')) {
|
||||
try {
|
||||
// If date provided is valid
|
||||
$oldDate = Date::createFromFormat('Y-m-d', Binput::get('start_date'));
|
||||
|
||||
segment_track('Status Page', [
|
||||
'start_date' => $oldDate->format('Y-m-d'),
|
||||
]);
|
||||
|
||||
if (Setting::get('app_tracking')) {
|
||||
Segment::track([
|
||||
'userId' => Config::get('app.key'),
|
||||
'event' => 'Home Page',
|
||||
'properties' => [
|
||||
'start_date' => $oldDate,
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
// If trying to get a future date fallback to today
|
||||
if ($today->gt($oldDate)) {
|
||||
$startDate = $oldDate;
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
// Fallback to today
|
||||
}
|
||||
}
|
||||
|
||||
$metrics = null;
|
||||
|
||||
if ($displayMetrics = Setting::get('display_graphs')) {
|
||||
$metrics = Metric::where('display_chart', 1)->get();
|
||||
}
|
||||
|
||||
$allIncidents = [];
|
||||
$daysToShow = Setting::get('app_incident_days') ?: 7;
|
||||
$incidentDays = range(0, $daysToShow);
|
||||
$dateFormat = Setting::get('date_format') ?: 'jS F Y';
|
||||
|
||||
foreach ($incidentDays as $i) {
|
||||
$date = $startDate->copy()->subDays($i);
|
||||
|
||||
$incidents = Incident::notScheduled()->whereBetween('created_at', [
|
||||
$date->format('Y-m-d').' 00:00:00',
|
||||
$date->format('Y-m-d').' 23:59:59',
|
||||
])->orderBy('created_at', 'desc')->get();
|
||||
|
||||
$allIncidents[] = [
|
||||
'date' => (new Date($date->toDateString()))->format($dateFormat),
|
||||
'incidents' => $incidents,
|
||||
];
|
||||
}
|
||||
|
||||
// Scheduled maintenance code.
|
||||
$scheduledMaintenance = Incident::scheduled()->orderBy('scheduled_at')->get();
|
||||
|
||||
// Component & Component Group lists.
|
||||
$usedComponentGroups = Component::where('group_id', '>', 0)->groupBy('group_id')->lists('group_id');
|
||||
$componentGroups = ComponentGroup::whereIn('id', $usedComponentGroups)->get();
|
||||
$ungroupedComponents = Component::where('group_id', 0)->orderBy('order')->orderBy('created_at')->get();
|
||||
|
||||
return View::make('index', [
|
||||
'componentGroups' => $componentGroups,
|
||||
'ungroupedComponents' => $ungroupedComponents,
|
||||
'displayMetrics' => $displayMetrics,
|
||||
'metrics' => $metrics,
|
||||
'allIncidents' => $allIncidents,
|
||||
'scheduledMaintenance' => $scheduledMaintenance,
|
||||
'pageTitle' => Setting::get('app_name'),
|
||||
'aboutApp' => Markdown::convertToHtml(Setting::get('app_about')),
|
||||
'canPageForward' => (bool) $today->gt($startDate),
|
||||
'previousDate' => $startDate->copy()->subWeek()->subDay()->toDateString(),
|
||||
'nextDate' => $startDate->copy()->addWeek()->addDay()->toDateString(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Controllers;
|
||||
|
||||
use CachetHQ\Cachet\Facades\Setting;
|
||||
use CachetHQ\Cachet\Models\Incident;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Facades\Response;
|
||||
use Roumen\Feed\Facades\Feed;
|
||||
|
||||
class RssController extends Controller
|
||||
{
|
||||
/**
|
||||
* Generates an RSS feed of all incidents.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function feedAction()
|
||||
{
|
||||
$feed = Feed::make();
|
||||
$feed->title = Setting::get('app_name');
|
||||
$feed->description = trans('cachet.feed');
|
||||
$feed->link = Setting::get('app_domain');
|
||||
|
||||
$feed->setDateFormat('datetime');
|
||||
|
||||
Incident::all()->map(function ($incident) use ($feed) {
|
||||
if ($incident->component) {
|
||||
$componentName = $incident->component->name;
|
||||
} else {
|
||||
$componentName = null;
|
||||
}
|
||||
|
||||
$feed->add(
|
||||
$incident->name,
|
||||
Setting::get('app_name'),
|
||||
Setting::get('app_domain'),
|
||||
$incident->created_at,
|
||||
($componentName === null ? $incident->humanStatus : $componentName.' '.$incident->humanStatus),
|
||||
$incident->message
|
||||
);
|
||||
});
|
||||
|
||||
return $feed->render('rss');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Controllers;
|
||||
|
||||
use CachetHQ\Cachet\Models\Setting;
|
||||
use CachetHQ\Cachet\Models\User;
|
||||
use GrahamCampbell\Binput\Facades\Binput;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
use Illuminate\Support\Facades\Request;
|
||||
use Illuminate\Support\Facades\Response;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\Facades\View;
|
||||
|
||||
class SetupController extends AbstractController
|
||||
{
|
||||
/**
|
||||
* Create a new setup controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->beforeFilter('csrf', ['only' => ['postCachet']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the setup page.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function getIndex()
|
||||
{
|
||||
return View::make('setup')->with([
|
||||
'pageTitle' => trans('setup.setup'),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles validation on step one of setup form.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function postStep1()
|
||||
{
|
||||
$postData = Binput::all();
|
||||
|
||||
segment_track('Setup', [
|
||||
'step' => '1',
|
||||
]);
|
||||
|
||||
$v = Validator::make($postData, [
|
||||
'settings.app_name' => 'required',
|
||||
'settings.app_domain' => 'required',
|
||||
'settings.app_timezone' => 'required',
|
||||
'settings.app_locale' => 'required',
|
||||
'settings.show_support' => 'boolean',
|
||||
]);
|
||||
|
||||
if ($v->passes()) {
|
||||
segment_track('Setup', [
|
||||
'event' => 'Step 1',
|
||||
'success' => true,
|
||||
]);
|
||||
|
||||
return Response::json(['status' => 1]);
|
||||
} else {
|
||||
// No good, let's try that again.
|
||||
|
||||
segment_track('Setup', [
|
||||
'event' => 'Step 1',
|
||||
'success' => false,
|
||||
]);
|
||||
|
||||
return Response::json(['errors' => $v->messages()], 400);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the actual app setup.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\Response
|
||||
*/
|
||||
public function postStep2()
|
||||
{
|
||||
$postData = Binput::all();
|
||||
|
||||
segment_track('Setup', [
|
||||
'step' => '2',
|
||||
]);
|
||||
|
||||
$v = Validator::make($postData, [
|
||||
'settings.app_name' => 'required',
|
||||
'settings.app_domain' => 'required',
|
||||
'settings.app_timezone' => 'required',
|
||||
'settings.app_locale' => 'required',
|
||||
'settings.show_support' => 'boolean',
|
||||
'user.username' => 'alpha_num|required',
|
||||
'user.email' => 'email|required',
|
||||
'user.password' => 'required',
|
||||
]);
|
||||
|
||||
if ($v->passes()) {
|
||||
// Pull the user details out.
|
||||
$userDetails = array_pull($postData, 'user');
|
||||
|
||||
$user = User::create([
|
||||
'username' => $userDetails['username'],
|
||||
'email' => $userDetails['email'],
|
||||
'password' => $userDetails['password'],
|
||||
'level' => 1,
|
||||
]);
|
||||
|
||||
Auth::login($user);
|
||||
|
||||
$settings = array_get($postData, 'settings');
|
||||
|
||||
foreach ($settings as $settingName => $settingValue) {
|
||||
Setting::create([
|
||||
'name' => $settingName,
|
||||
'value' => $settingValue,
|
||||
]);
|
||||
}
|
||||
|
||||
Session::flash('setup.done', true);
|
||||
|
||||
segment_track('Setup', [
|
||||
'event' => 'Step 2',
|
||||
'success' => true,
|
||||
]);
|
||||
|
||||
if (Request::ajax()) {
|
||||
return Response::json(['status' => 1]);
|
||||
}
|
||||
|
||||
return Redirect::to('dashboard');
|
||||
} else {
|
||||
segment_track('Setup', [
|
||||
'event' => 'Step 2',
|
||||
'success' => false,
|
||||
]);
|
||||
|
||||
// No good, let's try that again.
|
||||
if (Request::ajax()) {
|
||||
return Response::json(['errors' => $v->messages()], 400);
|
||||
}
|
||||
|
||||
return Redirect::back()->withInput()->with('errors', $v->messages());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http;
|
||||
|
||||
use Illuminate\Foundation\Http\Kernel as HttpKernel;
|
||||
|
||||
class Kernel extends HttpKernel
|
||||
{
|
||||
/**
|
||||
* The application's global HTTP middleware stack.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $middleware = [
|
||||
'Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode',
|
||||
'Illuminate\Cookie\Middleware\EncryptCookies',
|
||||
'Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse',
|
||||
'Illuminate\Session\Middleware\StartSession',
|
||||
'Illuminate\View\Middleware\ShareErrorsFromSession',
|
||||
];
|
||||
|
||||
/**
|
||||
* The application's route middleware.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $routeMiddleware = [
|
||||
'auth' => 'CachetHQ\Cachet\Http\Middleware\Authenticate',
|
||||
'auth.api' => 'CachetHQ\Cachet\Http\Middleware\ApiAuthenticate',
|
||||
'auth.basic' => 'Illuminate\Auth\Middleware\AuthenticateWithBasicAuth',
|
||||
'guest' => 'CachetHQ\Cachet\Http\Middleware\RedirectIfAuthenticated',
|
||||
'csrf' => 'CachetHQ\Cachet\Http\Middleware\VerifyCsrfToken',
|
||||
'admin' => 'CachetHQ\Cachet\Http\Middleware\Admin',
|
||||
'login.throttling' => 'CachetHQ\Cachet\Http\Middleware\LoginThrottling',
|
||||
'app.isSetup' => 'CachetHQ\Cachet\Http\Middleware\AppIsSetup',
|
||||
'app.hasSetting' => 'CachetHQ\Cachet\Http\Middleware\HasSetting',
|
||||
'allowedDomains' => 'CachetHQ\Cachet\Http\Middleware\AllowedDomains',
|
||||
'cors' => 'CachetHQ\Cachet\Http\Middleware\Cors',
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Contracts\Auth\Guard;
|
||||
use Illuminate\Support\Facades\Response;
|
||||
|
||||
class Admin
|
||||
{
|
||||
/**
|
||||
* The Guard implementation.
|
||||
*
|
||||
* @var Guard
|
||||
*/
|
||||
protected $auth;
|
||||
|
||||
/**
|
||||
* Create a new filter instance.
|
||||
*
|
||||
* @param Guard $auth
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Guard $auth)
|
||||
{
|
||||
$this->auth = $auth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the cors middleware.
|
||||
*
|
||||
* We're verifying that the current user is logged in to Cachet and is an admin level.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
if (!$this->auth->check() || ($this->auth->check() && !$this->auth->user()->isAdmin)) {
|
||||
return Response::view('errors.401', [
|
||||
'pageTitle' => trans('errors.unauthorized.title'),
|
||||
], 401);
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Middleware;
|
||||
|
||||
use CachetHQ\Cachet\Facades\Setting;
|
||||
use Closure;
|
||||
|
||||
class AllowedDomains
|
||||
{
|
||||
/**
|
||||
* Run the allowed domains middleware.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
$response = $next($request);
|
||||
|
||||
// Always allow our own domain.
|
||||
$ourDomain = Setting::get('app_domain');
|
||||
$response->headers->set('Access-Control-Allow-Origin', $ourDomain);
|
||||
|
||||
// Should we allow anyone else?
|
||||
if ($allowedDomains = Setting::get('allowed_domains')) {
|
||||
$domains = explode(',', $allowedDomains);
|
||||
foreach ($domains as $domain) {
|
||||
$response->headers->set('Access-Control-Allow-Origin', $domain);
|
||||
}
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Middleware;
|
||||
|
||||
use CachetHQ\Cachet\Models\User;
|
||||
use Closure;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
|
||||
class ApiAuthenticate
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
if ($apiToken = $request->header('X-Cachet-Token')) {
|
||||
try {
|
||||
User::findByApiToken($apiToken);
|
||||
} catch (ModelNotFoundException $e) {
|
||||
return response()->json([
|
||||
'message' => 'The API token you provided was not correct.',
|
||||
'status_code' => 401,
|
||||
], 401);
|
||||
}
|
||||
} else {
|
||||
return response()->json([
|
||||
'message' => 'You are not authorized to view this content.',
|
||||
'status_code' => 401,
|
||||
], 401);
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Middleware;
|
||||
|
||||
use CachetHQ\Cachet\Models\Setting;
|
||||
use Closure;
|
||||
use Exception;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
|
||||
class AppIsSetup
|
||||
{
|
||||
/**
|
||||
* Run the is setup filter.
|
||||
*
|
||||
* We're verifying that Cachet is correctly setup. If it is, they we're
|
||||
* sending the user to the dashboard so they can use Cachet.
|
||||
*
|
||||
* @param \Illuminate\Routing\Route $route
|
||||
* @param \Closure $next
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
try {
|
||||
$setting = Setting::where('name', 'app_name')->first();
|
||||
if ($setting && $setting->value) {
|
||||
return Redirect::route('dashboard');
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Contracts\Auth\Guard;
|
||||
|
||||
class Authenticate
|
||||
{
|
||||
/**
|
||||
* The Guard implementation.
|
||||
*
|
||||
* @var Guard
|
||||
*/
|
||||
protected $auth;
|
||||
|
||||
/**
|
||||
* Create a new filter instance.
|
||||
*
|
||||
* @param Guard $auth
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Guard $auth)
|
||||
{
|
||||
$this->auth = $auth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
if ($this->auth->guest()) {
|
||||
if ($request->ajax()) {
|
||||
return response('Unauthorized.', 401);
|
||||
} else {
|
||||
return redirect()->guest('auth/login');
|
||||
}
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
|
||||
class Cors
|
||||
{
|
||||
/**
|
||||
* Run the cors middleware.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
$response = $next($request);
|
||||
|
||||
$response->headers->set('Access-Control-Allow-Origin', '*');
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Middleware;
|
||||
|
||||
use CachetHQ\Cachet\Models\Setting;
|
||||
use Closure;
|
||||
use Exception;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
|
||||
class HasSetting
|
||||
{
|
||||
/**
|
||||
* Run the has setting middleware.
|
||||
*
|
||||
* We're verifying that the given setting exists in our database. If it
|
||||
* doesn't, then we're sending the user to the setup page so that they can
|
||||
* complete the installation of Cachet on their server.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
$settingName = $this->getSettingName($request);
|
||||
|
||||
try {
|
||||
$setting = Setting::where('name', $settingName)->first();
|
||||
if (!$setting || !$setting->value) {
|
||||
return Redirect::to('setup');
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
return Redirect::to('setup');
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the setting from the request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function getSettingName($request)
|
||||
{
|
||||
$actions = $request->route()->getAction();
|
||||
|
||||
return $actions['setting'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use GrahamCampbell\Throttle\Facades\Throttle;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
|
||||
class LoginThrottling
|
||||
{
|
||||
/**
|
||||
* Run the login throttling middleware.
|
||||
*
|
||||
* We're verifying that the user is not attempting to brute force Cachet's
|
||||
* login system. If the user has reached the rate limit, then we're sending
|
||||
* them away, otherwise, we do nothing, and allow them to continue.
|
||||
*
|
||||
* Note that this filter is not responsible for incrementing the hit count.
|
||||
* Another part of Cachet will increment the hit count for the given route
|
||||
* only if validation passes, and the user did not successfully login.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
if (!Throttle::check($request, 10, 10)) {
|
||||
return Redirect::back()->with('error', 'You have made too many login requests.');
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Contracts\Auth\Guard;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
|
||||
class RedirectIfAuthenticated
|
||||
{
|
||||
/**
|
||||
* The Guard implementation.
|
||||
*
|
||||
* @var Guard
|
||||
*/
|
||||
protected $auth;
|
||||
|
||||
/**
|
||||
* Create a new filter instance.
|
||||
*
|
||||
* @param Guard $auth
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Guard $auth)
|
||||
{
|
||||
$this->auth = $auth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
if ($this->auth->check()) {
|
||||
return new RedirectResponse(url('/home'));
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as BaseVerifier;
|
||||
|
||||
class VerifyCsrfToken extends BaseVerifier
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
return parent::handle($request, $next);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php namespace CachetHQ\Cachet\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
abstract class Request extends FormRequest
|
||||
{
|
||||
//
|
||||
}
|
||||
@@ -0,0 +1,200 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Routes;
|
||||
|
||||
use Illuminate\Contracts\Routing\Registrar;
|
||||
|
||||
class AdminRoutes
|
||||
{
|
||||
/**
|
||||
* Define the dashboard routes.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Routing\Registrar $router
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function map(Registrar $router)
|
||||
{
|
||||
$router->group([
|
||||
'middleware' => 'auth',
|
||||
'prefix' => 'dashboard',
|
||||
'namespace' => 'Admin',
|
||||
], function ($router) {
|
||||
// Dashboard
|
||||
$router->get('/', [
|
||||
'as' => 'dashboard',
|
||||
'uses' => 'DashboardController@showDashboard',
|
||||
]);
|
||||
|
||||
// Components
|
||||
$router->group(['prefix' => 'components'], function ($router) {
|
||||
$router->get('/', [
|
||||
'as' => 'dashboard.components',
|
||||
'uses' => 'ComponentController@showComponents',
|
||||
]);
|
||||
$router->get('add', [
|
||||
'as' => 'dashboard.components.add',
|
||||
'uses' => 'ComponentController@showAddComponent',
|
||||
]);
|
||||
$router->post('add', 'ComponentController@createComponentAction');
|
||||
$router->get('groups', [
|
||||
'as' => 'dashboard.components.groups',
|
||||
'uses' => 'ComponentController@showComponentGroups',
|
||||
]);
|
||||
$router->get('groups/add', [
|
||||
'as' => 'dashboard.components.groups.add',
|
||||
'uses' => 'ComponentController@showAddComponentGroup',
|
||||
]);
|
||||
$router->get('groups/edit/{component_group}', [
|
||||
'as' => 'dashboard.components.groups.edit',
|
||||
'uses' => 'ComponentController@showEditComponentGroup',
|
||||
]);
|
||||
$router->post('groups/edit/{component_group}', 'ComponentController@updateComponentGroupAction');
|
||||
|
||||
$router->delete('groups/{component_group}/delete', 'ComponentController@deleteComponentGroupAction');
|
||||
$router->post('groups/add', 'ComponentController@postAddComponentGroup');
|
||||
$router->delete('{component}/delete', 'ComponentController@deleteComponentAction');
|
||||
$router->get('{component}/edit', 'ComponentController@showEditComponent');
|
||||
$router->post('{component}/edit', 'ComponentController@updateComponentAction');
|
||||
});
|
||||
|
||||
// Incidents
|
||||
$router->group(['prefix' => 'incidents'], function ($router) {
|
||||
$router->get('/', [
|
||||
'as' => 'dashboard.incidents',
|
||||
'uses' => 'IncidentController@showIncidents',
|
||||
]);
|
||||
$router->get('add', [
|
||||
'as' => 'dashboard.incidents.add',
|
||||
'uses' => 'IncidentController@showAddIncident',
|
||||
]);
|
||||
$router->post('add', 'IncidentController@createIncidentAction');
|
||||
$router->delete('{incident}/delete', 'IncidentController@deleteIncidentAction');
|
||||
$router->get('{incident}/edit', 'IncidentController@showEditIncidentAction');
|
||||
$router->post('{incident}/edit', 'IncidentController@editIncidentAction');
|
||||
});
|
||||
|
||||
// Scheduled Maintenance
|
||||
$router->group(['prefix' => 'schedule'], function ($router) {
|
||||
$router->get('/', ['as' => 'dashboard.schedule', 'uses' => 'ScheduleController@showIndex']);
|
||||
|
||||
$router->get('add', [
|
||||
'as' => 'dashboard.schedule.add',
|
||||
'uses' => 'ScheduleController@showAddSchedule',
|
||||
]);
|
||||
$router->post('add', 'ScheduleController@addScheduleAction');
|
||||
|
||||
$router->get('{incident}/edit', [
|
||||
'as' => 'dashboard.schedule.edit',
|
||||
'uses' => 'ScheduleController@showEditSchedule',
|
||||
]);
|
||||
$router->post('{incident}/edit', 'ScheduleController@editScheduleAction');
|
||||
|
||||
$router->delete('{incident}/delete', [
|
||||
'as' => 'dashboard.schedule.delete',
|
||||
'uses' => 'ScheduleController@deleteScheduleAction',
|
||||
]);
|
||||
});
|
||||
|
||||
// Incident Templates
|
||||
$router->group(['prefix' => 'templates'], function ($router) {
|
||||
$router->get('/', [
|
||||
'as' => 'dashboard.templates',
|
||||
'uses' => 'IncidentController@showTemplates',
|
||||
]);
|
||||
|
||||
$router->get('add', [
|
||||
'as' => 'dashboard.templates.add',
|
||||
'uses' => 'IncidentController@showAddIncidentTemplate',
|
||||
]);
|
||||
$router->post('add', 'IncidentController@createIncidentTemplateAction');
|
||||
|
||||
$router->get('{incident_template}/edit', 'IncidentController@showEditTemplateAction');
|
||||
$router->post('{incident_template}/edit', 'IncidentController@editTemplateAction');
|
||||
$router->delete('{incident_template}/delete', 'IncidentController@deleteTemplateAction');
|
||||
});
|
||||
|
||||
// Metrics
|
||||
$router->group(['prefix' => 'metrics'], function ($router) {
|
||||
$router->get('/', [
|
||||
'as' => 'dashboard.metrics',
|
||||
'uses' => 'MetricController@showMetrics',
|
||||
]);
|
||||
|
||||
$router->get('add', [
|
||||
'as' => 'dashboard.metrics.add',
|
||||
'uses' => 'MetricController@showAddMetric',
|
||||
]);
|
||||
$router->post('add', 'MetricController@createMetricAction');
|
||||
$router->delete('{metric}/delete', 'MetricController@deleteMetricAction');
|
||||
$router->get('{metric}/edit', 'MetricController@showEditMetricAction');
|
||||
$router->post('{metric}/edit', 'MetricController@editMetricAction');
|
||||
});
|
||||
|
||||
// Notifications
|
||||
$router->group(['prefix' => 'notifications'], function ($router) {
|
||||
$router->get('/', [
|
||||
'as' => 'dashboard.notifications',
|
||||
'uses' => 'DashboardController@showNotifications',
|
||||
]);
|
||||
});
|
||||
|
||||
// Team Members
|
||||
$router->group(['prefix' => 'team'], function ($router) {
|
||||
$router->get('/', [
|
||||
'as' => 'dashboard.team',
|
||||
'uses' => 'TeamController@showTeamView',
|
||||
]);
|
||||
|
||||
$router->group(['middleware' => 'admin'], function ($router) {
|
||||
$router->get('add', [
|
||||
'as' => 'dashboard.team.add',
|
||||
'uses' => 'TeamController@showAddTeamMemberView',
|
||||
]);
|
||||
$router->get('{user}', 'TeamController@showTeamMemberView');
|
||||
$router->post('add', 'TeamController@postAddUser');
|
||||
$router->post('{user}', 'TeamController@postUpdateUser');
|
||||
});
|
||||
});
|
||||
|
||||
// Settings
|
||||
$router->group(['prefix' => 'settings'], function ($router) {
|
||||
$router->get('setup', [
|
||||
'as' => 'dashboard.settings.setup',
|
||||
'uses' => 'SettingsController@showSetupView',
|
||||
]);
|
||||
$router->get('security', [
|
||||
'as' => 'dashboard.settings.security',
|
||||
'uses' => 'SettingsController@showSecurityView',
|
||||
]);
|
||||
$router->get('theme', [
|
||||
'as' => 'dashboard.settings.theme',
|
||||
'uses' => 'SettingsController@showThemeView',
|
||||
]);
|
||||
$router->get('stylesheet', [
|
||||
'as' => 'dashboard.settings.stylesheet',
|
||||
'uses' => 'SettingsController@showStylesheetView',
|
||||
]);
|
||||
$router->post('/', 'SettingsController@postSettings');
|
||||
});
|
||||
|
||||
// User Settings
|
||||
$router->group(['prefix' => 'user'], function ($router) {
|
||||
$router->get('/', [
|
||||
'as' => 'dashboard.user',
|
||||
'uses' => 'UserController@showUser',
|
||||
]);
|
||||
$router->post('/', 'UserController@postUser');
|
||||
$router->get('{user}/api/regen', 'UserController@regenerateApiKey');
|
||||
});
|
||||
|
||||
// Internal API.
|
||||
// This should only be used for making requests within the dashboard.
|
||||
$router->group(['prefix' => 'api'], function ($router) {
|
||||
$router->get('incidents/templates', 'APIController@getIncidentTemplate');
|
||||
$router->post('components/order', 'APIController@postUpdateComponentOrder');
|
||||
$router->post('components/{component}', 'APIController@postUpdateComponent');
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Routes;
|
||||
|
||||
use Illuminate\Contracts\Routing\Registrar;
|
||||
|
||||
class ApiRoutes
|
||||
{
|
||||
/**
|
||||
* Define the api routes.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Routing\Registrar $router
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function map(Registrar $router)
|
||||
{
|
||||
$router->group([
|
||||
'middleware' => 'allowedDomains',
|
||||
'namespace' => 'Api',
|
||||
'prefix' => 'api/v1',
|
||||
], function ($router) {
|
||||
// Components
|
||||
$router->get('components', 'ComponentController@getComponents');
|
||||
$router->get('components/{id}', 'ComponentController@getComponent');
|
||||
|
||||
// Incidents
|
||||
$router->get('incidents', 'IncidentController@getIncidents');
|
||||
$router->get('incidents/{id}', 'IncidentController@getIncident');
|
||||
|
||||
// Metrics
|
||||
$router->get('metrics', 'MetricController@getMetrics');
|
||||
$router->get('metrics/{id}', 'MetricController@getMetric');
|
||||
$router->get('metrics/{id}/points', 'MetricController@getMetricPoints');
|
||||
|
||||
// Api protected
|
||||
$router->group(['middleware' => 'auth.api'], function ($router) {
|
||||
$router->post('components', 'ComponentController@postComponents');
|
||||
$router->post('incidents', 'IncidentController@postIncidents');
|
||||
$router->post('metrics', 'MetricController@postMetrics');
|
||||
$router->post('metrics/{id}/points', 'MetricPointController@postMetricPoints');
|
||||
|
||||
$router->put('components/{id}', 'ComponentController@putComponent');
|
||||
$router->put('incidents/{id}', 'IncidentController@putIncident');
|
||||
$router->put('metrics/{id}', 'MetricController@putMetric');
|
||||
$router->put('metrics/{id}/points/{metric_id}', 'MetricPointController@putMetricPoint');
|
||||
|
||||
$router->delete('components/{id}', 'ComponentController@deleteComponent');
|
||||
$router->delete('incidents/{id}', 'IncidentController@deleteIncident');
|
||||
$router->delete('metrics/{id}', 'MetricController@deleteMetric');
|
||||
$router->delete('metrics/{id}/points/{metric_id}', 'MetricPointController@deleteMetricPoint');
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Routes;
|
||||
|
||||
use Illuminate\Contracts\Routing\Registrar;
|
||||
|
||||
class AuthRoutes
|
||||
{
|
||||
/**
|
||||
* Define the auth routes.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Routing\Registrar $router
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function map(Registrar $router)
|
||||
{
|
||||
$router->group(['prefix' => 'auth'], function ($router) {
|
||||
$router->group(['middleware' => 'app.hasSetting', 'setting' => 'app_name'], function ($router) {
|
||||
// Login routes
|
||||
$router->get('login', [
|
||||
'middleware' => 'guest',
|
||||
'as' => 'login',
|
||||
'uses' => 'AuthController@showLogin',
|
||||
]);
|
||||
|
||||
$router->post('login', [
|
||||
'middleware' => ['guest', 'csrf', 'login.throttling'],
|
||||
'as' => 'logout',
|
||||
'uses' => 'AuthController@postLogin',
|
||||
]);
|
||||
|
||||
// Two factor authorization
|
||||
$router->get('2fa', [
|
||||
'as' => 'two-factor',
|
||||
'uses' => 'AuthController@showTwoFactorAuth',
|
||||
]);
|
||||
|
||||
$router->post('2fa', 'AuthController@postTwoFactor');
|
||||
});
|
||||
|
||||
$router->group(['middleware' => 'auth'], function ($router) {
|
||||
$router->get('logout', [
|
||||
'as' => 'logout',
|
||||
'uses' => 'AuthController@logoutAction',
|
||||
]);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Routes;
|
||||
|
||||
use Illuminate\Contracts\Routing\Registrar;
|
||||
|
||||
class SetupRoutes
|
||||
{
|
||||
/**
|
||||
* Define the setup routes.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Routing\Registrar $router
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function map(Registrar $router)
|
||||
{
|
||||
$router->group(['middleware' => 'app.isSetup'], function ($router) {
|
||||
$router->controller('setup', 'SetupController');
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Routes;
|
||||
|
||||
use Illuminate\Contracts\Routing\Registrar;
|
||||
|
||||
class StatusPageRoutes
|
||||
{
|
||||
/**
|
||||
* Define the status page routes.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Routing\Registrar $router
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function map(Registrar $router)
|
||||
{
|
||||
// Prevent access until the app is setup.
|
||||
$router->group(['middleware' => 'app.hasSetting', 'setting' => 'app_name'], function ($router) {
|
||||
$router->get('/', [
|
||||
'as' => 'status-page',
|
||||
'uses' => 'HomeController@showIndex',
|
||||
]);
|
||||
$router->get('/atom', 'AtomController@feedAction');
|
||||
$router->get('/rss', 'RssController@feedAction');
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
use CachetHQ\Cachet\Facades\Setting;
|
||||
use CachetHQ\Segment\Facades\Segment;
|
||||
use Illuminate\Database\QueryException;
|
||||
use Illuminate\Support\Facades\Request;
|
||||
|
||||
if (!function_exists('set_active')) {
|
||||
|
||||
/**
|
||||
* Set active class if request is in path.
|
||||
*
|
||||
* @param string $path
|
||||
* @param array $classes
|
||||
* @param string $active
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function set_active($path, array $classes = [], $active = 'active')
|
||||
{
|
||||
if (Request::is($path)) {
|
||||
$classes[] = $active;
|
||||
}
|
||||
|
||||
$class = implode(' ', $classes);
|
||||
|
||||
return empty($classes) ? '' : "class=\"{$class}\"";
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('segment_identify')) {
|
||||
/**
|
||||
* Identifies the user for Segment.com.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function segment_identify()
|
||||
{
|
||||
if (Config::get('segment.write_key')) {
|
||||
try {
|
||||
if (Setting::get('app_track')) {
|
||||
return Segment::identify([
|
||||
'anonymousId' => Config::get('app.key'),
|
||||
'context' => [
|
||||
'locale' => Config::get('app.locale'),
|
||||
'timezone' => Setting::get('app_timezone'),
|
||||
],
|
||||
]);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} catch (QueryException $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('segment_track')) {
|
||||
/**
|
||||
* Tracks events in Segment.com.
|
||||
*
|
||||
* @param string $event
|
||||
* @param array $properties
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function segment_track($event, array $properties)
|
||||
{
|
||||
if (Config::get('segment.write_key')) {
|
||||
try {
|
||||
if (Setting::get('app_track')) {
|
||||
return Segment::track([
|
||||
'anonymousId' => Config::get('app.key'),
|
||||
'event' => $event,
|
||||
'properties' => $properties,
|
||||
'context' => [
|
||||
'locale' => Config::get('app.locale'),
|
||||
'timezone' => Setting::get('app_timezone'),
|
||||
],
|
||||
]);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} catch (QueryException $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('segment_page')) {
|
||||
/**
|
||||
* Tracks pages in Segment.com.
|
||||
*
|
||||
* @param string $page
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function segment_page($page)
|
||||
{
|
||||
if (Config::get('segment.write_key')) {
|
||||
try {
|
||||
if (Setting::get('app_track')) {
|
||||
return Segment::page([
|
||||
'anonymousId' => Config::get('app.key'),
|
||||
'page' => $page,
|
||||
'context' => [
|
||||
'locale' => Config::get('app.locale'),
|
||||
'timezone' => Setting::get('app_timezone'),
|
||||
],
|
||||
]);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} catch (QueryException $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Watson\Validating\ValidatingTrait;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property int $user_id
|
||||
* @property string $name
|
||||
* @property string $description
|
||||
* @property int $status
|
||||
* @property string $link
|
||||
* @property int $order
|
||||
* @property int $group_id
|
||||
* @property \Carbon\Carbon $created_at
|
||||
* @property \Carbon\Carbon $updated_at
|
||||
* @property \Carbon\Carbon $deleted_at
|
||||
*/
|
||||
class Component extends Model
|
||||
{
|
||||
use SoftDeletes, ValidatingTrait;
|
||||
|
||||
/**
|
||||
* The validation rules.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $rules = [
|
||||
'user_id' => 'integer|required',
|
||||
'name' => 'required',
|
||||
'status' => 'integer|required',
|
||||
'link' => 'url',
|
||||
];
|
||||
|
||||
/**
|
||||
* The fillable properties.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'description',
|
||||
'status',
|
||||
'user_id',
|
||||
'tags',
|
||||
'link',
|
||||
'order',
|
||||
'group_id',
|
||||
];
|
||||
|
||||
/**
|
||||
* List of attributes that have default values.
|
||||
*
|
||||
* @var mixed[]
|
||||
*/
|
||||
protected $attributes = [
|
||||
'order' => 0,
|
||||
'group_id' => 0,
|
||||
'description' => '',
|
||||
'link' => '',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be mutated to dates.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $dates = ['deleted_at'];
|
||||
|
||||
/**
|
||||
* Components can belong to a group.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function group()
|
||||
{
|
||||
return $this->belongsTo('CachetHQ\Cachet\Models\ComponentGroup', 'group_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Lookup all of the incidents reported on the component.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function incidents()
|
||||
{
|
||||
return $this->hasMany('CachetHQ\Cachet\Models\Incident', 'component_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Components can have many tags.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
*/
|
||||
public function tags()
|
||||
{
|
||||
return $this->belongsToMany('CachetHQ\Cachet\Models\Tag');
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds all components by status.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param int $status
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeStatus(Builder $query, $status)
|
||||
{
|
||||
return $query->where('status', $status);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds all components which don't have the given status.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param int $status
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeNotStatus(Builder $query, $status)
|
||||
{
|
||||
return $query->where('status', '<>', $status);
|
||||
}
|
||||
|
||||
/**
|
||||
* Looks up the human readable version of the status.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getHumanStatusAttribute()
|
||||
{
|
||||
return trans('cachet.components.status.'.$this->status);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all of the tags on this component.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTagsListAttribute()
|
||||
{
|
||||
$tags = $this->tags->map(function ($tag) {
|
||||
return $tag->name;
|
||||
});
|
||||
|
||||
return implode(', ', $tags->toArray());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Watson\Validating\ValidatingTrait;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property string $name
|
||||
* @property \Carbon\Carbon $created_at
|
||||
* @property \Carbon\Carbon $updated_at
|
||||
* @property \Carbon\Carbon $deleted_at
|
||||
*/
|
||||
class ComponentGroup extends Model
|
||||
{
|
||||
use SoftDeletes, ValidatingTrait;
|
||||
|
||||
/**
|
||||
* The validation rules.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $rules = [
|
||||
'name' => 'required|unique:component_groups',
|
||||
];
|
||||
|
||||
/**
|
||||
* The fillable properties.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $fillable = ['name'];
|
||||
|
||||
/**
|
||||
* The attributes that should be mutated to dates.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $dates = ['deleted_at'];
|
||||
|
||||
/**
|
||||
* A group can have many components.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function components()
|
||||
{
|
||||
return $this->hasMany('CachetHQ\Cachet\Models\Component', 'group_id', 'id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use McCool\LaravelAutoPresenter\HasPresenter;
|
||||
use Watson\Validating\ValidatingTrait;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property int $component_id
|
||||
* @property int $user_id
|
||||
* @property string $name
|
||||
* @property int $status
|
||||
* @property string $message
|
||||
* @property string $humanStatus
|
||||
* @property \Carbon\Carbon $created_at
|
||||
* @property \Carbon\Carbon $updated_at
|
||||
* @property \Carbon\Carbon $deleted_at
|
||||
*/
|
||||
class Incident extends Model implements HasPresenter
|
||||
{
|
||||
use SoftDeletes, ValidatingTrait;
|
||||
|
||||
/**
|
||||
* The validation rules.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $rules = [
|
||||
'user_id' => 'required|integer',
|
||||
'component_id' => 'integer',
|
||||
'name' => 'required',
|
||||
'status' => 'required|integer',
|
||||
'message' => 'required',
|
||||
];
|
||||
|
||||
/**
|
||||
* The fillable properties.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $fillable = ['user_id', 'component_id', 'name', 'status', 'message', 'scheduled_at'];
|
||||
|
||||
/**
|
||||
* The accessors to append to the model's serialized form.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $appends = ['human_status'];
|
||||
|
||||
/**
|
||||
* The attributes that should be mutated to dates.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $dates = ['scheduled_at', 'deleted_at'];
|
||||
|
||||
/**
|
||||
* Finds all scheduled incidents (maintenance).
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeScheduled($query)
|
||||
{
|
||||
return $query->where('status', 0)->where('scheduled_at', '>=', Carbon::now());
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds all non-scheduled incidents.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeNotScheduled($query)
|
||||
{
|
||||
return $query->where(function ($query) {
|
||||
return $query->whereNull('scheduled_at')->orWhere('scheduled_at', '<=', Carbon::now());
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* An incident belongs to a component.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function component()
|
||||
{
|
||||
return $this->belongsTo('CachetHQ\Cachet\Models\Component', 'component_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a human readable version of the status.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getHumanStatusAttribute()
|
||||
{
|
||||
$statuses = trans('cachet.incidents.status');
|
||||
|
||||
return $statuses[$this->status];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the "incident" is scheduled or not.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getIsScheduledAttribute()
|
||||
{
|
||||
return $this->getOriginal('scheduled_at');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the presenter class.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPresenterClass()
|
||||
{
|
||||
return 'CachetHQ\Cachet\Presenters\IncidentPresenter';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Str;
|
||||
use Watson\Validating\ValidatingTrait;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property string $name
|
||||
* @property string $slug
|
||||
* @property string $template
|
||||
* @property \Carbon\Carbon $created_at
|
||||
* @property \Carbon\Carbon $updated_at
|
||||
*/
|
||||
class IncidentTemplate extends Model
|
||||
{
|
||||
use ValidatingTrait;
|
||||
|
||||
/**
|
||||
* The validation rules.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $rules = [
|
||||
'name' => 'required',
|
||||
'template' => 'required',
|
||||
];
|
||||
|
||||
/**
|
||||
* The fillable properties.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $fillable = ['name', 'template'];
|
||||
|
||||
/**
|
||||
* Overrides the models boot method.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
self::saving(function ($template) {
|
||||
$template->slug = Str::slug($template->name);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Models;
|
||||
|
||||
use DateInterval;
|
||||
use DateTime;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Watson\Validating\ValidatingTrait;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property string $name
|
||||
* @property string $suffix
|
||||
* @property string $description
|
||||
* @property int $display_chart
|
||||
* @property \Carbon\Carbon $created_at
|
||||
* @property \Carbon\Carbon $updated_at
|
||||
*/
|
||||
class Metric extends Model
|
||||
{
|
||||
use ValidatingTrait;
|
||||
|
||||
const CALC_SUM = 0;
|
||||
const CALC_AVG = 1;
|
||||
|
||||
/**
|
||||
* The model's attributes.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $attributes = [
|
||||
'name' => '',
|
||||
'display_chart' => 1,
|
||||
'default_value' => 0,
|
||||
'calc_type' => 0,
|
||||
];
|
||||
|
||||
/**
|
||||
* The validation rules.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $rules = [
|
||||
'name' => 'required',
|
||||
'suffix' => 'required',
|
||||
'display_chart' => 'boolean',
|
||||
'default_value' => 'numeric',
|
||||
];
|
||||
|
||||
/**
|
||||
* The fillable properties.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $fillable = ['name', 'suffix', 'description', 'display_chart', 'default_value', 'calc_type'];
|
||||
|
||||
/**
|
||||
* Metrics contain many metric points.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function points()
|
||||
{
|
||||
return $this->hasMany('CachetHQ\Cachet\Models\MetricPoint', 'metric_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the sum of all values a metric has.
|
||||
*
|
||||
* @param int $hour
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getValues($hour)
|
||||
{
|
||||
$dateTime = new DateTime();
|
||||
$dateTime->sub(new DateInterval('PT'.$hour.'H'));
|
||||
|
||||
if (Config::get('database.default') === 'mysql') {
|
||||
if (! isset($this->calc_type) || $this->calc_type === self::CALC_SUM) {
|
||||
$value = (int) $this->points()->whereRaw('DATE_FORMAT(created_at, "%Y%m%e%H") = '.$dateTime->format('YmdH'))->whereRaw('HOUR(created_at) = HOUR(DATE_SUB(NOW(), INTERVAL '.$hour.' HOUR))')->groupBy(DB::raw('HOUR(created_at)'))->sum('value');
|
||||
} elseif ($this->calc_type === self::CALC_AVG) {
|
||||
$value = (int) $this->points()->whereRaw('DATE_FORMAT(created_at, "%Y%m%e%H") = '.$dateTime->format('YmdH'))->whereRaw('HOUR(created_at) = HOUR(DATE_SUB(NOW(), INTERVAL '.$hour.' HOUR))')->groupBy(DB::raw('HOUR(created_at)'))->avg('value');
|
||||
}
|
||||
} else {
|
||||
// Default metrics calculations.
|
||||
if (! isset($this->calc_type) || $this->calc_type === self::CALC_SUM) {
|
||||
$queryType = "sum(metric_points.value)";
|
||||
} elseif ($this->calc_type === self::CALC_AVG) {
|
||||
$queryType = "avg(metric_points.value)";
|
||||
}
|
||||
|
||||
$query = DB::select("select {$queryType} as aggregate FROM metrics JOIN metric_points ON metric_points.metric_id = metrics.id WHERE to_char(metric_points.created_at, 'YYYYMMDDHH') = :timestamp AND to_char(metric_points.created_at, 'H') = to_char(now() - interval '{$hour} hour', 'H') GROUP BY to_char(metric_points.created_at, 'H')", [
|
||||
'timestamp' => $dateTime->format('YmdH'),
|
||||
]);
|
||||
|
||||
if (isset($query[0])) {
|
||||
$value = $query[0]->aggregate;
|
||||
} else {
|
||||
$value = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if ($value === 0 && $this->default_value != $value) {
|
||||
return $this->default_value;
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether a chart should be shown.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getShouldDisplayAttribute()
|
||||
{
|
||||
return $this->display_chart === 1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Watson\Validating\ValidatingTrait;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property int $metric_id
|
||||
* @property int $value
|
||||
* @property \Carbon\Carbon $created_at
|
||||
* @property \Carbon\Carbon $updated_at
|
||||
*/
|
||||
class MetricPoint extends Model
|
||||
{
|
||||
use ValidatingTrait;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $fillable = ['metric_id', 'value'];
|
||||
|
||||
/**
|
||||
* The validation rules.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $rules = [
|
||||
'value' => 'numeric|required',
|
||||
];
|
||||
|
||||
/**
|
||||
* A metric point belongs to a metric unit.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function metric()
|
||||
{
|
||||
return $this->belongsTo('CachetHQ\Cachet\Models\Metric', 'id', 'metric_id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Watson\Validating\ValidatingTrait;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property string $type
|
||||
* @property int $active
|
||||
* @property string $properties
|
||||
* @property \Carbon\Carbon $created_at
|
||||
* @property \Carbon\Carbon $updated_at
|
||||
* @property \Carbon\Carbon $deleted_at
|
||||
*/
|
||||
class Service extends Model
|
||||
{
|
||||
use ValidatingTrait;
|
||||
|
||||
/**
|
||||
* The validation rules.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $rules = [
|
||||
'type' => 'alpha_dash|required',
|
||||
'active' => 'required|in:0,1',
|
||||
'properties' => '',
|
||||
];
|
||||
|
||||
/**
|
||||
* Returns a decoded properties object for the service.
|
||||
*
|
||||
* @param string $properties
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
public function getPropertiesAttribute($properties)
|
||||
{
|
||||
return json_decode($properties);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the properties attribute which auto encodes to a JSON string.
|
||||
*
|
||||
* @param mixed $properties
|
||||
*/
|
||||
public function setPropertiesAttribute($properties)
|
||||
{
|
||||
$this->attributes['properties'] = json_encode($properties);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property string $name
|
||||
* @property string $value
|
||||
* @property \Carbon\Carbon $created_at
|
||||
* @property \Carbon\Carbon $updated_at
|
||||
*/
|
||||
class Setting extends Model
|
||||
{
|
||||
/**
|
||||
* The fillable properties.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $fillable = ['name', 'value'];
|
||||
|
||||
/**
|
||||
* List of attributes that have default values.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $attributes = ['value' => ''];
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Watson\Validating\ValidatingTrait;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property string $email
|
||||
* @property \Carbon\Carbon $created_at
|
||||
* @property \Carbon\Carbon $updated_at
|
||||
* @property \Carbon\Carbon $deleted_at
|
||||
*/
|
||||
class Subscriber extends Model
|
||||
{
|
||||
use SoftDeletes, ValidatingTrait;
|
||||
|
||||
/**
|
||||
* The validation rules.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $rules = [
|
||||
'email' => 'required|email',
|
||||
];
|
||||
|
||||
/**
|
||||
* The fillable properties.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $fillable = ['email'];
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Str;
|
||||
use Watson\Validating\ValidatingTrait;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property string $name
|
||||
* @property string $slug
|
||||
* @property \Carbon\Carbon $created_at
|
||||
* @property \Carbon\Carbon $updated_at
|
||||
*/
|
||||
class Tag extends Model
|
||||
{
|
||||
use ValidatingTrait;
|
||||
|
||||
/**
|
||||
* The fillable properties.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $fillable = ['name'];
|
||||
|
||||
/**
|
||||
* Overrides the models boot method.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
self::creating(function ($tag) {
|
||||
$tag->slug = Str::slug($tag->name);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Tags can have many components.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
*/
|
||||
public function components()
|
||||
{
|
||||
return $this->belongsToMany('CachetHQ\Cachet\Models\Component');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Models;
|
||||
|
||||
use Illuminate\Auth\Authenticatable;
|
||||
use Illuminate\Auth\Passwords\CanResetPassword;
|
||||
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
|
||||
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Watson\Validating\ValidatingTrait;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property string $username
|
||||
* @property string $password
|
||||
* @property string $remember_token
|
||||
* @property string $google_2fa_secret
|
||||
* @property string $email
|
||||
* @property string $api_key
|
||||
* @property int $active
|
||||
* @property int $level
|
||||
* @property \Carbon\Carbon $created_at
|
||||
* @property \Carbon\Carbon $updated_at
|
||||
*/
|
||||
class User extends Model implements AuthenticatableContract, CanResetPasswordContract
|
||||
{
|
||||
use Authenticatable, CanResetPassword, ValidatingTrait;
|
||||
|
||||
/**
|
||||
* The validation rules.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $rules = [
|
||||
'username' => 'required|alpha_num|unique:users',
|
||||
'email' => 'required|email|unique:users',
|
||||
'password' => 'required',
|
||||
];
|
||||
|
||||
/**
|
||||
* The hidden properties.
|
||||
*
|
||||
* These are excluded when we are serializing the model.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $hidden = ['password', 'remember_token', 'google_2fa_secret'];
|
||||
|
||||
/**
|
||||
* The properties that cannot be mass assigned.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $guarded = [];
|
||||
|
||||
/**
|
||||
* Overrides the models boot method.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
self::creating(function ($user) {
|
||||
if (! $user->api_key) {
|
||||
$user->api_key = self::generateApiKey();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Hash any password being inserted by default.
|
||||
*
|
||||
* @param string $password
|
||||
*
|
||||
* @return \CachetHQ\Cachet\Models\User
|
||||
*/
|
||||
public function setPasswordAttribute($password)
|
||||
{
|
||||
$this->attributes['password'] = Hash::make($password);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Gravatar URL for the users email address.
|
||||
*
|
||||
* @param int $size
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getGravatarAttribute($size = 200)
|
||||
{
|
||||
return sprintf('https://www.gravatar.com/avatar/%s?size=%d', md5($this->email), $size);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find by api_key, or throw an exception.
|
||||
*
|
||||
* @param string $token
|
||||
* @param string[] $columns
|
||||
*
|
||||
* @throws \Illuminate\Database\Eloquent\ModelNotFoundException
|
||||
*
|
||||
* @return \CachetHQ\Cachet\Models\User
|
||||
*/
|
||||
public static function findByApiToken($token, $columns = ['*'])
|
||||
{
|
||||
$user = static::where('api_key', $token)->first($columns);
|
||||
|
||||
if (!$user) {
|
||||
throw new ModelNotFoundException();
|
||||
}
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an API key.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function generateApiKey()
|
||||
{
|
||||
return str_random(20);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether a user is at admin level.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getIsAdminAttribute()
|
||||
{
|
||||
return $this->level == 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if a user has enabled two factor authentication.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getHasTwoFactorAttribute()
|
||||
{
|
||||
return trim($this->google_2fa_secret) !== '';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Presenters;
|
||||
|
||||
use CachetHQ\Cachet\Facades\Setting;
|
||||
use CachetHQ\Cachet\Models\Incident;
|
||||
use GrahamCampbell\Markdown\Facades\Markdown;
|
||||
use Jenssegers\Date\Date;
|
||||
use McCool\LaravelAutoPresenter\BasePresenter;
|
||||
|
||||
class IncidentPresenter extends BasePresenter
|
||||
{
|
||||
/**
|
||||
* Time zone setting.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $tz;
|
||||
|
||||
/**
|
||||
* Create a incident presenter instance.
|
||||
*
|
||||
* @param object $resource
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($resource)
|
||||
{
|
||||
parent::__construct($resource);
|
||||
|
||||
$this->tz = Setting::get('app_timezone');
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the message from Markdown into HTML.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function formattedMessage()
|
||||
{
|
||||
return Markdown::convertToHtml($this->wrappedObject->message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Present diff for humans date time.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function created_at_diff()
|
||||
{
|
||||
return (new Date($this->wrappedObject->created_at))
|
||||
->setTimezone($this->tz)
|
||||
->diffForHumans();
|
||||
}
|
||||
|
||||
/**
|
||||
* Present formatted date time.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function created_at_formatted()
|
||||
{
|
||||
return ucfirst((new Date($this->wrappedObject->created_at))
|
||||
->setTimezone($this->tz)
|
||||
->format('l jS F Y H:i:s'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Present formatted date time.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function created_at_iso()
|
||||
{
|
||||
return $this->wrappedObject->created_at->setTimezone($this->tz)->toISO8601String();
|
||||
}
|
||||
|
||||
/**
|
||||
* Present diff for humans date time.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function scheduled_at_diff()
|
||||
{
|
||||
return (new Date($this->wrappedObject->scheduled_at))
|
||||
->setTimezone($this->tz)
|
||||
->diffForHumans();
|
||||
}
|
||||
|
||||
/**
|
||||
* Present formated date time.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function scheduled_at_formatted()
|
||||
{
|
||||
return ucfirst((new Date($this->wrappedObject->scheduled_at))
|
||||
->setTimezone($this->tz)
|
||||
->format('l jS F Y H:i:s'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Present formatted date time.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function scheduled_at_iso()
|
||||
{
|
||||
return $this->wrappedObject->scheduled_at->setTimezone($this->tz)->toISO8601String();
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats the scheduled_at time ready to be used by bootstrap-datetimepicker.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function scheduled_at_datetimepicker()
|
||||
{
|
||||
return $this->wrappedObject->scheduled_at->setTimezone($this->tz)->format('d/m/Y H:i');
|
||||
}
|
||||
|
||||
/**
|
||||
* Present the status with an icon.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function icon()
|
||||
{
|
||||
switch ($this->wrappedObject->status) {
|
||||
case 0: // Scheduled
|
||||
return 'icon ion-android-calendar';
|
||||
case 1: // Investigating
|
||||
return 'icon ion-flag';
|
||||
case 2: // Identified
|
||||
return 'icon ion-alert';
|
||||
case 3: // Watching
|
||||
return 'icon ion-eye';
|
||||
case 4: // Fixed
|
||||
return 'icon ion-checkmark';
|
||||
default: // Something actually broke, this shouldn't happen.
|
||||
return '';
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Providers;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Bootstrap any application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Register any application services.
|
||||
*
|
||||
* This service provider is a great spot to register your various container
|
||||
* bindings with the application. As you can see, we are registering our
|
||||
* "Registrar" implementation here. You can add your own bindings too!
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$this->app->bind(
|
||||
'Illuminate\Contracts\Auth\Registrar',
|
||||
'CachetHQ\Cachet\Services\Registrar'
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php namespace CachetHQ\Cachet\Providers;
|
||||
|
||||
use Illuminate\Bus\Dispatcher;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class BusServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Bootstrap any application services.
|
||||
*
|
||||
* @param \Illuminate\Bus\Dispatcher $dispatcher
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot(Dispatcher $dispatcher)
|
||||
{
|
||||
$dispatcher->mapUsing(function ($command) {
|
||||
return Dispatcher::simpleMapping(
|
||||
$command, 'CachetHQ\Cachet\Commands', 'CachetHQ\Cachet\Handlers\Commands'
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Register any application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php namespace CachetHQ\Cachet\Providers;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class ConfigServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Overwrite any vendor / package configuration.
|
||||
*
|
||||
* This service provider is intended to provide a convenient location for you
|
||||
* to overwrite any "vendor" or package configuration that you may want to
|
||||
* modify before the application handles the incoming request / command.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
config([
|
||||
//
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Providers;
|
||||
|
||||
use CachetHQ\Cachet\Console\Commands\FixPermissionsCommand;
|
||||
use CachetHQ\Cachet\Console\Commands\OneClickDeployCommand;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class ConsoleServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Boot the service provider.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the service provider.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$this->app->singleton('CachetHQ\Cachet\Console\Commands\FixPermissionsCommand', function ($app) {
|
||||
$storageDirectory = storage_path();
|
||||
$databaseDirectory = base_path('database');
|
||||
$databasePath = $app->config->get('database.connections.sqlite.database');
|
||||
$databaseDefault = $app->config->get('database.default');
|
||||
|
||||
return new FixPermissionsCommand($storageDirectory, $databaseDirectory, $databasePath, $databaseDefault);
|
||||
});
|
||||
|
||||
$this->app->singleton('CachetHQ\Cachet\Console\Commands\OneClickDeployCommand', function ($app) {
|
||||
return new OneClickDeployCommand($app->environment('heroku'));
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php namespace CachetHQ\Cachet\Providers;
|
||||
|
||||
use Illuminate\Contracts\Events\Dispatcher as DispatcherContract;
|
||||
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
|
||||
|
||||
class EventServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* The event handler mappings for the application.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $listen = [
|
||||
'event.name' => [
|
||||
'EventListener',
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* Register any other events for your application.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Events\Dispatcher $events
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot(DispatcherContract $events)
|
||||
{
|
||||
parent::boot($events);
|
||||
|
||||
//
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Providers;
|
||||
|
||||
use CachetHQ\Cachet\Facades\Setting;
|
||||
use Illuminate\Database\QueryException;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class LoadConfigServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Boot the service provider.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
$appDomain = $appLocale = null;
|
||||
|
||||
try {
|
||||
// Get app custom configuration.
|
||||
$appDomain = Setting::get('app_domain');
|
||||
$appLocale = Setting::get('app_locale');
|
||||
} catch (QueryException $e) {
|
||||
// Don't throw any errors, we may not be setup yet.
|
||||
}
|
||||
|
||||
// Set the Segment.com settings.
|
||||
$segmentRepository = $this->app->make('CachetHQ\Cachet\Segment\RepositoryInterface');
|
||||
try {
|
||||
$this->app->config->set('cachethq/segment::write_key', $segmentRepository->fetch());
|
||||
} catch (\GuzzleHttp\Exception\ConnectException $e) {
|
||||
// We may not have any connection. Let's not cry about it.
|
||||
}
|
||||
|
||||
// Override default app values.
|
||||
$this->app->config->set('app.url', $appDomain ?: $this->app->config->get('app.url'));
|
||||
$this->app->config->set('app.locale', $appLocale ?: $this->app->config->get('app.locale'));
|
||||
|
||||
// Set custom lang.
|
||||
$this->app->translator->setLocale($appLocale);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the service provider.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Providers;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class RepositoryServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Boot the service provider.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the service provider.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$this->app->bind(
|
||||
'CachetHQ\Cachet\Repositories\Component\ComponentRepository',
|
||||
'CachetHQ\Cachet\Repositories\Component\EloquentComponentRepository'
|
||||
);
|
||||
$this->app->bind(
|
||||
'CachetHQ\Cachet\Repositories\Incident\IncidentRepository',
|
||||
'CachetHQ\Cachet\Repositories\Incident\EloquentIncidentRepository'
|
||||
);
|
||||
$this->app->bind(
|
||||
'CachetHQ\Cachet\Repositories\Metric\MetricRepository',
|
||||
'CachetHQ\Cachet\Repositories\Metric\EloquentMetricRepository'
|
||||
);
|
||||
$this->app->bind(
|
||||
'CachetHQ\Cachet\Repositories\MetricPoint\MetricPointRepository',
|
||||
'CachetHQ\Cachet\Repositories\MetricPoint\EloquentMetricPointRepository'
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php namespace CachetHQ\Cachet\Providers;
|
||||
|
||||
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
|
||||
use Illuminate\Routing\Router;
|
||||
|
||||
class RouteServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* This namespace is applied to the controller routes in your routes file.
|
||||
*
|
||||
* In addition, it is set as the URL generator's root namespace.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $namespace = 'CachetHQ\Cachet\Http\Controllers';
|
||||
|
||||
/**
|
||||
* Define your route model bindings, pattern filters, etc.
|
||||
*
|
||||
* @param \Illuminate\Routing\Router $router
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot(Router $router)
|
||||
{
|
||||
parent::boot($router);
|
||||
|
||||
$this->registerBindings();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register model bindings.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function registerBindings()
|
||||
{
|
||||
$this->app->router->model('component', 'CachetHQ\Cachet\Models\Component');
|
||||
$this->app->router->model('component_group', 'CachetHQ\Cachet\Models\ComponentGroup');
|
||||
$this->app->router->model('incident', 'CachetHQ\Cachet\Models\Incident');
|
||||
$this->app->router->model('incident_template', 'CachetHQ\Cachet\Models\IncidentTemplate');
|
||||
$this->app->router->model('metric', 'CachetHQ\Cachet\Models\Metric');
|
||||
$this->app->router->model('metric_point', 'CachetHQ\Cachet\Models\MetricPoint');
|
||||
$this->app->router->model('setting', 'CachetHQ\Cachet\Models\Setting');
|
||||
$this->app->router->model('user', 'CachetHQ\Cachet\Models\User');
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the routes for the application.
|
||||
*
|
||||
* @param \Illuminate\Routing\Router $router
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function map(Router $router)
|
||||
{
|
||||
$router->group(['namespace' => $this->namespace], function (Router $router) {
|
||||
foreach (glob(app_path('Http//Routes').'/*.php') as $file) {
|
||||
$this->app->make('CachetHQ\\Cachet\\Http\\Routes\\'.basename($file, '.php'))->map($router);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Providers;
|
||||
|
||||
use CachetHQ\Cachet\Segment\CacheRepository;
|
||||
use CachetHQ\Cachet\Segment\HttpRepository;
|
||||
use GuzzleHttp\Client;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class SegmentApiServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Boot the service provider.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the service provider.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$this->app->singleton('CachetHQ\Cachet\Segment\RepositoryInterface', function () {
|
||||
$url = 'https://gist.githubusercontent.com/jbrooksuk/5de24bc1cf90fb1a3d57/raw/cachet.json';
|
||||
$guzzleClient = new Client();
|
||||
$client = new HttpRepository($guzzleClient, $url);
|
||||
|
||||
return new CacheRepository($client);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Providers;
|
||||
|
||||
use CachetHQ\Cachet\Config\Repository;
|
||||
use CachetHQ\Cachet\Models\Setting as SettingModel;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class SettingsServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Boot the service provider.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the service provider.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$this->app->bindShared('setting', function () {
|
||||
return new Repository(new SettingModel());
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Providers;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class ViewComposerServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Boot the service provider.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the service provider.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$this->app->view->composer('*', 'CachetHQ\Cachet\Composers\LoggedUserComposer');
|
||||
$this->app->view->composer('index', 'CachetHQ\Cachet\Composers\IndexComposer');
|
||||
$this->app->view->composer('dashboard.*', 'CachetHQ\Cachet\Composers\DashboardComposer');
|
||||
$this->app->view->composer([
|
||||
'setup',
|
||||
'dashboard.settings.app-setup',
|
||||
], 'CachetHQ\Cachet\Composers\TimezoneLocaleComposer');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Repositories\Component;
|
||||
|
||||
interface ComponentRepository
|
||||
{
|
||||
/**
|
||||
* Returns all models.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Collection
|
||||
*/
|
||||
public function all();
|
||||
|
||||
/**
|
||||
* Create a new model.
|
||||
*
|
||||
* @param int $userId
|
||||
* @param array $data
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
public function create($userId, array $data);
|
||||
|
||||
/**
|
||||
* Update a model by id.
|
||||
*
|
||||
* @param int $id
|
||||
* @param array $data
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
public function update($id, array $data);
|
||||
|
||||
/**
|
||||
* Finds a model by id.
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @throws \Illuminate\Database\Eloquent\ModelNotFoundException
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
public function findOrFail($id);
|
||||
|
||||
/**
|
||||
* Returns an object with related relationships.
|
||||
*
|
||||
* @param int $id
|
||||
* @param string[] $with
|
||||
*
|
||||
* @throws \Illuminate\Database\Eloquent\ModelNotFoundException
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
public function with($id, array $with = []);
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Repositories\Component;
|
||||
|
||||
use CachetHQ\Cachet\Models\Component;
|
||||
use CachetHQ\Cachet\Repositories\EloquentRepository;
|
||||
|
||||
class EloquentComponentRepository extends EloquentRepository implements ComponentRepository
|
||||
{
|
||||
/**
|
||||
* The eloquent model instance.
|
||||
*
|
||||
* @var \CachetHQ\Cachet\Models\Component
|
||||
*/
|
||||
protected $model;
|
||||
|
||||
/**
|
||||
* Create a new eloquent component repository instance.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\Component $model
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Component $model)
|
||||
{
|
||||
$this->model = $model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new model.
|
||||
*
|
||||
* @param int $userId
|
||||
* @param array $data
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
public function create($userId, array $data)
|
||||
{
|
||||
$component = new $this->model($data);
|
||||
$component->user_id = $userId;
|
||||
|
||||
$this->validate($component);
|
||||
|
||||
$component->saveOrFail();
|
||||
|
||||
return $component;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a model by id.
|
||||
*
|
||||
* @param int $id
|
||||
* @param array $data
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
public function update($id, array $data)
|
||||
{
|
||||
$component = $this->model->findOrFail($id);
|
||||
$component->fill($data);
|
||||
$this->validate($component);
|
||||
|
||||
$component->update($data);
|
||||
|
||||
return $component;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,175 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Repositories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
|
||||
abstract class EloquentRepository
|
||||
{
|
||||
/**
|
||||
* Returns all models.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Collection
|
||||
*/
|
||||
public function all()
|
||||
{
|
||||
return $this->model->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns paginated result.
|
||||
*
|
||||
* @param int $perPage
|
||||
*
|
||||
* @return \Illuminate\Pagination\Paginator
|
||||
*/
|
||||
public function paginate($perPage = 20)
|
||||
{
|
||||
return $this->model->paginate($perPage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an object with related relationships.
|
||||
*
|
||||
* @param int $id
|
||||
* @param string[] $with
|
||||
*
|
||||
* @throws \Illuminate\Database\Eloquent\ModelNotFoundException
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
public function with($id, array $with = [])
|
||||
{
|
||||
return $this->model->with($with)->findOrFail($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the model to query against a user id.
|
||||
*
|
||||
* @param int $id
|
||||
* @param string $column
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function withAuth($id, $column = 'user_id')
|
||||
{
|
||||
$this->model = $this->model->where($column, $id);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds a model by ID.
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
public function find($id)
|
||||
{
|
||||
return $this->model->find($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds a model by id.
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @throws \Illuminate\Database\Eloquent\ModelNotFoundException
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
public function findOrFail($id)
|
||||
{
|
||||
return $this->model->findOrFail($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds a model by type.
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $value
|
||||
* @param array $columns
|
||||
*
|
||||
* @throws \Illuminate\Database\Eloquent\ModelNotFoundException
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
public function findByOrFail($key, $value, $columns = ['*'])
|
||||
{
|
||||
$model = $this->model->where($key, $value)->first($columns);
|
||||
|
||||
if ($model === null) {
|
||||
throw new ModelNotFoundException();
|
||||
}
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Counts the number of rows returned.
|
||||
*
|
||||
* @param string|null $key
|
||||
* @param string|null $value
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function count($key = null, $value = null)
|
||||
{
|
||||
if ($key === null || $value === null) {
|
||||
return $this->model->count();
|
||||
}
|
||||
|
||||
return $this->model->where($key, $value)->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a model by id.
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
$this->model->destroy($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate a given model with Watson validation.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Model $model
|
||||
*
|
||||
* @throws \CachetHQ\Cachet\Repositories\InvalidModelValidationException
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function validate(Model $model)
|
||||
{
|
||||
if ($model->isInvalid()) {
|
||||
throw new InvalidModelValidationException('Validation failed on the model.');
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate whether a model has a correct relationship.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Model $model
|
||||
* @param string $relationship
|
||||
*
|
||||
* @throws \CachetHQ\Cachet\Repositories\InvalidRelationshipException
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function hasRelationship(Model $model, $relationship)
|
||||
{
|
||||
if ($model->$relationship === null) {
|
||||
throw new InvalidRelationshipException('The relationship was not valid.');
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Repositories\Incident;
|
||||
|
||||
use CachetHQ\Cachet\Models\Incident;
|
||||
use CachetHQ\Cachet\Repositories\EloquentRepository;
|
||||
|
||||
class EloquentIncidentRepository extends EloquentRepository implements IncidentRepository
|
||||
{
|
||||
/**
|
||||
* The eloquent model instance.
|
||||
*
|
||||
* @var \CachetHQ\Cachet\Models\Incident
|
||||
*/
|
||||
protected $model;
|
||||
|
||||
/**
|
||||
* Create a new eloquent incident repository instance.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\Incident $model
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Incident $model)
|
||||
{
|
||||
$this->model = $model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new model.
|
||||
*
|
||||
* @param int $userId
|
||||
* @param array $data
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
public function create($userId, array $data)
|
||||
{
|
||||
$incident = new $this->model($data);
|
||||
$incident->user_id = $userId;
|
||||
$this->validate($incident);
|
||||
|
||||
if (isset($data['component_id'])) {
|
||||
$this->hasRelationship($incident, 'component');
|
||||
}
|
||||
|
||||
$incident->saveOrFail();
|
||||
|
||||
return $incident;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a model by id.
|
||||
*
|
||||
* @param int $id
|
||||
* @param array $data
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
public function update($id, array $data)
|
||||
{
|
||||
$incident = $this->model->findOrFail($id);
|
||||
$incident->fill($data);
|
||||
$this->validate($incident);
|
||||
|
||||
if (isset($data['component_id'])) {
|
||||
$this->hasRelationship($incident, 'component');
|
||||
}
|
||||
|
||||
$incident->update($data);
|
||||
|
||||
return $incident;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Repositories\Incident;
|
||||
|
||||
interface IncidentRepository
|
||||
{
|
||||
/**
|
||||
* Returns all models.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Collection
|
||||
*/
|
||||
public function all();
|
||||
|
||||
/**
|
||||
* Returns paginated result.
|
||||
*
|
||||
* @param int $perPage
|
||||
*
|
||||
* @return \Illuminate\Pagination\Paginator
|
||||
*/
|
||||
public function paginate($perPage = 20);
|
||||
|
||||
/**
|
||||
* Create a new model.
|
||||
*
|
||||
* @param int $userId
|
||||
* @param array $data
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
public function create($userId, array $data);
|
||||
|
||||
/**
|
||||
* Finds a model by id.
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @throws \Illuminate\Database\Eloquent\ModelNotFoundException
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
public function findOrFail($id);
|
||||
|
||||
/**
|
||||
* Update a model by id.
|
||||
*
|
||||
* @param int $id
|
||||
* @param array $data
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
public function update($id, array $data);
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Repositories;
|
||||
|
||||
use Exception;
|
||||
|
||||
class InvalidModelValidationException extends Exception
|
||||
{
|
||||
//
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Repositories;
|
||||
|
||||
use Exception;
|
||||
|
||||
class InvalidRelationshipException extends Exception
|
||||
{
|
||||
//
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Repositories\Metric;
|
||||
|
||||
use CachetHQ\Cachet\Models\Metric;
|
||||
use CachetHQ\Cachet\Repositories\EloquentRepository;
|
||||
|
||||
class EloquentMetricRepository extends EloquentRepository implements MetricRepository
|
||||
{
|
||||
/**
|
||||
* The eloquent model instance.
|
||||
*
|
||||
* @var \CachetHQ\Cachet\Models\Metric
|
||||
*/
|
||||
protected $model;
|
||||
|
||||
/**
|
||||
* Create a new eloquent metric repository instance.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\Metric $model
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Metric $model)
|
||||
{
|
||||
$this->model = $model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new model.
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
public function create(array $data)
|
||||
{
|
||||
$metric = new $this->model($data);
|
||||
|
||||
$this->validate($metric);
|
||||
|
||||
$metric->saveOrFail();
|
||||
|
||||
return $metric;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a model by id.
|
||||
*
|
||||
* @param int $id
|
||||
* @param array $data
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
public function update($id, array $data)
|
||||
{
|
||||
$metric = $this->model->findOrFail($id);
|
||||
$metric->fill($data);
|
||||
|
||||
$this->validate($metric);
|
||||
|
||||
$metric->update($data);
|
||||
|
||||
return $metric;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all metric point models.
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Collection
|
||||
*/
|
||||
public function points($id)
|
||||
{
|
||||
$metric = $this->model->findOrFail($id);
|
||||
|
||||
return $metric->points;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Repositories\Metric;
|
||||
|
||||
interface MetricRepository
|
||||
{
|
||||
/**
|
||||
* Returns all models.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Collection
|
||||
*/
|
||||
public function all();
|
||||
|
||||
/**
|
||||
* Returns all metric point models.
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Collection
|
||||
*/
|
||||
public function points($id);
|
||||
|
||||
/**
|
||||
* Create a new model.
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
public function create(array $data);
|
||||
|
||||
/**
|
||||
* Finds a model by id.
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @throws \Illuminate\Database\Eloquent\ModelNotFoundException
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
public function findOrFail($id);
|
||||
|
||||
/**
|
||||
* Update a model by id.
|
||||
*
|
||||
* @param int $id
|
||||
* @param array $data
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
public function update($id, array $data);
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Repositories\MetricPoint;
|
||||
|
||||
use CachetHQ\Cachet\Models\MetricPoint;
|
||||
use CachetHQ\Cachet\Repositories\EloquentRepository;
|
||||
|
||||
class EloquentMetricPointRepository extends EloquentRepository implements MetricPointRepository
|
||||
{
|
||||
/**
|
||||
* The eloquent model instance.
|
||||
*
|
||||
* @var \CachetHQ\Cachet\Models\MetricPoint
|
||||
*/
|
||||
protected $model;
|
||||
|
||||
/**
|
||||
* Create a new eloquent metric point repository instance.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\MetricPoint $model
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(MetricPoint $model)
|
||||
{
|
||||
$this->model = $model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new model.
|
||||
*
|
||||
* @param int $id
|
||||
* @param array $data
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
public function create($id, array $data)
|
||||
{
|
||||
$data['metric_id'] = $id;
|
||||
$metric = new $this->model($data);
|
||||
|
||||
$this->validate($metric);
|
||||
|
||||
$metric->saveOrFail();
|
||||
|
||||
return $metric;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a model by id.
|
||||
*
|
||||
* @param int $id
|
||||
* @param array $data
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
public function update($id, array $data)
|
||||
{
|
||||
$metric = $this->model->findOrFail($id);
|
||||
$metric->fill($data);
|
||||
|
||||
$this->validate($metric);
|
||||
|
||||
$metric->update($data);
|
||||
|
||||
return $metric;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Repositories\MetricPoint;
|
||||
|
||||
interface MetricPointRepository
|
||||
{
|
||||
/**
|
||||
* Returns all models.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Collection
|
||||
*/
|
||||
public function all();
|
||||
|
||||
/**
|
||||
* Create a new model.
|
||||
*
|
||||
* @param int $id
|
||||
* @param array $data
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
public function create($id, array $data);
|
||||
|
||||
/**
|
||||
* Finds a model by id.
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @throws \Illuminate\Database\Eloquent\ModelNotFoundException
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
public function findOrFail($id);
|
||||
|
||||
/**
|
||||
* Update a model by id.
|
||||
*
|
||||
* @param int $id
|
||||
* @param array $data
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
public function update($id, array $data);
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Segment;
|
||||
|
||||
use CachetHQ\Cachet\Facades\Setting;
|
||||
use CachetHQ\Cachet\Models\Setting as SettingModel;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\QueryException;
|
||||
|
||||
class CacheRepository implements RepositoryInterface
|
||||
{
|
||||
/**
|
||||
* @var \CachetHQ\Cachet\Segment\RepositoryInterface
|
||||
*/
|
||||
protected $repository;
|
||||
|
||||
/**
|
||||
* Instantiates a new instance of the Cache Repository.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Segment\RepositoryInterface $repository
|
||||
*/
|
||||
public function __construct(RepositoryInterface $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether to use the segment_write_key setting or to fetch a new.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function fetch()
|
||||
{
|
||||
$writeKey = null;
|
||||
|
||||
// We might not be setup yet.
|
||||
try {
|
||||
// Firstly, does the setting exist?
|
||||
if (false === ($writeKey = Setting::get('segment_write_key'))) {
|
||||
// No, let's go fetch it.
|
||||
$writeKey = $this->repository->fetch();
|
||||
Setting::set('segment_write_key', $writeKey);
|
||||
} else {
|
||||
// It does, but how old is it?
|
||||
$setting = SettingModel::where('name', 'segment_write_key')->first();
|
||||
|
||||
// It's older than an hour, let's refresh
|
||||
if ($setting->updated_at->lt(Carbon::now()->subHour())) {
|
||||
$writeKey = $this->repository->fetch();
|
||||
|
||||
// Update the setting. This is done manual to make sure updated_at is overwritten.
|
||||
$setting->value = $writeKey;
|
||||
$setting->updated_at = Carbon::now();
|
||||
$setting->save();
|
||||
}
|
||||
}
|
||||
} catch (QueryException $e) {
|
||||
// Just return it until we're setup.
|
||||
$writeKey = $this->repository->fetch();
|
||||
}
|
||||
|
||||
return $writeKey;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Segment;
|
||||
|
||||
use GuzzleHttp\ClientInterface;
|
||||
|
||||
class HttpRepository implements RepositoryInterface
|
||||
{
|
||||
/**
|
||||
* @var \Guzzle\GuzzleClient
|
||||
*/
|
||||
protected $client;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $url;
|
||||
|
||||
/**
|
||||
* Instantiates a new instance of the SegmentApi class.
|
||||
*
|
||||
* @param \Guzzle\GuzzleClient $client
|
||||
* @param string $url
|
||||
*/
|
||||
public function __construct(ClientInterface $client, $url)
|
||||
{
|
||||
$this->client = $client;
|
||||
$this->url = $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the segment_write_key from the given url.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function fetch()
|
||||
{
|
||||
return $this->client->get($this->url)->json()['segment_write_key'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Segment;
|
||||
|
||||
interface RepositoryInterface
|
||||
{
|
||||
/**
|
||||
* Returns the segment_write_key.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function fetch();
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php namespace CachetHQ\Cachet\Services;
|
||||
|
||||
use CachetHQ\Cachet\User;
|
||||
use Illuminate\Contracts\Auth\Registrar as RegistrarContract;
|
||||
use Validator;
|
||||
|
||||
class Registrar implements RegistrarContract
|
||||
{
|
||||
/**
|
||||
* Get a validator for an incoming registration request.
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return \Illuminate\Contracts\Validation\Validator
|
||||
*/
|
||||
public function validator(array $data)
|
||||
{
|
||||
return Validator::make($data, [
|
||||
'name' => 'required|max:255',
|
||||
'email' => 'required|email|max:255|unique:users',
|
||||
'password' => 'required|confirmed|min:6',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new user instance after a valid registration.
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return User
|
||||
*/
|
||||
public function create(array $data)
|
||||
{
|
||||
return User::create([
|
||||
'name' => $data['name'],
|
||||
'email' => $data['email'],
|
||||
'password' => bcrypt($data['password']),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -1,256 +0,0 @@
|
||||
$(function() {
|
||||
// Ajax Setup
|
||||
$.ajaxPrefilter(function(options, originalOptions, jqXHR) {
|
||||
var token;
|
||||
if (! options.crossDomain) {
|
||||
token = $('meta[name="token"]').attr('content');
|
||||
if (token) {
|
||||
return jqXHR.setRequestHeader('X-CSRF-Token', token);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$.ajaxSetup({
|
||||
statusCode: {
|
||||
401: function () {
|
||||
window.location.href = '/';
|
||||
},
|
||||
403: function () {
|
||||
window.location.href = '/';
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Prevent double form submission
|
||||
$('form').submit(function() {
|
||||
var $form = $(this);
|
||||
$form.find(':submit').prop('disabled', true);
|
||||
});
|
||||
|
||||
// Mock the DELETE form requests.
|
||||
$('[data-method]').not(".disabled").append(function() {
|
||||
var methodForm = "\n";
|
||||
methodForm += "<form action='" + $(this).attr('href') + "' method='POST' style='display:none'>\n";
|
||||
methodForm += " <input type='hidden' name='_method' value='" + $(this).attr('data-method') + "'>\n";
|
||||
if ($(this).attr('data-token')) {
|
||||
methodForm += "<input type='hidden' name='_token' value='" + $(this).attr('data-token') + "'>\n";
|
||||
}
|
||||
methodForm += "</form>\n";
|
||||
return methodForm;
|
||||
})
|
||||
.removeAttr('href')
|
||||
.attr('onclick', ' if ($(this).hasClass(\'confirm-action\')) { if(confirm("Are you sure you want to do this?")) { $(this).find("form").submit(); } } else { $(this).find("form").submit(); }');
|
||||
|
||||
// Messenger config
|
||||
Messenger.options = {
|
||||
extraClasses: 'messenger-fixed messenger-on-top',
|
||||
theme: 'air'
|
||||
};
|
||||
|
||||
// App setup
|
||||
window.CachetHQ = {};
|
||||
|
||||
moment.locale(Global.locale);
|
||||
|
||||
$('abbr.timeago').each(function () {
|
||||
var $el = $(this);
|
||||
$el
|
||||
.livestamp($el.data('timeago'))
|
||||
.tooltip();
|
||||
});
|
||||
|
||||
window.CachetHQ.Notifier = function () {
|
||||
this.notify = function (message, type, options) {
|
||||
type = (typeof type === 'undefined' || type === 'error') ? 'error' : type;
|
||||
|
||||
var defaultOptions = {
|
||||
message: message,
|
||||
type: type,
|
||||
showCloseButton: true
|
||||
};
|
||||
|
||||
options = _.extend(defaultOptions, options);
|
||||
|
||||
Messenger().post(options);
|
||||
};
|
||||
};
|
||||
|
||||
$(".sidebar-toggler").click(function(e) {
|
||||
e.preventDefault();
|
||||
$(".wrapper").toggleClass("toggled");
|
||||
});
|
||||
|
||||
$('.color-code').minicolors({
|
||||
control: 'hue',
|
||||
defaultValue: $(this).val() || '',
|
||||
inline: false,
|
||||
letterCase: 'lowercase',
|
||||
opacity: false,
|
||||
position: 'bottom left',
|
||||
theme: 'bootstrap'
|
||||
});
|
||||
|
||||
$('[data-toggle="tooltip"]').tooltip();
|
||||
|
||||
$('button.close').on('click', function() {
|
||||
$(this).parents('div.alert').addClass('hide');
|
||||
});
|
||||
|
||||
$('form[name=IncidentForm] select[name=incident\\[component_id\\]]').on('change', function() {
|
||||
var $option = $(this).find('option:selected');
|
||||
var $componentStatus = $('#component-status');
|
||||
|
||||
if ($option.val() !== '') {
|
||||
if ($componentStatus.hasClass('hidden')) {
|
||||
$componentStatus.removeClass('hidden');
|
||||
} else {
|
||||
$componentStatus.addClass('hidden');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Date picker.
|
||||
$('input[rel=datepicker]').datetimepicker({
|
||||
format: "DD/MM/YYYY HH:mm",
|
||||
minDate: new Date(), // Don't allow dates before today.
|
||||
sideBySide: true,
|
||||
icons: {
|
||||
time: 'ion-clock',
|
||||
date: 'ion-android-calendar',
|
||||
up: 'ion-ios-arrow-up',
|
||||
down: 'ion-ios-arrow-down',
|
||||
previous: 'ion-ios-arrow-left',
|
||||
next: 'ion-ios-arrow-right',
|
||||
today: 'ion-android-home',
|
||||
clear: 'ion-trash-a',
|
||||
}
|
||||
});
|
||||
|
||||
// Sortable components.
|
||||
var componentList = document.getElementById("component-list");
|
||||
if (componentList) {
|
||||
new Sortable(componentList, {
|
||||
group: "omega",
|
||||
handle: ".drag-handle",
|
||||
onUpdate: function() {
|
||||
// Loop each component, setting the order input to the new order.
|
||||
var $components = $('#component-list .striped-list-item');
|
||||
$.each($components, function(id) {
|
||||
// Order should start from 1 now.
|
||||
$(this).find('input[rel=order]').val(id + 1);
|
||||
});
|
||||
|
||||
// Now POST the form to the internal API.
|
||||
$.ajax({
|
||||
async: true,
|
||||
url: '/dashboard/api/components/order',
|
||||
type: 'POST',
|
||||
data: $('form[name=componentList]').serializeObject(),
|
||||
success: function() {
|
||||
(new CachetHQ.Notifier()).notify('Components updated.', 'success');
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Toggle inline component statuses.
|
||||
$('form.component-inline').on('click', 'input[type=radio]', function() {
|
||||
var $form = $(this).parents('form');
|
||||
var formData = $form.serializeObject();
|
||||
|
||||
$.ajax({
|
||||
async: true,
|
||||
url: '/dashboard/api/components/' + formData.component_id,
|
||||
type: 'POST',
|
||||
data: formData,
|
||||
success: function(component) {
|
||||
(new CachetHQ.Notifier()).notify($form.data('messenger'), 'success');
|
||||
},
|
||||
error: function(a, b, c) {
|
||||
(new CachetHQ.Notifier()).notify('Something went wrong updating the component.');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Incident management
|
||||
$('select[name=template]').on('change', function() {
|
||||
var $this = $(this).find('option:selected'),
|
||||
slug = $this.val();
|
||||
|
||||
// Only fetch the template if we've picked one.
|
||||
if (slug) {
|
||||
$.ajax({
|
||||
async: true,
|
||||
dataType: 'json',
|
||||
data: {
|
||||
slug: slug
|
||||
},
|
||||
url: '/dashboard/api/incidents/templates',
|
||||
success: function(tpl) {
|
||||
var $form = $('form[role=form]');
|
||||
$form.find('input[name=incident\\[name\\]]').val(tpl.name);
|
||||
$form.find('textarea[name=incident\\[message\\]]').val(tpl.template);
|
||||
},
|
||||
error: function() {
|
||||
(new CachetHQ.Notifier()).notify('There was an error finding that template.');
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Banner removal JS
|
||||
$('#remove-banner').click(function(){
|
||||
$('#banner-view').remove();
|
||||
$('input[name=remove_banner]').val('1');
|
||||
});
|
||||
|
||||
// Setup wizard
|
||||
$('.wizard-next').on('click', function () {
|
||||
var $form = $('#setup-form'),
|
||||
$btn = $(this),
|
||||
current = $btn.data('currentBlock'),
|
||||
next = $btn.data('nextBlock');
|
||||
|
||||
$btn.button('loading');
|
||||
|
||||
// Only validate going forward. If current group is invalid, do not go further
|
||||
if (next > current) {
|
||||
var url = '/setup/step' + current;
|
||||
$.post(url, $form.serializeObject())
|
||||
.done(function(response) {
|
||||
goToStep(current, next);
|
||||
})
|
||||
.fail(function(response) {
|
||||
var errors = _.toArray(response.responseJSON.errors);
|
||||
_.each(errors, function(error) {
|
||||
(new CachetHQ.Notifier()).notify(error);
|
||||
});
|
||||
})
|
||||
.always(function() {
|
||||
$btn.button('reset');
|
||||
});
|
||||
|
||||
return false;
|
||||
} else {
|
||||
goToStep(current, next);
|
||||
$btn.button('reset');
|
||||
}
|
||||
});
|
||||
|
||||
function goToStep(current, next) {
|
||||
// validation was ok. We can go on next step.
|
||||
$('.block-' + current)
|
||||
.removeClass('show')
|
||||
.addClass('hidden');
|
||||
|
||||
$('.block-' + next)
|
||||
.removeClass('hidden')
|
||||
.addClass('show');
|
||||
|
||||
$('.steps .step')
|
||||
.removeClass("active")
|
||||
.filter(":lt(" + (next) + ")")
|
||||
.addClass("active");
|
||||
}
|
||||
});
|
||||
@@ -1,24 +0,0 @@
|
||||
body.error-page {
|
||||
background-color: #f3f3f4;
|
||||
|
||||
.middle-box {
|
||||
height: 400px;
|
||||
width: 400px;
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
margin-top: -250px;
|
||||
margin-left: -200px;
|
||||
z-index: 100;
|
||||
|
||||
h1 {
|
||||
font-size: 9em;
|
||||
}
|
||||
}
|
||||
|
||||
h3 {
|
||||
&.font-bold {
|
||||
font-weight: 600;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
.uppercase {
|
||||
text-transform: uppercase;
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
// Theme colours.
|
||||
$cachet-base-light: #fff;
|
||||
$cachet-base-medium: #f0f3f4;
|
||||
$cachet-base-dark: #333;
|
||||
|
||||
$cachet-primary: #7ED321;
|
||||
$cachet-secondary: #6DB81C;
|
||||
|
||||
$cachet-link: #7ed321;
|
||||
$cachet-link-hover: #01579b;
|
||||
|
||||
$cachet-gray-light: #e8e8e8;
|
||||
$cachet-gray: #999;
|
||||
$cachet-gray-darker: #666;
|
||||
|
||||
$cachet-icons: #5e5e5e;
|
||||
|
||||
// Statuses
|
||||
$cachet-green: $cachet-primary;
|
||||
$cachet-dark-green: darken($cachet-green, 10%);
|
||||
|
||||
$cachet-blue: #3498db;
|
||||
$cachet-dark-blue: darken($cachet-blue, 10%);
|
||||
|
||||
$cachet-red: #ff6f6f;
|
||||
$cachet-dark-red: darken($cachet-red, 10%);
|
||||
|
||||
$cachet-teal: #0dccc0;
|
||||
$cachet-dark-teal: darken($cachet-teal, 10%);
|
||||
|
||||
$cachet-yellow: #F7CA18;
|
||||
$cachet-dark-yellow: darken($cachet-yellow, 10%);
|
||||
|
||||
$cachet-pink: #b23f73;
|
||||
$cachet-dark-pink: darken($cachet-pink, 10%);
|
||||
|
||||
$cachet-grey: #ecf0f1;
|
||||
$cachet-dark-grey: darken($cachet-grey, 10%);
|
||||
|
||||
$cachet-orange: #FF8800;
|
||||
$dark-orange: darken($cachet-orange, 10%);
|
||||
@@ -1,297 +0,0 @@
|
||||
body.status-page {
|
||||
font-family: 'Open Sans', 'Helevetic Neue', Arial, sans-serif;
|
||||
background-color: #F0F3F4;
|
||||
color: #333333;
|
||||
font-size: 1.4em;
|
||||
font-weight: $base-font-weight;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
|
||||
hr {
|
||||
margin-top: 10px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
h1, h2, h3, h4, h5 {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.tooltip {
|
||||
.tooltip-inner {
|
||||
padding: 8px 12px;
|
||||
font-size: 14px;
|
||||
}
|
||||
}
|
||||
|
||||
.help-icon {
|
||||
cursor: help;
|
||||
}
|
||||
|
||||
.text-success, .text-component-1 {
|
||||
color: $cachet_green;
|
||||
}
|
||||
|
||||
.text-info, .text-component-2 {
|
||||
color: $cachet_blue;
|
||||
}
|
||||
|
||||
.text-alert, .text-component-3 {
|
||||
color: $cachet_yellow;
|
||||
}
|
||||
|
||||
.text-danger, .text-component-4 {
|
||||
color: $cachet_red;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 960px;
|
||||
margin-bottom: 40px;
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.page-header {
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.app-banner {
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
.about-app {
|
||||
margin-top: 40px;
|
||||
margin-bottom: 40px;
|
||||
p {
|
||||
font-size: 1.2em;
|
||||
}
|
||||
}
|
||||
|
||||
.alert {
|
||||
border-radius: 0;
|
||||
font-size: 1.2em;
|
||||
&.alert-success {
|
||||
background-color: $cachet_green;
|
||||
border-color: $cachet_dark-green;
|
||||
color: white;
|
||||
}
|
||||
|
||||
&.alert-info {
|
||||
background: $cachet_blue;
|
||||
border-color: $cachet_dark-blue;
|
||||
color: #FFF;
|
||||
}
|
||||
|
||||
&.alert-danger {
|
||||
background: $cachet_red;
|
||||
border-color: $cachet_dark-red;
|
||||
color: #FFF;
|
||||
}
|
||||
}
|
||||
|
||||
.timeline {
|
||||
.content-wrapper {
|
||||
margin-top: 40px;
|
||||
margin-bottom: 40px;
|
||||
}
|
||||
h3 {
|
||||
margin-top: 30px;
|
||||
margin-bottom: 40px;
|
||||
font-size: 22px;
|
||||
small {
|
||||
margin-left: 15px;
|
||||
}
|
||||
}
|
||||
|
||||
.panel {
|
||||
.panel-body {
|
||||
h1 {
|
||||
margin-top: 0;
|
||||
margin-bottom: 4px;
|
||||
font-size: 2em;
|
||||
}
|
||||
h2 {
|
||||
margin-top: 0;
|
||||
margin-bottom: 4px;
|
||||
font-size: 1.8em;
|
||||
}
|
||||
h3 {
|
||||
margin-top: 0;
|
||||
margin-bottom: 4px;
|
||||
font-size: 1.6em;
|
||||
}
|
||||
h4 {
|
||||
margin-top: 0;
|
||||
margin-bottom: 4px;
|
||||
font-size: 1.4em;
|
||||
}
|
||||
h5 {
|
||||
margin-top: 0;
|
||||
margin-bottom: 4px;
|
||||
font-size: 1.2em;
|
||||
}
|
||||
p {
|
||||
margin: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.moment {
|
||||
width: 100%;
|
||||
padding-bottom: 10px;
|
||||
position: relative;
|
||||
&.first {
|
||||
&:before {
|
||||
height: 130%;
|
||||
top: -20px;
|
||||
}
|
||||
&:after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
left: 23px;
|
||||
top: -20px;
|
||||
width: 7px;
|
||||
height: 7px;
|
||||
background: $cachet_gray_light;
|
||||
border-radius: 50%;
|
||||
}
|
||||
}
|
||||
&:before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
left: 26px;
|
||||
top: 5px;
|
||||
width: 2px;
|
||||
height: 100%;
|
||||
background: #7266BA;
|
||||
}
|
||||
.status-icon {
|
||||
background: #fff;
|
||||
width: 35px;
|
||||
height: 35px;
|
||||
border-radius: 50%;
|
||||
border: 1px solid #e8e8e8;
|
||||
position: absolute;
|
||||
left: 25px;
|
||||
top: 14px;
|
||||
.icon {
|
||||
position: absolute;
|
||||
top: 7px;
|
||||
left: 11px;
|
||||
|
||||
&.ion-alert {
|
||||
left: 15px;
|
||||
}
|
||||
}
|
||||
&.status-0 {
|
||||
color: $cachet_pink;
|
||||
}
|
||||
&.status-1 {
|
||||
color: $cachet_orange;
|
||||
}
|
||||
&.status-2 {
|
||||
color: $cachet_yellow;
|
||||
}
|
||||
&.status-3 {
|
||||
color: $cachet_blue;
|
||||
}
|
||||
&.status-4 {
|
||||
color: $cachet_green;
|
||||
}
|
||||
}
|
||||
&.last:before {
|
||||
background: #fff;
|
||||
}
|
||||
.panel {
|
||||
margin: 0;
|
||||
border-radius: 2px;
|
||||
|
||||
&.panel-message {
|
||||
border: 1px solid #e8e8e8;
|
||||
.date {
|
||||
color: darken(#c7c7c7, 20%);
|
||||
}
|
||||
|
||||
&:before {
|
||||
position: absolute;
|
||||
top: 16px;
|
||||
left: 1px;
|
||||
display: inline-block;
|
||||
border-top: 15px solid transparent;
|
||||
border-left: 0 solid #e8e8e8;
|
||||
border-right: 15px solid #e8e8e8;
|
||||
border-bottom: 15px solid transparent;
|
||||
content: " ";
|
||||
}
|
||||
|
||||
&:after {
|
||||
position: absolute;
|
||||
top: 17px;
|
||||
left: 2px;
|
||||
display: inline-block;
|
||||
border-top: 14px solid transparent;
|
||||
border-left: 0 solid #fff;
|
||||
border-right: 14px solid #fff;
|
||||
border-bottom: 14px solid transparent;
|
||||
content: " ";
|
||||
}
|
||||
}
|
||||
|
||||
.panel-body {
|
||||
border-top: 1px solid #eee;
|
||||
p {
|
||||
margin: 0;
|
||||
font-size: 1em;
|
||||
// font-weight: normal;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@media (max-width: 767px) {
|
||||
.timeline .moment .content {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.list-group {
|
||||
margin-bottom: 20px;
|
||||
padding-left: 0;
|
||||
border-radius: 0;
|
||||
|
||||
.list-group-item {
|
||||
border-radius: 0;
|
||||
background-color: #ffffff;
|
||||
border: 1px solid $cachet_gray_light;
|
||||
font-size: 1.1em;
|
||||
padding: 15px 15px;
|
||||
|
||||
h4 {
|
||||
margin: 0;
|
||||
font-weight: 400;
|
||||
max-width: 90%;
|
||||
}
|
||||
|
||||
p, time {
|
||||
margin-bottom: 0;
|
||||
line-height: 1.3em;
|
||||
}
|
||||
}
|
||||
|
||||
&.components {
|
||||
margin-bottom: 30px;
|
||||
p {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
.badge {
|
||||
color: transparent;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
footer.footer {
|
||||
padding-top: 40px;
|
||||
padding-bottom: 40px;
|
||||
color: #777;
|
||||
text-align: center;
|
||||
border-top: 1px solid $cachet_gray_light;
|
||||
background-color: lighten($cachet_gray_light, 5%);
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
@import "palette";
|
||||
|
||||
$ionicons-font-path: "../../../fonts" !default;
|
||||
@import "../bower_components/ionicons/scss/ionicons";
|
||||
|
||||
@import "modules/bootstrap";
|
||||
|
||||
html, body {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
@import "helpers";
|
||||
|
||||
// Module overrides
|
||||
@import "modules/tabs";
|
||||
@import "modules/forms";
|
||||
@import "modules/well";
|
||||
|
||||
// Styles for partials
|
||||
@import "partials/base";
|
||||
@import "partials/wrapper";
|
||||
@import "partials/navbar";
|
||||
@import "partials/sidebar";
|
||||
@import "partials/content";
|
||||
@import "partials/modals";
|
||||
|
||||
// Styles for specific page
|
||||
@import "pages/login";
|
||||
@import "pages/setup";
|
||||
@import "pages/dashboard";
|
||||
|
||||
// Styles for plugins
|
||||
@import "plugins/messenger";
|
||||
@import "plugins/animate";
|
||||
@import "plugins/bootstrap-datetimepicker/bootstrap-datetimepicker";
|
||||
|
||||
// Status Page will need to override certain styles.
|
||||
@import "status-page";
|
||||
|
||||
// Error pages can have their own overrides.
|
||||
@import "errors";
|
||||
@@ -1,52 +0,0 @@
|
||||
// Bootstrap variable overrides and custom variables
|
||||
@import "variables";
|
||||
|
||||
// Core variables and mixins
|
||||
@import "../../bower_components/bootstrap-sass/assets/stylesheets/bootstrap/variables";
|
||||
@import "../../bower_components/bootstrap-sass/assets/stylesheets/bootstrap/mixins";
|
||||
|
||||
// Reset and dependencies
|
||||
@import "../../bower_components/bootstrap-sass/assets/stylesheets/bootstrap/normalize";
|
||||
@import "../../bower_components/bootstrap-sass/assets/stylesheets/bootstrap/print";
|
||||
|
||||
// Core CSS
|
||||
@import "../../bower_components/bootstrap-sass/assets/stylesheets/bootstrap/scaffolding";
|
||||
@import "../../bower_components/bootstrap-sass/assets/stylesheets/bootstrap/type";
|
||||
@import "../../bower_components/bootstrap-sass/assets/stylesheets/bootstrap/code";
|
||||
@import "../../bower_components/bootstrap-sass/assets/stylesheets/bootstrap/grid";
|
||||
@import "../../bower_components/bootstrap-sass/assets/stylesheets/bootstrap/tables";
|
||||
@import "../../bower_components/bootstrap-sass/assets/stylesheets/bootstrap/forms";
|
||||
@import "../../bower_components/bootstrap-sass/assets/stylesheets/bootstrap/buttons";
|
||||
|
||||
// Components
|
||||
@import "../../bower_components/bootstrap-sass/assets/stylesheets/bootstrap/component-animations";
|
||||
@import "../../bower_components/bootstrap-sass/assets/stylesheets/bootstrap/dropdowns";
|
||||
@import "../../bower_components/bootstrap-sass/assets/stylesheets/bootstrap/button-groups";
|
||||
@import "../../bower_components/bootstrap-sass/assets/stylesheets/bootstrap/input-groups";
|
||||
@import "../../bower_components/bootstrap-sass/assets/stylesheets/bootstrap/navs";
|
||||
@import "../../bower_components/bootstrap-sass/assets/stylesheets/bootstrap/navbar";
|
||||
@import "../../bower_components/bootstrap-sass/assets/stylesheets/bootstrap/breadcrumbs";
|
||||
@import "../../bower_components/bootstrap-sass/assets/stylesheets/bootstrap/pagination";
|
||||
@import "../../bower_components/bootstrap-sass/assets/stylesheets/bootstrap/pager";
|
||||
@import "../../bower_components/bootstrap-sass/assets/stylesheets/bootstrap/labels";
|
||||
@import "../../bower_components/bootstrap-sass/assets/stylesheets/bootstrap/badges";
|
||||
@import "../../bower_components/bootstrap-sass/assets/stylesheets/bootstrap/jumbotron";
|
||||
@import "../../bower_components/bootstrap-sass/assets/stylesheets/bootstrap/thumbnails";
|
||||
@import "../../bower_components/bootstrap-sass/assets/stylesheets/bootstrap/alerts";
|
||||
@import "../../bower_components/bootstrap-sass/assets/stylesheets/bootstrap/progress-bars";
|
||||
@import "../../bower_components/bootstrap-sass/assets/stylesheets/bootstrap/media";
|
||||
@import "../../bower_components/bootstrap-sass/assets/stylesheets/bootstrap/list-group";
|
||||
@import "../../bower_components/bootstrap-sass/assets/stylesheets/bootstrap/panels";
|
||||
@import "../../bower_components/bootstrap-sass/assets/stylesheets/bootstrap/responsive-embed";
|
||||
@import "../../bower_components/bootstrap-sass/assets/stylesheets/bootstrap/wells";
|
||||
@import "../../bower_components/bootstrap-sass/assets/stylesheets/bootstrap/close";
|
||||
|
||||
// Components w/ JavaScript
|
||||
@import "../../bower_components/bootstrap-sass/assets/stylesheets/bootstrap/modals";
|
||||
@import "../../bower_components/bootstrap-sass/assets/stylesheets/bootstrap/tooltip";
|
||||
@import "../../bower_components/bootstrap-sass/assets/stylesheets/bootstrap/popovers";
|
||||
@import "../../bower_components/bootstrap-sass/assets/stylesheets/bootstrap/carousel";
|
||||
|
||||
// Utility classes
|
||||
@import "../../bower_components/bootstrap-sass/assets/stylesheets/bootstrap/utilities";
|
||||
@import "../../bower_components/bootstrap-sass/assets/stylesheets/bootstrap/responsive-utilities";
|
||||
@@ -1,55 +0,0 @@
|
||||
label {
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
textarea {
|
||||
resize: none;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
.markdown-control {
|
||||
position: relative;
|
||||
|
||||
&:before {
|
||||
position:absolute;
|
||||
display:block;
|
||||
right:0%;
|
||||
bottom:0%;
|
||||
width:40px;
|
||||
height:40px;
|
||||
font-size: 2em;
|
||||
font-family: "Ionicons";
|
||||
content: "\f4e6";
|
||||
}
|
||||
}
|
||||
|
||||
.form-control {
|
||||
display: block;
|
||||
width: 100%;
|
||||
height: 34px;
|
||||
padding: 6px 12px;
|
||||
font-size: 14px;
|
||||
line-height: 1.42857143;
|
||||
color: #555;
|
||||
background-color: #fff;
|
||||
background-image: none;
|
||||
border: 1px solid #ccc;
|
||||
@include box-shadow(none !important);
|
||||
@include transition(border-color ease-in-out .15s, box-shadow ease-in-out .15s);
|
||||
|
||||
&:focus {
|
||||
border-color: #66afe9;
|
||||
}
|
||||
}
|
||||
|
||||
.component-inline {
|
||||
@media (max-width: $screen-xs-max) {
|
||||
.radio-items {
|
||||
text-align: left;
|
||||
.radio-inline {
|
||||
margin-left: 0;
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user