├── .env.example ├── .gitattributes ├── .gitignore ├── README.md ├── app ├── Console │ └── Kernel.php ├── Conversations │ ├── SiteDestroyConversation.php │ └── StartConversation.php ├── Exceptions │ ├── Handler.php │ ├── InvalidUrlException.php │ ├── SiteNotFoundException.php │ └── WebhookException.php ├── Helpers │ └── Str.php ├── Http │ ├── Controllers │ │ ├── Auth │ │ │ ├── ForgotPasswordController.php │ │ │ ├── LoginController.php │ │ │ ├── RegisterController.php │ │ │ └── ResetPasswordController.php │ │ ├── BotManController.php │ │ ├── BrokenLinks │ │ │ └── ShowController.php │ │ ├── Controller.php │ │ ├── Downtime │ │ │ └── ShowController.php │ │ ├── Help │ │ │ └── ShowController.php │ │ ├── MixedContent │ │ │ └── ShowController.php │ │ ├── Sites │ │ │ ├── DestroyController.php │ │ │ ├── IndexController.php │ │ │ ├── ShowController.php │ │ │ └── StoreController.php │ │ ├── Token │ │ │ └── StoreController.php │ │ ├── Uptime │ │ │ └── ShowController.php │ │ ├── Users │ │ │ └── StoreController.php │ │ ├── Webhook │ │ │ └── StoreController.php │ │ └── WebhookReceivedController.php │ ├── Kernel.php │ └── Middleware │ │ ├── EncryptCookies.php │ │ ├── LoadUserMiddleware.php │ │ ├── RedirectIfAuthenticated.php │ │ ├── TrimStrings.php │ │ ├── TrustProxies.php │ │ └── VerifyCsrfToken.php ├── Jobs │ └── Webhook │ │ ├── BrokenLinksFound.php │ │ └── UptimeCheckFailed.php ├── Models │ └── User.php ├── OhDear │ ├── BrokenLink.php │ ├── Check.php │ ├── Downtime.php │ ├── MixedContent.php │ ├── Services │ │ └── OhDear.php │ ├── Site.php │ └── Uptime.php └── Providers │ ├── AppServiceProvider.php │ ├── AuthServiceProvider.php │ ├── BotMan │ └── DriverServiceProvider.php │ ├── BroadcastServiceProvider.php │ ├── EventServiceProvider.php │ └── RouteServiceProvider.php ├── artisan ├── bootstrap ├── app.php └── cache │ └── .gitignore ├── composer.json ├── composer.lock ├── config ├── app.php ├── auth.php ├── botman │ ├── config.php │ ├── telegram.php │ └── web.php ├── broadcasting.php ├── cache.php ├── database.php ├── filesystems.php ├── hashing.php ├── logging.php ├── mail.php ├── queue.php ├── services.php ├── session.php └── view.php ├── database ├── .gitignore ├── factories │ └── UserFactory.php ├── migrations │ ├── 2014_10_12_000000_create_users_table.php │ └── 2014_10_12_100000_create_password_resets_table.php └── seeds │ └── DatabaseSeeder.php ├── package.json ├── phpunit.xml ├── public ├── .htaccess ├── css │ └── app.css ├── favicon.ico ├── img │ └── ohdear_avatar.png ├── index.php ├── js │ └── app.js ├── logo.png └── robots.txt ├── resources ├── assets │ ├── js │ │ ├── app.js │ │ └── bootstrap.js │ └── sass │ │ ├── _variables.scss │ │ └── app.scss ├── lang │ └── en │ │ ├── auth.php │ │ ├── ohdear.php │ │ ├── pagination.php │ │ ├── passwords.php │ │ └── validation.php ├── markdown │ └── help.md └── views │ ├── tinker.blade.php │ └── welcome.blade.php ├── routes ├── api.php ├── botman.php ├── channels.php ├── console.php └── web.php ├── server.php ├── storage ├── app │ ├── .gitignore │ └── public │ │ └── .gitignore ├── framework │ ├── .gitignore │ ├── cache │ │ └── .gitignore │ ├── sessions │ │ └── .gitignore │ ├── testing │ │ └── .gitignore │ └── views │ │ └── .gitignore └── logs │ └── .gitignore ├── tests ├── CreatesApplication.php ├── Fakes │ ├── OhDear.php │ ├── OhDearEmpty.php │ └── responses │ │ ├── downtimes.php │ │ ├── sites_list.json │ │ └── uptimes.php ├── Feature │ ├── BrokenLinksTest.php │ ├── DowntimeTest.php │ ├── HelpTest.php │ ├── MixedContentTest.php │ ├── SitesTest.php │ ├── StartConversationTest.php │ ├── TokenTest.php │ ├── UptimeTest.php │ ├── WebhookReceivedTest.php │ └── WebhookTest.php └── TestCase.php ├── webpack.mix.js └── yarn.lock /.env.example: -------------------------------------------------------------------------------- 1 | APP_NAME=Laravel 2 | APP_ENV=local 3 | APP_KEY= 4 | APP_DEBUG=true 5 | APP_URL=http://localhost 6 | 7 | LOG_CHANNEL=stack 8 | 9 | DB_CONNECTION=mysql 10 | DB_HOST=127.0.0.1 11 | DB_PORT=3306 12 | DB_DATABASE=homestead 13 | DB_USERNAME=homestead 14 | DB_PASSWORD=secret 15 | 16 | BROADCAST_DRIVER=log 17 | CACHE_DRIVER=file 18 | SESSION_DRIVER=file 19 | SESSION_LIFETIME=120 20 | QUEUE_DRIVER=sync 21 | 22 | REDIS_HOST=127.0.0.1 23 | REDIS_PASSWORD=null 24 | REDIS_PORT=6379 25 | 26 | MAIL_DRIVER=smtp 27 | MAIL_HOST=smtp.mailtrap.io 28 | MAIL_PORT=2525 29 | MAIL_USERNAME=null 30 | MAIL_PASSWORD=null 31 | MAIL_ENCRYPTION=null 32 | 33 | PUSHER_APP_ID= 34 | PUSHER_APP_KEY= 35 | PUSHER_APP_SECRET= 36 | PUSHER_APP_CLUSTER=mt1 37 | 38 | MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}" 39 | MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" 40 | 41 | TELEGRAM_TOKEN= -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | *.css linguist-vendored 3 | *.scss linguist-vendored 4 | *.js linguist-vendored 5 | CHANGELOG.md export-ignore 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | /public/hot 3 | /public/storage 4 | /storage/*.key 5 | /vendor 6 | /.idea 7 | /.vagrant 8 | /.discovery 9 | Homestead.json 10 | Homestead.yaml 11 | npm-debug.log 12 | .env 13 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 |

Mr. Dear

