idx
int64
0
60.3k
question
stringlengths
92
4.62k
target
stringlengths
7
635
53,900
public function sleep ( $ seconds ) { foreach ( $ this -> eyeQueues as $ queue ) { $ this -> cache -> add ( 'eyewitness_q_idle_time_' . $ queue -> id , 0 , 180 ) ; if ( $ seconds < 1 ) { $ this -> cache -> increment ( 'eyewitness_q_idle_time_' . $ queue -> id , 1 ) ; } else { $ this -> cache -> increment ( 'eyewitness_...
Capture how long a worker is sleeping for . We need to cycle all tubes this worker checks to give each of them credit for the sleep . This allows us to handle different worker configurations and should cover all situations .
53,901
protected function handleStatusAlerts ( $ db ) { if ( $ db [ 'status' ] ) { if ( $ this -> eye -> status ( ) -> isSick ( 'database_status_' . $ db [ 'connection' ] ) ) { $ this -> eye -> notifier ( ) -> alert ( new Online ( $ db ) ) ; } $ this -> eye -> status ( ) -> setHealthy ( 'database_status_' . $ db [ 'connection...
Handle any status issues .
53,902
protected function handleSizeAlerts ( $ db ) { if ( ( $ db [ 'alert_greater_than_mb' ] > 0 ) && ( $ db [ 'size' ] > $ db [ 'alert_greater_than_mb' ] ) ) { if ( $ this -> eye -> status ( ) -> isHealthy ( 'database_size_' . $ db [ 'connection' ] ) ) { $ this -> eye -> notifier ( ) -> alert ( new SizeLarge ( $ db ) ) ; } ...
Handle any size issues .
53,903
protected function checkDatabaseStatus ( $ connection ) { try { DB :: connection ( $ connection ) -> getPdo ( ) ; } catch ( Exception $ e ) { $ this -> eye -> logger ( ) -> error ( 'DB status failed' , $ e , $ connection ) ; return false ; } return true ; }
Check if the database connection is working .
53,904
protected function getDatabaseSize ( $ connection ) { switch ( $ this -> getDriverName ( $ connection ) ) { case 'mysql' : $ size = $ this -> checkMySqlDatabaseSize ( $ connection ) ; break ; case 'sqlite' : $ size = $ this -> checkSqLiteDatabaseSize ( $ connection ) ; break ; case 'pgsql' : $ size = $ this -> checkPos...
Get the size of the database .
53,905
protected function checkMySqlDatabaseSize ( $ connection ) { try { $ result = ( array ) DB :: connection ( $ connection ) -> table ( 'information_schema.TABLES' ) -> select ( DB :: raw ( "sum( data_length + index_length ) AS size" ) ) -> where ( 'table_schema' , DB :: connection ( $ connection ) -> getConfig ( 'databas...
Return the size of the mySql database .
53,906
protected function checkSqLiteDatabaseSize ( $ connection ) { try { $ path = realpath ( DB :: connection ( $ connection ) -> getConfig ( 'database' ) ) ; if ( $ path !== false ) { return filesize ( $ path ) ; } } catch ( Exception $ e ) { $ this -> eye -> logger ( ) -> debug ( 'Error during sqLite DB size check' , [ 'e...
Return the size of the Sqlite database .
53,907
public function show ( $ queue_id , $ job_id ) { $ queue = Queue :: findOrFail ( $ queue_id ) ; $ job = $ this -> eye -> queue ( ) -> getFailedJob ( $ job_id ) ; return view ( 'eyewitness::queue.failed_job' ) -> withJob ( $ job ) -> withQueue ( $ queue ) ; }
Show the given job .
53,908
public function retry ( $ queue_id , $ job_id ) { try { Artisan :: call ( 'queue:retry' , [ 'id' => [ $ job_id ] ] ) ; } catch ( Exception $ e ) { $ this -> eye -> logger ( ) -> error ( 'Retry of failed job unsuccessful' , $ e , [ 'job_id' => $ job_id , 'queue_id' => $ queue_id ] ) ; return redirect ( route ( 'eyewitne...
Retry the given job .
53,909
public function retryAll ( $ queue_id ) { $ queue = Queue :: findOrFail ( $ queue_id ) ; $ jobs = $ this -> eye -> queue ( ) -> getFailedJobs ( $ queue ) ; $ failed = false ; foreach ( $ jobs as $ job ) { try { Artisan :: call ( 'queue:retry' , [ 'id' => [ $ job -> id ] ] ) ; } catch ( Exception $ e ) { $ this -> eye -...
Retry all the jobs on this queue .
53,910
protected function runScheduledEvents ( ) { foreach ( $ this -> schedule -> dueEvents ( $ this -> laravel ) as $ event ) { $ event = $ this -> convertEvent ( $ event ) ; if ( $ this -> canAccessFiltersPass ( $ event ) && ( ! $ event -> filtersPass ( $ this -> laravel ) ) ) { continue ; } if ( $ event -> onOneServer ) {...
Run the scheduled events . This is an extension of the original run command but allows us to insert our custom event and tracking .
53,911
protected function findEventMutex ( $ mutex ) { return collect ( $ this -> schedule -> events ( ) ) -> filter ( function ( $ value ) use ( $ mutex ) { if ( Eye :: laravelVersionIs ( '<' , '5.4.0' ) ) { $ value = $ this -> convertEvent ( $ value ) ; } return $ value -> mutexName ( ) === $ mutex ; } ) -> first ( ) ; }
Find the event that matches the mutex .
53,912
protected function runEvent ( $ event , $ force = true ) { $ this -> convertEvent ( $ event ) -> ignoreMutex ( $ force ) -> runInForeground ( ) -> run ( $ this -> laravel ) ; }
Run an event .
53,913
public function registerNotificationDirectives ( ) { Blade :: directive ( 'eyewitness_error' , function ( $ message ) { return $ this -> baseNotification ( $ message , 'bg-red' , 'bold-remove' , 'svgcolor-red' ) ; } ) ; Blade :: directive ( 'eyewitness_success' , function ( $ message ) { return $ this -> baseNotificati...
Register notification directives .
53,914
protected function baseNotification ( $ message , $ bgColor , $ icon , $ iconColor , $ escape = true ) { $ s = "<?php echo '<div class=\"flex " . $ bgColor . " bg-circuit bg-md rounded text-center text-white text-sm font-bold mb-6 px-4 py-3 shadow\" role=\"alert\">" ; $ s .= '<div class="bg-white rounded shadow-lg -mt-...
The base notification to use .
53,915
public function registerSvgDirectives ( ) { Blade :: directive ( 'eyewitness_svg' , function ( $ arguments ) { $ arguments = trim ( trim ( $ arguments , "(" ) , ")" ) ; $ arguments = explode ( ',' , $ arguments . ',' ) ; $ icon = trim ( $ arguments [ 0 ] , "' " ) ; $ class = trim ( isset ( $ arguments [ 1 ] ) ? $ argum...
Register svg directives .
53,916
public function registerImageDirectives ( ) { Blade :: directive ( 'eyewitness_img' , function ( $ file ) { $ file = trim ( trim ( $ file , "(" ) , ")" ) ; $ string = $ this -> loadFile ( __DIR__ . '/../../resources/assets/images/' . trim ( $ file , "'" ) ) ; return '<img src="data:image/x-icon;base64,' . base64_encode...
Register image directives .
53,917
public function getIconString ( $ icon , $ class = '' , $ width = '' , $ height = '' ) { $ string = $ this -> loadFile ( __DIR__ . '/../../resources/assets/icons/' . $ icon . '.svg' ) ; $ string = substr_replace ( $ string , ' class="' . $ class . '"' , 4 , 0 ) ; if ( $ width ) { $ string = substr_replace ( $ string , ...
The icon svg as a string .
53,918
public function composer ( ) { $ this -> headers [ 'headers' ] = [ 'Accept' => 'application/json' ] ; try { if ( $ this -> isRunningGuzzle5 ( ) ) { $ this -> headers [ 'body' ] = [ 'lock' => fopen ( config ( 'eyewitness.composer_lock_file_location' ) , 'r' ) ] ; } else { $ this -> headers [ 'multipart' ] = [ [ 'name' =...
Run a check for the composer lock against the SensioLabs API .
53,919
protected function ping ( $ route , $ data = [ ] ) { if ( ! config ( 'eyewitness.api_enabled' , false ) ) { return [ false , 'Api Disabled' ] ; } $ data [ 'app_token' ] = config ( 'eyewitness.app_token' ) ; $ data [ 'secret_key' ] = config ( 'eyewitness.secret_key' ) ; $ data [ 'application_environment' ] = app ( ) -> ...
Send the ping notification to the Eyewitness . io API . Includes a backoff retry attempt if the inital pings fails .
53,920
protected function ensureOutputIsBeingCapturedForEyewitness ( ) { if ( ! config ( 'eyewitness.capture_cron_output' ) ) { return ; } if ( $ this -> outputNotBeingCaptured ( ) ) { $ this -> output = storage_path ( 'logs/eyewitness-cron-' . sha1 ( $ this -> mutexName ( ) ) . '.cron.log' ) ; } }
Ensure that output is being captured if not already set by the event .
53,921
protected function retrieveOutput ( ) { if ( ( ! config ( 'eyewitness.capture_cron_output' ) ) || ( ! file_exists ( $ this -> output ) ) ) { return null ; } $ text = file_get_contents ( $ this -> output ) ; if ( str_contains ( $ this -> output , 'eyewitness_cron_' ) && file_exists ( $ this -> output ) ) { unlink ( $ th...
Get the output from the last scheduled job . Only remove the file if we created it specifically for Eyewitness - otherwise leave it alone for the framework to handle as normal .
53,922
public function getNextRunDue ( $ schedule , $ timezone ) { return Carbon :: instance ( CronExpression :: factory ( $ schedule ) -> getNextRunDate ( 'now' , 0 , false , $ timezone ) ) ; }
Determine when the next occurance of the scheduler is due to run .
53,923
public function getNextCheckDue ( $ schedule , $ timezone , $ extra_seconds = 0 ) { return $ this -> getNextRunDue ( $ schedule , $ timezone ) -> addMinutes ( 5 ) -> addSeconds ( $ extra_seconds ) ; }
Determine when the next check of the scheduler is due .
53,924
public function setNextSchedule ( $ scheduler ) { $ scheduler -> next_run_due = $ this -> getNextRunDue ( $ scheduler -> schedule , $ scheduler -> timezone ) ; $ scheduler -> next_check_due = $ this -> getNextCheckDue ( $ scheduler -> schedule , $ scheduler -> timezone , $ scheduler -> alert_run_time_greater_than ) ; $...
Set the next checks for the scheduler .
53,925
public function show ( Request $ request ) { $ this -> validate ( $ request , [ 'domain' => 'required|string' ] ) ; $ dns = DNS :: where ( 'meta' , $ request -> domain ) -> orderBy ( 'created_at' , 'desc' ) -> get ( ) ; if ( ! count ( $ dns ) ) { return redirect ( route ( 'eyewitness.dashboard' ) . '#dns' ) -> withErro...
Show the DNS history .
53,926
protected function parseMeta ( $ meta ) { $ fields = [ ] ; foreach ( $ meta as $ key => $ value ) { $ fields [ ] = [ 'title' => $ key , 'value' => $ value , ] ; } return $ fields ; }
Format the meta content for Slack attachments .
53,927
public static function phpBinary ( ) { if ( Eye :: laravelVersionIs ( '<' , '5.5.26' ) ) { return SymfonyProcessUtils :: escapeArgument ( ( new PhpExecutableFinder ) -> find ( false ) ) ; } return LaravelProcessUtils :: escapeArgument ( ( new PhpExecutableFinder ) -> find ( false ) ) ; }
Determine the proper PHP executable .
53,928
public static function artisanBinary ( ) { if ( Eye :: laravelVersionIs ( '<' , '5.5.26' ) ) { return defined ( 'ARTISAN_BINARY' ) ? SymfonyProcessUtils :: escapeArgument ( ARTISAN_BINARY ) : 'artisan' ; } return defined ( 'ARTISAN_BINARY' ) ? LaravelProcessUtils :: escapeArgument ( ARTISAN_BINARY ) : 'artisan' ; }
Determine the proper Artisan executable .
53,929
public function login ( Request $ request ) { if ( $ request -> session ( ) -> has ( 'eyewitness:auth' ) || Eye :: check ( $ request ) ) { return redirect ( route ( 'eyewitness.dashboard' ) . '#overview' ) ; } if ( config ( 'eyewitness.login_disabled' , false ) ) { return redirect ( '/' ) ; } return view ( 'eyewitness:...
Get login page .
53,930
public function authenticate ( Request $ request ) { if ( config ( 'eyewitness.login_disabled' , false ) ) { return redirect ( '/' ) ; } if ( ! app ( Eye :: class ) -> checkConfig ( ) ) { return redirect ( ) -> route ( 'eyewitness.login' ) -> withError ( 'Eyewitness has not been configured correctly. Login has been dis...
Attempt to authenticate .
53,931
public function handle ( ) { if ( ! $ this -> option ( 'force' ) && ! $ this -> confirmRegenerate ( ) ) { return $ this -> info ( 'Aborted. No changes were made. If you need assistance please contact us anytime at: support@eyewitness.io' ) ; } $ app_token = $ this -> generateRandom ( 16 ) ; $ secret_key = $ this -> gen...
Set the application token and the secret key in the config file .
53,932
protected function modifyEnvironmentFile ( $ param , $ type , $ value ) { if ( $ this -> paramAlreadyInFile ( $ param , $ type ) ) { $ this -> overwriteExistingParamToFile ( $ param , $ type , $ value ) ; } else { $ this -> addNewParamToFile ( $ param , $ value ) ; } }
Update the application environment file with the new config .
53,933
protected function checkCaching ( ) { if ( app ( ) -> routesAreCached ( ) && app ( ) -> configurationIsCached ( ) ) { $ this -> info ( 'p.s. you need to run "config:cache" + "route:cache" + "queue:restart" to ensure your application updates and queue monitoring works correctly.' ) ; } elseif ( app ( ) -> configurationI...
Check if any caching has occured .
53,934
public function writeEnvFile ( $ string ) { file_put_contents ( $ this -> laravel -> environmentPath ( ) . '/' . $ this -> laravel -> environmentFile ( ) , $ string ) ; }
Get the env file contents .
53,935
public function getConfig ( ) { $ data [ 'eyewitness_version' ] = $ this -> version ( ) ; $ data [ 'eyewitness_config' ] = config ( 'eyewitness' ) ; $ data [ 'application_debug' ] = config ( 'app.debug' ) ; $ data [ 'application_environment' ] = app ( ) -> environment ( ) ; return $ data ; }
Get current configuration .
53,936
public function getCustomWitnesses ( $ filterIsDue = false ) { $ list = collect ( ) ; foreach ( config ( 'eyewitness.custom_witnesses' , [ ] ) as $ witness ) { if ( $ this -> isValidWitness ( $ witness ) ) { $ instance = app ( $ witness ) ; if ( $ filterIsDue ) { if ( $ instance -> isDue ( ) ) { $ list -> push ( $ inst...
Load all custom witnesses and optionally filter if they are due to run .
53,937
public function application ( ) { if ( is_null ( $ this -> application ) ) { $ this -> application = app ( Application :: class ) ; } return $ this -> application ; }
Return the Application instance .
53,938
public function scheduler ( ) { if ( is_null ( $ this -> scheduler ) ) { $ this -> scheduler = app ( Scheduler :: class ) ; } return $ this -> scheduler ; }
Return the Scheduler instance .
53,939
public function database ( ) { if ( is_null ( $ this -> database ) ) { $ this -> database = app ( Database :: class ) ; } return $ this -> database ; }
Return the Database instance .
53,940
public function composer ( ) { if ( is_null ( $ this -> composer ) ) { $ this -> composer = app ( Composer :: class ) ; } return $ this -> composer ; }
Return the Composer instance .
53,941
public function notifier ( ) { if ( is_null ( $ this -> notifier ) ) { $ this -> notifier = app ( Notifier :: class ) ; } return $ this -> notifier ; }
Return the Notifier instance .
53,942
public function status ( ) { if ( is_null ( $ this -> status ) ) { $ this -> status = app ( Status :: class ) ; } return $ this -> status ; }
Return the Eyewitness status instance .
53,943
public function logger ( ) { if ( is_null ( $ this -> logger ) ) { $ this -> logger = app ( Logger :: class ) ; } return $ this -> logger ; }
Return the Eyewitness logger instance .
53,944
public function server ( ) { if ( is_null ( $ this -> server ) ) { $ this -> server = app ( Server :: class ) ; } return $ this -> server ; }
Return the Server instance .
53,945
public function debug ( ) { if ( is_null ( $ this -> debug ) ) { $ this -> debug = app ( Debug :: class ) ; } return $ this -> debug ; }
Return the Debug instance .
53,946
public function queue ( ) { if ( is_null ( $ this -> queue ) ) { $ this -> queue = app ( Queue :: class ) ; } return $ this -> queue ; }
Return the Queue instance .
53,947
public function disk ( ) { if ( is_null ( $ this -> disk ) ) { $ this -> disk = app ( Disk :: class ) ; } return $ this -> disk ; }
Return the Disk instance .
53,948
public function dns ( ) { if ( is_null ( $ this -> dns ) ) { $ this -> dns = app ( Dns :: class ) ; } return $ this -> dns ; }
Return the Dns instance .
53,949
public function ssl ( ) { if ( is_null ( $ this -> ssl ) ) { $ this -> ssl = app ( Ssl :: class ) ; } return $ this -> ssl ; }
Return the Ssl instance .
53,950
public function log ( ) { if ( is_null ( $ this -> log ) ) { $ this -> log = app ( Log :: class ) ; } return $ this -> log ; }
Return the Log instance .
53,951
public function api ( ) { if ( is_null ( $ this -> api ) ) { $ this -> api = app ( Api :: class ) ; } return $ this -> api ; }
Return the Api instance .
53,952
public static function laravelVersionIs ( $ operator , $ version , $ laravel = null ) { if ( is_null ( $ laravel ) ) { $ laravel = app ( ) -> version ( ) ; } $ laravel = strtok ( $ laravel , ' ' ) ; return version_compare ( $ laravel , $ version , $ operator ) ; }
Compare Laravel 5 . x version to the variable given .
53,953
public function poll ( ) { if ( ! count ( config ( 'eyewitness.application_domains' ) ) ) { $ this -> eye -> logger ( ) -> debug ( 'No application domain set for SSL monitor' ) ; return ; } foreach ( config ( 'eyewitness.application_domains' ) as $ domain ) { if ( $ this -> isValidDomain ( $ domain ) ) { $ this -> star...
Poll the SSL for its checks .
53,954
public function result ( ) { if ( ! count ( config ( 'eyewitness.application_domains' ) ) ) { $ this -> eye -> logger ( ) -> debug ( 'No application domain set for SSL monitor' ) ; return ; } foreach ( config ( 'eyewitness.application_domains' ) as $ domain ) { $ result = $ this -> getResults ( $ domain ) ; if ( $ resu...
Determine the SSL scan results .
53,955
protected function startScan ( $ domain ) { $ result = $ this -> eye -> api ( ) -> sslStart ( $ domain ) ; if ( isset ( $ result [ 'multiple_ips' ] ) && isset ( $ result [ 'token' ] ) ) { $ result = $ this -> eye -> api ( ) -> sslStart ( $ domain , $ result [ 'multiple_ips' ] , $ result [ 'token' ] ) ; } if ( isset ( $...
Start the scan for a given domain for a valid SSL certificate against the API .
53,956
protected function getResults ( $ domain ) { if ( ! Cache :: has ( 'eyewitness_ssl_job_id_' . $ domain ) ) { return null ; } $ result = $ this -> eye -> api ( ) -> sslResult ( Cache :: pull ( 'eyewitness_ssl_job_id_' . $ domain ) ) ; if ( isset ( $ result [ 'error' ] ) ) { return $ this -> eye -> logger ( ) -> error ( ...
Get the scan results from the API .
53,957
protected function checkForSslRecordChanges ( $ domain , $ result ) { if ( ! $ ssl_history = History :: where ( 'meta' , $ domain ) -> first ( ) ) { return ; } if ( $ ssl_history -> record [ 'valid' ] !== $ result [ 'certificates' ] [ 'information' ] [ 0 ] [ 'valid_now' ] ) { if ( ! $ result [ 'certificates' ] [ 'infor...
Check if the supplied result is different from the most recently stored SSL record available .
53,958
protected function saveSslRecord ( $ domain , $ result ) { $ record [ 'grade' ] = $ result [ 'results' ] [ 'grade' ] ; $ record [ 'results_url' ] = 'https://www.htbridge.com/ssl/?id=' . $ result [ 'internals' ] [ 'short_id' ] ; if ( isset ( $ result [ 'certificates' ] [ 'information' ] [ 0 ] ) ) { $ record [ 'valid' ] ...
Save the SSL record to the database .
53,959
protected function isValidDomain ( $ domain ) { if ( filter_var ( $ domain , FILTER_VALIDATE_URL ) === false ) { $ this -> eye -> logger ( ) -> debug ( 'SSL URL not valid' , $ domain ) ; return false ; } return true ; }
Check if the URL is valid .
53,960
protected function outputNotBeingCaptured ( ) { if ( is_null ( $ this -> output ) ) { return true ; } if ( is_callable ( [ $ this , 'getDefaultOutput' ] ) ) { return $ this -> output === $ this -> getDefaultOutput ( ) ; } return in_array ( $ this -> output , [ 'NUL' , '/dev/null' ] ) ; }
Check if output is being captured .
53,961
public function recordEventStart ( ) { try { $ this -> scheduler = Scheduler :: firstOrNew ( [ 'mutex' => $ this -> mutexName ( ) ] ) ; if ( ! $ this -> scheduler -> exists ) { $ this -> scheduler -> fill ( [ 'schedule' => $ this -> expression , 'command' => $ this -> getCommandName ( ) , 'timezone' => $ this -> timezo...
Set everything and pass the start of the job to Eyewitness to record .
53,962
public function recordEventFinish ( ) { if ( is_null ( $ this -> history ) ) { return ; } $ this -> history -> time_to_run = $ this -> calculateRunTime ( ) ; $ this -> history -> exitcode = $ this -> exitcode ; $ this -> history -> output = $ this -> retrieveOutput ( ) ; $ this -> history -> save ( ) ; }
Pass the results of the of the job to Eyewitness to record .
53,963
protected function handleNotifications ( ) { if ( ( $ this -> exitcode > 0 ) && $ this -> scheduler -> alert_on_fail ) { return app ( Eye :: class ) -> notifier ( ) -> alert ( new Error ( [ 'scheduler' => $ this -> scheduler , 'exitcode' => $ this -> exitcode ] ) ) ; } if ( ( $ this -> scheduler -> alert_run_time_great...
Handle any required notifications from the job .
53,964
public function mutexName ( ) { if ( Eye :: laravelVersionIs ( '>=' , '5.2.0' ) ) { return 'framework' . DIRECTORY_SEPARATOR . 'schedule-' . sha1 ( $ this -> expression . $ this -> command ) ; } return 'framework/schedule-' . md5 ( $ this -> expression . $ this -> command ) ; }
Get the mutex name for the scheduled command .
53,965
public function forgetMutex ( ) { if ( Eye :: laravelVersionIs ( '<' , '5.4.0' ) ) { if ( file_exists ( $ this -> mutexPath ( ) ) ) { unlink ( $ this -> mutexPath ( ) ) ; } } elseif ( Eye :: laravelVersionIs ( '<' , '5.4.17' ) ) { $ this -> cache -> forget ( $ this -> mutexName ( ) ) ; } else { $ this -> mutex -> forge...
Run the correct shutdown function based upon the Laravel version .
53,966
protected function setMutex ( ) { if ( Eye :: laravelVersionIs ( '<' , '5.4.0' ) ) { return touch ( $ this -> mutexPath ( ) ) ; } elseif ( Eye :: laravelVersionIs ( '<' , '5.4.17' ) ) { return $ this -> cache -> add ( $ this -> mutexName ( ) , true , 1440 ) ; } return $ this -> mutex -> create ( $ this ) ; }
Run the correct mutex based upon the Laravel version .
53,967
protected function filterArtisanCommand ( $ command ) { $ parts = explode ( " " , $ command ) ; if ( isset ( $ parts [ 2 ] ) ) { if ( str_contains ( strtolower ( $ parts [ 0 ] ) , 'php' ) && str_contains ( strtolower ( $ parts [ 1 ] ) , 'artisan' ) ) { unset ( $ parts [ 0 ] ) ; unset ( $ parts [ 1 ] ) ; return implode ...
Get the command name without the junk .
53,968
protected function hasDnsRecordChanged ( $ domain , $ record ) { if ( ! $ dns_history = History :: where ( 'meta' , $ domain ) -> orderBy ( 'created_at' , 'desc' ) -> first ( ) ) { $ this -> saveDnsRecord ( $ domain , $ record ) ; return false ; } $ differences = $ this -> compareDnsRecords ( $ dns_history -> record , ...
Check if the supplied record is different from the most recently stored DNS record available .
53,969
protected function saveDnsRecord ( $ domain , $ record ) { $ this -> sortArray ( $ record ) ; try { History :: create ( [ 'type' => 'dns' , 'meta' => $ domain , 'record' => $ this -> utf8_converter ( $ record ) ] ) ; } catch ( Exception $ e ) { $ this -> eye -> logger ( ) -> error ( 'DNS record save failed' , $ e , $ d...
Save the DNS record to the database .
53,970
protected function compareDnsRecords ( $ original , $ new ) { $ differences [ 'original' ] = $ original ; $ differences [ 'new' ] = $ new ; foreach ( $ original as $ original_id => $ original_record ) { foreach ( $ new as $ new_id => $ new_record ) { if ( $ original_record == $ new_record ) { unset ( $ differences [ 'o...
Compare two DNS record arrays . We can not just do a normal array compare - because the arrays can appear to be different even after sorting .
53,971
protected function utf8_converter ( $ array ) { array_walk_recursive ( $ array , function ( & $ item , $ key ) { if ( ! mb_detect_encoding ( $ item , 'utf-8' , true ) ) { $ item = utf8_encode ( $ item ) ; } } ) ; return $ array ; }
A special way to convert UTF8 encoding into JSON . Useful for dns provides like Google who sometimes return records with special chars in the records .
53,972
protected function sortArray ( & $ array , $ sort_flags = SORT_REGULAR ) { if ( ! is_array ( $ array ) ) { return ; } ksort ( $ array , $ sort_flags ) ; foreach ( $ array as & $ arr ) { $ this -> sortArray ( $ arr , $ sort_flags ) ; } }
Recursive ksort function to sort array .
53,973
public function handle ( $ request , Closure $ next ) { if ( session ( 'eyewitness:auth' ) || app ( Eye :: class ) -> check ( $ request ) ) { return $ next ( $ request ) ; } return redirect ( ) -> route ( 'eyewitness.login' ) -> withWarning ( 'Sorry - you must login to Eyewitness first.' ) ; }
Authenticate a user for Eyewitness .
53,974
protected function runWorker ( $ connection , $ queue , $ delay , $ memory , $ daemon = false ) { if ( ! $ daemon ) { $ this -> worker -> setCache ( $ this -> laravel [ 'cache' ] -> driver ( ) ) ; } $ queue = $ this -> getQueue ( $ queue , $ connection ) ; $ connection = $ this -> getConnectionName ( $ connection ) ; f...
This extends the Work Command for applications running Laravel version < 5 . 3 . 0 .
53,975
public function poll ( ) { if ( ! app ( ) -> environment ( 'production' ) ) { $ this -> eye -> status ( ) -> setHealthy ( 'debug' ) ; return ; } if ( config ( 'app.debug' ) ) { if ( $ this -> eye -> status ( ) -> isHealthy ( 'debug' ) ) { $ this -> eye -> notifier ( ) -> alert ( new Enabled ) ; } $ this -> eye -> statu...
Poll the Debug for its checks .
53,976
protected static function handleGlobalScope ( $ type ) { if ( Eye :: laravelVersionIs ( '>=' , '5.2.0' ) ) { static :: addGlobalScope ( 'type' , function ( Builder $ builder ) use ( $ type ) { $ builder -> where ( 'type' , $ type ) ; } ) ; } else { static :: addGlobalScope ( new TypeLegacy ( $ type ) ) ; } }
Add a global scope to the model . But we have to handle the different scenario as Laravel 5 . 1 has a different way compared to all other versions .
53,977
public function boot ( ) { $ this -> eye = app ( Eye :: class ) ; $ this -> loadTools ( ) ; $ this -> loadRoutes ( ) ; $ this -> loadViews ( ) ; $ this -> loadConsole ( ) ; }
Bootstrap the package .
53,978
protected function loadRoutes ( ) { if ( $ this -> eye -> laravelVersionIs ( '>=' , '5.4.0' ) ) { Route :: aliasMiddleware ( 'eyewitness_auth' , Authenticate :: class ) ; } else { Route :: middleware ( 'eyewitness_auth' , Authenticate :: class ) ; } if ( ! $ this -> app -> routesAreCached ( ) ) { require __DIR__ . '/.....
Load the package routes .
53,979
protected function loadConsole ( ) { if ( ! $ this -> app -> runningInConsole ( ) ) { return ; } $ this -> publishes ( [ __DIR__ . '/../config/eyewitness.php' => config_path ( 'eyewitness.php' ) ] ) ; if ( $ this -> eye -> laravelVersionIs ( '>=' , '5.4.0' ) ) { $ this -> loadMigrationsFrom ( __DIR__ . '/../database/mi...
Load the console .
53,980
public function show ( $ id ) { $ queue = Queue :: findOrFail ( $ id ) ; return view ( 'eyewitness::queue.show' ) -> withEye ( app ( Eye :: class ) ) -> withQueue ( $ queue ) -> withTransformer ( new ChartTransformer ) ; }
Show the queue .
53,981
public function update ( Request $ request , $ id ) { $ queue = Queue :: findOrFail ( $ id ) ; $ this -> validate ( $ request , [ 'alert_on_failed_job' => 'required|boolean' , 'alert_heartbeat_greater_than' => 'required|numeric|min:0|max:99999' , 'alert_pending_jobs_greater_than' => 'required|numeric|min:0|max:99999' ,...
Update the queue .
53,982
public function destroy ( $ id ) { $ queue = Queue :: findOrFail ( $ id ) ; $ queue -> history ( ) -> delete ( ) ; $ queue -> delete ( ) ; return redirect ( route ( 'eyewitness.dashboard' ) . '#queue' ) -> withSuccess ( 'The queue has been deleted.' ) ; }
Destroy the queue .
53,983
public function isHealthy ( $ monitor ) { $ result = $ this -> getStatus ( $ monitor ) ; if ( is_null ( $ result ) ) { return false ; } return $ result -> healthy ; }
Determine if the given monitor is healthy .
53,984
public function isSick ( $ monitor ) { $ result = $ this -> getStatus ( $ monitor ) ; if ( is_null ( $ result ) ) { return false ; } return ( ! $ result -> healthy ) ; }
Determine if the given monitor is sick .
53,985
public function setStatus ( $ monitor , $ status ) { Statuses :: where ( 'monitor' , $ monitor ) -> delete ( ) ; Statuses :: create ( [ 'monitor' => $ monitor , 'healthy' => $ status ] ) ; $ this -> status = Statuses :: all ( ) ; }
Set the status of a specific monitor
53,986
public function update ( Request $ request ) { if ( $ request -> has ( 'notification' ) ) { foreach ( $ request -> notification as $ id => $ severity ) { if ( in_array ( strtolower ( $ severity ) , [ 'low' , 'medium' , 'high' , 'disabled' ] ) ) { Severity :: where ( 'id' , $ id ) -> update ( [ 'severity' => strtolower ...
Update the notifications list . It is a little ineffiecient but the reality is this will occur very infrequently .
53,987
protected function runWorker ( $ connection , $ queue ) { foreach ( explode ( ',' , $ queue ) as $ tube ) { $ this -> worker -> eyeQueues [ ] = Queue :: firstOrCreate ( [ 'connection' => $ connection , 'tube' => $ tube , 'driver' => $ this -> getDriverName ( $ connection ) , 'healthy' => 1 ] ) ; } return parent :: runW...
Here we intercept the run command and make sure we create a model to represent each queue tube for future tracking .
53,988
public function poll ( ) { $ this -> checkForNewSchedulers ( ) ; foreach ( $ this -> getMissedSchedules ( ) as $ scheduler ) { $ this -> notifyIfChanges ( $ scheduler ) ; $ this -> setNextSchedule ( $ scheduler ) ; } foreach ( $ this -> getOverdueNoExitSchedules ( ) as $ history ) { $ history -> output = "No finish pin...
Poll the scheduler for its checks .
53,989
protected function notifyIfChanges ( $ scheduler ) { if ( is_null ( $ scheduler -> healthy ) ) { return ; } if ( $ this -> wasUpAndIsNowDown ( $ scheduler ) ) { $ scheduler -> healthy = false ; $ scheduler -> save ( ) ; if ( $ scheduler -> alert_on_missed ) { $ this -> eye -> notifier ( ) -> alert ( new Missed ( [ 'sch...
Check if the status of the scheduler has changed and send a notification accordingly if needed .
53,990
public function getScheduledEvents ( ) { $ schedule = app ( Schedule :: class ) ; $ events = array_map ( function ( $ event ) { $ e = $ this -> convertEvent ( $ event ) ; return [ 'schedule' => $ e -> expression , 'command' => $ e -> getCommandName ( ) , 'timezone' => $ e -> timezone , 'mutex' => $ e -> mutexName ( ) ,...
Get a list of all scheduled events and their cron frequency .
53,991
public function checkForNewSchedulers ( ) { $ current = SchedulerRepo :: all ( ) ; foreach ( $ this -> getScheduledEvents ( ) as $ event ) { if ( count ( $ current -> where ( 'mutex' , $ event [ 'mutex' ] ) ) < 1 ) { $ command = new SchedulerRepo ; $ command -> fill ( $ event ) ; $ command -> save ( ) ; } } }
Check for any new schedulers and add them to the database .
53,992
public function show ( Request $ request , $ id ) { $ notification = History :: findOrFail ( $ id ) ; return view ( 'eyewitness::notifications.show' ) -> withNotification ( $ notification ) ; }
Show the given notification .
53,993
public function update ( Request $ request , $ id ) { $ notification = History :: findOrFail ( $ id ) ; $ notification -> acknowledged = true ; $ notification -> save ( ) ; return redirect ( route ( 'eyewitness.dashboard' ) . '#notifications' ) -> withSuccess ( 'The notification has been acknowledged.' ) ; }
Acknowledge the given notification .
53,994
public function generateScheduler ( $ scheduler ) { if ( count ( $ this -> scheduler ) ) { return $ this -> scheduler ; } $ history = Scheduler :: where ( 'scheduler_id' , $ scheduler -> id ) -> get ( ) -> groupBy ( function ( $ item ) { return $ item -> created_at -> format ( 'Y-m-d' ) ; } ) -> map ( function ( $ row ...
Get the scheduler data and transform it into the required format for our charts .
53,995
public function generateCustom ( $ witness ) { if ( isset ( $ this -> custom [ $ witness -> getSafeName ( ) ] ) ) { return $ this -> custom [ $ witness -> getSafeName ( ) ] ; } $ history = CustomHistory :: where ( 'meta' , $ witness -> getSafeName ( ) ) -> get ( ) -> groupBy ( function ( $ item ) { return $ item -> cre...
Get the witness data and transform it into the required format for our charts .
53,996
public function destroy ( Request $ request , $ id ) { $ recipient = Recipient :: findOrFail ( $ id ) ; $ recipient -> delete ( ) ; return redirect ( route ( 'eyewitness.settings.index' ) . '#recipients' ) -> withSuccess ( 'The recipient has been deleted. They will not receive any further notifications from Eyewitness....
Delete the given recipient .
53,997
public function pushover ( Request $ request ) { $ this -> validate ( $ request , [ 'pushoverkey' => 'required|string|min:1|max:80' , 'pushoverapi' => 'required|string|min:1|max:80' , 'low' => 'required|boolean' , 'medium' => 'required|boolean' , 'high' => 'required|boolean' , ] ) ; Recipient :: create ( [ 'type' => 'p...
Create a PushOver recipient .
53,998
public function hipchat ( Request $ request ) { $ this -> validate ( $ request , [ 'hipchattoken' => 'required|string|min:1|max:80' , 'roomid' => 'required|string|min:4|max:7' , 'low' => 'required|boolean' , 'medium' => 'required|boolean' , 'high' => 'required|boolean' , ] ) ; Recipient :: create ( [ 'type' => 'hipchat...
Create a HipChat recipient .
53,999
public function webhook ( Request $ request ) { $ this -> validate ( $ request , [ 'webhook' => 'required|url' , 'low' => 'required|boolean' , 'medium' => 'required|boolean' , 'high' => 'required|boolean' , ] ) ; Recipient :: create ( [ 'type' => 'webhook' , 'address' => $ request -> webhook , 'low' => $ request -> low...
Create a Webhook recipient .