mirror of
				https://github.com/HackTricks-wiki/hacktricks.git
				synced 2025-10-10 18:36:50 +00:00 
			
		
		
		
	Translated ['', 'src/welcome/hacktricks-values-and-faq.md'] to zh
This commit is contained in:
		
							parent
							
								
									ff226d09ac
								
							
						
					
					
						commit
						ab3cb48424
					
				| @ -1,57 +1,57 @@ | ||||
| # HackTricks 的价值观与常见问题 | ||||
| # HackTricks 价值观与常见问题 | ||||
| 
 | ||||
| {{#include ../banners/hacktricks-training.md}} | ||||
| 
 | ||||
| ## HackTricks 价值观 | ||||
| ## HackTricks Values | ||||
| 
 | ||||
| > [!TIP] | ||||
| > 这些是 **HackTricks Project 的价值观**: | ||||
| > 这些是 **HackTricks 项目的价值观**: | ||||
| > | ||||
| > - 提供 **FREE** 的 **EDUCATIONAL hacking** 资源,面向 **ALL Internet**。 | ||||
| >  - Hacking 是关于学习的,学习应该尽可能免费。 | ||||
| >  - 本书的目的是作为一个全面的 **educational resource**。 | ||||
| > - **STORE** 社区发布的精彩 **hacking** 技术,同时给予 **ORIGINAL** **AUTHORS** 所有 **credits**。 | ||||
| >  - **We don't want the credit from other people**, 我们只是想为所有人保存很酷的技巧。 | ||||
| >  - 我们也在 HackTricks 中撰写 **our own researches**。 | ||||
| >  - 在若干情况下,我们只会在 **HackTricks** 中写出该技术重要部分的 **summary**,并 **encourage the lector to visit the original post** 以获取更多细节。 | ||||
| > - **ORGANIZE** 书中所有的 hacking 技术,使其 **MORE ACCESSIBLE** | ||||
| >  - HackTricks 团队花了数千小时免费 **only to organize the content**,以便人们能 **learn faster** | ||||
| > - 向 **ALL** Internet 免费提供 **EDUCATIONAL hacking** 资源。 | ||||
| >  - Hacking 就是关于学习,学习应尽可能免费。 | ||||
| >  - 本书的目的是作为一个全面的 **教育资源**。 | ||||
| > - **存储** 社区发布的很棒 **hacking** 技术,并给予 **原作者** 所有的 **署名**。 | ||||
| >  - **我们不想从其他人那里获取荣誉**,我们只是想为大家保存很酷的技巧。 | ||||
| >  - 我们也在 HackTricks 中撰写 **我们自己的研究**。 | ||||
| >  - 在若干情况下,我们只会在 HackTricks 中写出该技术重要部分的 **摘要**,并**鼓励读者访问原始帖子**以获取更多细节。 | ||||
| > - **组织** 本书中的所有 hacking 技术,使其 **更易访问** | ||||
| >  - HackTricks 团队免费投入了数千小时,仅仅是为了**组织内容**,以便人们**更快学习** | ||||
| 
 | ||||
| <figure><img src="../images/hack tricks gif.gif" alt="" width="375"><figcaption></figcaption></figure> | ||||
| 
 | ||||
| ## HackTricks 常见问题 | ||||
| ## HackTricks faq | ||||
| 
 | ||||
| > [!TIP] | ||||
| > | ||||
| > - **Thank you so much for these resources, how can I thank you?** | ||||
| > - **非常感谢这些资源,我如何表达谢意?** | ||||
| 
 | ||||
| 你可以在推特上公开感谢 HackTricks 团队,将所有这些资源整理公开,并在推文中提到 [**@hacktricks_live**](https://twitter.com/hacktricks_live).\ | ||||
| 如果你特别感激,也可以 [**sponsor the project here**](https://github.com/sponsors/carlospolop).\ | ||||
| 别忘了在 Github 项目中 **give a star**!(链接见下方)。 | ||||
| 你可以在推特上公开感谢 HackTricks 团队,将推文 @mention [**@hacktricks_live**](https://twitter.com/hacktricks_live)。\ | ||||
| 如果你特别感激,你也可以在此 [**赞助该项目**](https://github.com/sponsors/carlospolop)。\ | ||||
| 并别忘了 **在 Github 项目上点星!**(链接见下方)。 | ||||
| 
 | ||||
| > [!TIP] | ||||
| > | ||||
| > - **How can I contribute to the project?** | ||||
| > - **我如何为项目做贡献?** | ||||
| 
 | ||||
| 你可以通过向相应的 Github 页面发送 **Pull Request** 来 **share new tips and tricks with the community or fix bugs**: | ||||
| 你可以通过向相应的 Github 页面提交 **Pull Request**,与社区分享新的技巧或修复你在书中发现的错误: | ||||
| 
 | ||||
| - [https://github.com/carlospolop/hacktricks](https://github.com/carlospolop/hacktricks) | ||||
| - [https://github.com/carlospolop/hacktricks-cloud](https://github.com/carlospolop/hacktricks-cloud) | ||||
| 
 | ||||
| 别忘了在 Github 项目中 **give a star**! | ||||
| 别忘了 **为 Github 项目加星!** | ||||
| 
 | ||||
| > [!TIP] | ||||
| > | ||||
| > - **Can I copy some content from HackTricks and put it in my blog?** | ||||
| > - **我可以把 HackTricks 的部分内容复制到我的博客吗?** | ||||
| 
 | ||||
| 可以,但 **不要忘记标注具体的链接**,说明内容来自何处。 | ||||
| 可以,但**不要忘记注明内容来源的具体链接**。 | ||||
| 
 | ||||
| > [!TIP] | ||||
| > | ||||
| > - **How can I cite a page of HackTricks?** | ||||
| > - **我如何引用 HackTricks 的某一页面?** | ||||
| 
 | ||||
| 只要出现你获取信息的页面的链接就足够了。\ | ||||
| 如果你需要 bibtex,你可以使用类似下面的格式: | ||||
| 只要显示出你获取信息的页面链接就足够。\ | ||||
| 如果你需要 bibtex,你可以使用类似如下的内容: | ||||
| ```latex | ||||
| @misc{hacktricks-bibtexing, | ||||
| author = {"HackTricks Team" or the Authors name of the specific page/trick}, | ||||
| @ -62,82 +62,82 @@ url = {\url{https://book.hacktricks.wiki/specific-page}}, | ||||
| ``` | ||||
| > [!WARNING] | ||||
| > | ||||
| > - **Can I copy all HackTricks in my blog?** | ||||
| > - **我可以把整个 HackTricks 复制到我的博客吗?** | ||||
| 
 | ||||
| **我不建议这样做**。这对任何人都**没有好处**,因为所有内容已经在官方的 HackTricks 书中免费公开可用。 | ||||
| **我更不希望这样做**。那样**不会为任何人带来好处**,因为所有**内容已在官方 HackTricks 书籍中免费公开**。 | ||||
| 
 | ||||
| 如果你担心内容会消失,可以在 Github 上 fork 或下载,正如我说的,它已经是免费的。 | ||||
| 如果你担心它会消失,只需在 Github 上 fork 或下载它,正如我说的,它已经是免费的。 | ||||
| 
 | ||||
| > [!WARNING] | ||||
| > | ||||
| > - **Why do you have sponsors? Are HackTricks books for commercial purposes?** | ||||
| > - **你为什么有赞助?HackTricks 书籍是用于商业目的的吗?** | ||||
| 
 | ||||
| 第一个 **HackTricks** **价值** 是向**全世界**提供**免费(FREE)**的黑客教育资源。HackTricks 团队已**投入数千小时**来提供这些内容,依然是**免费的**。 | ||||
| 第一个 **HackTricks** **价值** 是向 **全世界** 提供 **FREE hacking educational resources**。HackTricks 团队已**投入数千小时**来提供这些内容,再次强调,是 **FREE** 的。 | ||||
| 
 | ||||
| 如果你认为 HackTricks 书是为了**商业目的**而制作的,那你就**完全错了**。 | ||||
| 如果你认为 HackTricks 书籍是为了 **商业目的**,那你**完全错了**。 | ||||
| 
 | ||||
| 我们有赞助商是因为,即使所有内容都是免费的,我们也希望**给社区提供一种表示感谢的方式**。因此,我们提供人们通过 [**Github sponsors**](https://github.com/sponsors/carlospolop) 捐助 HackTricks 的选项,并允许**相关的网络安全公司**赞助 HackTricks,并在书中放置一些**广告**,这些**广告**始终放在**能被看见但不会干扰学习**的地方。 | ||||
| 我们之所以有赞助,是因为即使所有内容都是 FREE,我们也希望为社区提供一种在愿意时**表达对我们工作的支持**的方式。因此,我们为人们提供通过 [**Github sponsors**](https://github.com/sponsors/carlospolop) 向 HackTricks 捐赠的选项,并允许相关的网络安全公司赞助 HackTricks,在书中放置一些广告,这些**广告**始终放在能让它们**可见**但不会在读者专注于内容时**干扰学习**的位置。 | ||||
| 
 | ||||
| 你不会在 HackTricks 看到像其他内容远不如 HackTricks 的博客那样恼人的广告,因为 HackTricks 并非为商业目的而制作。 | ||||
| 你不会在 HackTricks 看到像那些内容远不及 HackTricks 的博客那样充斥着烦人的广告,因为 HackTricks 并非为商业目的而制作。 | ||||
| 
 | ||||
| > [!CAUTION] | ||||
| > | ||||
| > - **What should I do if some HackTricks page is based on my blog post but it isn't referenced?** | ||||
| > - **如果某些 HackTricks 页面基于我的博客文章但没有被引用,我该怎么办?** | ||||
| 
 | ||||
| **我们非常抱歉。这样的事情不应该发生**。请通过 Github issues、Twitter、Discord 等方式告知我们 —— 提供包含该内容的 HackTricks 页面链接和你博客的链接,**我们会检查并尽快添加引用**。 | ||||
| **我们非常抱歉。这种情况本不该发生**。请通过 Github issues、Twitter、Discord 等方式告知我们包含该内容的 HackTricks 页面链接以及你的博客链接,**我们将检查并尽快添加引用**。 | ||||
| 
 | ||||
| > [!CAUTION] | ||||
| > | ||||
| > - **What should I do if there is content from my blog in HackTricks and I don't want it there?** | ||||
| > - **如果 HackTricks 中有来自我博客的内容而我不希望它在那里,我该怎么办?** | ||||
| 
 | ||||
| 请注意,在 HackTricks 中有指向你页面的链接会带来: | ||||
| 请注意,HackTricks 中有你页面的链接会: | ||||
| 
 | ||||
| - 提升你的 **SEO** | ||||
| - 内容会被**翻译成 15 种以上语言**,让更多人能够访问该内容 | ||||
| - **HackTricks 鼓励**人们**查看你的网站**(有好几位作者告诉我们,自从他们的页面出现在 HackTricks 后访问量增加了) | ||||
| - 该内容会被**翻译成超过 15 种语言**,使更多人能够访问该内容 | ||||
| - **HackTricks 会鼓励**人们**查看你的页面**(有人告诉我们,自从他们的某些页面出现在 HackTricks 后,访问量有所增加) | ||||
| 
 | ||||
| 但是,如果你仍然希望我们把你博客的内容从 HackTricks 中移除,只需告知我们,我们会**删除所有指向你博客的链接**以及任何基于其的内容。 | ||||
| 不过,如果你仍然希望从 HackTricks 中移除你的博客内容,请告知我们,我们将会**删除所有指向你博客的链接**以及任何基于它的内容。 | ||||
| 
 | ||||
| > [!CAUTION] | ||||
| > | ||||
| > - **What should I do if I find copy-pasted content in HackTricks?** | ||||
| > - **如果我在 HackTricks 发现有复制粘贴的内容,我该怎么办?** | ||||
| 
 | ||||
| 我们始终**给予原作者全部署名**。如果你发现某页有复制粘贴的内容且没有标注原始来源,请告知我们,我们会**删除它**、**在文本前添加链接**,或**重写并加入链接**。 | ||||
| 我们始终**给予原作者全部署名**。如果你发现某页为复制粘贴内容且未引用原始来源,请告知我们,我们将会**删除该内容**、**在文本前添加链接**或**重写内容并加入链接**。 | ||||
| 
 | ||||
| ## LICENSE | ||||
| ## 许可证 | ||||
| 
 | ||||
| 版权所有 © 除非另有说明,保留所有权利。 | ||||
| 版权所有 © 未经另行说明,保留一切权利。 | ||||
| 
 | ||||
| #### License Summary: | ||||
| #### 许可摘要: | ||||
| 
 | ||||
| - Attribution: You are free to: | ||||
| - Share — copy and redistribute the material in any medium or format. | ||||
| - Adapt — remix, transform, and build upon the material. | ||||
| - 署名:你可以: | ||||
| - 共享 — 在任何媒介或格式复制并重新分发该材料。 | ||||
| - 修改 — 重新混合、变更并以该材料为基础进行创作。 | ||||
| 
 | ||||
| #### Additional Terms: | ||||
| #### 附加条款: | ||||
| 
 | ||||
| - Third-Party Content: 本书/博客的某些部分可能包含来自其他来源的内容,例如其他博客或出版物的摘录。此类内容的使用遵循合理使用原则或已获得相应版权所有者的明确许可。有关第三方内容的具体许可信息,请参阅原始来源。 | ||||
| - Authorship: HackTricks 原创内容受本许可条款约束。鼓励在共享或改编本作品时对作者进行署名。 | ||||
| - 第三方内容:本博客/书籍的部分内容可能包含来自其他来源的内容,例如其他博客或出版物的摘录。此类内容的使用遵循合理使用原则或已获得相应版权持有人的明确许可。有关第三方内容的具体许可信息,请参阅原始来源。 | ||||
| - 作者权:由 HackTricks 创作的原始内容受本许可条款约束。我们鼓励在分享或改编时对作者进行署名。 | ||||
| 
 | ||||
| #### Exemptions: | ||||
| #### 豁免: | ||||
| 
 | ||||
| - Commercial Use: 如需就本内容的商业用途进行咨询,请与我联系。 | ||||
| - 商业使用:如需就本内容的商业使用进行咨询,请与我联系。 | ||||
| 
 | ||||
| 本许可不授予与内容相关的任何商标或品牌权利。本博客/书中出现的所有商标和品牌均为其各自所有者的财产。 | ||||
| 本许可不授予与内容相关的任何商标或品牌权利。本博客/书籍中出现的所有商标和品牌均为其各自所有者的财产。 | ||||
| 
 | ||||
| **通过访问或使用 HackTricks,您同意遵守本许可条款。如果您不同意这些条款,请不要访问本网站。** | ||||
| **通过访问或使用 HackTricks,你同意遵守本许可条款。如果你不同意这些条款,请不要访问本网站。** | ||||
| 
 | ||||
| ## **Disclaimer** | ||||
| ## **免责声明** | ||||
| 
 | ||||
| > [!CAUTION] | ||||
| > 本书《HackTricks》仅用于教育和信息目的。书中内容按“原样”提供,作者和出版者不对本书中信息、产品、服务或相关图示的完整性、准确性、可靠性、适用性或可用性作任何明示或暗示的陈述或保证。您对该等信息的任何依赖均由您自行承担风险。 | ||||
| > 本书“HackTricks”仅用于教育和信息目的。本书内容以“按现状”('as is')提供,作者和出版者不对本书所含信息、产品、服务或相关图示的完整性、准确性、可靠性、适用性或可用性做出任何明示或暗示的陈述或保证。因此,您对这些信息的任何依赖均完全由您自行承担风险。 | ||||
| > | ||||
| > 作者和出版者在任何情况下均不对任何损失或损害承担责任,包括但不限于间接或衍生损失或损害,或因使用本书而导致的数据或利润损失。 | ||||
| > 作者和出版者在任何情况下均不对任何损失或损害承担责任,包括但不限于间接或继发性损失或损害,或因使用本书而导致的数据损失或利润损失或任何其他损失或损害。 | ||||
| > | ||||
| > 此外,本书中描述的技术和提示仅用于教育和信息目的,不应用于任何非法或恶意活动。作者和出版者不支持或鼓励任何非法或不道德的活动,使用本书所含信息的后果由用户自行承担。 | ||||
| > 此外,本书所述的技术和提示仅用于教育和信息目的,不应用于任何非法或恶意活动。作者和出版者不赞同或支持任何非法或不道德的活动,对本书所含信息的任何使用均由用户自行承担风险并自负其责。 | ||||
| > | ||||
| > 用户应对基于本书信息所采取的任何行为独自负责,并在尝试实施书中任何技术或提示时始终寻求专业建议和帮助。 | ||||
| > 用户对基于本书所含信息所采取的任何行为负全部责任,并在尝试实施本书所述任何技术或提示时应始终寻求专业建议与帮助。 | ||||
| > | ||||
| > 使用本书即表示用户同意解除作者和出版者因使用本书或其中任何信息而可能导致的任何及所有责任。 | ||||
| > 通过使用本书,用户同意解除作者和出版者对因使用本书或其包含的任何信息而可能导致的任何及所有损害、损失或伤害的责任。 | ||||
| 
 | ||||
| {{#include ../banners/hacktricks-training.md}} | ||||
|  | ||||
| @ -6,34 +6,63 @@ | ||||
| */ | ||||
| 
 | ||||
| (() => { | ||||
|   "use strict"; | ||||
|     "use strict"; | ||||
|    | ||||
|     /* ───────────── 0. helpers (main thread) ───────────── */ | ||||
|     const clear = el => { while (el.firstChild) el.removeChild(el.firstChild); }; | ||||
|    | ||||
|     /* ───────────── 1. Web‑Worker code ─────────────────── */ | ||||
|     const workerCode = ` | ||||
|       self.window = self; | ||||
|       self.search = self.search || {}; | ||||
|       const abs = p => location.origin + p; | ||||
|    | ||||
|       /* 1 — elasticlunr */ | ||||
|       try { importScripts('https://cdn.jsdelivr.net/npm/elasticlunr@0.9.5/elasticlunr.min.js'); } | ||||
|       catch { importScripts(abs('/elasticlunr.min.js')); } | ||||
|    | ||||
|     /* 2 — decompress gzip data */ | ||||
|     async function decompressGzip(arrayBuffer){ | ||||
|       if(typeof DecompressionStream !== 'undefined'){ | ||||
|         /* Modern browsers: use native DecompressionStream */ | ||||
|         const stream = new Response(arrayBuffer).body.pipeThrough(new DecompressionStream('gzip')); | ||||
|         const decompressed = await new Response(stream).arrayBuffer(); | ||||
|         return new TextDecoder().decode(decompressed); | ||||
|       } else { | ||||
|         /* Fallback: use pako library */ | ||||
|         if(typeof pako === 'undefined'){ | ||||
|           try { importScripts('https://cdn.jsdelivr.net/npm/pako@2.1.0/dist/pako.min.js'); } | ||||
|           catch(e){ throw new Error('pako library required for decompression: '+e); } | ||||
|         } | ||||
|         const uint8Array = new Uint8Array(arrayBuffer); | ||||
|         const decompressed = pako.ungzip(uint8Array, {to: 'string'}); | ||||
|         return decompressed; | ||||
|       } | ||||
|     } | ||||
| 
 | ||||
|   /* ───────────── 0. helpers (main thread) ───────────── */ | ||||
|   const clear = el => { while (el.firstChild) el.removeChild(el.firstChild); }; | ||||
| 
 | ||||
|   /* ───────────── 1. Web‑Worker code ─────────────────── */ | ||||
|   const workerCode = ` | ||||
|     self.window = self; | ||||
|     self.search = self.search || {}; | ||||
|     const abs = p => location.origin + p; | ||||
| 
 | ||||
|     /* 1 — elasticlunr */ | ||||
|     try { importScripts('https://cdn.jsdelivr.net/npm/elasticlunr@0.9.5/elasticlunr.min.js'); } | ||||
|     catch { importScripts(abs('/elasticlunr.min.js')); } | ||||
| 
 | ||||
|     /* 2 — load a single index (remote → local) */ | ||||
|     /* 3 — load a single index (remote → local) */ | ||||
|     async function loadIndex(remote, local, isCloud=false){ | ||||
|       let rawLoaded = false; | ||||
|       if(remote){ | ||||
|         /* Try ONLY compressed version from GitHub (remote already includes .js.gz) */ | ||||
|         try { | ||||
|           const r = await fetch(remote,{mode:'cors'}); | ||||
|           if (!r.ok) throw new Error('HTTP '+r.status); | ||||
|           importScripts(URL.createObjectURL(new Blob([await r.text()],{type:'application/javascript'}))); | ||||
|           rawLoaded = true; | ||||
|         } catch(e){ console.warn('remote',remote,'failed →',e); } | ||||
|           if (r.ok) { | ||||
|             const compressed = await r.arrayBuffer(); | ||||
|             const text = await decompressGzip(compressed); | ||||
|             importScripts(URL.createObjectURL(new Blob([text],{type:'application/javascript'}))); | ||||
|             rawLoaded = true; | ||||
|             console.log('Loaded compressed from GitHub:',remote); | ||||
|           } | ||||
|         } catch(e){ console.warn('compressed GitHub',remote,'failed →',e); } | ||||
|       } | ||||
|       /* If remote (GitHub) failed, fall back to local uncompressed file */ | ||||
|       if(!rawLoaded && local){ | ||||
|         try { importScripts(abs(local)); rawLoaded = true; } | ||||
|         try {  | ||||
|           importScripts(abs(local));  | ||||
|           rawLoaded = true; | ||||
|           console.log('Loaded local fallback:',local); | ||||
|         } | ||||
|         catch(e){ console.error('local',local,'failed →',e); } | ||||
|       } | ||||
|       if(!rawLoaded) return null;                 /* give up on this index */ | ||||
| @ -61,151 +90,159 @@ | ||||
| 
 | ||||
|       return local ? loadIndex(null, local, isCloud) : null; | ||||
|     } | ||||
|      | ||||
|     let built = []; | ||||
|     const MAX = 30, opts = {bool:'AND', expand:true}; | ||||
|      | ||||
|     self.onmessage = async ({data}) => { | ||||
|       if(data.type === 'init'){ | ||||
|         const lang = data.lang || 'en'; | ||||
|         const searchindexBase = 'https://raw.githubusercontent.com/HackTricks-wiki/hacktricks-searchindex/master'; | ||||
| 
 | ||||
|     (async () => { | ||||
|       const htmlLang = (document.documentElement.lang || 'en').toLowerCase(); | ||||
|       const lang = htmlLang.split('-')[0]; | ||||
|       const mainReleaseBase = 'https://github.com/HackTricks-wiki/hacktricks/releases/download'; | ||||
|       const cloudReleaseBase = 'https://github.com/HackTricks-wiki/hacktricks-cloud/releases/download'; | ||||
|         /* Remote sources are .js.gz (compressed), local fallback is .js (uncompressed) */ | ||||
|         const mainFilenames = Array.from(new Set(['searchindex-' + lang + '.js.gz', 'searchindex-en.js.gz'])); | ||||
|         const cloudFilenames = Array.from(new Set(['searchindex-cloud-' + lang + '.js.gz', 'searchindex-cloud-en.js.gz'])); | ||||
| 
 | ||||
|       const mainTags = Array.from(new Set([\`searchindex-\${lang}\`, 'searchindex-en', 'searchindex-master']));
 | ||||
|       const cloudTags = Array.from(new Set([\`searchindex-\${lang}\`, 'searchindex-en', 'searchindex-master']));
 | ||||
|         const MAIN_REMOTE_SOURCES  = mainFilenames.map(function(filename) { return searchindexBase + '/' + filename; }); | ||||
|         const CLOUD_REMOTE_SOURCES = cloudFilenames.map(function(filename) { return searchindexBase + '/' + filename; }); | ||||
| 
 | ||||
|       const MAIN_REMOTE_SOURCES  = mainTags.map(tag => \`\${mainReleaseBase}/\${tag}/searchindex.js\`);
 | ||||
|       const CLOUD_REMOTE_SOURCES = cloudTags.map(tag => \`\${cloudReleaseBase}/\${tag}/searchindex.js\`);
 | ||||
| 
 | ||||
|       const indices = []; | ||||
|       const main = await loadWithFallback(MAIN_REMOTE_SOURCES , '/searchindex.js',        false); if(main)  indices.push(main); | ||||
|       const cloud= await loadWithFallback(CLOUD_REMOTE_SOURCES, '/searchindex-cloud.js',  true ); if(cloud) indices.push(cloud); | ||||
| 
 | ||||
|       if(!indices.length){ postMessage({ready:false, error:'no-index'}); return; } | ||||
| 
 | ||||
|       /* build index objects */ | ||||
|       const built = indices.map(d => ({ | ||||
|         idx : elasticlunr.Index.load(d.json), | ||||
|         urls: d.urls, | ||||
|         cloud: d.cloud, | ||||
|         base: d.cloud ? 'https://cloud.hacktricks.wiki/' : '' | ||||
|       })); | ||||
| 
 | ||||
|       postMessage({ready:true}); | ||||
|       const MAX = 30, opts = {bool:'AND', expand:true}; | ||||
| 
 | ||||
|       self.onmessage = ({data:q}) => { | ||||
|         if(!q){ postMessage([]); return; } | ||||
| 
 | ||||
|         const all = []; | ||||
|         for(const s of built){ | ||||
|           const res = s.idx.search(q,opts); | ||||
|           if(!res.length) continue; | ||||
|           const max = res[0].score || 1; | ||||
|           res.forEach(r => { | ||||
|             const doc = s.idx.documentStore.getDoc(r.ref); | ||||
|             all.push({ | ||||
|               norm : r.score / max, | ||||
|               title: doc.title, | ||||
|               body : doc.body, | ||||
|               breadcrumbs: doc.breadcrumbs, | ||||
|               url  : s.base + s.urls[r.ref], | ||||
|               cloud: s.cloud | ||||
|         const indices = []; | ||||
|         const main = await loadWithFallback(MAIN_REMOTE_SOURCES , '/searchindex-book.js',        false); if(main)  indices.push(main); | ||||
|         const cloud= await loadWithFallback(CLOUD_REMOTE_SOURCES, '/searchindex.js',  true ); if(cloud) indices.push(cloud);   | ||||
|         if(!indices.length){ postMessage({ready:false, error:'no-index'}); return; } | ||||
|    | ||||
|         /* build index objects */ | ||||
|         built = indices.map(d => ({ | ||||
|           idx : elasticlunr.Index.load(d.json), | ||||
|           urls: d.urls, | ||||
|           cloud: d.cloud, | ||||
|           base: d.cloud ? 'https://cloud.hacktricks.wiki/' : '' | ||||
|         })); | ||||
|    | ||||
|         postMessage({ready:true}); | ||||
|         return; | ||||
|       } | ||||
|        | ||||
|       const q = data.query || data; | ||||
|       if(!q){ postMessage([]); return; } | ||||
|    | ||||
|           const all = []; | ||||
|           for(const s of built){ | ||||
|             const res = s.idx.search(q,opts); | ||||
|             if(!res.length) continue; | ||||
|             const max = res[0].score || 1; | ||||
|             res.forEach(r => { | ||||
|               const doc = s.idx.documentStore.getDoc(r.ref); | ||||
|               all.push({ | ||||
|                 norm : r.score / max, | ||||
|                 title: doc.title, | ||||
|                 body : doc.body, | ||||
|                 breadcrumbs: doc.breadcrumbs, | ||||
|                 url  : s.base + s.urls[r.ref], | ||||
|                 cloud: s.cloud | ||||
|               }); | ||||
|             }); | ||||
|           }); | ||||
|         } | ||||
|         all.sort((a,b)=>b.norm-a.norm); | ||||
|         postMessage(all.slice(0,MAX)); | ||||
|       }; | ||||
|     })(); | ||||
|   `;
 | ||||
|           } | ||||
|           all.sort((a,b)=>b.norm-a.norm); | ||||
|           postMessage(all.slice(0,MAX)); | ||||
|     }; | ||||
|     `;
 | ||||
|    | ||||
|     /* ───────────── 2. spawn worker ───────────── */ | ||||
|     const worker = new Worker(URL.createObjectURL(new Blob([workerCode],{type:'application/javascript'}))); | ||||
|      | ||||
|     /* ───────────── 2.1. initialize worker with language ───────────── */ | ||||
|     const htmlLang = (document.documentElement.lang || 'en').toLowerCase(); | ||||
|     const lang = htmlLang.split('-')[0]; | ||||
|     worker.postMessage({type: 'init', lang: lang}); | ||||
|    | ||||
|     /* ───────────── 3. DOM refs ─────────────── */ | ||||
|     const wrap    = document.getElementById('search-wrapper'); | ||||
|     const bar     = document.getElementById('searchbar'); | ||||
|     const list    = document.getElementById('searchresults'); | ||||
|     const listOut = document.getElementById('searchresults-outer'); | ||||
|     const header  = document.getElementById('searchresults-header'); | ||||
|     const icon    = document.getElementById('search-toggle'); | ||||
|    | ||||
|     const READY_ICON = icon.innerHTML; | ||||
|     icon.textContent = '⏳'; | ||||
|     icon.setAttribute('aria-label','Loading search …'); | ||||
|       icon.setAttribute('title','Search is loading, please wait...'); | ||||
| 
 | ||||
|   /* ───────────── 2. spawn worker ───────────── */ | ||||
|   const worker = new Worker(URL.createObjectURL(new Blob([workerCode],{type:'application/javascript'}))); | ||||
| 
 | ||||
|   /* ───────────── 3. DOM refs ─────────────── */ | ||||
|   const wrap    = document.getElementById('search-wrapper'); | ||||
|   const bar     = document.getElementById('searchbar'); | ||||
|   const list    = document.getElementById('searchresults'); | ||||
|   const listOut = document.getElementById('searchresults-outer'); | ||||
|   const header  = document.getElementById('searchresults-header'); | ||||
|   const icon    = document.getElementById('search-toggle'); | ||||
| 
 | ||||
|   const READY_ICON = icon.innerHTML; | ||||
|   icon.textContent = '⏳'; | ||||
|   icon.setAttribute('aria-label','Loading search …'); | ||||
|   icon.setAttribute('title','Search is loading, please wait...'); | ||||
| 
 | ||||
|   const HOT=83, ESC=27, DOWN=40, UP=38, ENTER=13; | ||||
|   let debounce, teaserCount=0; | ||||
| 
 | ||||
|   /* ───────────── helpers (teaser, metric) ───────────── */ | ||||
|   const escapeHTML = (()=>{const M={'&':'&','<':'<','>':'>','"':'"','\'':'''};return s=>s.replace(/[&<>'"]/g,c=>M[c]);})(); | ||||
|   const URL_MARK='highlight'; | ||||
|   function metric(c,t){return c?`${c} search result${c>1?'s':''} for '${t}':`:`No search results for '${t}'.`;} | ||||
| 
 | ||||
|   function makeTeaser(body,terms){ | ||||
|     const stem=w=>elasticlunr.stemmer(w.toLowerCase()); | ||||
|     const T=terms.map(stem),W_S=40,W_F=8,W_N=2,WIN=30; | ||||
|     const W=[],sents=body.toLowerCase().split('. '); | ||||
|     let i=0,v=W_F,found=false; | ||||
|     sents.forEach(s=>{v=W_F; s.split(' ').forEach(w=>{ if(w){ if(T.some(t=>stem(w).startsWith(t))){v=W_S;found=true;} W.push([w,v,i]); v=W_N;} i+=w.length+1; }); i++;}); | ||||
|     if(!W.length) return body; | ||||
|     const win=Math.min(W.length,WIN); | ||||
|     const sums=[W.slice(0,win).reduce((a,[,wt])=>a+wt,0)]; | ||||
|     for(let k=1;k<=W.length-win;k++) sums[k]=sums[k-1]-W[k-1][1]+W[k+win-1][1]; | ||||
|     const best=found?sums.lastIndexOf(Math.max(...sums)):0; | ||||
|     const out=[]; i=W[best][2]; | ||||
|     for(let k=best;k<best+win;k++){const [w,wt,pos]=W[k]; if(i<pos){out.push(body.substring(i,pos)); i=pos;} if(wt===W_S) out.push('<em>'); out.push(body.substr(pos,w.length)); if(wt===W_S) out.push('</em>'); i=pos+w.length;} | ||||
|     return out.join(''); | ||||
|   } | ||||
| 
 | ||||
|   function format(d,terms){ | ||||
|     const teaser=makeTeaser(escapeHTML(d.body),terms); | ||||
|     teaserCount++; | ||||
|     const enc=encodeURIComponent(terms.join(' ')).replace(/'/g,'%27'); | ||||
|     const parts=d.url.split('#'); if(parts.length===1) parts.push(''); | ||||
|     const abs=d.url.startsWith('http'); | ||||
|     const href=`${abs?'':path_to_root}${parts[0]}?${URL_MARK}=${enc}#${parts[1]}`; | ||||
|     const style=d.cloud?" style=\"color:#1e88e5\"":""; | ||||
|     const isCloud=d.cloud?" [Cloud]":" [Book]"; | ||||
|     return `<a href="${href}" aria-details="teaser_${teaserCount}"${style}>`+ | ||||
|            `${d.breadcrumbs}${isCloud}<span class="teaser" id="teaser_${teaserCount}" aria-label="Search Result Teaser">${teaser}</span></a>`; | ||||
|   } | ||||
| 
 | ||||
|   /* ───────────── UI control ───────────── */ | ||||
|   function showUI(s){wrap.classList.toggle('hidden',!s); icon.setAttribute('aria-expanded',s); if(s){window.scrollTo(0,0); bar.focus(); bar.select();} else {listOut.classList.add('hidden'); [...list.children].forEach(li=>li.classList.remove('focus'));}} | ||||
|   function blur(){const t=document.createElement('input'); t.style.cssText='position:absolute;opacity:0;'; icon.appendChild(t); t.focus(); t.remove();} | ||||
| 
 | ||||
|   icon.addEventListener('click',()=>showUI(wrap.classList.contains('hidden'))); | ||||
| 
 | ||||
|   document.addEventListener('keydown',e=>{ | ||||
|     if(e.altKey||e.ctrlKey||e.metaKey||e.shiftKey) return; | ||||
|     const f=/^(?:input|select|textarea)$/i.test(e.target.nodeName); | ||||
|     if(e.keyCode===HOT && !f){e.preventDefault(); showUI(true);} else if(e.keyCode===ESC){e.preventDefault(); showUI(false); blur();} | ||||
|     else if(e.keyCode===DOWN && document.activeElement===bar){e.preventDefault(); const first=list.firstElementChild; if(first){blur(); first.classList.add('focus');}} | ||||
|     else if([DOWN,UP,ENTER].includes(e.keyCode) && document.activeElement!==bar){const cur=list.querySelector('li.focus'); if(!cur) return; e.preventDefault(); if(e.keyCode===DOWN){const nxt=cur.nextElementSibling; if(nxt){cur.classList.remove('focus'); nxt.classList.add('focus');}} else if(e.keyCode===UP){const prv=cur.previousElementSibling; cur.classList.remove('focus'); if(prv){prv.classList.add('focus');} else {bar.focus();}} else {const a=cur.querySelector('a'); if(a) window.location.assign(a.href);}} | ||||
|   }); | ||||
| 
 | ||||
|   bar.addEventListener('input',e=>{ clearTimeout(debounce); debounce=setTimeout(()=>worker.postMessage(e.target.value.trim()),120); }); | ||||
| 
 | ||||
|   /* ───────────── worker messages ───────────── */ | ||||
|   worker.onmessage = ({data}) => { | ||||
|     if(data && data.ready!==undefined){ | ||||
|       if(data.ready){  | ||||
|         icon.innerHTML=READY_ICON;  | ||||
|         icon.setAttribute('aria-label','Open search (S)');  | ||||
|         icon.removeAttribute('title'); | ||||
|       } | ||||
|       else {  | ||||
|         icon.textContent='❌';  | ||||
|         icon.setAttribute('aria-label','Search unavailable');  | ||||
|         icon.setAttribute('title','Search is unavailable'); | ||||
|       } | ||||
|       return; | ||||
|    | ||||
|     const HOT=83, ESC=27, DOWN=40, UP=38, ENTER=13; | ||||
|     let debounce, teaserCount=0; | ||||
|    | ||||
|     /* ───────────── helpers (teaser, metric) ───────────── */ | ||||
|     const escapeHTML = (()=>{const M={'&':'&','<':'<','>':'>','"':'"','\'':'''};return s=>s.replace(/[&<>'"]/g,c=>M[c]);})(); | ||||
|     const URL_MARK='highlight'; | ||||
|     function metric(c,t){return c?`${c} search result${c>1?'s':''} for '${t}':`:`No search results for '${t}'.`;} | ||||
|    | ||||
|     function makeTeaser(body,terms){ | ||||
|       const stem=w=>elasticlunr.stemmer(w.toLowerCase()); | ||||
|       const T=terms.map(stem),W_S=40,W_F=8,W_N=2,WIN=30; | ||||
|       const W=[],sents=body.toLowerCase().split('. '); | ||||
|       let i=0,v=W_F,found=false; | ||||
|       sents.forEach(s=>{v=W_F; s.split(' ').forEach(w=>{ if(w){ if(T.some(t=>stem(w).startsWith(t))){v=W_S;found=true;} W.push([w,v,i]); v=W_N;} i+=w.length+1; }); i++;}); | ||||
|       if(!W.length) return body; | ||||
|       const win=Math.min(W.length,WIN); | ||||
|       const sums=[W.slice(0,win).reduce((a,[,wt])=>a+wt,0)]; | ||||
|       for(let k=1;k<=W.length-win;k++) sums[k]=sums[k-1]-W[k-1][1]+W[k+win-1][1]; | ||||
|       const best=found?sums.lastIndexOf(Math.max(...sums)):0; | ||||
|       const out=[]; i=W[best][2]; | ||||
|       for(let k=best;k<best+win;k++){const [w,wt,pos]=W[k]; if(i<pos){out.push(body.substring(i,pos)); i=pos;} if(wt===W_S) out.push('<em>'); out.push(body.substr(pos,w.length)); if(wt===W_S) out.push('</em>'); i=pos+w.length;} | ||||
|       return out.join(''); | ||||
|     } | ||||
|     const docs=data, q=bar.value.trim(), terms=q.split(/\s+/).filter(Boolean); | ||||
|     header.textContent=metric(docs.length,q); | ||||
|     clear(list); | ||||
|     docs.forEach(d=>{const li=document.createElement('li'); li.innerHTML=format(d,terms); list.appendChild(li);}); | ||||
|     listOut.classList.toggle('hidden',!docs.length); | ||||
|   }; | ||||
| })(); | ||||
| 
 | ||||
|    | ||||
|     function format(d,terms){ | ||||
|       const teaser=makeTeaser(escapeHTML(d.body),terms); | ||||
|       teaserCount++; | ||||
|       const enc=encodeURIComponent(terms.join(' ')).replace(/'/g,'%27'); | ||||
|       const parts=d.url.split('#'); if(parts.length===1) parts.push(''); | ||||
|       const abs=d.url.startsWith('http'); | ||||
|       const href=`${abs?'':path_to_root}${parts[0]}?${URL_MARK}=${enc}#${parts[1]}`; | ||||
|       const style=d.cloud?" style=\"color:#1e88e5\"":""; | ||||
|       const isCloud=d.cloud?" [Cloud]":" [Book]"; | ||||
|       return `<a href="${href}" aria-details="teaser_${teaserCount}"${style}>`+ | ||||
|              `${d.breadcrumbs}${isCloud}<span class="teaser" id="teaser_${teaserCount}" aria-label="Search Result Teaser">${teaser}</span></a>`; | ||||
|     } | ||||
|    | ||||
|     /* ───────────── UI control ───────────── */ | ||||
|     function showUI(s){wrap.classList.toggle('hidden',!s); icon.setAttribute('aria-expanded',s); if(s){window.scrollTo(0,0); bar.focus(); bar.select();} else {listOut.classList.add('hidden'); [...list.children].forEach(li=>li.classList.remove('focus'));}} | ||||
|     function blur(){const t=document.createElement('input'); t.style.cssText='position:absolute;opacity:0;'; icon.appendChild(t); t.focus(); t.remove();} | ||||
|    | ||||
|     icon.addEventListener('click',()=>showUI(wrap.classList.contains('hidden'))); | ||||
|    | ||||
|     document.addEventListener('keydown',e=>{ | ||||
|       if(e.altKey||e.ctrlKey||e.metaKey||e.shiftKey) return; | ||||
|       const f=/^(?:input|select|textarea)$/i.test(e.target.nodeName); | ||||
|       if(e.keyCode===HOT && !f){e.preventDefault(); showUI(true);} else if(e.keyCode===ESC){e.preventDefault(); showUI(false); blur();} | ||||
|       else if(e.keyCode===DOWN && document.activeElement===bar){e.preventDefault(); const first=list.firstElementChild; if(first){blur(); first.classList.add('focus');}} | ||||
|       else if([DOWN,UP,ENTER].includes(e.keyCode) && document.activeElement!==bar){const cur=list.querySelector('li.focus'); if(!cur) return; e.preventDefault(); if(e.keyCode===DOWN){const nxt=cur.nextElementSibling; if(nxt){cur.classList.remove('focus'); nxt.classList.add('focus');}} else if(e.keyCode===UP){const prv=cur.previousElementSibling; cur.classList.remove('focus'); if(prv){prv.classList.add('focus');} else {bar.focus();}} else {const a=cur.querySelector('a'); if(a) window.location.assign(a.href);}} | ||||
|     }); | ||||
|    | ||||
|     bar.addEventListener('input',e=>{ clearTimeout(debounce); debounce=setTimeout(()=>worker.postMessage({query: e.target.value.trim()}),120); }); | ||||
|    | ||||
|     /* ───────────── worker messages ───────────── */ | ||||
|     worker.onmessage = ({data}) => { | ||||
|       if(data && data.ready!==undefined){ | ||||
|         if(data.ready){  | ||||
|           icon.innerHTML=READY_ICON;  | ||||
|           icon.setAttribute('aria-label','Open search (S)');  | ||||
|           icon.removeAttribute('title'); | ||||
|         } | ||||
|         else {  | ||||
|           icon.textContent='❌';  | ||||
|           icon.setAttribute('aria-label','Search unavailable');  | ||||
|           icon.setAttribute('title','Search is unavailable'); | ||||
|         } | ||||
|         return; | ||||
|       } | ||||
|       const docs=data, q=bar.value.trim(), terms=q.split(/\s+/).filter(Boolean); | ||||
|       header.textContent=metric(docs.length,q); | ||||
|       clear(list); | ||||
|       docs.forEach(d=>{const li=document.createElement('li'); li.innerHTML=format(d,terms); list.appendChild(li);}); | ||||
|       listOut.classList.toggle('hidden',!docs.length); | ||||
|     }; | ||||
|   })(); | ||||
|    | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user