Skip to content

Commit 231e423

Browse files
committed
fix: 扩展运行时派生规则
1 parent 1f0375c commit 231e423

4 files changed

Lines changed: 130 additions & 7 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "stackprism",
33
"private": true,
4-
"version": "1.2.74",
4+
"version": "1.2.75",
55
"type": "module",
66
"description": "StackPrism 用于检测网页前端、后端、CDN、SaaS、广告营销、统计、登录、支付、网站程序和主题模板线索。",
77
"scripts": {

src/background/merge.ts

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,40 @@ export const isFrontendFallback = (item: any) => item?.category === '前端库'
5353

5454
const frontendTechnologyCategories = new Set(['前端库', '前端框架', 'UI / CSS 框架'])
5555
const frontendFallbackEvidencePattern = /^/
56+
const phpRuntimeTechnologyNames = new Set(
57+
[
58+
'WordPress',
59+
'ThinkPHP',
60+
'Discuz!',
61+
'phpBB',
62+
'Drupal',
63+
'Joomla',
64+
'Typecho',
65+
'Z-BlogPHP',
66+
'Emlog',
67+
'Magento / Adobe Commerce',
68+
'OpenCart',
69+
'PrestaShop',
70+
'DedeCMS',
71+
'EmpireCMS',
72+
'PHPCMS',
73+
'PHPWind',
74+
'BBSXP',
75+
'HDWiki',
76+
'MediaWiki',
77+
'Laravel',
78+
'Laravel Livewire',
79+
'Symfony',
80+
'Yii',
81+
'CodeIgniter',
82+
'CakePHP',
83+
'Laminas / Zend Framework',
84+
'Zend Framework',
85+
'Swoole',
86+
'OpenSwoole',
87+
'FrankenPHP'
88+
].map(normalizeTechName)
89+
)
5690

5791
const frontendAliasTechnologies: Record<string, { category: string; name: string; url?: string }> = {
5892
angular: { category: '前端框架', name: 'Angular' },
@@ -96,6 +130,38 @@ export const cleanMergedTechnologyEvidence = (items: any[]) => {
96130
return evidence.filter(item => !isFrontendFallbackEvidence(item))
97131
}
98132

133+
const isPhpRuntimeTechnology = (item: any) =>
134+
item?.category === '开发语言 / 运行时' && normalizeTechName(item?.name) === normalizeTechName('PHP')
135+
136+
const isPhpRuntimeSourceTechnology = (item: any) => phpRuntimeTechnologyNames.has(normalizeTechName(item?.name))
137+
138+
const phpRuntimeInferenceEvidence = (item: any) => {
139+
const name = String(item?.name || '').trim() || 'PHP 系技术'
140+
if (item?.category === '后端 / 服务器框架') {
141+
return `由 ${name} 后端框架推断 PHP 后端运行时`
142+
}
143+
if (item?.category === '网站程序' || item?.category === 'CMS / 电商平台') {
144+
return `由 ${name} 站点程序推断 PHP 后端运行时`
145+
}
146+
return `由 ${name} 技术线索推断 PHP 后端运行时`
147+
}
148+
149+
export const inferRuntimeTechnologiesFromDetectedTechnologies = (items: any[]) => {
150+
if (!Array.isArray(items) || !items.length || items.some(isPhpRuntimeTechnology)) return items
151+
const source = items.find(isPhpRuntimeSourceTechnology)
152+
if (!source) return items
153+
return [
154+
...items,
155+
{
156+
category: '开发语言 / 运行时',
157+
name: 'PHP',
158+
confidence: '中',
159+
evidence: [phpRuntimeInferenceEvidence(source)],
160+
source: '派生推断'
161+
}
162+
]
163+
}
164+
99165
const isWordPressThemeDirectoryFallbackEvidence = (evidenceText: string) =>
100166
/(?:|)/i.test(evidenceText) && /\/wp-content\/themes\//i.test(evidenceText)
101167

@@ -172,9 +238,10 @@ export const suppressWordPressThemeDirectoryFallbacks = (items: any[]) => {
172238

173239
export const mergeTechnologyRecords = (items: any[]) => {
174240
const map = new Map<string, any>()
175-
for (const item of suppressDuplicateWebsiteProgramCategories(
241+
const normalizedItems = suppressDuplicateWebsiteProgramCategories(
176242
suppressWordPressThemeDirectoryFallbacks(canonicalizeFrontendAliasTechnologies(suppressFrontendFallbackDuplicates(items)))
177-
)) {
243+
)
244+
for (const item of inferRuntimeTechnologiesFromDetectedTechnologies(normalizedItems)) {
178245
const key = `${item.category}::${item.name}`.toLowerCase()
179246
const current = map.get(key) || { ...item, evidence: [] }
180247
if (!current.url && item.url) {

src/background/popup-cache.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { clearBadge, clearTabSession, getPopupCache, getTabData, getTabSnapshot,
44
import {
55
canonicalizeFrontendAliasTechnologies,
66
cleanMergedTechnologyEvidence,
7+
inferRuntimeTechnologiesFromDetectedTechnologies,
78
mergeTechnologyRecords,
89
strongerConfidence,
910
suppressDuplicateWebsiteProgramCategories,
@@ -136,9 +137,10 @@ export const filterTechnologiesBySettings = (technologies: any[], settings: any)
136137

137138
const mergeDisplayTechnologyRecords = (items: any[]) => {
138139
const map = new Map()
139-
for (const item of suppressDuplicateWebsiteProgramCategories(
140+
const normalizedItems = suppressDuplicateWebsiteProgramCategories(
140141
suppressWordPressThemeDirectoryFallbacks(canonicalizeFrontendAliasTechnologies(suppressFrontendFallbackDuplicates(items)))
141-
)) {
142+
)
143+
for (const item of inferRuntimeTechnologiesFromDetectedTechnologies(normalizedItems)) {
142144
if (!item?.name) continue
143145
const category = item.category || '其他库'
144146
const key = `${category}::${item.name}`.toLowerCase()

src/injected/page-detector.ts

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -522,9 +522,63 @@ const detectPageTechnologies = (ruleConfig: Record<string, unknown> = {}) => {
522522
return items.some(item => item?.category === category && normalizeRuleName(item.name) === normalizedName)
523523
}
524524

525+
const phpRuntimeTechnologyNames = new Set(
526+
[
527+
'WordPress',
528+
'ThinkPHP',
529+
'Discuz!',
530+
'phpBB',
531+
'Drupal',
532+
'Joomla',
533+
'Typecho',
534+
'Z-BlogPHP',
535+
'Emlog',
536+
'Magento / Adobe Commerce',
537+
'OpenCart',
538+
'PrestaShop',
539+
'DedeCMS',
540+
'EmpireCMS',
541+
'PHPCMS',
542+
'PHPWind',
543+
'BBSXP',
544+
'HDWiki',
545+
'MediaWiki',
546+
'Laravel',
547+
'Laravel Livewire',
548+
'Symfony',
549+
'Yii',
550+
'CodeIgniter',
551+
'CakePHP',
552+
'Laminas / Zend Framework',
553+
'Zend Framework',
554+
'Swoole',
555+
'OpenSwoole',
556+
'FrankenPHP'
557+
].map(normalizeRuleName)
558+
)
559+
560+
function isPhpRuntimeSourceTechnology(item) {
561+
return phpRuntimeTechnologyNames.has(normalizeRuleName(item?.name))
562+
}
563+
564+
function phpRuntimeInferenceEvidence(item) {
565+
const name = String(item?.name || '').trim() || 'PHP 系技术'
566+
if (item?.category === '后端 / 服务器框架') {
567+
return `由 ${name} 后端框架推断 PHP 后端运行时`
568+
}
569+
if (item?.category === '网站程序' || item?.category === 'CMS / 电商平台') {
570+
return `由 ${name} 站点程序推断 PHP 后端运行时`
571+
}
572+
return `由 ${name} 技术线索推断 PHP 后端运行时`
573+
}
574+
525575
function inferLanguagesFromDetectedTechnologies(add, items) {
526-
if (hasTechnology(items, '网站程序', 'WordPress') && !hasTechnology(items, '开发语言 / 运行时', 'PHP')) {
527-
add('开发语言 / 运行时', 'PHP', '中', '由 WordPress 站点程序推断 PHP 后端运行时')
576+
if (hasTechnology(items, '开发语言 / 运行时', 'PHP')) {
577+
return
578+
}
579+
const source = items.find(isPhpRuntimeSourceTechnology)
580+
if (source) {
581+
add('开发语言 / 运行时', 'PHP', '中', phpRuntimeInferenceEvidence(source))
528582
}
529583
}
530584

0 commit comments

Comments
 (0)