-
Notifications
You must be signed in to change notification settings - Fork 800
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update threats data handling in Protect
changelog Update My Jetpack for latest compatibility with protect-status package changelog
- Loading branch information
1 parent
cb52442
commit f234dd1
Showing
58 changed files
with
698 additions
and
3,621 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './utils.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
export type FixerStatus = 'not_started' | 'in_progress' | 'fixed' | 'not_fixed'; | ||
|
||
/** | ||
* Threat Fix Status | ||
* | ||
* Individual fixer status for a threat. | ||
*/ | ||
export type ThreatFixStatusError = { | ||
error: string; | ||
}; | ||
|
||
export type ThreatFixStatusSuccess = { | ||
status: FixerStatus; | ||
last_updated: string; | ||
}; | ||
|
||
export type ThreatFixStatus = ThreatFixStatusError | ThreatFixStatusSuccess; | ||
|
||
/** | ||
* Fixers Status | ||
* | ||
* Overall status of all fixers. | ||
*/ | ||
type FixersStatusBase = { | ||
ok: boolean; // Discriminator for overall success | ||
}; | ||
|
||
export type FixersStatusError = FixersStatusBase & { | ||
ok: false; | ||
error: string; | ||
}; | ||
|
||
export type FixersStatusSuccess = FixersStatusBase & { | ||
ok: true; | ||
threats: { | ||
[ key: number ]: ThreatFixStatus; | ||
}; | ||
}; | ||
|
||
export type FixersStatus = FixersStatusSuccess | FixersStatusError; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { code, color, grid, plugins, shield, wordpress } from '@wordpress/icons'; | ||
import { ThreatFixStatus } from './types/fixers.js'; | ||
import { Threat } from './types/threat.js'; | ||
|
||
export const getThreatIcon = ( threat: Threat ) => { | ||
const type = getThreatType( threat ); | ||
|
||
switch ( type ) { | ||
case 'plugin': | ||
return plugins; | ||
case 'theme': | ||
return color; | ||
case 'core': | ||
return wordpress; | ||
case 'file': | ||
return code; | ||
case 'database': | ||
return grid; | ||
default: | ||
return shield; | ||
} | ||
}; | ||
|
||
export const getThreatType = ( threat: Threat ) => { | ||
if ( threat.signature === 'Vulnerable.WP.Core' ) { | ||
return 'core'; | ||
} | ||
if ( threat.extension ) { | ||
return threat.extension.type; | ||
} | ||
if ( threat.filename ) { | ||
return 'file'; | ||
} | ||
if ( threat.table ) { | ||
return 'database'; | ||
} | ||
|
||
return null; | ||
}; | ||
|
||
export const getThreatSubtitle = ( threat: Threat ) => { | ||
const type = getThreatType( threat ); | ||
|
||
switch ( type ) { | ||
case 'plugin': | ||
case 'theme': | ||
return `${ threat.extension?.name } (${ threat.extension?.version })`; | ||
case 'core': | ||
return 'WordPress Core'; | ||
case 'file': | ||
// Trim leading slash | ||
if ( threat.filename.startsWith( '/' ) ) { | ||
return threat.filename.slice( 1 ); | ||
} | ||
return threat.filename; | ||
case 'database': | ||
return threat.table; | ||
default: | ||
return ''; | ||
} | ||
}; | ||
|
||
const FIXER_IS_STALE_THRESHOLD = 1000 * 60 * 60 * 24; // 24 hours | ||
|
||
export const fixerTimestampIsStale = ( lastUpdatedTimestamp: string ) => { | ||
const now = new Date(); | ||
const lastUpdated = new Date( lastUpdatedTimestamp ); | ||
return now.getTime() - lastUpdated.getTime() >= FIXER_IS_STALE_THRESHOLD; | ||
}; | ||
|
||
export const fixerStatusIsStale = ( fixerStatus: ThreatFixStatus ) => { | ||
return ( | ||
'status' in fixerStatus && | ||
fixerStatus.status === 'in_progress' && | ||
fixerTimestampIsStale( fixerStatus.last_updated ) | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.