4 | 5 | I'm here to help you manage your sites on [Oh Dear! App](https://ohdear.app) by chat. Also I can text you if something is going wrong (Let's hope it'll be no need to 😉) 6 | 7 | ## Interacting with the bot 8 | 9 | ### Commands 10 | 11 | - `/sites` - I'll show you a list with your current sites and their most recent status result. 12 | - `/newsite {url}` - We will begin a delightful conversation in order to add a new site to your collection. 13 | - `/deletesite {url or id}` - I get it, you don't want to see that site anymore, but first we will confirm you really want to do this. 14 | - `/site {url or id}` - I'll be glad to show you all the information regarding to a specific site. 15 | - `/downtime {url or id}` - Let's see how many times your site was down for the last month. 16 | - `/uptime {url or id}` - I'll tell you the percentage your site was up on the last month. 17 | - `/brokenlinks {url or id}` - Check out your website's broken links in a second. 18 | - `/mixedcontent {url or id}` - Check out your website's mixed content. 19 | 20 | ### Action Buttons 21 | 22 | Since the moment you ask me about your sites (`/sites`) I'll show you the name of your sites along with 23 | an indicator to see quickly if it's online (✅ or 🔴) in form of a button. You can click it to see more 24 | information about your site and another group of buttons to check other common actions like Broken Links, 25 | Downtime, etc... 26 | 27 | ### Webhooks 28 | 29 | During the `/start` process, the bot will ask you for your API token in order to interact with your sites, but also 30 | your `webhook signing secret`. This information can be found at the end of the [Notifications page](https://ohdear.app/team-settings/notifications). 31 | 32 | With this key configured, the bot can warn you if there's any problem with your site. Currently notifications supported are: 33 | - Uptime Check Failed 34 | - Broken Links Found 35 | 36 | ## Installation 37 | 38 | This bot is currently functional at [MrDear_bot](http://t.me/MrDear_bot) on Telegram, so you don't have to do anything to 39 | get up and running. 40 | 41 | However, there's a chance you want to host it yourself. If that's your case, just follow the few steps described below. 42 | 43 | ``` 44 | composer install 45 | php artisan migrate 46 | cp .env.example .env 47 | ``` 48 | ### Registering the bot 49 | 50 | After that, you will need to [create your own Telegram Bot](https://core.telegram.org/bots#3-how-do-i-create-a-bot). 51 | 52 | Once you have obtained the access token, place it in your `.env` file like `TELEGRAM_TOKEN=token`. 53 | 54 | Telegram needs to send the incoming messages to your bot. In order to configure that, you can use the following command 55 | 56 | ``` 57 | php artisan botman:telegram:register 58 | ``` 59 | 60 | The default url will be `yourdomain.com/botman`. It must be `HTTPS` 61 | 62 | > If you're developing in a local environment, take in mind using [Laravel Valet](https://laravel.com/docs/5.7/valet) feature `valet share`. It uses ngrok 63 | > under the hood to make your project accessible from the outside. 64 | 65 | That's it. You can now talk to your bot through Telegram. 66 | 67 | ### Troubleshooting 68 | 69 | If your is not running as you've expected you have a few tools to help you see what's going on: 70 | 71 | - If you're using `valet share` for local development you already have a custom dashboard to check incoming requests at http://127.0.0.1:4040 by ngrok. 72 | - To see the full error, check the `storage/logs/laravel.log` file. Take in mind that Telegram re-sends a failed request up to 4 more times. 73 | - To debug the application, you can use [Beyond Code](https://github.com/beyondcode) package called `laravel-dump-server`. It's already installed 74 | in this project, you just need to run `php artisan dump-server` and put some `dump($var)` in your code to see it in the terminal. 75 | ## Security Vulnerabilities 76 | 77 | If you discover a security vulnerability within this bot, please send an e-mail to David Llop at d.lloople@icloud.com. All security vulnerabilities will be promptly addressed. 78 | 79 | ## License 80 | 81 | Mr. Dear is free software distributed under the terms of the MIT license. -------------------------------------------------------------------------------- /app/Console/Kernel.php: -------------------------------------------------------------------------------- 1 | command('inspire') 28 | // ->hourly(); 29 | } 30 | 31 | /** 32 | * Register the commands for the application. 33 | * 34 | * @return void 35 | */ 36 | protected function commands() 37 | { 38 | $this->load(__DIR__.'/Commands'); 39 | 40 | require base_path('routes/console.php'); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /app/Conversations/SiteDestroyConversation.php: -------------------------------------------------------------------------------- 1 | dear = $dear; 24 | $this->site = $site; 25 | } 26 | 27 | public function run() 28 | { 29 | $this->askFirstConfirmation(); 30 | } 31 | 32 | public function askFirstConfirmation() 33 | { 34 | $this->ask($this->getQuestion(trans('ohdear.sites.delete_confirm_1')), function (Answer $answer) { 35 | 36 | $nextStep = $answer->isInteractiveMessageReply() 37 | ? $answer->getValue() 38 | : $this->answerToBoolean($answer->getText()); 39 | 40 | if (! $nextStep) { 41 | $this->bot->reply(trans('ohdear.sites.delete_cancel')); 42 | 43 | return; 44 | } 45 | 46 | $this->askSecondConfirmation(); 47 | 48 | }); 49 | } 50 | 51 | private function getQuestion(string $message): Question 52 | { 53 | return Question::create($message) 54 | ->fallback('Unable to delete the site, please try again later.') 55 | ->addButtons([ 56 | Button::create('Yes')->value(true), 57 | Button::create('No')->value(false), 58 | ]); 59 | } 60 | 61 | public function askSecondConfirmation() 62 | { 63 | $this->ask($this->getQuestion(trans('ohdear.sites.delete_confirm_2')), function (Answer $answer) { 64 | 65 | $nextStep = $answer->isInteractiveMessageReply() 66 | ? $answer->getValue() 67 | : $this->answerToBoolean($answer->getText()); 68 | 69 | if (! $nextStep) { 70 | $this->bot->reply(trans('ohdear.sites.delete_cancel')); 71 | 72 | return; 73 | } 74 | 75 | $this->site->delete(); 76 | 77 | $this->bot->reply(trans('ohdear.sites.deleted')); 78 | }); 79 | } 80 | 81 | public function answerToBoolean(string $answer) 82 | { 83 | $positiveMessages = ['true', 'yes', 'of course', 'yeah', 'affirmative', 'i confirm']; 84 | 85 | return in_array(strtolower($answer), $positiveMessages); 86 | } 87 | 88 | } -------------------------------------------------------------------------------- /app/Conversations/StartConversation.php: -------------------------------------------------------------------------------- 1 | bot->reply(trans('ohdear.greetings')); 13 | 14 | if (! auth()->user()->token) { 15 | $this->askToken(); 16 | } else { 17 | $this->bot->reply(trans('ohdear.already_set_up')); 18 | } 19 | } 20 | 21 | public function askToken() 22 | { 23 | $this->ask(trans('ohdear.token.question'), function (Answer $answer) { 24 | 25 | auth()->user()->token = encrypt($answer->getText()); 26 | auth()->user()->save(); 27 | 28 | $this->bot->reply(trans('ohdear.token.stored')); 29 | 30 | $this->askWebhook(); 31 | }); 32 | } 33 | 34 | public function askWebhook() 35 | { 36 | $this->ask(trans('ohdear.webhook.question'), function (Answer $answer) { 37 | 38 | auth()->user()->webhook = encrypt($answer->getText()); 39 | auth()->user()->save(); 40 | 41 | $this->bot->reply( 42 | trans('ohdear.webhook.stored', ['url' => auth()->user()->getWebhookUrl()]), 43 | ['parse_mode' => 'Markdown'] 44 | ); 45 | }, ['parse_mode' => 'Markdown']); 46 | } 47 | 48 | } -------------------------------------------------------------------------------- /app/Exceptions/Handler.php: -------------------------------------------------------------------------------- 1 | reply(trans('ohdear.sites.not_found')); 18 | 19 | return response('Site not found'); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /app/Exceptions/WebhookException.php: -------------------------------------------------------------------------------- 1 | $this->getMessage()], 400); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /app/Helpers/Str.php: -------------------------------------------------------------------------------- 1 | 'year', 12 | 2592000 => 'month', 13 | 604800 => 'week', 14 | 86400 => 'day', 15 | 3600 => 'hour', 16 | 60 => 'minute', 17 | 1 => 'second', 18 | ]; 19 | 20 | public static function validate_url($url) 21 | { 22 | $regex = '/(https?:\/\/www\.|https?:\/\/)[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?/'; 23 | 24 | return preg_match($regex, $url) === 1; 25 | } 26 | 27 | public static function replace_last($search, $replace, $subject) 28 | { 29 | $pos = strrpos($subject, $search); 30 | 31 | if ($pos === false) { 32 | return $subject; 33 | } 34 | 35 | return substr_replace($subject, $replace, $pos, strlen($search)); 36 | 37 | } 38 | 39 | public static function plural(string $word, int $count) 40 | { 41 | if ($count > 1) { 42 | $word .= 's'; 43 | } 44 | 45 | return $word; 46 | } 47 | 48 | public static function elapsed_time_greatest($date) 49 | { 50 | foreach (self::PERIOD_INTERVALS as $interval) { 51 | $elapsedTime = $date->{'diffIn' . ucfirst($interval).'s'}(); 52 | 53 | if ($elapsedTime) { 54 | return $elapsedTime . ' ' . self::plural($interval, $elapsedTime); 55 | } 56 | } 57 | } 58 | 59 | public static function elapsed_time(Carbon $begin, Carbon $end) 60 | { 61 | $diff = $end->getTimestamp() - $begin->getTimestamp(); 62 | 63 | $diff = $diff < 1 ? 1 : $diff; 64 | 65 | $string = ''; 66 | $separator = ''; 67 | 68 | foreach (self::PERIOD_INTERVALS as $unit => $interval) { 69 | if ($diff < $unit) { 70 | continue; 71 | } 72 | 73 | $elapsedInterval = floor($diff / $unit); 74 | 75 | $string .= $separator . $elapsedInterval . ' ' . self::plural($interval, $elapsedInterval); 76 | 77 | $diff -= $elapsedInterval * $unit; 78 | 79 | $separator = ', '; 80 | } 81 | 82 | return self::replace_last(',', ' and', $string); 83 | } 84 | } -------------------------------------------------------------------------------- /app/Http/Controllers/Auth/ForgotPasswordController.php: -------------------------------------------------------------------------------- 1 | middleware('guest'); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /app/Http/Controllers/Auth/LoginController.php: -------------------------------------------------------------------------------- 1 | middleware('guest')->except('logout'); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /app/Http/Controllers/Auth/RegisterController.php: -------------------------------------------------------------------------------- 1 | middleware('guest'); 40 | } 41 | 42 | /** 43 | * Get a validator for an incoming registration request. 44 | * 45 | * @param array $data 46 | * @return \Illuminate\Contracts\Validation\Validator 47 | */ 48 | protected function validator(array $data) 49 | { 50 | return Validator::make($data, [ 51 | 'name' => 'required|string|max:255', 52 | 'email' => 'required|string|email|max:255|unique:users', 53 | 'password' => 'required|string|min:6|confirmed', 54 | ]); 55 | } 56 | 57 | /** 58 | * Create a new user instance after a valid registration. 59 | * 60 | * @param array $data 61 | * @return User 62 | */ 63 | protected function create(array $data) 64 | { 65 | return User::create([ 66 | 'name' => $data['name'], 67 | 'email' => $data['email'], 68 | 'password' => bcrypt($data['password']), 69 | ]); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /app/Http/Controllers/Auth/ResetPasswordController.php: -------------------------------------------------------------------------------- 1 | middleware('guest'); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /app/Http/Controllers/BotManController.php: -------------------------------------------------------------------------------- 1 | listen(); 15 | } 16 | 17 | /** 18 | * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View 19 | */ 20 | public function tinker() 21 | { 22 | return view('tinker'); 23 | } 24 | 25 | } -------------------------------------------------------------------------------- /app/Http/Controllers/BrokenLinks/ShowController.php: -------------------------------------------------------------------------------- 1 | dear = $dear; 20 | } 21 | 22 | /** 23 | * Handle the incoming request. 24 | * 25 | * @param \BotMan\BotMan\BotMan $bot 26 | * @param string $url 27 | * 28 | * @return void 29 | * @throws \App\Exceptions\SiteNotFoundException 30 | */ 31 | public function __invoke(BotMan $bot, string $url) 32 | { 33 | $bot->types(); 34 | 35 | $site = $this->dear->findSite($url); 36 | 37 | $links = $this->dear->getBrokenLinks($site->id); 38 | 39 | if ($links->isEmpty()) { 40 | $bot->reply(trans('ohdear.brokenlinks.perfect')); 41 | 42 | } else { 43 | 44 | $links->each(function (BrokenLink $link) use ($bot) { 45 | $bot->reply(trans('ohdear.brokenlinks.result', [ 46 | 'url' => $link->crawledUrl, 47 | 'code' => $link->statusCode, 48 | 'origin' => $link->foundOnUrl 49 | ]), ['disable_web_page_preview' => true]); 50 | }); 51 | } 52 | 53 | $bot->reply($site->getKeyboard()); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /app/Http/Controllers/Controller.php: -------------------------------------------------------------------------------- 1 | dear = $dear; 19 | } 20 | 21 | /** 22 | * Handle the incoming request. 23 | * 24 | * @param \BotMan\BotMan\BotMan $bot 25 | * @param string $url 26 | * 27 | * @return void 28 | * @throws \App\Exceptions\SiteNotFoundException 29 | */ 30 | public function __invoke(BotMan $bot, string $url) 31 | { 32 | $bot->types(); 33 | 34 | $site = $this->dear->findSite($url); 35 | 36 | $downtime = $this->dear->getSiteDowntime($site->id); 37 | 38 | if ($downtime->isEmpty()) { 39 | $bot->reply(trans('ohdear.downtime.perfect')); 40 | } else { 41 | 42 | $bot->reply(trans('ohdear.downtime.summary', [ 43 | 'elapsed' => $downtime->first()->elapsed, 44 | 'emoji' => $downtime->first()->getElapsedEmoji(), 45 | ])); 46 | 47 | $downtime->each(function (Downtime $downtime) use ($bot) { 48 | 49 | $bot->reply(trans('ohdear.downtime.result', [ 50 | 'downtime' => $downtime->getDowntime(), 51 | 'date' => $downtime->startedAt, 52 | ])); 53 | }); 54 | } 55 | 56 | $bot->reply($site->getKeyboard()); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /app/Http/Controllers/Help/ShowController.php: -------------------------------------------------------------------------------- 1 | types(); 21 | 22 | $bot->reply(trans('ohdear.help.title')); 23 | 24 | $bot->typesAndWaits(1); 25 | 26 | $bot->reply(file_get_contents(resource_path('markdown/help.md')), [ 27 | 'parse_mode' => 'Markdown' 28 | ]); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /app/Http/Controllers/MixedContent/ShowController.php: -------------------------------------------------------------------------------- 1 | dear = $dear; 19 | } 20 | 21 | /** 22 | * Handle the incoming request. 23 | * 24 | * @param \BotMan\BotMan\BotMan $bot 25 | * @param string $url 26 | * 27 | * @return void 28 | * @throws \App\Exceptions\SiteNotFoundException 29 | */ 30 | public function __invoke(BotMan $bot, string $url) 31 | { 32 | $bot->types(); 33 | 34 | $site = $this->dear->findSite($url); 35 | 36 | $mixedContent = $this->dear->getMixedContent($site->id); 37 | 38 | if ($mixedContent->isEmpty()) { 39 | $bot->reply(trans('ohdear.mixedcontent.perfect')); 40 | } else { 41 | 42 | $mixedContent->each(function (MixedContent $mixed) use ($bot) { 43 | $bot->reply(trans('ohdear.mixedcontent.result', [ 44 | 'url' => $mixed->mixedContentUrl, 45 | 'origin' => $mixed->foundOnUrl, 46 | ]), ['disable_web_page_preview' => true]); 47 | }); 48 | } 49 | 50 | $bot->reply($site->getKeyboard()); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /app/Http/Controllers/Sites/DestroyController.php: -------------------------------------------------------------------------------- 1 | dear = $dear; 20 | } 21 | 22 | /** 23 | * Handle the incoming request. 24 | * 25 | * @param \BotMan\BotMan\BotMan $bot 26 | * @param string $url 27 | * 28 | * @return void 29 | * @throws \App\Exceptions\SiteNotFoundException 30 | */ 31 | public function __invoke(BotMan $bot, string $url) 32 | { 33 | $site = $this->dear->findSite($url); 34 | 35 | $bot->startConversation(new SiteDestroyConversation($this->dear, $site)); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /app/Http/Controllers/Sites/IndexController.php: -------------------------------------------------------------------------------- 1 | dear = $dear; 21 | } 22 | 23 | /** 24 | * Handle the incoming request. 25 | * 26 | * @param \BotMan\BotMan\BotMan $bot 27 | * 28 | * @return void 29 | */ 30 | public function __invoke(BotMan $bot) 31 | { 32 | $bot->types(); 33 | 34 | $sites = $this->dear->sites(); 35 | 36 | if (! $sites->count()) { 37 | $bot->reply(trans('ohdear.sites.list_empty')); 38 | 39 | return; 40 | } 41 | 42 | $buttons = $sites->map(function (Site $site) { 43 | return Button::create($site->getResume())->value("/site {$site->id}"); 44 | })->toArray(); 45 | 46 | $message = (new Question(trans('ohdear.sites.list_message')))->addButtons($buttons); 47 | 48 | $bot->reply($message); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /app/Http/Controllers/Sites/ShowController.php: -------------------------------------------------------------------------------- 1 | dear = $dear; 20 | } 21 | 22 | /** 23 | * Handle the incoming request. 24 | * 25 | * @param \BotMan\BotMan\BotMan $bot 26 | * @param string $url 27 | * 28 | * @return void 29 | * @throws \App\Exceptions\SiteNotFoundException 30 | */ 31 | public function __invoke(BotMan $bot, string $url) 32 | { 33 | $bot->types(); 34 | 35 | $site = $this->dear->findSite($url); 36 | 37 | $bot->reply($site->getInformation()); 38 | $bot->reply($site->getKeyboard()); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /app/Http/Controllers/Sites/StoreController.php: -------------------------------------------------------------------------------- 1 | dear = $dear; 19 | } 20 | 21 | /** 22 | * Handle the incoming request. 23 | * 24 | * @param \BotMan\BotMan\BotMan $bot 25 | * @param string $url 26 | * 27 | * @return void 28 | */ 29 | public function __invoke(BotMan $bot, string $url) 30 | { 31 | $bot->types(); 32 | 33 | if ($this->dear->findSiteByUrl($url)) { 34 | $bot->reply(trans('ohdear.sites.already_exists')); 35 | return; 36 | } 37 | 38 | try { 39 | $site = $this->dear->createSite($url); 40 | 41 | $bot->reply(trans('ohdear.sites.created')); 42 | 43 | } catch (InvalidUrlException $e) { 44 | $bot->reply(trans('ohdear.sites.invalid_url')); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /app/Http/Controllers/Token/StoreController.php: -------------------------------------------------------------------------------- 1 | user()->token = encrypt($token); 21 | auth()->user()->save(); 22 | 23 | $bot->reply(trans('ohdear.token.stored')); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /app/Http/Controllers/Uptime/ShowController.php: -------------------------------------------------------------------------------- 1 | dear = $dear; 19 | } 20 | 21 | /** 22 | * Handle the incoming request. 23 | * 24 | * @param \BotMan\BotMan\BotMan $bot 25 | * @param string $url 26 | * 27 | * @return void 28 | * @throws \App\Exceptions\SiteNotFoundException 29 | */ 30 | public function __invoke(BotMan $bot, string $url) 31 | { 32 | $bot->types(); 33 | 34 | $site = $this->dear->findSite($url); 35 | 36 | $uptime = $this->dear->getSiteUptime($site->id); 37 | 38 | $daysWithDowntime = $uptime->filter(function (Uptime $uptime) { 39 | return $uptime->uptimePercentage !== 100; 40 | 41 | })->each(function (Uptime $uptime) use ($bot) { 42 | 43 | $bot->reply(trans('ohdear.uptime.result', [ 44 | 'percentage' => $uptime->uptimePercentage, 45 | 'date' => $uptime->datetime, 46 | 'emoji' => $uptime->getPercentageEmoji() 47 | ])); 48 | 49 | }); 50 | 51 | if ($daysWithDowntime->isEmpty()) { 52 | $firstDay = $uptime->reverse()->first(); 53 | $lastDay = $uptime->first(); 54 | $bot->reply(trans('ohdear.uptime.perfect', [ 55 | 'begin' => $firstDay->datetime, 'end' => $lastDay->datetime 56 | ])); 57 | } 58 | 59 | $bot->reply($site->getKeyboard()); 60 | } 61 | 62 | 63 | } 64 | -------------------------------------------------------------------------------- /app/Http/Controllers/Users/StoreController.php: -------------------------------------------------------------------------------- 1 | startConversation(new StartConversation()); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /app/Http/Controllers/Webhook/StoreController.php: -------------------------------------------------------------------------------- 1 | user()->webhook = encrypt($secret); 16 | auth()->user()->save(); 17 | 18 | $bot->reply( 19 | trans('ohdear.webhook.stored', ['url' => auth()->user()->getWebhookUrl()]), 20 | ['parse_mode' => 'Markdown'] 21 | ); 22 | } 23 | } -------------------------------------------------------------------------------- /app/Http/Controllers/WebhookReceivedController.php: -------------------------------------------------------------------------------- 1 | header('OhDear-Signature'); 15 | 16 | if (! $signature) { 17 | throw WebhookException::missingSignature(); 18 | } 19 | 20 | if (! $user->webhook) { 21 | throw WebhookException::signingSecretNotSet(); 22 | } 23 | 24 | $computedSignature = hash_hmac('sha256', $request->getContent(), decrypt($user->webhook)); 25 | 26 | if (! hash_equals($signature, $computedSignature)) { 27 | throw WebhookException::invalidSignature($signature); 28 | } 29 | 30 | $eventPayload = json_decode($request->getContent()); 31 | 32 | if (! isset($eventPayload->type)) { 33 | throw WebhookException::missingType(); 34 | } 35 | 36 | $jobClass = $this->determineJobClass($eventPayload->type); 37 | 38 | if (! class_exists($jobClass)) { 39 | throw WebhookException::unrecognizedType($eventPayload->type); 40 | } 41 | 42 | dispatch(new $jobClass($eventPayload, $user)); 43 | 44 | return response('User will be notified. Thank you OhDear!'); 45 | } 46 | 47 | protected function determineJobClass(string $type): string 48 | { 49 | return '\\App\\Jobs\\Webhook\\'.ucfirst($type); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /app/Http/Kernel.php: -------------------------------------------------------------------------------- 1 | [ 31 | \App\Http\Middleware\EncryptCookies::class, 32 | \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, 33 | \Illuminate\Session\Middleware\StartSession::class, 34 | // \Illuminate\Session\Middleware\AuthenticateSession::class, 35 | \Illuminate\View\Middleware\ShareErrorsFromSession::class, 36 | \App\Http\Middleware\VerifyCsrfToken::class, 37 | \Illuminate\Routing\Middleware\SubstituteBindings::class, 38 | ], 39 | 40 | 'api' => [ 41 | 'throttle:60,1', 42 | 'bindings', 43 | ], 44 | ]; 45 | 46 | /** 47 | * The application's route middleware. 48 | * 49 | * These middleware may be assigned to groups or used individually. 50 | * 51 | * @var array 52 | */ 53 | protected $routeMiddleware = [ 54 | 'auth' => \Illuminate\Auth\Middleware\Authenticate::class, 55 | 'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class, 56 | 'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class, 57 | 'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class, 58 | 'can' => \Illuminate\Auth\Middleware\Authorize::class, 59 | 'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class, 60 | 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class, 61 | ]; 62 | } 63 | -------------------------------------------------------------------------------- /app/Http/Middleware/EncryptCookies.php: -------------------------------------------------------------------------------- 1 | getDriver()->getUser($message); 26 | 27 | $user = User::firstOrCreate(['telegram_id' => $botUser->getId()], [ 28 | 'name' => $botUser->getFirstName() ?? $botUser->getId(), 29 | 'surname' => $botUser->getLastName(), 30 | 'username' => $botUser->getUsername(), 31 | 'email' => $botUser->getId() . '@ohdearbot.com', 32 | 'password' => Hash::make($botUser->getUsername() . '-ohdearbot'), 33 | ]); 34 | 35 | auth()->login($user); 36 | 37 | return $next($message); 38 | } 39 | } -------------------------------------------------------------------------------- /app/Http/Middleware/RedirectIfAuthenticated.php: -------------------------------------------------------------------------------- 1 | check()) { 21 | return redirect('/home'); 22 | } 23 | 24 | return $next($request); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/Http/Middleware/TrimStrings.php: -------------------------------------------------------------------------------- 1 | payload = $payload; 29 | $this->user = $user; 30 | $this->botman = resolve('botman'); 31 | } 32 | 33 | public function handle() 34 | { 35 | $this->botman->say( 36 | trans('ohdear.webhook.broken_links_found', ['url' => $this->payload->site->url]), 37 | $this->user->telegram_id, 38 | TelegramDriver::class, 39 | ['disable_web_page_preview' => true] 40 | ); 41 | 42 | foreach ($this->payload->run->result_payload->broken_links as $brokenLink) { 43 | $this->reportBrokenLink($brokenLink); 44 | } 45 | } 46 | 47 | private function reportBrokenLink($link) 48 | { 49 | $this->botman->say(trans('ohdear.brokenlinks.result', [ 50 | 'url' => $link->crawled_url, 51 | 'code' => $link->status_code, 52 | 'origin' => $link->found_on_url, 53 | ]), 54 | $this->user->telegram_id, 55 | TelegramDriver::class, 56 | ['disable_web_page_preview' => true] 57 | ); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /app/Jobs/Webhook/UptimeCheckFailed.php: -------------------------------------------------------------------------------- 1 | payload = $payload; 29 | $this->user = $user; 30 | $this->botman = resolve('botman'); 31 | } 32 | 33 | public function handle() 34 | { 35 | $this->botman->say( 36 | trans('ohdear.webhook.uptime_check_failed', ['url' => $this->payload->site->url]), 37 | $this->user->telegram_id, 38 | TelegramDriver::class 39 | ); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /app/Models/User.php: -------------------------------------------------------------------------------- 1 | token); 31 | } 32 | 33 | public function getRouteKeyName() 34 | { 35 | return 'username'; 36 | } 37 | 38 | public function getWebhookUrl() 39 | { 40 | return url('webhook') . '/' . auth()->user()->username; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /app/OhDear/BrokenLink.php: -------------------------------------------------------------------------------- 1 | isFailed() ? "🔴" : "✅"; 11 | } 12 | 13 | public function getTypeAsTitle() 14 | { 15 | $result = str_replace('_', ' ', $this->type); 16 | 17 | return ucwords($result); 18 | } 19 | 20 | private function isSuccess() 21 | { 22 | return $this->latestRunResult === 'succeeded'; 23 | } 24 | 25 | private function isFailed() 26 | { 27 | return $this->latestRunResult === 'failed'; 28 | } 29 | } -------------------------------------------------------------------------------- /app/OhDear/Downtime.php: -------------------------------------------------------------------------------- 1 | '🎉', 14 | 'week' => '🙌', 15 | 'day' => '👍', 16 | 'hour' => '😕', 17 | 'minute' => '😞', 18 | 'second' => '😱' 19 | ]; 20 | 21 | public function __construct(array $attributes, $ohDear = null) 22 | { 23 | parent::__construct($attributes, $ohDear); 24 | 25 | $this->startedAt = Carbon::parse($this->startedAt); 26 | $this->endedAt = Carbon::parse($this->endedAt); 27 | $this->elapsed = Str::elapsed_time_greatest($this->endedAt); 28 | } 29 | 30 | public function getDowntime() 31 | { 32 | return Str::elapsed_time($this->startedAt, $this->endedAt); 33 | } 34 | 35 | public function getElapsedEmoji() 36 | { 37 | foreach (self::INTERVALS_EMOJIS as $key => $emoji) { 38 | if (stripos($this->elapsed, $key) !== false) { 39 | return $emoji; 40 | } 41 | } 42 | 43 | return '😱'; 44 | } 45 | } -------------------------------------------------------------------------------- /app/OhDear/MixedContent.php: -------------------------------------------------------------------------------- 1 | ohDear = new \OhDear\PhpSdk\OhDear(auth()->user()->getToken(), null); 28 | 29 | $this->client = $this->ohDear->client; 30 | } 31 | 32 | public function sites(): Collection 33 | { 34 | return $this->collect($this->get('sites')['data'], Site::class); 35 | } 36 | 37 | /** 38 | * @param string $url 39 | * 40 | * @return \App\OhDear\Site 41 | * @throws \App\Exceptions\InvalidUrlException 42 | */ 43 | public function createSite(string $url): Site 44 | { 45 | $site = $this->ohDear->post('sites', ['url' => $this->validatedUrl($url)]); 46 | 47 | return new Site($site, $this); 48 | } 49 | 50 | /** 51 | * @param string $url 52 | * 53 | * @return \App\OhDear\Site|null 54 | */ 55 | public function findSiteByUrl(string $url): ?Site 56 | { 57 | try { 58 | 59 | $site = Str::validate_url($url) 60 | ? $this->get("sites/url/{$url}") 61 | : $this->searchSiteByUrl($url); 62 | 63 | return new Site($site, $this); 64 | 65 | } catch (NotFoundException $e) { 66 | 67 | return null; 68 | 69 | } 70 | } 71 | 72 | private function searchSiteByUrl(string $url): Site 73 | { 74 | return $this->sites()->first(function (Site $site) use ($url) { 75 | return stripos($site->url, $url) !== false; 76 | }, function () { 77 | throw new NotFoundException(); 78 | }); 79 | } 80 | 81 | /** 82 | * @param $id 83 | * 84 | * @return \App\OhDear\Site 85 | * @throws \App\Exceptions\SiteNotFoundException 86 | */ 87 | public function findSite($id): Site 88 | { 89 | try { 90 | if (is_numeric($id)) { 91 | return new Site($this->get("sites/{$id}"), $this); 92 | } elseif (Str::validate_url($id)) { 93 | return new Site($this->get("sites/url/{$id}"), $this); 94 | } 95 | 96 | return $this->searchSiteByUrl($id); 97 | 98 | } catch (NotFoundException $e) { 99 | 100 | throw new SiteNotFoundException(); 101 | 102 | } 103 | } 104 | 105 | public function deleteSite($siteId) 106 | { 107 | return $this->ohDear->delete("sites/{$siteId}"); 108 | } 109 | 110 | public function getSiteDowntime($siteId) 111 | { 112 | return $this->collect($this->get("sites/{$siteId}/downtime{$this->getDefaultStartedEndedFilter()}")['data'], 113 | Downtime::class); 114 | } 115 | 116 | public function getSiteUptime($siteId) 117 | { 118 | return $this->collect($this->get("sites/{$siteId}/uptime{$this->getDefaultStartedEndedFilter()}&split=day"), 119 | Uptime::class); 120 | } 121 | 122 | public function getBrokenLinks($siteId) 123 | { 124 | return $this->collect($this->get("broken-links/{$siteId}")['data'], BrokenLink::class); 125 | } 126 | 127 | public function getMixedContent($siteId) 128 | { 129 | return $this->collect($this->get("mixed-content/{$siteId}")['data'], MixedContent::class); 130 | } 131 | 132 | public function collect($collection, $class) 133 | { 134 | return collect($collection)->map(function ($attributes) use ($class) { 135 | return new $class($attributes, $this); 136 | }); 137 | } 138 | 139 | /** 140 | * @param string $url 141 | * 142 | * @return string 143 | * @throws \App\Exceptions\InvalidUrlException 144 | */ 145 | protected function validatedUrl(string $url) 146 | { 147 | if (! Str::validate_url($url)) { 148 | throw new InvalidUrlException; 149 | } 150 | 151 | return $url; 152 | } 153 | 154 | private function getDefaultStartedEndedFilter() 155 | { 156 | return "?filter[started_at]=" . now()->subDays(30)->format('YmdHis') . "&filter[ended_at]=" . date('YmdHis'); 157 | } 158 | } -------------------------------------------------------------------------------- /app/OhDear/Site.php: -------------------------------------------------------------------------------- 1 | checks = collect($this->checks)->map(function ($check) { 16 | return new Check($check->attributes, $this->ohDear); 17 | }); 18 | } 19 | 20 | public function getResume() 21 | { 22 | return "{$this->getStatusEmoji()} {$this->sortUrl}"; 23 | } 24 | 25 | public function getInformation() 26 | { 27 | return "{$this->getStatusEmoji()} {$this->sortUrl}" 28 | . PHP_EOL 29 | . collect($this->checks)->map(function (Check $check) { 30 | 31 | if (! $check->enabled) { 32 | return null; 33 | } 34 | 35 | return "{$check->getResultAsIcon()} {$check->getTypeAsTitle()}"; 36 | 37 | })->filter()->implode(PHP_EOL); 38 | } 39 | 40 | public function getKeyboard() 41 | { 42 | return (new Question(trans('ohdear.sites.next_action'))) 43 | ->addButtons([ 44 | Button::create('Uptime')->value("/uptime {$this->id}"), 45 | Button::create('Downtime')->value("/downtime {$this->id}"), 46 | Button::create('Broken Links')->value("/brokenlinks {$this->id}"), 47 | Button::create('Mixed Content')->value("/mixedcontent {$this->id}"), 48 | ]); 49 | } 50 | 51 | public function isUp() 52 | { 53 | return $this->summarizedCheckResult === 'succeeded'; 54 | } 55 | 56 | public function delete() 57 | { 58 | return $this->ohDear->deleteSite($this->id); 59 | } 60 | 61 | public function getStatusEmoji() 62 | { 63 | return $this->isUp() ? "✅" : "🔴"; 64 | } 65 | } -------------------------------------------------------------------------------- /app/OhDear/Uptime.php: -------------------------------------------------------------------------------- 1 | 100, 13 | '🙌' => 75, 14 | '😕' => 50, 15 | '😞' => 25, 16 | '😱' => 0, 17 | ]; 18 | 19 | public function __construct(array $attributes, $ohDear = null) 20 | { 21 | parent::__construct($attributes, $ohDear); 22 | 23 | $this->datetime = Carbon::parse($this->datetime); 24 | } 25 | 26 | public function getPercentageEmoji() 27 | { 28 | foreach (self::PERCENTAGES_EMOJIS as $emoji => $cut) { 29 | 30 | if (abs($this->uptimePercentage - $cut) <= 12.5) { 31 | return $emoji; 32 | } 33 | } 34 | 35 | return '😱'; 36 | } 37 | 38 | } -------------------------------------------------------------------------------- /app/Providers/AppServiceProvider.php: -------------------------------------------------------------------------------- 1 | app->singleton(OhDear::class, OhDear::class); 29 | 30 | Carbon::setToStringFormat('D, F d, Y'); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /app/Providers/AuthServiceProvider.php: -------------------------------------------------------------------------------- 1 | 'App\Policies\ModelPolicy', 17 | ]; 18 | 19 | /** 20 | * Register any authentication / authorization services. 21 | * 22 | * @return void 23 | */ 24 | public function boot() 25 | { 26 | $this->registerPolicies(); 27 | 28 | // 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /app/Providers/BotMan/DriverServiceProvider.php: -------------------------------------------------------------------------------- 1 | drivers as $driver) { 26 | DriverManager::loadDriver($driver); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /app/Providers/BroadcastServiceProvider.php: -------------------------------------------------------------------------------- 1 | [ 17 | 'App\Listeners\EventListener', 18 | ], 19 | ]; 20 | 21 | /** 22 | * Register any events for your application. 23 | * 24 | * @return void 25 | */ 26 | public function boot() 27 | { 28 | parent::boot(); 29 | 30 | // 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /app/Providers/RouteServiceProvider.php: -------------------------------------------------------------------------------- 1 | mapApiRoutes(); 39 | 40 | $this->mapWebRoutes(); 41 | 42 | $this->mapBotManCommands(); 43 | } 44 | 45 | /** 46 | * Defines the BotMan "hears" commands. 47 | * 48 | * @return void 49 | */ 50 | protected function mapBotManCommands() 51 | { 52 | require base_path('routes/botman.php'); 53 | } 54 | 55 | /** 56 | * Define the "web" routes for the application. 57 | * 58 | * These routes all receive session state, CSRF protection, etc. 59 | * 60 | * @return void 61 | */ 62 | protected function mapWebRoutes() 63 | { 64 | Route::middleware('web') 65 | ->namespace($this->namespace) 66 | ->group(base_path('routes/web.php')); 67 | } 68 | 69 | /** 70 | * Define the "api" routes for the application. 71 | * 72 | * These routes are typically stateless. 73 | * 74 | * @return void 75 | */ 76 | protected function mapApiRoutes() 77 | { 78 | Route::prefix('api') 79 | ->middleware('api') 80 | ->namespace($this->namespace) 81 | ->group(base_path('routes/api.php')); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /artisan: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env php 2 | make(Illuminate\Contracts\Console\Kernel::class); 34 | 35 | $status = $kernel->handle( 36 | $input = new Symfony\Component\Console\Input\ArgvInput, 37 | new Symfony\Component\Console\Output\ConsoleOutput 38 | ); 39 | 40 | /* 41 | |-------------------------------------------------------------------------- 42 | | Shutdown The Application 43 | |-------------------------------------------------------------------------- 44 | | 45 | | Once Artisan has finished running, we will fire off the shutdown events 46 | | so that any final work may be done by the application before we shut 47 | | down the process. This is the last thing to happen to the request. 48 | | 49 | */ 50 | 51 | $kernel->terminate($input, $status); 52 | 53 | exit($status); 54 | -------------------------------------------------------------------------------- /bootstrap/app.php: -------------------------------------------------------------------------------- 1 | singleton( 30 | Illuminate\Contracts\Http\Kernel::class, 31 | App\Http\Kernel::class 32 | ); 33 | 34 | $app->singleton( 35 | Illuminate\Contracts\Console\Kernel::class, 36 | App\Console\Kernel::class 37 | ); 38 | 39 | $app->singleton( 40 | Illuminate\Contracts\Debug\ExceptionHandler::class, 41 | App\Exceptions\Handler::class 42 | ); 43 | 44 | /* 45 | |-------------------------------------------------------------------------- 46 | | Return The Application 47 | |-------------------------------------------------------------------------- 48 | | 49 | | This script returns the application instance. The instance is given to 50 | | the calling script so we can separate the building of the instances 51 | | from the actual running of the application and sending responses. 52 | | 53 | */ 54 | 55 | return $app; 56 | -------------------------------------------------------------------------------- /bootstrap/cache/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "lloople/bot-mr-dear", 3 | "description": "Interact with your Oh Dear! sites chating with this bot.", 4 | "keywords": [ 5 | "chatbot", 6 | "monitoring", 7 | "ohdear" 8 | ], 9 | "license": "MIT", 10 | "type": "project", 11 | "require": { 12 | "php": ">=7.1.3", 13 | "botman/botman": "~2.0", 14 | "botman/driver-telegram": "^1.5", 15 | "botman/driver-web": "~1.0", 16 | "botman/studio-addons": "~1.2.1", 17 | "botman/tinker": "~1.0", 18 | "fideloper/proxy": "~4.0", 19 | "laravel/framework": "5.6.*", 20 | "laravel/tinker": "~1.0", 21 | "ohdearapp/ohdear-php-sdk": "^1.2" 22 | }, 23 | "require-dev": { 24 | "beyondcode/laravel-dump-server": "^1.2", 25 | "filp/whoops": "~2.0", 26 | "fzaninotto/faker": "~1.4", 27 | "mockery/mockery": "0.9.*", 28 | "nunomaduro/collision": "~2.0", 29 | "phpunit/phpunit": "~6.0" 30 | }, 31 | "autoload": { 32 | "classmap": [ 33 | "database" 34 | ], 35 | "psr-4": { 36 | "App\\": "app/" 37 | } 38 | }, 39 | "autoload-dev": { 40 | "psr-4": { 41 | "Tests\\": "tests/" 42 | } 43 | }, 44 | "scripts": { 45 | "post-root-package-install": [ 46 | "php -r \"file_exists('.env') || copy('.env.example', '.env');\"" 47 | ], 48 | "post-create-project-cmd": [ 49 | "php artisan key:generate" 50 | ], 51 | "post-install-cmd": [ 52 | "Illuminate\\Foundation\\ComposerScripts::postInstall", 53 | "BotMan\\Studio\\Providers\\DriverServiceProvider::publishDriverConfigurations" 54 | ], 55 | "post-update-cmd": [ 56 | "Illuminate\\Foundation\\ComposerScripts::postUpdate", 57 | "BotMan\\Studio\\Providers\\DriverServiceProvider::publishDriverConfigurations" 58 | ], 59 | "post-autoload-dump": [ 60 | "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump", 61 | "@php artisan package:discover" 62 | ] 63 | }, 64 | "config": { 65 | "preferred-install": "dist", 66 | "sort-packages": true, 67 | "optimize-autoloader": true 68 | }, 69 | "extra": { 70 | "laravel": { 71 | "dont-discover": [] 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /config/app.php: -------------------------------------------------------------------------------- 1 | env('APP_NAME', 'Laravel'), 16 | 17 | /* 18 | |-------------------------------------------------------------------------- 19 | | Application Environment 20 | |-------------------------------------------------------------------------- 21 | | 22 | | This value determines the "environment" your application is currently 23 | | running in. This may determine how you prefer to configure various 24 | | services your application utilizes. Set this in your ".env" file. 25 | | 26 | */ 27 | 28 | 'env' => env('APP_ENV', 'production'), 29 | 30 | /* 31 | |-------------------------------------------------------------------------- 32 | | Application Debug Mode 33 | |-------------------------------------------------------------------------- 34 | | 35 | | When your application is in debug mode, detailed error messages with 36 | | stack traces will be shown on every error that occurs within your 37 | | application. If disabled, a simple generic error page is shown. 38 | | 39 | */ 40 | 41 | 'debug' => env('APP_DEBUG', false), 42 | 43 | /* 44 | |-------------------------------------------------------------------------- 45 | | Application URL 46 | |-------------------------------------------------------------------------- 47 | | 48 | | This URL is used by the console to properly generate URLs when using 49 | | the Artisan command line tool. You should set this to the root of 50 | | your application so that it is used when running Artisan tasks. 51 | | 52 | */ 53 | 54 | 'url' => env('APP_URL', 'http://localhost'), 55 | 56 | /* 57 | |-------------------------------------------------------------------------- 58 | | Application Timezone 59 | |-------------------------------------------------------------------------- 60 | | 61 | | Here you may specify the default timezone for your application, which 62 | | will be used by the PHP date and date-time functions. We have gone 63 | | ahead and set this to a sensible default for you out of the box. 64 | | 65 | */ 66 | 67 | 'timezone' => 'UTC', 68 | 69 | /* 70 | |-------------------------------------------------------------------------- 71 | | Application Locale Configuration 72 | |-------------------------------------------------------------------------- 73 | | 74 | | The application locale determines the default locale that will be used 75 | | by the translation service provider. You are free to set this value 76 | | to any of the locales which will be supported by the application. 77 | | 78 | */ 79 | 80 | 'locale' => 'en', 81 | 82 | /* 83 | |-------------------------------------------------------------------------- 84 | | Application Fallback Locale 85 | |-------------------------------------------------------------------------- 86 | | 87 | | The fallback locale determines the locale to use when the current one 88 | | is not available. You may change the value to correspond to any of 89 | | the language folders that are provided through your application. 90 | | 91 | */ 92 | 93 | 'fallback_locale' => 'en', 94 | 95 | /* 96 | |-------------------------------------------------------------------------- 97 | | Encryption Key 98 | |-------------------------------------------------------------------------- 99 | | 100 | | This key is used by the Illuminate encrypter service and should be set 101 | | to a random, 32 character string, otherwise these encrypted strings 102 | | will not be safe. Please do this before deploying an application! 103 | | 104 | */ 105 | 106 | 'key' => env('APP_KEY'), 107 | 108 | 'cipher' => 'AES-256-CBC', 109 | 110 | /* 111 | |-------------------------------------------------------------------------- 112 | | Autoloaded Service Providers 113 | |-------------------------------------------------------------------------- 114 | | 115 | | The service providers listed here will be automatically loaded on the 116 | | request to your application. Feel free to add your own services to 117 | | this array to grant expanded functionality to your applications. 118 | | 119 | */ 120 | 121 | 'providers' => [ 122 | 123 | /* 124 | * Laravel Framework Service Providers... 125 | */ 126 | Illuminate\Auth\AuthServiceProvider::class, 127 | Illuminate\Broadcasting\BroadcastServiceProvider::class, 128 | Illuminate\Bus\BusServiceProvider::class, 129 | Illuminate\Cache\CacheServiceProvider::class, 130 | Illuminate\Foundation\Providers\ConsoleSupportServiceProvider::class, 131 | Illuminate\Cookie\CookieServiceProvider::class, 132 | Illuminate\Database\DatabaseServiceProvider::class, 133 | Illuminate\Encryption\EncryptionServiceProvider::class, 134 | Illuminate\Filesystem\FilesystemServiceProvider::class, 135 | Illuminate\Foundation\Providers\FoundationServiceProvider::class, 136 | Illuminate\Hashing\HashServiceProvider::class, 137 | Illuminate\Mail\MailServiceProvider::class, 138 | Illuminate\Notifications\NotificationServiceProvider::class, 139 | Illuminate\Pagination\PaginationServiceProvider::class, 140 | Illuminate\Pipeline\PipelineServiceProvider::class, 141 | Illuminate\Queue\QueueServiceProvider::class, 142 | Illuminate\Redis\RedisServiceProvider::class, 143 | Illuminate\Auth\Passwords\PasswordResetServiceProvider::class, 144 | Illuminate\Session\SessionServiceProvider::class, 145 | Illuminate\Translation\TranslationServiceProvider::class, 146 | Illuminate\Validation\ValidationServiceProvider::class, 147 | Illuminate\View\ViewServiceProvider::class, 148 | 149 | /* 150 | * Package Service Providers... 151 | */ 152 | Laravel\Tinker\TinkerServiceProvider::class, 153 | 154 | /* 155 | * BotMan Service Providers... 156 | */ 157 | BotMan\Tinker\TinkerServiceProvider::class, 158 | App\Providers\BotMan\DriverServiceProvider::class, 159 | BotMan\BotMan\BotManServiceProvider::class, 160 | BotMan\Studio\Providers\StudioServiceProvider::class, 161 | 162 | /* 163 | * Application Service Providers... 164 | */ 165 | App\Providers\AppServiceProvider::class, 166 | App\Providers\AuthServiceProvider::class, 167 | // App\Providers\BroadcastServiceProvider::class, 168 | App\Providers\EventServiceProvider::class, 169 | App\Providers\RouteServiceProvider::class, 170 | 171 | ], 172 | 173 | /* 174 | |-------------------------------------------------------------------------- 175 | | Class Aliases 176 | |-------------------------------------------------------------------------- 177 | | 178 | | This array of class aliases will be registered when this application 179 | | is started. However, feel free to register as many as you wish as 180 | | the aliases are "lazy" loaded so they don't hinder performance. 181 | | 182 | */ 183 | 184 | 'aliases' => [ 185 | 186 | 'App' => Illuminate\Support\Facades\App::class, 187 | 'Artisan' => Illuminate\Support\Facades\Artisan::class, 188 | 'Auth' => Illuminate\Support\Facades\Auth::class, 189 | 'Blade' => Illuminate\Support\Facades\Blade::class, 190 | 'Broadcast' => Illuminate\Support\Facades\Broadcast::class, 191 | 'Bus' => Illuminate\Support\Facades\Bus::class, 192 | 'Cache' => Illuminate\Support\Facades\Cache::class, 193 | 'Config' => Illuminate\Support\Facades\Config::class, 194 | 'Cookie' => Illuminate\Support\Facades\Cookie::class, 195 | 'Crypt' => Illuminate\Support\Facades\Crypt::class, 196 | 'DB' => Illuminate\Support\Facades\DB::class, 197 | 'Eloquent' => Illuminate\Database\Eloquent\Model::class, 198 | 'Event' => Illuminate\Support\Facades\Event::class, 199 | 'File' => Illuminate\Support\Facades\File::class, 200 | 'Gate' => Illuminate\Support\Facades\Gate::class, 201 | 'Hash' => Illuminate\Support\Facades\Hash::class, 202 | 'Lang' => Illuminate\Support\Facades\Lang::class, 203 | 'Log' => Illuminate\Support\Facades\Log::class, 204 | 'Mail' => Illuminate\Support\Facades\Mail::class, 205 | 'Notification' => Illuminate\Support\Facades\Notification::class, 206 | 'Password' => Illuminate\Support\Facades\Password::class, 207 | 'Queue' => Illuminate\Support\Facades\Queue::class, 208 | 'Redirect' => Illuminate\Support\Facades\Redirect::class, 209 | 'Redis' => Illuminate\Support\Facades\Redis::class, 210 | 'Request' => Illuminate\Support\Facades\Request::class, 211 | 'Response' => Illuminate\Support\Facades\Response::class, 212 | 'Route' => Illuminate\Support\Facades\Route::class, 213 | 'Schema' => Illuminate\Support\Facades\Schema::class, 214 | 'Session' => Illuminate\Support\Facades\Session::class, 215 | 'Storage' => Illuminate\Support\Facades\Storage::class, 216 | 'URL' => Illuminate\Support\Facades\URL::class, 217 | 'Validator' => Illuminate\Support\Facades\Validator::class, 218 | 'View' => Illuminate\Support\Facades\View::class, 219 | 220 | ], 221 | 222 | ]; 223 | -------------------------------------------------------------------------------- /config/auth.php: -------------------------------------------------------------------------------- 1 | [ 17 | 'guard' => 'web', 18 | 'passwords' => 'users', 19 | ], 20 | 21 | /* 22 | |-------------------------------------------------------------------------- 23 | | Authentication Guards 24 | |-------------------------------------------------------------------------- 25 | | 26 | | Next, you may define every authentication guard for your application. 27 | | Of course, a great default configuration has been defined for you 28 | | here which uses session storage and the Eloquent user provider. 29 | | 30 | | All authentication drivers have a user provider. This defines how the 31 | | users are actually retrieved out of your database or other storage 32 | | mechanisms used by this application to persist your user's data. 33 | | 34 | | Supported: "session", "token" 35 | | 36 | */ 37 | 38 | 'guards' => [ 39 | 'web' => [ 40 | 'driver' => 'session', 41 | 'provider' => 'users', 42 | ], 43 | 44 | 'api' => [ 45 | 'driver' => 'token', 46 | 'provider' => 'users', 47 | ], 48 | ], 49 | 50 | /* 51 | |-------------------------------------------------------------------------- 52 | | User Providers 53 | |-------------------------------------------------------------------------- 54 | | 55 | | All authentication drivers have a user provider. This defines how the 56 | | users are actually retrieved out of your database or other storage 57 | | mechanisms used by this application to persist your user's data. 58 | | 59 | | If you have multiple user tables or models you may configure multiple 60 | | sources which represent each model / table. These sources may then 61 | | be assigned to any extra authentication guards you have defined. 62 | | 63 | | Supported: "database", "eloquent" 64 | | 65 | */ 66 | 67 | 'providers' => [ 68 | 'users' => [ 69 | 'driver' => 'eloquent', 70 | 'model' => App\Models\User::class, 71 | ], 72 | 73 | // 'users' => [ 74 | // 'driver' => 'database', 75 | // 'table' => 'users', 76 | // ], 77 | ], 78 | 79 | /* 80 | |-------------------------------------------------------------------------- 81 | | Resetting Passwords 82 | |-------------------------------------------------------------------------- 83 | | 84 | | You may specify multiple password reset configurations if you have more 85 | | than one user table or model in the application and you want to have 86 | | separate password reset settings based on the specific user types. 87 | | 88 | | The expire time is the number of minutes that the reset token should be 89 | | considered valid. This security feature keeps tokens short-lived so 90 | | they have less time to be guessed. You may change this as needed. 91 | | 92 | */ 93 | 94 | 'passwords' => [ 95 | 'users' => [ 96 | 'provider' => 'users', 97 | 'table' => 'password_resets', 98 | 'expire' => 60, 99 | ], 100 | ], 101 | 102 | ]; 103 | -------------------------------------------------------------------------------- /config/botman/config.php: -------------------------------------------------------------------------------- 1 | 40, 16 | 17 | /* 18 | |-------------------------------------------------------------------------- 19 | | User Cache Time 20 | |-------------------------------------------------------------------------- 21 | | 22 | | BotMan caches user information of the incoming messages. 23 | | This value defines the number of minutes that this 24 | | data will remain stored in the cache. 25 | | 26 | */ 27 | 'user_cache_time' => 30, 28 | ]; 29 | -------------------------------------------------------------------------------- /config/botman/telegram.php: -------------------------------------------------------------------------------- 1 | env('TELEGRAM_TOKEN'), 15 | ]; 16 | -------------------------------------------------------------------------------- /config/botman/web.php: -------------------------------------------------------------------------------- 1 | [ 15 | 'driver' => 'web', 16 | ], 17 | ]; 18 | -------------------------------------------------------------------------------- /config/broadcasting.php: -------------------------------------------------------------------------------- 1 | env('BROADCAST_DRIVER', 'null'), 19 | 20 | /* 21 | |-------------------------------------------------------------------------- 22 | | Broadcast Connections 23 | |-------------------------------------------------------------------------- 24 | | 25 | | Here you may define all of the broadcast connections that will be used 26 | | to broadcast events to other systems or over websockets. Samples of 27 | | each available type of connection are provided inside this array. 28 | | 29 | */ 30 | 31 | 'connections' => [ 32 | 33 | 'pusher' => [ 34 | 'driver' => 'pusher', 35 | 'key' => env('PUSHER_APP_KEY'), 36 | 'secret' => env('PUSHER_APP_SECRET'), 37 | 'app_id' => env('PUSHER_APP_ID'), 38 | 'options' => [ 39 | 'cluster' => env('PUSHER_APP_CLUSTER'), 40 | 'encrypted' => true, 41 | ], 42 | ], 43 | 44 | 'redis' => [ 45 | 'driver' => 'redis', 46 | 'connection' => 'default', 47 | ], 48 | 49 | 'log' => [ 50 | 'driver' => 'log', 51 | ], 52 | 53 | 'null' => [ 54 | 'driver' => 'null', 55 | ], 56 | 57 | ], 58 | 59 | ]; 60 | -------------------------------------------------------------------------------- /config/cache.php: -------------------------------------------------------------------------------- 1 | env('CACHE_DRIVER', 'file'), 19 | 20 | /* 21 | |-------------------------------------------------------------------------- 22 | | Cache Stores 23 | |-------------------------------------------------------------------------- 24 | | 25 | | Here you may define all of the cache "stores" for your application as 26 | | well as their drivers. You may even define multiple stores for the 27 | | same cache driver to group types of items stored in your caches. 28 | | 29 | */ 30 | 31 | 'stores' => [ 32 | 33 | 'apc' => [ 34 | 'driver' => 'apc', 35 | ], 36 | 37 | 'array' => [ 38 | 'driver' => 'array', 39 | ], 40 | 41 | 'database' => [ 42 | 'driver' => 'database', 43 | 'table' => 'cache', 44 | 'connection' => null, 45 | ], 46 | 47 | 'file' => [ 48 | 'driver' => 'file', 49 | 'path' => storage_path('framework/cache/data'), 50 | ], 51 | 52 | 'memcached' => [ 53 | 'driver' => 'memcached', 54 | 'persistent_id' => env('MEMCACHED_PERSISTENT_ID'), 55 | 'sasl' => [ 56 | env('MEMCACHED_USERNAME'), 57 | env('MEMCACHED_PASSWORD'), 58 | ], 59 | 'options' => [ 60 | // Memcached::OPT_CONNECT_TIMEOUT => 2000, 61 | ], 62 | 'servers' => [ 63 | [ 64 | 'host' => env('MEMCACHED_HOST', '127.0.0.1'), 65 | 'port' => env('MEMCACHED_PORT', 11211), 66 | 'weight' => 100, 67 | ], 68 | ], 69 | ], 70 | 71 | 'redis' => [ 72 | 'driver' => 'redis', 73 | 'connection' => 'default', 74 | ], 75 | 76 | ], 77 | 78 | /* 79 | |-------------------------------------------------------------------------- 80 | | Cache Key Prefix 81 | |-------------------------------------------------------------------------- 82 | | 83 | | When utilizing a RAM based store such as APC or Memcached, there might 84 | | be other applications utilizing the same cache. So, we'll specify a 85 | | value to get prefixed to all our keys so we can avoid collisions. 86 | | 87 | */ 88 | 89 | 'prefix' => env( 90 | 'CACHE_PREFIX', 91 | str_slug(env('APP_NAME', 'laravel'), '_').'_cache' 92 | ), 93 | 94 | ]; 95 | -------------------------------------------------------------------------------- /config/database.php: -------------------------------------------------------------------------------- 1 | env('DB_CONNECTION', 'mysql'), 17 | 18 | /* 19 | |-------------------------------------------------------------------------- 20 | | Database Connections 21 | |-------------------------------------------------------------------------- 22 | | 23 | | Here are each of the database connections setup for your application. 24 | | Of course, examples of configuring each database platform that is 25 | | supported by Laravel is shown below to make development simple. 26 | | 27 | | 28 | | All database work in Laravel is done through the PHP PDO facilities 29 | | so make sure you have the driver for your particular database of 30 | | choice installed on your machine before you begin development. 31 | | 32 | */ 33 | 34 | 'connections' => [ 35 | 36 | 'sqlite' => [ 37 | 'driver' => 'sqlite', 38 | 'database' => env('DB_DATABASE', database_path('database.sqlite')), 39 | 'prefix' => '', 40 | ], 41 | 42 | 'mysql' => [ 43 | 'driver' => 'mysql', 44 | 'host' => env('DB_HOST', '127.0.0.1'), 45 | 'port' => env('DB_PORT', '3306'), 46 | 'database' => env('DB_DATABASE', 'forge'), 47 | 'username' => env('DB_USERNAME', 'forge'), 48 | 'password' => env('DB_PASSWORD', ''), 49 | 'unix_socket' => env('DB_SOCKET', ''), 50 | 'charset' => 'utf8mb4', 51 | 'collation' => 'utf8mb4_unicode_ci', 52 | 'prefix' => '', 53 | 'strict' => true, 54 | 'engine' => null, 55 | ], 56 | 57 | 'pgsql' => [ 58 | 'driver' => 'pgsql', 59 | 'host' => env('DB_HOST', '127.0.0.1'), 60 | 'port' => env('DB_PORT', '5432'), 61 | 'database' => env('DB_DATABASE', 'forge'), 62 | 'username' => env('DB_USERNAME', 'forge'), 63 | 'password' => env('DB_PASSWORD', ''), 64 | 'charset' => 'utf8', 65 | 'prefix' => '', 66 | 'schema' => 'public', 67 | 'sslmode' => 'prefer', 68 | ], 69 | 70 | 'sqlsrv' => [ 71 | 'driver' => 'sqlsrv', 72 | 'host' => env('DB_HOST', 'localhost'), 73 | 'port' => env('DB_PORT', '1433'), 74 | 'database' => env('DB_DATABASE', 'forge'), 75 | 'username' => env('DB_USERNAME', 'forge'), 76 | 'password' => env('DB_PASSWORD', ''), 77 | 'charset' => 'utf8', 78 | 'prefix' => '', 79 | ], 80 | 81 | ], 82 | 83 | /* 84 | |-------------------------------------------------------------------------- 85 | | Migration Repository Table 86 | |-------------------------------------------------------------------------- 87 | | 88 | | This table keeps track of all the migrations that have already run for 89 | | your application. Using this information, we can determine which of 90 | | the migrations on disk haven't actually been run in the database. 91 | | 92 | */ 93 | 94 | 'migrations' => 'migrations', 95 | 96 | /* 97 | |-------------------------------------------------------------------------- 98 | | Redis Databases 99 | |-------------------------------------------------------------------------- 100 | | 101 | | Redis is an open source, fast, and advanced key-value store that also 102 | | provides a richer set of commands than a typical key-value systems 103 | | such as APC or Memcached. Laravel makes it easy to dig right in. 104 | | 105 | */ 106 | 107 | 'redis' => [ 108 | 109 | 'client' => 'predis', 110 | 111 | 'default' => [ 112 | 'host' => env('REDIS_HOST', '127.0.0.1'), 113 | 'password' => env('REDIS_PASSWORD', null), 114 | 'port' => env('REDIS_PORT', 6379), 115 | 'database' => 0, 116 | ], 117 | 118 | ], 119 | 120 | ]; 121 | -------------------------------------------------------------------------------- /config/filesystems.php: -------------------------------------------------------------------------------- 1 | env('FILESYSTEM_DRIVER', 'local'), 17 | 18 | /* 19 | |-------------------------------------------------------------------------- 20 | | Default Cloud Filesystem Disk 21 | |-------------------------------------------------------------------------- 22 | | 23 | | Many applications store files both locally and in the cloud. For this 24 | | reason, you may specify a default "cloud" driver here. This driver 25 | | will be bound as the Cloud disk implementation in the container. 26 | | 27 | */ 28 | 29 | 'cloud' => env('FILESYSTEM_CLOUD', 's3'), 30 | 31 | /* 32 | |-------------------------------------------------------------------------- 33 | | Filesystem Disks 34 | |-------------------------------------------------------------------------- 35 | | 36 | | Here you may configure as many filesystem "disks" as you wish, and you 37 | | may even configure multiple disks of the same driver. Defaults have 38 | | been setup for each driver as an example of the required options. 39 | | 40 | | Supported Drivers: "local", "ftp", "s3", "rackspace" 41 | | 42 | */ 43 | 44 | 'disks' => [ 45 | 46 | 'local' => [ 47 | 'driver' => 'local', 48 | 'root' => storage_path('app'), 49 | ], 50 | 51 | 'public' => [ 52 | 'driver' => 'local', 53 | 'root' => storage_path('app/public'), 54 | 'url' => env('APP_URL').'/storage', 55 | 'visibility' => 'public', 56 | ], 57 | 58 | 's3' => [ 59 | 'driver' => 's3', 60 | 'key' => env('AWS_ACCESS_KEY_ID'), 61 | 'secret' => env('AWS_SECRET_ACCESS_KEY'), 62 | 'region' => env('AWS_DEFAULT_REGION'), 63 | 'bucket' => env('AWS_BUCKET'), 64 | 'url' => env('AWS_URL'), 65 | ], 66 | 67 | ], 68 | 69 | ]; 70 | -------------------------------------------------------------------------------- /config/hashing.php: -------------------------------------------------------------------------------- 1 | 'bcrypt', 19 | 20 | ]; 21 | -------------------------------------------------------------------------------- /config/logging.php: -------------------------------------------------------------------------------- 1 | env('LOG_CHANNEL', 'stack'), 17 | 18 | /* 19 | |-------------------------------------------------------------------------- 20 | | Log Channels 21 | |-------------------------------------------------------------------------- 22 | | 23 | | Here you may configure the log channels for your application. Out of 24 | | the box, Laravel uses the Monolog PHP logging library. This gives 25 | | you a variety of powerful log handlers / formatters to utilize. 26 | | 27 | | Available Drivers: "single", "daily", "slack", "syslog", 28 | | "errorlog", "custom", "stack" 29 | | 30 | */ 31 | 32 | 'channels' => [ 33 | 'stack' => [ 34 | 'driver' => 'stack', 35 | 'channels' => ['single'], 36 | ], 37 | 38 | 'single' => [ 39 | 'driver' => 'single', 40 | 'path' => storage_path('logs/laravel.log'), 41 | 'level' => 'debug', 42 | ], 43 | 44 | 'daily' => [ 45 | 'driver' => 'daily', 46 | 'path' => storage_path('logs/laravel.log'), 47 | 'level' => 'debug', 48 | 'days' => 7, 49 | ], 50 | 51 | 'slack' => [ 52 | 'driver' => 'slack', 53 | 'url' => env('LOG_SLACK_WEBHOOK_URL'), 54 | 'username' => 'Laravel Log', 55 | 'emoji' => ':boom:', 56 | 'level' => 'critical', 57 | ], 58 | 59 | 'syslog' => [ 60 | 'driver' => 'syslog', 61 | 'level' => 'debug', 62 | ], 63 | 64 | 'errorlog' => [ 65 | 'driver' => 'errorlog', 66 | 'level' => 'debug', 67 | ], 68 | ], 69 | 70 | ]; 71 | -------------------------------------------------------------------------------- /config/mail.php: -------------------------------------------------------------------------------- 1 | env('MAIL_DRIVER', 'smtp'), 20 | 21 | /* 22 | |-------------------------------------------------------------------------- 23 | | SMTP Host Address 24 | |-------------------------------------------------------------------------- 25 | | 26 | | Here you may provide the host address of the SMTP server used by your 27 | | applications. A default option is provided that is compatible with 28 | | the Mailgun mail service which will provide reliable deliveries. 29 | | 30 | */ 31 | 32 | 'host' => env('MAIL_HOST', 'smtp.mailgun.org'), 33 | 34 | /* 35 | |-------------------------------------------------------------------------- 36 | | SMTP Host Port 37 | |-------------------------------------------------------------------------- 38 | | 39 | | This is the SMTP port used by your application to deliver e-mails to 40 | | users of the application. Like the host we have set this value to 41 | | stay compatible with the Mailgun e-mail application by default. 42 | | 43 | */ 44 | 45 | 'port' => env('MAIL_PORT', 587), 46 | 47 | /* 48 | |-------------------------------------------------------------------------- 49 | | Global "From" Address 50 | |-------------------------------------------------------------------------- 51 | | 52 | | You may wish for all e-mails sent by your application to be sent from 53 | | the same address. Here, you may specify a name and address that is 54 | | used globally for all e-mails that are sent by your application. 55 | | 56 | */ 57 | 58 | 'from' => [ 59 | 'address' => env('MAIL_FROM_ADDRESS', 'hello@example.com'), 60 | 'name' => env('MAIL_FROM_NAME', 'Example'), 61 | ], 62 | 63 | /* 64 | |-------------------------------------------------------------------------- 65 | | E-Mail Encryption Protocol 66 | |-------------------------------------------------------------------------- 67 | | 68 | | Here you may specify the encryption protocol that should be used when 69 | | the application send e-mail messages. A sensible default using the 70 | | transport layer security protocol should provide great security. 71 | | 72 | */ 73 | 74 | 'encryption' => env('MAIL_ENCRYPTION', 'tls'), 75 | 76 | /* 77 | |-------------------------------------------------------------------------- 78 | | SMTP Server Username 79 | |-------------------------------------------------------------------------- 80 | | 81 | | If your SMTP server requires a username for authentication, you should 82 | | set it here. This will get used to authenticate with your server on 83 | | connection. You may also set the "password" value below this one. 84 | | 85 | */ 86 | 87 | 'username' => env('MAIL_USERNAME'), 88 | 89 | 'password' => env('MAIL_PASSWORD'), 90 | 91 | /* 92 | |-------------------------------------------------------------------------- 93 | | Sendmail System Path 94 | |-------------------------------------------------------------------------- 95 | | 96 | | When using the "sendmail" driver to send e-mails, we will need to know 97 | | the path to where Sendmail lives on this server. A default path has 98 | | been provided here, which will work well on most of your systems. 99 | | 100 | */ 101 | 102 | 'sendmail' => '/usr/sbin/sendmail -bs', 103 | 104 | /* 105 | |-------------------------------------------------------------------------- 106 | | Markdown Mail Settings 107 | |-------------------------------------------------------------------------- 108 | | 109 | | If you are using Markdown based email rendering, you may configure your 110 | | theme and component paths here, allowing you to customize the design 111 | | of the emails. Or, you may simply stick with the Laravel defaults! 112 | | 113 | */ 114 | 115 | 'markdown' => [ 116 | 'theme' => 'default', 117 | 118 | 'paths' => [ 119 | resource_path('views/vendor/mail'), 120 | ], 121 | ], 122 | 123 | ]; 124 | -------------------------------------------------------------------------------- /config/queue.php: -------------------------------------------------------------------------------- 1 | env('QUEUE_DRIVER', 'sync'), 19 | 20 | /* 21 | |-------------------------------------------------------------------------- 22 | | Queue Connections 23 | |-------------------------------------------------------------------------- 24 | | 25 | | Here you may configure the connection information for each server that 26 | | is used by your application. A default configuration has been added 27 | | for each back-end shipped with Laravel. You are free to add more. 28 | | 29 | */ 30 | 31 | 'connections' => [ 32 | 33 | 'sync' => [ 34 | 'driver' => 'sync', 35 | ], 36 | 37 | 'database' => [ 38 | 'driver' => 'database', 39 | 'table' => 'jobs', 40 | 'queue' => 'default', 41 | 'retry_after' => 90, 42 | ], 43 | 44 | 'beanstalkd' => [ 45 | 'driver' => 'beanstalkd', 46 | 'host' => 'localhost', 47 | 'queue' => 'default', 48 | 'retry_after' => 90, 49 | ], 50 | 51 | 'sqs' => [ 52 | 'driver' => 'sqs', 53 | 'key' => env('SQS_KEY', 'your-public-key'), 54 | 'secret' => env('SQS_SECRET', 'your-secret-key'), 55 | 'prefix' => env('SQS_PREFIX', 'https://sqs.us-east-1.amazonaws.com/your-account-id'), 56 | 'queue' => env('SQS_QUEUE', 'your-queue-name'), 57 | 'region' => env('SQS_REGION', 'us-east-1'), 58 | ], 59 | 60 | 'redis' => [ 61 | 'driver' => 'redis', 62 | 'connection' => 'default', 63 | 'queue' => 'default', 64 | 'retry_after' => 90, 65 | 'block_for' => null, 66 | ], 67 | 68 | ], 69 | 70 | /* 71 | |-------------------------------------------------------------------------- 72 | | Failed Queue Jobs 73 | |-------------------------------------------------------------------------- 74 | | 75 | | These options configure the behavior of failed queue job logging so you 76 | | can control which database and table are used to store the jobs that 77 | | have failed. You may change them to any database / table you wish. 78 | | 79 | */ 80 | 81 | 'failed' => [ 82 | 'database' => env('DB_CONNECTION', 'mysql'), 83 | 'table' => 'failed_jobs', 84 | ], 85 | 86 | ]; 87 | -------------------------------------------------------------------------------- /config/services.php: -------------------------------------------------------------------------------- 1 | [ 18 | 'domain' => env('MAILGUN_DOMAIN'), 19 | 'secret' => env('MAILGUN_SECRET'), 20 | ], 21 | 22 | 'ses' => [ 23 | 'key' => env('SES_KEY'), 24 | 'secret' => env('SES_SECRET'), 25 | 'region' => 'us-east-1', 26 | ], 27 | 28 | 'sparkpost' => [ 29 | 'secret' => env('SPARKPOST_SECRET'), 30 | ], 31 | 32 | 'stripe' => [ 33 | 'model' => App\User::class, 34 | 'key' => env('STRIPE_KEY'), 35 | 'secret' => env('STRIPE_SECRET'), 36 | ], 37 | 38 | ]; 39 | -------------------------------------------------------------------------------- /config/session.php: -------------------------------------------------------------------------------- 1 | env('SESSION_DRIVER', 'file'), 20 | 21 | /* 22 | |-------------------------------------------------------------------------- 23 | | Session Lifetime 24 | |-------------------------------------------------------------------------- 25 | | 26 | | Here you may specify the number of minutes that you wish the session 27 | | to be allowed to remain idle before it expires. If you want them 28 | | to immediately expire on the browser closing, set that option. 29 | | 30 | */ 31 | 32 | 'lifetime' => env('SESSION_LIFETIME', 120), 33 | 34 | 'expire_on_close' => false, 35 | 36 | /* 37 | |-------------------------------------------------------------------------- 38 | | Session Encryption 39 | |-------------------------------------------------------------------------- 40 | | 41 | | This option allows you to easily specify that all of your session data 42 | | should be encrypted before it is stored. All encryption will be run 43 | | automatically by Laravel and you can use the Session like normal. 44 | | 45 | */ 46 | 47 | 'encrypt' => false, 48 | 49 | /* 50 | |-------------------------------------------------------------------------- 51 | | Session File Location 52 | |-------------------------------------------------------------------------- 53 | | 54 | | When using the native session driver, we need a location where session 55 | | files may be stored. A default has been set for you but a different 56 | | location may be specified. This is only needed for file sessions. 57 | | 58 | */ 59 | 60 | 'files' => storage_path('framework/sessions'), 61 | 62 | /* 63 | |-------------------------------------------------------------------------- 64 | | Session Database Connection 65 | |-------------------------------------------------------------------------- 66 | | 67 | | When using the "database" or "redis" session drivers, you may specify a 68 | | connection that should be used to manage these sessions. This should 69 | | correspond to a connection in your database configuration options. 70 | | 71 | */ 72 | 73 | 'connection' => null, 74 | 75 | /* 76 | |-------------------------------------------------------------------------- 77 | | Session Database Table 78 | |-------------------------------------------------------------------------- 79 | | 80 | | When using the "database" session driver, you may specify the table we 81 | | should use to manage the sessions. Of course, a sensible default is 82 | | provided for you; however, you are free to change this as needed. 83 | | 84 | */ 85 | 86 | 'table' => 'sessions', 87 | 88 | /* 89 | |-------------------------------------------------------------------------- 90 | | Session Cache Store 91 | |-------------------------------------------------------------------------- 92 | | 93 | | When using the "apc" or "memcached" session drivers, you may specify a 94 | | cache store that should be used for these sessions. This value must 95 | | correspond with one of the application's configured cache stores. 96 | | 97 | */ 98 | 99 | 'store' => null, 100 | 101 | /* 102 | |-------------------------------------------------------------------------- 103 | | Session Sweeping Lottery 104 | |-------------------------------------------------------------------------- 105 | | 106 | | Some session drivers must manually sweep their storage location to get 107 | | rid of old sessions from storage. Here are the chances that it will 108 | | happen on a given request. By default, the odds are 2 out of 100. 109 | | 110 | */ 111 | 112 | 'lottery' => [2, 100], 113 | 114 | /* 115 | |-------------------------------------------------------------------------- 116 | | Session Cookie Name 117 | |-------------------------------------------------------------------------- 118 | | 119 | | Here you may change the name of the cookie used to identify a session 120 | | instance by ID. The name specified here will get used every time a 121 | | new session cookie is created by the framework for every driver. 122 | | 123 | */ 124 | 125 | 'cookie' => env( 126 | 'SESSION_COOKIE', 127 | str_slug(env('APP_NAME', 'laravel'), '_').'_session' 128 | ), 129 | 130 | /* 131 | |-------------------------------------------------------------------------- 132 | | Session Cookie Path 133 | |-------------------------------------------------------------------------- 134 | | 135 | | The session cookie path determines the path for which the cookie will 136 | | be regarded as available. Typically, this will be the root path of 137 | | your application but you are free to change this when necessary. 138 | | 139 | */ 140 | 141 | 'path' => '/', 142 | 143 | /* 144 | |-------------------------------------------------------------------------- 145 | | Session Cookie Domain 146 | |-------------------------------------------------------------------------- 147 | | 148 | | Here you may change the domain of the cookie used to identify a session 149 | | in your application. This will determine which domains the cookie is 150 | | available to in your application. A sensible default has been set. 151 | | 152 | */ 153 | 154 | 'domain' => env('SESSION_DOMAIN', null), 155 | 156 | /* 157 | |-------------------------------------------------------------------------- 158 | | HTTPS Only Cookies 159 | |-------------------------------------------------------------------------- 160 | | 161 | | By setting this option to true, session cookies will only be sent back 162 | | to the server if the browser has a HTTPS connection. This will keep 163 | | the cookie from being sent to you if it can not be done securely. 164 | | 165 | */ 166 | 167 | 'secure' => env('SESSION_SECURE_COOKIE', false), 168 | 169 | /* 170 | |-------------------------------------------------------------------------- 171 | | HTTP Access Only 172 | |-------------------------------------------------------------------------- 173 | | 174 | | Setting this value to true will prevent JavaScript from accessing the 175 | | value of the cookie and the cookie will only be accessible through 176 | | the HTTP protocol. You are free to modify this option if needed. 177 | | 178 | */ 179 | 180 | 'http_only' => true, 181 | 182 | /* 183 | |-------------------------------------------------------------------------- 184 | | Same-Site Cookies 185 | |-------------------------------------------------------------------------- 186 | | 187 | | This option determines how your cookies behave when cross-site requests 188 | | take place, and can be used to mitigate CSRF attacks. By default, we 189 | | do not enable this as other CSRF protection services are in place. 190 | | 191 | | Supported: "lax", "strict" 192 | | 193 | */ 194 | 195 | 'same_site' => null, 196 | 197 | ]; 198 | -------------------------------------------------------------------------------- /config/view.php: -------------------------------------------------------------------------------- 1 | [ 17 | resource_path('views'), 18 | ], 19 | 20 | /* 21 | |-------------------------------------------------------------------------- 22 | | Compiled View Path 23 | |-------------------------------------------------------------------------- 24 | | 25 | | This option determines where all the compiled Blade templates will be 26 | | stored for your application. Typically, this is within the storage 27 | | directory. However, as usual, you are free to change this value. 28 | | 29 | */ 30 | 31 | 'compiled' => realpath(storage_path('framework/views')), 32 | 33 | ]; 34 | -------------------------------------------------------------------------------- /database/.gitignore: -------------------------------------------------------------------------------- 1 | *.sqlite 2 | -------------------------------------------------------------------------------- /database/factories/UserFactory.php: -------------------------------------------------------------------------------- 1 | define(App\Models\User::class, function (Faker $faker) { 17 | static $password; 18 | 19 | return [ 20 | 'name' => $faker->name, 21 | 'email' => $faker->unique()->safeEmail, 22 | 'password' => $password ?: $password = bcrypt('secret'), 23 | 'remember_token' => str_random(10), 24 | ]; 25 | }); 26 | -------------------------------------------------------------------------------- /database/migrations/2014_10_12_000000_create_users_table.php: -------------------------------------------------------------------------------- 1 | increments('id'); 18 | $table->string('name'); 19 | $table->string('email')->unique(); 20 | $table->string('password'); 21 | $table->text('token')->nullable(); 22 | $table->text('webhook')->nullable(); 23 | $table->string('username')->nullable(); 24 | $table->string('surname')->nullable(); 25 | $table->string('telegram_id')->nullable(); 26 | $table->rememberToken(); 27 | $table->timestamps(); 28 | }); 29 | } 30 | 31 | /** 32 | * Reverse the migrations. 33 | * 34 | * @return void 35 | */ 36 | public function down() 37 | { 38 | Schema::dropIfExists('users'); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /database/migrations/2014_10_12_100000_create_password_resets_table.php: -------------------------------------------------------------------------------- 1 | string('email')->index(); 18 | $table->string('token'); 19 | $table->timestamp('created_at')->nullable(); 20 | }); 21 | } 22 | 23 | /** 24 | * Reverse the migrations. 25 | * 26 | * @return void 27 | */ 28 | public function down() 29 | { 30 | Schema::dropIfExists('password_resets'); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /database/seeds/DatabaseSeeder.php: -------------------------------------------------------------------------------- 1 | call(UsersTableSeeder::class); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "private": true, 3 | "scripts": { 4 | "dev": "npm run development", 5 | "development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js", 6 | "watch": "npm run development -- --watch", 7 | "watch-poll": "npm run watch -- --watch-poll", 8 | "hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js", 9 | "prod": "npm run production", 10 | "production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js" 11 | }, 12 | "devDependencies": { 13 | "axios": "^0.18", 14 | "bootstrap": "^4.0.0", 15 | "popper.js": "^1.12", 16 | "cross-env": "^5.1", 17 | "jquery": "^3.5", 18 | "laravel-mix": "^2.0", 19 | "lodash": "^4.17.19", 20 | "vue": "^2.5.7" 21 | }, 22 | "dependencies": { 23 | "botman-tinker": "^0.0.1" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 13 | ./tests/Feature 14 | 15 | 16 | 17 | ./tests/Unit 18 | 19 | 20 | 21 | ./tests/BotMan 22 | 23 | 24 | 25 | 26 | ./app 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /public/.htaccess: -------------------------------------------------------------------------------- 1 | 2 | 3 | Options -MultiViews 4 | 5 | 6 | RewriteEngine On 7 | 8 | # Redirect Trailing Slashes If Not A Folder... 9 | RewriteCond %{REQUEST_FILENAME} !-d 10 | RewriteCond %{REQUEST_URI} (.+)/$ 11 | RewriteRule ^ %1 [L,R=301] 12 | 13 | # Handle Front Controller... 14 | RewriteCond %{REQUEST_FILENAME} !-d 15 | RewriteCond %{REQUEST_FILENAME} !-f 16 | RewriteRule ^ index.php [L] 17 | 18 | # Handle Authorization Header 19 | RewriteCond %{HTTP:Authorization} . 20 | RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] 21 | 22 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lloople/bot-mr-dear/abbff7dc9689e8ac8682dc50e71d772e2a0136b4/public/favicon.ico -------------------------------------------------------------------------------- /public/img/ohdear_avatar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lloople/bot-mr-dear/abbff7dc9689e8ac8682dc50e71d772e2a0136b4/public/img/ohdear_avatar.png -------------------------------------------------------------------------------- /public/index.php: -------------------------------------------------------------------------------- 1 | 8 | */ 9 | 10 | define('LARAVEL_START', microtime(true)); 11 | 12 | /* 13 | |-------------------------------------------------------------------------- 14 | | Register The Auto Loader 15 | |-------------------------------------------------------------------------- 16 | | 17 | | Composer provides a convenient, automatically generated class loader for 18 | | our application. We just need to utilize it! We'll simply require it 19 | | into the script here so that we don't have to worry about manual 20 | | loading any of our classes later on. It feels great to relax. 21 | | 22 | */ 23 | 24 | require __DIR__.'/../vendor/autoload.php'; 25 | 26 | /* 27 | |-------------------------------------------------------------------------- 28 | | Turn On The Lights 29 | |-------------------------------------------------------------------------- 30 | | 31 | | We need to illuminate PHP development, so let us turn on the lights. 32 | | This bootstraps the framework and gets it ready for use, then it 33 | | will load up this application so that we can run it and send 34 | | the responses back to the browser and delight our users. 35 | | 36 | */ 37 | 38 | $app = require_once __DIR__.'/../bootstrap/app.php'; 39 | 40 | /* 41 | |-------------------------------------------------------------------------- 42 | | Run The Application 43 | |-------------------------------------------------------------------------- 44 | | 45 | | Once we have the application, we can handle the incoming request 46 | | through the kernel, and send the associated response back to 47 | | the client's browser allowing them to enjoy the creative 48 | | and wonderful application we have prepared for them. 49 | | 50 | */ 51 | 52 | $kernel = $app->make(Illuminate\Contracts\Http\Kernel::class); 53 | 54 | $response = $kernel->handle( 55 | $request = Illuminate\Http\Request::capture() 56 | ); 57 | 58 | $response->send(); 59 | 60 | $kernel->terminate($request, $response); 61 | -------------------------------------------------------------------------------- /public/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lloople/bot-mr-dear/abbff7dc9689e8ac8682dc50e71d772e2a0136b4/public/logo.png -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | User-agent: * 2 | Disallow: 3 | -------------------------------------------------------------------------------- /resources/assets/js/app.js: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * First we will load all of this project's JavaScript dependencies which 4 | * includes Vue and other libraries. It is a great starting point when 5 | * building robust, powerful web applications using Vue and Laravel. 6 | */ 7 | 8 | require('./bootstrap'); 9 | 10 | window.Vue = require('vue'); 11 | 12 | /** 13 | * Next, we will create a fresh Vue application instance and attach it to 14 | * the page. Then, you may begin adding components to this application 15 | * or customize the JavaScript scaffolding to fit your unique needs. 16 | */ 17 | 18 | import {TinkerComponent} from 'botman-tinker'; 19 | Vue.component('botman-tinker', TinkerComponent); 20 | 21 | const app = new Vue({ 22 | el: '#app' 23 | }); -------------------------------------------------------------------------------- /resources/assets/js/bootstrap.js: -------------------------------------------------------------------------------- 1 | window._ = require('lodash'); 2 | window.Popper = require('popper.js').default; 3 | 4 | /** 5 | * We'll load jQuery and the Bootstrap jQuery plugin which provides support 6 | * for JavaScript based Bootstrap features such as modals and tabs. This 7 | * code may be modified to fit the specific needs of your application. 8 | */ 9 | 10 | try { 11 | window.$ = window.jQuery = require('jquery'); 12 | 13 | require('bootstrap'); 14 | } catch (e) {} 15 | 16 | /** 17 | * We'll load the axios HTTP library which allows us to easily issue requests 18 | * to our Laravel back-end. This library automatically handles sending the 19 | * CSRF token as a header based on the value of the "XSRF" token cookie. 20 | */ 21 | 22 | window.axios = require('axios'); 23 | 24 | window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest'; 25 | 26 | /** 27 | * Next we will register the CSRF Token as a common header with Axios so that 28 | * all outgoing HTTP requests automatically have it attached. This is just 29 | * a simple convenience so we don't have to attach every token manually. 30 | */ 31 | 32 | let token = document.head.querySelector('meta[name="csrf-token"]'); 33 | 34 | if (token) { 35 | window.axios.defaults.headers.common['X-CSRF-TOKEN'] = token.content; 36 | } else { 37 | console.error('CSRF token not found: https://laravel.com/docs/csrf#csrf-x-csrf-token'); 38 | } 39 | 40 | /** 41 | * Echo exposes an expressive API for subscribing to channels and listening 42 | * for events that are broadcast by Laravel. Echo and event broadcasting 43 | * allows your team to easily build robust real-time web applications. 44 | */ 45 | 46 | // import Echo from 'laravel-echo' 47 | 48 | // window.Pusher = require('pusher-js'); 49 | 50 | // window.Echo = new Echo({ 51 | // broadcaster: 'pusher', 52 | // key: process.env.MIX_PUSHER_APP_KEY, 53 | // cluster: process.env.MIX_PUSHER_APP_CLUSTER, 54 | // encrypted: true 55 | // }); -------------------------------------------------------------------------------- /resources/assets/sass/_variables.scss: -------------------------------------------------------------------------------- 1 | // Body 2 | $body-bg: #f5f8fa; 3 | 4 | // Typography 5 | $font-family-sans-serif: "Raleway", sans-serif; 6 | $font-size-base: 0.9rem; 7 | $line-height-base: 1.6; -------------------------------------------------------------------------------- /resources/assets/sass/app.scss: -------------------------------------------------------------------------------- 1 | // Fonts 2 | @import url("https://fonts.googleapis.com/css?family=Raleway:300,400,600"); 3 | 4 | // Variables 5 | @import "variables"; 6 | 7 | // Bootstrap 8 | @import '~bootstrap/scss/bootstrap'; 9 | 10 | .navbar-laravel { 11 | background-color: #fff; 12 | box-shadow: 0 2px 4px rgba(0, 0, 0, 0.04); 13 | } -------------------------------------------------------------------------------- /resources/lang/en/auth.php: -------------------------------------------------------------------------------- 1 | 'These credentials do not match our records.', 17 | 'throttle' => 'Too many login attempts. Please try again in :seconds seconds.', 18 | 19 | ]; 20 | -------------------------------------------------------------------------------- /resources/lang/en/ohdear.php: -------------------------------------------------------------------------------- 1 | 'Hello there! 👋', 5 | 'already_set_up' => 'You have completed the setup already. If you need to change any of your configuration, use /token {token} or /webhook {secret}.', 6 | 'sites' => [ 7 | 'list_message' => 'Choose a site to interact with.', 8 | 'list_empty' => 'There are no sites on your account. Perhaps you want to add a new one right now? use the command /newsite', 9 | 'not_found' => 'You\'re not currently monitoring this site.', 10 | 'created' => '👍 Oh Dear is now monitoring your site. All checks have been enabled by default.', 11 | 'invalid_url' => 'Sorry, I cannot say that\'s a valid url. Example: https://example.com', 12 | 'already_exists' => 'You\'re already monitoring that url 😅', 13 | 'delete_confirm_1' => '⚠️ Are you sure you want to stop monitoring this site? All history data will be lost and this step cannot be undone.', 14 | 'delete_confirm_2' => 'I\'ll proceed to delete the site *https://example.com*. Are you totally sure you want to continue?', 15 | 'delete_cancel' => 'Alright, we will keep monitoring the site a bit longer 🙂', 16 | 'deleted' => 'I deleted the site. You\'re no longer monitoring it.', 17 | 'next_action' => 'What do you want to do next?', 18 | ], 19 | 'token' => [ 20 | 'question' => 'I see you have no token configured, can you send it to me? I\'ll save it encrypted don\'t worry.', 21 | 'stored' => 'Thank you for trusting me! You can delete the token message now for more security', 22 | ], 23 | 'uptime' => [ 24 | 'result' => 'Your site had a :percentage% of uptime on :date :emoji', 25 | 'perfect' => 'Your site had a perfect uptime from :begin to :end! 🙌' 26 | ], 27 | 'downtime' => [ 28 | 'result' => 'Your website was down for :downtime on :date', 29 | 'perfect' => 'Your site was up all the time during the last month! 🎉', 30 | 'summary' => 'The last time your site was down was :elapsed ago :emoji' 31 | ], 32 | 'brokenlinks' => [ 33 | 'perfect' => 'Your site has no broken links! 🙌', 34 | 'result' => 'The url :url returned a :code error'.PHP_EOL.'It was found on :origin' 35 | ], 36 | 'mixedcontent' => [ 37 | 'perfect' => 'Your site has no mixed content! 🙌', 38 | 'result' => ':url'.PHP_EOL.'Was found on :origin' 39 | ], 40 | 'help' => [ 41 | 'title' => 'Looks like you\'re a bit lost, let me help you out 😉' 42 | ], 43 | 'webhook' => [ 44 | 'question' => 'I see you have no webhook configured. This is required if you want me to warn you if any of your sites have any issue. You can find your webhook secret in the bottom of the [Notifications](https://ohdear.app/team-settings/notifications) section.', 45 | 'stored' => 'Remember to add the url :url to your [OhDear Notifications](https://ohdear.app/team-settings/notifications). I\'ll let you know if any of your sites has any problem 👍', 46 | 'uptime_check_failed' => '😱 Hey! your site :url seems down!', 47 | 'broken_links_found' => '⚠️ Whoops, we found broken links in your site :url' 48 | ] 49 | ]; -------------------------------------------------------------------------------- /resources/lang/en/pagination.php: -------------------------------------------------------------------------------- 1 | '« Previous', 17 | 'next' => 'Next »', 18 | 19 | ]; 20 | -------------------------------------------------------------------------------- /resources/lang/en/passwords.php: -------------------------------------------------------------------------------- 1 | 'Passwords must be at least six characters and match the confirmation.', 17 | 'reset' => 'Your password has been reset!', 18 | 'sent' => 'We have e-mailed your password reset link!', 19 | 'token' => 'This password reset token is invalid.', 20 | 'user' => "We can't find a user with that e-mail address.", 21 | 22 | ]; 23 | -------------------------------------------------------------------------------- /resources/lang/en/validation.php: -------------------------------------------------------------------------------- 1 | 'The :attribute must be accepted.', 17 | 'active_url' => 'The :attribute is not a valid URL.', 18 | 'after' => 'The :attribute must be a date after :date.', 19 | 'after_or_equal' => 'The :attribute must be a date after or equal to :date.', 20 | 'alpha' => 'The :attribute may only contain letters.', 21 | 'alpha_dash' => 'The :attribute may only contain letters, numbers, and dashes.', 22 | 'alpha_num' => 'The :attribute may only contain letters and numbers.', 23 | 'array' => 'The :attribute must be an array.', 24 | 'before' => 'The :attribute must be a date before :date.', 25 | 'before_or_equal' => 'The :attribute must be a date before or equal to :date.', 26 | 'between' => [ 27 | 'numeric' => 'The :attribute must be between :min and :max.', 28 | 'file' => 'The :attribute must be between :min and :max kilobytes.', 29 | 'string' => 'The :attribute must be between :min and :max characters.', 30 | 'array' => 'The :attribute must have between :min and :max items.', 31 | ], 32 | 'boolean' => 'The :attribute field must be true or false.', 33 | 'confirmed' => 'The :attribute confirmation does not match.', 34 | 'date' => 'The :attribute is not a valid date.', 35 | 'date_format' => 'The :attribute does not match the format :format.', 36 | 'different' => 'The :attribute and :other must be different.', 37 | 'digits' => 'The :attribute must be :digits digits.', 38 | 'digits_between' => 'The :attribute must be between :min and :max digits.', 39 | 'dimensions' => 'The :attribute has invalid image dimensions.', 40 | 'distinct' => 'The :attribute field has a duplicate value.', 41 | 'email' => 'The :attribute must be a valid email address.', 42 | 'exists' => 'The selected :attribute is invalid.', 43 | 'file' => 'The :attribute must be a file.', 44 | 'filled' => 'The :attribute field must have a value.', 45 | 'image' => 'The :attribute must be an image.', 46 | 'in' => 'The selected :attribute is invalid.', 47 | 'in_array' => 'The :attribute field does not exist in :other.', 48 | 'integer' => 'The :attribute must be an integer.', 49 | 'ip' => 'The :attribute must be a valid IP address.', 50 | 'ipv4' => 'The :attribute must be a valid IPv4 address.', 51 | 'ipv6' => 'The :attribute must be a valid IPv6 address.', 52 | 'json' => 'The :attribute must be a valid JSON string.', 53 | 'max' => [ 54 | 'numeric' => 'The :attribute may not be greater than :max.', 55 | 'file' => 'The :attribute may not be greater than :max kilobytes.', 56 | 'string' => 'The :attribute may not be greater than :max characters.', 57 | 'array' => 'The :attribute may not have more than :max items.', 58 | ], 59 | 'mimes' => 'The :attribute must be a file of type: :values.', 60 | 'mimetypes' => 'The :attribute must be a file of type: :values.', 61 | 'min' => [ 62 | 'numeric' => 'The :attribute must be at least :min.', 63 | 'file' => 'The :attribute must be at least :min kilobytes.', 64 | 'string' => 'The :attribute must be at least :min characters.', 65 | 'array' => 'The :attribute must have at least :min items.', 66 | ], 67 | 'not_in' => 'The selected :attribute is invalid.', 68 | 'numeric' => 'The :attribute must be a number.', 69 | 'present' => 'The :attribute field must be present.', 70 | 'regex' => 'The :attribute format is invalid.', 71 | 'required' => 'The :attribute field is required.', 72 | 'required_if' => 'The :attribute field is required when :other is :value.', 73 | 'required_unless' => 'The :attribute field is required unless :other is in :values.', 74 | 'required_with' => 'The :attribute field is required when :values is present.', 75 | 'required_with_all' => 'The :attribute field is required when :values is present.', 76 | 'required_without' => 'The :attribute field is required when :values is not present.', 77 | 'required_without_all' => 'The :attribute field is required when none of :values are present.', 78 | 'same' => 'The :attribute and :other must match.', 79 | 'size' => [ 80 | 'numeric' => 'The :attribute must be :size.', 81 | 'file' => 'The :attribute must be :size kilobytes.', 82 | 'string' => 'The :attribute must be :size characters.', 83 | 'array' => 'The :attribute must contain :size items.', 84 | ], 85 | 'string' => 'The :attribute must be a string.', 86 | 'timezone' => 'The :attribute must be a valid zone.', 87 | 'unique' => 'The :attribute has already been taken.', 88 | 'uploaded' => 'The :attribute failed to upload.', 89 | 'url' => 'The :attribute format is invalid.', 90 | 91 | /* 92 | |-------------------------------------------------------------------------- 93 | | Custom Validation Language Lines 94 | |-------------------------------------------------------------------------- 95 | | 96 | | Here you may specify custom validation messages for attributes using the 97 | | convention "attribute.rule" to name the lines. This makes it quick to 98 | | specify a specific custom language line for a given attribute rule. 99 | | 100 | */ 101 | 102 | 'custom' => [ 103 | 'attribute-name' => [ 104 | 'rule-name' => 'custom-message', 105 | ], 106 | ], 107 | 108 | /* 109 | |-------------------------------------------------------------------------- 110 | | Custom Validation Attributes 111 | |-------------------------------------------------------------------------- 112 | | 113 | | The following language lines are used to swap attribute place-holders 114 | | with something more reader friendly such as E-Mail Address instead 115 | | of "email". This simply helps us make messages a little cleaner. 116 | | 117 | */ 118 | 119 | 'attributes' => [], 120 | 121 | ]; 122 | -------------------------------------------------------------------------------- /resources/markdown/help.md: -------------------------------------------------------------------------------- 1 | /help 2 | See this helping message 🙂. 3 | 4 | /sites 5 | See a quick list of all your sites and the most recent status of each one. 6 | 7 | */token {token}* 8 | Register your token to interact with OhDear. You can add a new token here https://ohdear.app/user-settings/api. 9 | 10 | */newsite {url}* 11 | Register a new site on your account. It must be a valid url with protocol and all those things that are hard to type from a phone keyboard 😛. 12 | 13 | */deletesite {url or id}* 14 | Stop monitoring a specific site. I'll ask you to confirm this action twice. 15 | 16 | */site {url or id}* 17 | See all the information of a specific site. It will also show you a few buttons to interact with this actions directly 👇 18 | 19 | */downtime {url or id}* 20 | Check the downtime of the site for the last month. 21 | 22 | */uptime {url or id}* 23 | Cueck the percentage of uptime of the site for the last month. 24 | 25 | */brokenlinks {url or id}* 26 | Check out your website's broken links. 27 | 28 | */mixedcontent {url or id}* 29 | Check out your website's mixed content. -------------------------------------------------------------------------------- /resources/views/tinker.blade.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | BotMan Studio 9 | 10 | 11 | 12 | 13 | 14 | 33 | 34 | 35 |
36 |
37 | 38 |
39 |
40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /resources/views/welcome.blade.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | BotMan Studio 9 | 10 | 11 | 12 | 13 | 14 | 53 | 54 | 55 |
56 |
57 | 60 | 61 | 68 |
69 |
70 | 71 | -------------------------------------------------------------------------------- /routes/api.php: -------------------------------------------------------------------------------- 1 | get('/user', function (Request $request) { 17 | return $request->user(); 18 | }); 19 | -------------------------------------------------------------------------------- /routes/botman.php: -------------------------------------------------------------------------------- 1 | middleware->received(new \App\Http\Middleware\LoadUserMiddleware()); 6 | 7 | $botman->hears('/help', \App\Http\Controllers\Help\ShowController::class); 8 | 9 | $botman->hears('/start', \App\Http\Controllers\Users\StoreController::class); 10 | $botman->hears('/token {token}', \App\Http\Controllers\Token\StoreController::class); 11 | 12 | 13 | $botman->hears('/sites', \App\Http\Controllers\Sites\IndexController::class); 14 | $botman->hears('/newsite (.*[^\s])', \App\Http\Controllers\Sites\StoreController::class); 15 | $botman->hears('/site (.*[^\s])', \App\Http\Controllers\Sites\ShowController::class); 16 | $botman->hears('/deletesite (.*[^\s])', \App\Http\Controllers\Sites\DestroyController::class); 17 | $botman->hears('/downtime (.*[^\s])', \App\Http\Controllers\Downtime\ShowController::class); 18 | $botman->hears('/uptime (.*[^\s])', \App\Http\Controllers\Uptime\ShowController::class); 19 | $botman->hears('/brokenlinks (.*[^\s])', \App\Http\Controllers\BrokenLinks\ShowController::class); 20 | $botman->hears('/mixedcontent (.*[^\s])', \App\Http\Controllers\MixedContent\ShowController::class); 21 | $botman->hears('/webhook (.*)', \App\Http\Controllers\Webhook\StoreController::class); 22 | -------------------------------------------------------------------------------- /routes/channels.php: -------------------------------------------------------------------------------- 1 | id === (int) $id; 16 | }); 17 | -------------------------------------------------------------------------------- /routes/console.php: -------------------------------------------------------------------------------- 1 | comment(Inspiring::quote()); 18 | })->describe('Display an inspiring quote'); 19 | -------------------------------------------------------------------------------- /routes/web.php: -------------------------------------------------------------------------------- 1 | name('webhook'); -------------------------------------------------------------------------------- /server.php: -------------------------------------------------------------------------------- 1 | 8 | */ 9 | 10 | $uri = urldecode( 11 | parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH) 12 | ); 13 | 14 | // This file allows us to emulate Apache's "mod_rewrite" functionality from the 15 | // built-in PHP web server. This provides a convenient way to test a Laravel 16 | // application without having installed a "real" web server software here. 17 | if ($uri !== '/' && file_exists(__DIR__.'/public'.$uri)) { 18 | return false; 19 | } 20 | 21 | require_once __DIR__.'/public/index.php'; 22 | -------------------------------------------------------------------------------- /storage/app/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !public/ 3 | !.gitignore 4 | -------------------------------------------------------------------------------- /storage/app/public/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /storage/framework/.gitignore: -------------------------------------------------------------------------------- 1 | config.php 2 | routes.php 3 | schedule-* 4 | compiled.php 5 | services.json 6 | events.scanned.php 7 | routes.scanned.php 8 | down 9 | -------------------------------------------------------------------------------- /storage/framework/cache/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /storage/framework/sessions/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /storage/framework/testing/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /storage/framework/views/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /storage/logs/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /tests/CreatesApplication.php: -------------------------------------------------------------------------------- 1 | make(Kernel::class)->bootstrap(); 30 | 31 | $this->botman = $app->make('botman'); 32 | $this->bot = new BotManTester($this->botman, $fakeDriver, $this); 33 | 34 | Hash::driver('bcrypt')->setRounds(4); 35 | 36 | $app->singleton(OhDear::class, \Tests\Fakes\OhDear::class); 37 | 38 | return $app; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /tests/Fakes/OhDear.php: -------------------------------------------------------------------------------- 1 | sites = $this->collect($this->getFakeSites(), Site::class); 22 | } 23 | 24 | private function getFakeSites() 25 | { 26 | return json_decode(file_get_contents(base_path('tests/Fakes/responses/sites_list.json')), true)['data']; 27 | } 28 | 29 | public function sites(): Collection 30 | { 31 | return $this->sites; 32 | } 33 | 34 | public function createSite(string $url): Site 35 | { 36 | $siteData = $this->getFakeSites()[0]; 37 | 38 | $siteData['url'] = $this->validatedUrl($url); 39 | 40 | $siteData['sort_url'] = str_replace('http://', '', $siteData['url']); 41 | $siteData['sort_url'] = str_replace('https://', '', $siteData['sort_url']); 42 | 43 | return new Site($siteData, $this); 44 | } 45 | 46 | public function findSiteByUrl(string $url): ?Site 47 | { 48 | return $this->sites->first(function (Site $site) use ($url) { 49 | return stripos($site->url, $url) !== false; 50 | }, null); 51 | } 52 | 53 | public function findSite($id): Site 54 | { 55 | if (is_numeric($id)) { 56 | return $this->sites()->first(function (Site $site) use ($id) { 57 | return $site->id == $id; 58 | }, function () { throw new SiteNotFoundException(); }); 59 | } 60 | 61 | return $this->sites()->first(function (Site $site) use ($id) { 62 | return stripos($site->url, $id) !== false; 63 | }, function () { throw new SiteNotFoundException(); }); 64 | 65 | } 66 | 67 | public function deleteSite($siteId) 68 | { 69 | $this->sites = $this->sites->reject(function (Site $site) use ($siteId) { 70 | return $site->id === $siteId; 71 | }); 72 | 73 | return ! $this->sites->firstWhere('id', $siteId); 74 | } 75 | 76 | public function getSiteDowntime($siteId) 77 | { 78 | $downtimes = include base_path('tests/Fakes/responses/downtimes.php'); 79 | 80 | return $this->collect($downtimes[$siteId], Downtime::class); 81 | } 82 | 83 | public function getSiteUptime($siteId) 84 | { 85 | $uptimes = include base_path('tests/Fakes/responses/uptimes.php'); 86 | 87 | return $this->collect($uptimes[$siteId], Uptime::class); 88 | } 89 | 90 | public function getBrokenLinks($siteId) 91 | { 92 | $brokenLinks = [ 93 | '9999' => [ 94 | [ 95 | 'crawledUrl' => 'https://example.com/broken', 96 | 'statusCode' => 404, 97 | 'foundOnUrl' => 'https://example.com', 98 | ], 99 | [ 100 | 'crawledUrl' => 'https://example.com/backend', 101 | 'statusCode' => 403, 102 | 'foundOnUrl' => 'https://example.com', 103 | ], 104 | ], 105 | '1111' => [], 106 | ]; 107 | 108 | return $this->collect($brokenLinks[$siteId], BrokenLink::class); 109 | } 110 | 111 | public function getMixedContent($siteId) 112 | { 113 | $mixedContent = [ 114 | '9999' => [ 115 | [ 116 | 'elementName' => 'img', 117 | 'mixedContentUrl' => 'http://example.com/nonsecureimg.jpg', 118 | 'foundOnUrl' => 'https://example.com', 119 | ], 120 | [ 121 | 'elementName' => 'iframe', 122 | 'mixedContentUrl' => 'http://example.iframe.com', 123 | 'foundOnUrl' => 'https://example.com/iframe', 124 | ], 125 | ], 126 | '1111' => [], 127 | ]; 128 | 129 | return $this->collect($mixedContent[$siteId], MixedContent::class); 130 | } 131 | } -------------------------------------------------------------------------------- /tests/Fakes/OhDearEmpty.php: -------------------------------------------------------------------------------- 1 | [], 5 | '1111' => [ 6 | [ 7 | 'started_at' => now()->subDay()->subMonths(3)->format('Y-m-d H:i:s'), 8 | 'ended_at' => now()->subDay()->subMonths(3)->addMinute()->addSeconds(34)->format('Y-m-d H:i:s'), 9 | ], 10 | [ 11 | 'started_at' => now()->subDay()->subMonths(5)->format('Y-m-d H:i:s'), 12 | 'ended_at' => now()->subDay()->subMonths(5)->addHour()->format('Y-m-d H:i:s'), 13 | ], 14 | 15 | ], 16 | '2222' => [ 17 | [ 18 | 'started_at' => now()->subDays(22)->format('Y-m-d H:i:s'), 19 | 'ended_at' => now()->subDays(22)->addMinutes(8)->addSeconds(10)->format('Y-m-d H:i:s'), 20 | ], 21 | [ 22 | 'started_at' => now()->subDays(28)->format('Y-m-d H:i:s'), 23 | 'ended_at' => now()->subDays(28)->addHour()->format('Y-m-d H:i:s'), 24 | ], 25 | ], 26 | '3333' => [ 27 | [ 28 | 'started_at' => now()->subDays(4)->format('Y-m-d H:i:s'), 29 | 'ended_at' => now()->subDays(2)->addHours(5)->addMinutes(3)->format('Y-m-d H:i:s'), 30 | ], 31 | [ 32 | 'started_at' => now()->subDays(7)->format('Y-m-d H:i:s'), 33 | 'ended_at' => now()->subDays(7)->addHour()->format('Y-m-d H:i:s'), 34 | ], 35 | ], 36 | '4444' => [ 37 | [ 38 | 'started_at' => now()->subHours(8)->format('Y-m-d H:i:s'), 39 | 'ended_at' => now()->subHours(8)->addMinutes(6)->format('Y-m-d H:i:s'), 40 | ], 41 | [ 42 | 'started_at' => now()->subHours(15)->format('Y-m-d H:i:s'), 43 | 'ended_at' => now()->subHours(14)->format('Y-m-d H:i:s'), 44 | ], 45 | 46 | ], 47 | '5555' => [ 48 | [ 49 | 'started_at' => now()->subMinutes(34)->format('Y-m-d H:i:s'), 50 | 'ended_at' => now()->subMinutes(34)->addSeconds(55)->format('Y-m-d H:i:s'), 51 | ], 52 | [ 53 | 'started_at' => now()->subMinutes(55)->subMonth()->format('Y-m-d H:i:s'), 54 | 'ended_at' => now()->subMinutes(54)->format('Y-m-d H:i:s'), 55 | ], 56 | ], 57 | ]; -------------------------------------------------------------------------------- /tests/Fakes/responses/sites_list.json: -------------------------------------------------------------------------------- 1 | { 2 | "data": [ 3 | { 4 | "id": 9999, 5 | "url": "https://example.com", 6 | "sort_url": "example.com", 7 | "team_id": 8888, 8 | "latest_run_date": "2018-09-01 19:32:00", 9 | "summarized_check_result": "succeeded", 10 | "uses_https": true, 11 | "checks": [ 12 | { 13 | "id": 17438, 14 | "type": "uptime", 15 | "enabled": true, 16 | "latest_run_ended_at": "2018-09-01 19:32:00", 17 | "latest_run_result": "succeeded" 18 | }, 19 | { 20 | "id": 17439, 21 | "type": "broken_links", 22 | "enabled": true, 23 | "latest_run_ended_at": "2018-09-01 17:52:42", 24 | "latest_run_result": "succeeded" 25 | }, 26 | { 27 | "id": 17440, 28 | "type": "mixed_content", 29 | "enabled": true, 30 | "latest_run_ended_at": "2018-09-01 17:52:42", 31 | "latest_run_result": "succeeded" 32 | }, 33 | { 34 | "id": 17441, 35 | "type": "certificate_health", 36 | "enabled": true, 37 | "latest_run_ended_at": "2018-09-01 19:29:53", 38 | "latest_run_result": "succeeded" 39 | }, 40 | { 41 | "id": 17442, 42 | "type": "certificate_transparency", 43 | "enabled": true, 44 | "latest_run_ended_at": null, 45 | "latest_run_result": null 46 | } 47 | ], 48 | "created_at": "2018-09-01 17:52:20", 49 | "updated_at": "2018-09-01 17:56:54" 50 | }, 51 | { 52 | "id": 9998, 53 | "url": "http://failed.example.com", 54 | "sort_url": "failed.example.com", 55 | "team_id": 8888, 56 | "latest_run_date": "2018-09-01 20:23:20", 57 | "summarized_check_result": "failed", 58 | "uses_https": false, 59 | "checks": [ 60 | { 61 | "id": 17443, 62 | "type": "uptime", 63 | "enabled": true, 64 | "latest_run_ended_at": "2018-09-01 20:23:20", 65 | "latest_run_result": "failed" 66 | }, 67 | { 68 | "id": 17444, 69 | "type": "broken_links", 70 | "enabled": true, 71 | "latest_run_ended_at": "2018-09-01 20:23:20", 72 | "latest_run_result": "succeeded" 73 | } 74 | ], 75 | "created_at": "2018-09-01 20:23:16", 76 | "updated_at": "2018-09-01 20:23:16" 77 | }, 78 | { 79 | "id": 1111, 80 | "url": "https://months.example.com", 81 | "sort_url": "months.example.com", 82 | "summarized_check_result": "succeeded", 83 | "checks" : [] 84 | }, 85 | { 86 | "id": 2222, 87 | "url": "https://weeks.example.com", 88 | "sort_url": "weeks.example.com", 89 | "summarized_check_result": "succeeded", 90 | "checks" : [] 91 | }, 92 | { 93 | "id": 3333, 94 | "url": "https://days.example.com", 95 | "sort_url": "days.example.com", 96 | "summarized_check_result": "succeeded", 97 | "checks" : [] 98 | }, 99 | { 100 | "id": 4444, 101 | "url": "https://hours.example.com", 102 | "sort_url": "hours.example.com", 103 | "summarized_check_result": "succeeded", 104 | "checks" : [] 105 | }, 106 | { 107 | "id": 5555, 108 | "url": "https://minutes.example.com", 109 | "sort_url": "minutes.example.com", 110 | "summarized_check_result": "succeeded", 111 | "checks" : [] 112 | } 113 | ], 114 | "links": { 115 | "first": "https://ohdear.app/api/sites?page%5Bsize%5D=200&page%5Bnumber%5D=1", 116 | "last": "https://ohdear.app/api/sites?page%5Bsize%5D=200&page%5Bnumber%5D=1", 117 | "prev": null, 118 | "next": null 119 | }, 120 | "meta": { 121 | "current_page": 1, 122 | "from": 1, 123 | "last_page": 1, 124 | "path": "https://ohdear.app/api/sites", 125 | "per_page": 200, 126 | "to": 1, 127 | "total": 1 128 | } 129 | } -------------------------------------------------------------------------------- /tests/Fakes/responses/uptimes.php: -------------------------------------------------------------------------------- 1 | [ 5 | [ 6 | 'datetime' => now()->subDay()->subMonths(3)->format('Y-m-d H:i:s'), 7 | 'uptime_percentage' => 100, 8 | ], 9 | [ 10 | 'datetime' => now()->subDay()->subMonths(5)->format('Y-m-d H:i:s'), 11 | 'uptime_percentage' => 90, 12 | ], 13 | 14 | ], 15 | '2222' => [ 16 | [ 17 | 'datetime' => now()->subDays(22)->format('Y-m-d H:i:s'), 18 | 'uptime_percentage' => 100, 19 | ], 20 | [ 21 | 'datetime' => now()->subDays(28)->format('Y-m-d H:i:s'), 22 | 'uptime_percentage' => 100, 23 | ], 24 | ], 25 | '3333' => [ 26 | [ 27 | 'datetime' => now()->subDays(4)->format('Y-m-d H:i:s'), 28 | 'uptime_percentage' => 62, 29 | ], 30 | [ 31 | 'datetime' => now()->subDays(7)->format('Y-m-d H:i:s'), 32 | 'uptime_percentage' => 90, 33 | ], 34 | ], 35 | '4444' => [ 36 | [ 37 | 'datetime' => now()->subHours(8)->format('Y-m-d H:i:s'), 38 | 'uptime_percentage' => 90, 39 | ], 40 | [ 41 | 'datetime' => now()->subHours(15)->format('Y-m-d H:i:s'), 42 | 'uptime_percentage' => 90, 43 | ], 44 | 45 | ], 46 | '5555' => [ 47 | [ 48 | 'datetime' => now()->subMinutes(34)->format('Y-m-d H:i:s'), 49 | 'uptime_percentage' => 90, 50 | ], 51 | [ 52 | 'datetime' => now()->subMinutes(55)->subMonth()->format('Y-m-d H:i:s'), 53 | 'uptime_percentage' => 90, 54 | ], 55 | ], 56 | ]; -------------------------------------------------------------------------------- /tests/Feature/BrokenLinksTest.php: -------------------------------------------------------------------------------- 1 | bot->receives('/brokenlinks example') 17 | ->assertReply(trans('ohdear.brokenlinks.result', [ 18 | 'url' => 'https://example.com/broken', 19 | 'code' => '404', 20 | 'origin' => 'https://example.com', 21 | ])) 22 | ->assertReply(trans('ohdear.brokenlinks.result', [ 23 | 'url' => 'https://example.com/backend', 24 | 'code' => '403', 25 | 'origin' => 'https://example.com', 26 | ])); 27 | } 28 | 29 | /** @test */ 30 | public function can_get_a_message_when_there_are_no_broken_links() 31 | { 32 | 33 | $this->bot->receives('/brokenlinks 1111') 34 | ->assertReply(trans('ohdear.brokenlinks.perfect')); 35 | } 36 | } -------------------------------------------------------------------------------- /tests/Feature/DowntimeTest.php: -------------------------------------------------------------------------------- 1 | bot->receives('/downtime 9998') 18 | ->assertReply(trans('ohdear.downtime.perfect')); 19 | } 20 | 21 | /** @test */ 22 | public function can_see_sites_downtime_in_months() 23 | { 24 | $this->bot->receives('/downtime https://months.example.com') 25 | ->assertReply(trans('ohdear.downtime.summary', [ 26 | 'elapsed' => '3 months', 27 | 'emoji' => '🎉', 28 | ])) 29 | ->assertReply(trans('ohdear.downtime.result', [ 30 | 'downtime' => '1 minute and 34 seconds', 31 | 'date' => now()->subDay()->subMonths(3), 32 | ])); 33 | } 34 | 35 | /** @test */ 36 | public function can_see_sites_downtime_in_weeks() 37 | { 38 | $this->bot->receives('/downtime https://weeks.example.com') 39 | ->assertReply(trans('ohdear.downtime.summary', [ 40 | 'elapsed' => '3 weeks', 41 | 'emoji' => '🙌', 42 | ])) 43 | ->assertReply(trans('ohdear.downtime.result', [ 44 | 'downtime' => '8 minutes and 10 seconds', 45 | 'date' => now()->subDays(22), 46 | ])); 47 | } 48 | 49 | /** @test */ 50 | public function can_see_sites_downtime_in_days() 51 | { 52 | $this->bot->receives('/downtime https://days.example.com') 53 | ->assertReply(trans('ohdear.downtime.summary', [ 54 | 'elapsed' => '1 day', 55 | 'emoji' => '👍', 56 | ])) 57 | ->assertReply(trans('ohdear.downtime.result', [ 58 | 'downtime' => '2 days, 5 hours and 3 minutes', 59 | 'date' => now()->subDays(4), 60 | ])); 61 | } 62 | 63 | /** @test */ 64 | public function can_see_sites_downtime_in_hours() 65 | { 66 | $this->bot->receives('/downtime https://hours.example.com') 67 | ->assertReply(trans('ohdear.downtime.summary', [ 68 | 'elapsed' => '7 hours', 69 | 'emoji' => '😕', 70 | ])) 71 | ->assertReply(trans('ohdear.downtime.result', [ 72 | 'downtime' => '6 minutes', 73 | 'date' => now()->subHours(8), 74 | ])); 75 | } 76 | 77 | /** @test */ 78 | public function can_see_sites_downtime_in_minutes() 79 | { 80 | $this->bot->receives('/downtime https://minutes.example.com') 81 | ->assertReply(trans('ohdear.downtime.summary', [ 82 | 'elapsed' => '33 minutes', 83 | 'emoji' => '😞', 84 | ])) 85 | ->assertReply(trans('ohdear.downtime.result', [ 86 | 'downtime' => '55 seconds', 87 | 'date' => now()->subMinutes(34), 88 | ])); 89 | } 90 | 91 | /** @test */ 92 | public function can_see_zero_downtimes() 93 | { 94 | $this->bot->receives('/downtime 9998') 95 | ->assertReply(trans('ohdear.downtime.perfect')); 96 | } 97 | } -------------------------------------------------------------------------------- /tests/Feature/HelpTest.php: -------------------------------------------------------------------------------- 1 | bot->receives('/help') 17 | ->assertReply(trans('ohdear.help.title')) 18 | ->assertReply(file_get_contents(resource_path('markdown/help.md'))); 19 | } 20 | 21 | } -------------------------------------------------------------------------------- /tests/Feature/MixedContentTest.php: -------------------------------------------------------------------------------- 1 | bot->receives('/mixedcontent example') 17 | ->assertReply(trans('ohdear.mixedcontent.result', [ 18 | 'url' => 'http://example.com/nonsecureimg.jpg', 19 | 'origin' => 'https://example.com', 20 | ])) 21 | ->assertReply(trans('ohdear.mixedcontent.result', [ 22 | 'url' => 'http://example.iframe.com', 23 | 'origin' => 'https://example.com/iframe', 24 | ])); 25 | } 26 | 27 | /** @test */ 28 | public function can_get_a_message_when_there_are_no_mixed_content() 29 | { 30 | 31 | $this->bot->receives('/mixedcontent 1111') 32 | ->assertReply(trans('ohdear.mixedcontent.perfect')); 33 | } 34 | } -------------------------------------------------------------------------------- /tests/Feature/SitesTest.php: -------------------------------------------------------------------------------- 1 | bot->receives('/sites') 27 | ->assertQuestion(trans('ohdear.sites.list_message')); 28 | } 29 | 30 | /** @test */ 31 | public function can_say_there_are_no_sites() 32 | { 33 | $this->app->bind(OhDear::class, OhDearEmpty::class); 34 | 35 | $this->bot->receives('/sites') 36 | ->assertReply(trans('ohdear.sites.list_empty')); 37 | } 38 | 39 | /** @test */ 40 | public function incorrect_url_gets_rejected() 41 | { 42 | $this->bot->receives('/newsite new.example.com') 43 | ->assertReply(trans('ohdear.sites.invalid_url')); 44 | } 45 | 46 | /** @test */ 47 | public function can_create_a_new_site() 48 | { 49 | $this->bot->receives('/newsite https://new.example.com') 50 | ->assertReply(trans('ohdear.sites.created')); 51 | } 52 | 53 | /** @test */ 54 | public function cannot_create_a_site_with_already_in_use_url() 55 | { 56 | $this->bot->receives('/newsite https://example.com') 57 | ->assertReply(trans('ohdear.sites.already_exists')); 58 | } 59 | 60 | /** @test */ 61 | public function can_show_a_site() 62 | { 63 | $this->bot->receives('/site https://example.com') 64 | ->assertReply(self::EXAMPLE_SITE_RESPONSE); 65 | } 66 | 67 | /** @test */ 68 | public function emoji_change_if_site_is_down() 69 | { 70 | $this->bot->receives('/site http://failed.example.com') 71 | ->assertReply('🔴 failed.example.com' 72 | .PHP_EOL.'🔴 Uptime' 73 | .PHP_EOL.'✅ Broken Links'); 74 | } 75 | 76 | /** @test */ 77 | public function can_show_a_site_by_domain() 78 | { 79 | $this->bot->receives('/site example') 80 | ->assertReply(self::EXAMPLE_SITE_RESPONSE); 81 | } 82 | 83 | /** @test */ 84 | public function can_show_a_site_by_id() 85 | { 86 | $this->bot->receives('/site 9999') 87 | ->assertReply(self::EXAMPLE_SITE_RESPONSE); 88 | } 89 | 90 | /** @test */ 91 | public function can_display_a_message_with_missing_site() 92 | { 93 | $this->expectException(SiteNotFoundException::class); 94 | 95 | $this->bot->receives('/site https://new.example.com') 96 | ->assertReply(trans('ohdear.sites.not_found')); 97 | } 98 | 99 | /** @test */ 100 | public function can_delete_a_site() 101 | { 102 | $this->assertNotNull(app(OhDear::class)->findSiteByUrl('https://example.com')); 103 | 104 | $this->bot->receives('/deletesite https://example.com') 105 | ->assertQuestion(trans('ohdear.sites.delete_confirm_1')) 106 | ->receivesInteractiveMessage(true) 107 | ->assertQuestion(trans('ohdear.sites.delete_confirm_2')) 108 | ->receivesInteractiveMessage(true) 109 | ->assertReply(trans('ohdear.sites.deleted')); 110 | 111 | $this->assertNull(app(OhDear::class)->findSiteByUrl('https://example.com')); 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /tests/Feature/StartConversationTest.php: -------------------------------------------------------------------------------- 1 | bot->receives('/start') 18 | ->assertReply(trans('ohdear.greetings')) 19 | ->assertReply(trans('ohdear.token.question')) 20 | ->receives('tokensecret') 21 | ->assertReply(trans('ohdear.token.stored')) 22 | ->assertReply(trans('ohdear.webhook.question')) 23 | ->receives('webhooksecret'); 24 | 25 | $user = User::first(); 26 | 27 | $this->bot->assertReply(trans('ohdear.webhook.stored', ['url' => $user->getWebhookUrl()])); 28 | 29 | $this->assertNotEquals('tokensecret', $user->token); 30 | $this->assertEquals('tokensecret', decrypt($user->token)); 31 | 32 | $this->assertNotEquals('webhooksecret', $user->webhook); 33 | $this->assertEquals('webhooksecret', decrypt($user->webhook)); 34 | } 35 | 36 | /** @test */ 37 | public function start_command_does_not_work_if_its_already_configured() 38 | { 39 | factory(User::class)->create(['telegram_id' => 'ohdearapp', 'token' => '123']); 40 | 41 | $this->bot->setUser(['id' => 'ohdearapp']) 42 | ->receives('/start') 43 | ->assertReply(trans('ohdear.greetings')) 44 | ->assertReply(trans('ohdear.already_set_up')); 45 | } 46 | } -------------------------------------------------------------------------------- /tests/Feature/TokenTest.php: -------------------------------------------------------------------------------- 1 | bot->receives('/token secret') 18 | ->assertReply(trans('ohdear.token.stored')); 19 | 20 | $this->assertEquals('secret', User::first()->getToken()); 21 | } 22 | } -------------------------------------------------------------------------------- /tests/Feature/UptimeTest.php: -------------------------------------------------------------------------------- 1 | bot->receives('/uptime https://months.example.com') 17 | ->assertReply(trans('ohdear.uptime.result', [ 18 | 'percentage' => '90', 19 | 'date' => now()->subDay()->subMonths(5), 20 | 'emoji' => '🎉', 21 | ])); 22 | } 23 | 24 | /** @test */ 25 | public function can_see_a_perfect_uptime() 26 | { 27 | $this->bot->receives('/uptime https://weeks.example.com') 28 | ->assertReply(trans('ohdear.uptime.perfect', [ 29 | 'begin' => now()->subDays(28), 30 | 'end' => now()->subDays(22), 31 | ])); 32 | } 33 | 34 | /** @test */ 35 | public function can_show_lower_emoji_if_percentage_is_closer() 36 | { 37 | $this->bot->receives('/uptime https://days.example.com') 38 | ->assertReply(trans('ohdear.uptime.result', [ 39 | 'percentage' => '62', 40 | 'date' => now()->subDays(4), 41 | 'emoji' => '😕', 42 | ])); 43 | } 44 | } -------------------------------------------------------------------------------- /tests/Feature/WebhookReceivedTest.php: -------------------------------------------------------------------------------- 1 | create(['username' => 'foobar', 'telegram_id' => 'ohdearapp', 'webhook' => encrypt('secret')]); 22 | 23 | $response = $this->postJson(route('webhook', $user)); 24 | 25 | $response->assertStatus(400); 26 | 27 | $response->assertSeeText('The request did not contain a header named `OhDear-Signature`.'); 28 | } 29 | 30 | /** @test */ 31 | public function it_fails_if_user_does_not_set_the_webhook_secret() 32 | { 33 | $user = factory(User::class)->create(['username' => 'foobar', 'telegram_id' => 'ohdearapp', 'webhook' => null]); 34 | 35 | $response = $this->postJson(route('webhook', $user), [], ['OhDear-Signature' => 'not-in-use-right-now']); 36 | 37 | $response->assertStatus(400); 38 | 39 | $response->assertSeeText('The OhDear webhook signing secret is not set.'); 40 | 41 | } 42 | 43 | /** @test */ 44 | public function it_fails_if_signature_is_not_valid() 45 | { 46 | $user = factory(User::class)->create(['username' => 'foobar', 'telegram_id' => 'ohdearapp', 'webhook' => encrypt('secret')]); 47 | 48 | $response = $this->postJson(route('webhook', $user), [], ['OhDear-Signature' => 'it-will-fail']); 49 | 50 | $response->assertStatus(400); 51 | 52 | $response->assertSeeText("The signature `it-will-fail` found in the header"); 53 | } 54 | 55 | /** @test */ 56 | public function it_fails_if_type_is_not_in_the_payload() 57 | { 58 | $user = factory(User::class)->create(['username' => 'foobar', 'telegram_id' => 'ohdearapp', 'webhook' => encrypt('secret')]); 59 | 60 | $signature = hash_hmac('sha256', '{"foo":"bar"}', 'secret'); 61 | 62 | $response = $this->postJson(route('webhook', $user), ['foo' => 'bar'], ['OhDear-Signature' => $signature]); 63 | 64 | $response->assertStatus(400); 65 | 66 | $response->assertSeeText('The webhook call did not contain a type.'); 67 | } 68 | 69 | /** @test */ 70 | public function it_fails_if_the_type_job_does_not_exists() 71 | { 72 | $user = factory(User::class)->create(['username' => 'foobar', 'telegram_id' => 'ohdearapp', 'webhook' => encrypt('secret')]); 73 | 74 | $signature = hash_hmac('sha256', '{"type":"notFoundJob"}', 'secret'); 75 | 76 | $response = $this->postJson(route('webhook', $user), ['type' => 'notFoundJob'], ['OhDear-Signature' => $signature]); 77 | 78 | $response->assertStatus(400); 79 | 80 | $response->assertSeeText("The type notFoundJob is not currently supported."); 81 | } 82 | 83 | /** @test */ 84 | public function uptime_check_failed_is_queued_for_the_specific_user() 85 | { 86 | Queue::fake(); 87 | 88 | $user = factory(User::class)->create(['username' => 'foobar', 'telegram_id' => 'ohdearapp', 'webhook' => encrypt('secret')]); 89 | 90 | $signature = hash_hmac('sha256', json_encode($this->uptimeCheckFailedPayload()), 'secret'); 91 | 92 | $response = $this->postJson(route('webhook', $user), $this->uptimeCheckFailedPayload(), ['OhDear-Signature' => $signature]); 93 | 94 | $response->assertSuccessful(); 95 | 96 | Queue::assertPushed(UptimeCheckFailed::class, function ($job) { 97 | return $job->user->telegram_id === 'ohdearapp'; 98 | }); 99 | } 100 | 101 | /** @test */ 102 | public function broken_links_found_is_queued_for_the_specific_user() 103 | { 104 | Queue::fake(); 105 | 106 | $user = factory(User::class)->create(['username' => 'foobar', 'telegram_id' => 'ohdearapp', 'webhook' => encrypt('secret')]); 107 | 108 | $signature = hash_hmac('sha256', json_encode($this->brokenLinksFoundPayload()), 'secret'); 109 | 110 | $response = $this->postJson(route('webhook', $user), $this->brokenLinksFoundPayload(), ['OhDear-Signature' => $signature]); 111 | 112 | $response->assertSuccessful(); 113 | 114 | Queue::assertPushed(BrokenLinksFound::class, function ($job) { 115 | return $job->user->telegram_id === 'ohdearapp'; 116 | }); 117 | } 118 | 119 | private function uptimeCheckFailedPayload() 120 | { 121 | return [ 122 | 'type' => 'uptimeCheckFailed', 123 | 'site' => [ 124 | 'url' => 'https://foo.bar' 125 | ], 126 | ]; 127 | } 128 | 129 | private function brokenLinksFoundPayload() 130 | { 131 | return [ 132 | 'type' => 'brokenLinksFound', 133 | 'site' => [ 134 | 'url' => 'https://foo.bar' 135 | ], 136 | 'run' => [ 137 | 'result_payload' => [ 138 | [ 139 | 'cralwed_url' => 'https://foo.bar/foo', 140 | 'status_code' => 404, 141 | 'found_on_url' => 'https://foo.bar' 142 | ] 143 | ] 144 | ] 145 | ]; 146 | } 147 | } -------------------------------------------------------------------------------- /tests/Feature/WebhookTest.php: -------------------------------------------------------------------------------- 1 | bot->receives('/webhook secret'); 18 | 19 | $this->assertEquals('secret', decrypt(User::first()->webhook)); 20 | } 21 | 22 | } -------------------------------------------------------------------------------- /tests/TestCase.php: -------------------------------------------------------------------------------- 1 |