get(); if(sizeof($name) == 0) { return false; } else if(sizeof($name) == 1) { return $name[0]; } else { $name = $name->keyBy('name'); return $name->all(); } } /** * Create / update value for Setting object. * * @param String $name Name of setting * @param String $value Value of setting * @return \App\Setting */ public static function set(String $name, String $value) { $setting = SettingsHelper::get($name); if($value == false) { $value = "0"; } if($setting !== false) { $setting->value = $value; $setting->save(); } else { $setting = Setting::create([ 'name' => $name, 'value' => $value, ]); } return $setting; } /** * Get the app's base path * * @return string */ public static function getBase() { $base = env('BASE_PATH', '/'); if($base == '') { $base = '/'; } else { if($base[0] != '/') { $base = '/' . $base; } if($base[-1] != '/') { $base = $base . '/'; } } return $base; } /** * Check whether a setting is defined in ENV vars or through DB * * @param string $key * @return boolean */ public static function settingIsEditable(string $key) { // Try exact key $val = exec('echo $' . $key); if($val == "") { return true; } // Try key all caps $val = exec('echo $' . strtoupper($key)); if($val == "") { return true; } return false; } /** * Get the application config * * @return array */ public static function getConfig() { return [ 'base' => SettingsHelper::getBase(), 'graphs' => [ 'download_upload_graph_enabled' => SettingsHelper::get('download_upload_graph_enabled'), 'download_upload_graph_width' => SettingsHelper::get('download_upload_graph_width'), 'ping_graph_enabled' => SettingsHelper::get('ping_graph_enabled'), 'ping_graph_width' => SettingsHelper::get('ping_graph_width'), 'failure_graph_enabled' => SettingsHelper::get('failure_graph_enabled'), 'failure_graph_width' => SettingsHelper::get('failure_graph_width'), ], 'editable' => [ 'slack_webhook' => SettingsHelper::settingIsEditable('slack_webhook'), 'telegram_bot_token' => SettingsHelper::settingIsEditable('telegram_bot_token'), 'telegram_chat_id' => SettingsHelper::settingIsEditable('telegram_chat_id'), ] ]; } /** * Send test notification to agents * * @param boolean|string $agent * @return void */ public static function testNotification($agent = true) { $agents = [ 'slack', 'telegram' ]; if($agent === true) { event(new TestNotificationEvent($agents)); return true; } if(in_array($agent, $agents)) { event(new TestNotificationEvent([ $agent ])); return true; } } }