├── .gitignore
├── CONTRIBUTING.markdown
├── LICENSE
├── README.markdown
├── chrome.manifest
├── container
├── chrome
│ ├── background.html
│ ├── config.js
│ ├── container.js
│ ├── host_file_wrapper.js
│ └── timer.js
└── firefox
│ ├── config.js
│ ├── container.js
│ ├── firstrun.js
│ ├── host_file_wrapper.js
│ ├── hostadmin.css
│ ├── hostadmin.xul
│ ├── refresh_dns.js
│ ├── statusbar.js
│ └── timer.js
├── core
├── editor.html
├── editor.js
├── glue.js
├── hostadmin.js
├── init.js
├── lib
│ ├── CodeMirror
│ │ ├── LICENSE
│ │ ├── addon
│ │ │ └── selection
│ │ │ │ └── active-line.js
│ │ ├── lib
│ │ │ ├── codemirror.css
│ │ │ └── codemirror.js
│ │ └── mode
│ │ │ └── hostadmin
│ │ │ └── hostadmin.js
│ ├── bootstrap
│ │ ├── css
│ │ │ └── bootstrap.min.css
│ │ ├── img
│ │ │ ├── glyphicons-halflings-white.png
│ │ │ └── glyphicons-halflings.png
│ │ └── js
│ │ │ └── bootstrap.min.js
│ ├── jquery-1.8.3.min.js
│ └── levenshtein.js
├── popup.html
└── popup.js
├── defaults
└── preferences
│ └── prefs.js
├── dist
├── dist-chrome.sh
├── dist-firefox.sh
├── icons
├── icon128.png
├── icon16.png
├── icon24.png
└── icon32.png
├── install.rdf
├── manifest.json
└── npapi
├── hostadmin.amd64.so
├── hostadmin.dll
├── hostadmin.plugin
└── Contents
│ ├── Info.plist
│ └── MacOS
│ └── hostadmin
├── hostadmin.x86.so
└── src
├── Makefile
├── const.h
├── hostadmin-Info.plist
├── hostadmin.c
├── hostadmin.def
├── hostadmin.h
├── hostadmin.rc
├── hostadmin.sln
├── hostadmin.vcproj
├── hostadmin.xcodeproj
├── project.pbxproj
└── project.xcworkspace
│ └── contents.xcworkspacedata
└── npapi_headers
├── npapi.h
├── npfunctions.h
├── npruntime.h
└── nptypes.h
/.gitignore:
--------------------------------------------------------------------------------
1 | .*
2 |
3 | npapi/src/hostadmin.vcproj.*
4 | npapi/src/hostadmin.ncb
5 | npapi/src/hostadmin.suo
6 | npapi/src/Release/
7 | npapi/src/Debug/
8 |
9 | npapi/src/*.so
10 | npapi/src/*.o
11 |
12 | xcuserdata
13 |
14 | .DS_Store
15 | *.swp
16 | *~.nib
17 |
18 | *.zip
19 | *.crx
20 | *.xpi
21 |
--------------------------------------------------------------------------------
/CONTRIBUTING.markdown:
--------------------------------------------------------------------------------
1 | Contributing to HostAdmin
2 | =========================
3 | Patchs are welcomed. Follow instructions below to make some change to HostAdmin
4 |
5 | Envirment
6 | ---------
7 |
8 | ### Getting sources
9 |
10 |
11 | git clone https://github.com/tg123/chrome-hostadmin.git
12 |
13 |
14 |
15 | ### Firefox
16 |
17 | 1. Create your dev profile. You can get detail from [Setting up an extension development environment](https://developer.mozilla.org/en/docs/Setting_up_extension_development_environment)
18 |
19 | 1. Link HostAdmin to Firefox dev profile (Linux)
20 |
21 |
22 | ln -s /path/to/chrome-hostadmin/ ~/.mozilla/firefox/YOURDEVPROFILENAME/extensions/\{bd54afa8-b14a-4d7a-aecf-37e34e882796\}
23 |
24 |
25 | 1. Start dev firefox with dev profile
26 |
27 |
28 | firefox -P dev
29 |
30 |
31 |
32 | ### Chrome
33 |
34 | 1. Open [chrome://extensions/](chrome://extensions/)
35 | 1. Enable `Developer mode` and use `Load unpacked extension` to load HostAdmin. You can get more help from [Getting Started: Building a Chrome Extension](https://developer.chrome.com/extensions/getstarted.html)
36 |
37 | 1. NPAPI (Optional)
38 |
39 |
40 | You may want edit NPAPI, you can find source at `npapi/src`
41 | * Build on Linux (gcc, Just make to build hostadmin.so)
42 | * Mac (open hostadmin.xcodeproj with XCode, Command + B to build hostadmin.plugin)
43 | * Windows (open hostadmin.sln with Visual Studio Express 2008, build .dll)
44 |
45 |
46 |
47 | Build Distributions
48 | -------------------
49 |
50 | You can build .xpi(Firefox) and .zip(Chrome) using dist script. *Notice:* If you are building on Mac, you need `gnu coreutils` ratcher built-in `BSD coreutils`.
51 |
52 |
53 | Build all
54 |
55 | ./dist
56 |
57 |
58 | Clean up
59 |
60 | ./dist clean
61 |
62 |
63 | Sometimes, you may want .crx version.
64 |
65 | ./dist-chrome.sh crx
66 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Mozilla Public License, version 2.0
2 |
3 | 1. Definitions
4 |
5 | 1.1. "Contributor"
6 |
7 | means each individual or legal entity that creates, contributes to the
8 | creation of, or owns Covered Software.
9 |
10 | 1.2. "Contributor Version"
11 |
12 | means the combination of the Contributions of others (if any) used by a
13 | Contributor and that particular Contributor's Contribution.
14 |
15 | 1.3. "Contribution"
16 |
17 | means Covered Software of a particular Contributor.
18 |
19 | 1.4. "Covered Software"
20 |
21 | means Source Code Form to which the initial Contributor has attached the
22 | notice in Exhibit A, the Executable Form of such Source Code Form, and
23 | Modifications of such Source Code Form, in each case including portions
24 | thereof.
25 |
26 | 1.5. "Incompatible With Secondary Licenses"
27 | means
28 |
29 | a. that the initial Contributor has attached the notice described in
30 | Exhibit B to the Covered Software; or
31 |
32 | b. that the Covered Software was made available under the terms of
33 | version 1.1 or earlier of the License, but not also under the terms of
34 | a Secondary License.
35 |
36 | 1.6. "Executable Form"
37 |
38 | means any form of the work other than Source Code Form.
39 |
40 | 1.7. "Larger Work"
41 |
42 | means a work that combines Covered Software with other material, in a
43 | separate file or files, that is not Covered Software.
44 |
45 | 1.8. "License"
46 |
47 | means this document.
48 |
49 | 1.9. "Licensable"
50 |
51 | means having the right to grant, to the maximum extent possible, whether
52 | at the time of the initial grant or subsequently, any and all of the
53 | rights conveyed by this License.
54 |
55 | 1.10. "Modifications"
56 |
57 | means any of the following:
58 |
59 | a. any file in Source Code Form that results from an addition to,
60 | deletion from, or modification of the contents of Covered Software; or
61 |
62 | b. any new file in Source Code Form that contains any Covered Software.
63 |
64 | 1.11. "Patent Claims" of a Contributor
65 |
66 | means any patent claim(s), including without limitation, method,
67 | process, and apparatus claims, in any patent Licensable by such
68 | Contributor that would be infringed, but for the grant of the License,
69 | by the making, using, selling, offering for sale, having made, import,
70 | or transfer of either its Contributions or its Contributor Version.
71 |
72 | 1.12. "Secondary License"
73 |
74 | means either the GNU General Public License, Version 2.0, the GNU Lesser
75 | General Public License, Version 2.1, the GNU Affero General Public
76 | License, Version 3.0, or any later versions of those licenses.
77 |
78 | 1.13. "Source Code Form"
79 |
80 | means the form of the work preferred for making modifications.
81 |
82 | 1.14. "You" (or "Your")
83 |
84 | means an individual or a legal entity exercising rights under this
85 | License. For legal entities, "You" includes any entity that controls, is
86 | controlled by, or is under common control with You. For purposes of this
87 | definition, "control" means (a) the power, direct or indirect, to cause
88 | the direction or management of such entity, whether by contract or
89 | otherwise, or (b) ownership of more than fifty percent (50%) of the
90 | outstanding shares or beneficial ownership of such entity.
91 |
92 |
93 | 2. License Grants and Conditions
94 |
95 | 2.1. Grants
96 |
97 | Each Contributor hereby grants You a world-wide, royalty-free,
98 | non-exclusive license:
99 |
100 | a. under intellectual property rights (other than patent or trademark)
101 | Licensable by such Contributor to use, reproduce, make available,
102 | modify, display, perform, distribute, and otherwise exploit its
103 | Contributions, either on an unmodified basis, with Modifications, or
104 | as part of a Larger Work; and
105 |
106 | b. under Patent Claims of such Contributor to make, use, sell, offer for
107 | sale, have made, import, and otherwise transfer either its
108 | Contributions or its Contributor Version.
109 |
110 | 2.2. Effective Date
111 |
112 | The licenses granted in Section 2.1 with respect to any Contribution
113 | become effective for each Contribution on the date the Contributor first
114 | distributes such Contribution.
115 |
116 | 2.3. Limitations on Grant Scope
117 |
118 | The licenses granted in this Section 2 are the only rights granted under
119 | this License. No additional rights or licenses will be implied from the
120 | distribution or licensing of Covered Software under this License.
121 | Notwithstanding Section 2.1(b) above, no patent license is granted by a
122 | Contributor:
123 |
124 | a. for any code that a Contributor has removed from Covered Software; or
125 |
126 | b. for infringements caused by: (i) Your and any other third party's
127 | modifications of Covered Software, or (ii) the combination of its
128 | Contributions with other software (except as part of its Contributor
129 | Version); or
130 |
131 | c. under Patent Claims infringed by Covered Software in the absence of
132 | its Contributions.
133 |
134 | This License does not grant any rights in the trademarks, service marks,
135 | or logos of any Contributor (except as may be necessary to comply with
136 | the notice requirements in Section 3.4).
137 |
138 | 2.4. Subsequent Licenses
139 |
140 | No Contributor makes additional grants as a result of Your choice to
141 | distribute the Covered Software under a subsequent version of this
142 | License (see Section 10.2) or under the terms of a Secondary License (if
143 | permitted under the terms of Section 3.3).
144 |
145 | 2.5. Representation
146 |
147 | Each Contributor represents that the Contributor believes its
148 | Contributions are its original creation(s) or it has sufficient rights to
149 | grant the rights to its Contributions conveyed by this License.
150 |
151 | 2.6. Fair Use
152 |
153 | This License is not intended to limit any rights You have under
154 | applicable copyright doctrines of fair use, fair dealing, or other
155 | equivalents.
156 |
157 | 2.7. Conditions
158 |
159 | Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted in
160 | Section 2.1.
161 |
162 |
163 | 3. Responsibilities
164 |
165 | 3.1. Distribution of Source Form
166 |
167 | All distribution of Covered Software in Source Code Form, including any
168 | Modifications that You create or to which You contribute, must be under
169 | the terms of this License. You must inform recipients that the Source
170 | Code Form of the Covered Software is governed by the terms of this
171 | License, and how they can obtain a copy of this License. You may not
172 | attempt to alter or restrict the recipients' rights in the Source Code
173 | Form.
174 |
175 | 3.2. Distribution of Executable Form
176 |
177 | If You distribute Covered Software in Executable Form then:
178 |
179 | a. such Covered Software must also be made available in Source Code Form,
180 | as described in Section 3.1, and You must inform recipients of the
181 | Executable Form how they can obtain a copy of such Source Code Form by
182 | reasonable means in a timely manner, at a charge no more than the cost
183 | of distribution to the recipient; and
184 |
185 | b. You may distribute such Executable Form under the terms of this
186 | License, or sublicense it under different terms, provided that the
187 | license for the Executable Form does not attempt to limit or alter the
188 | recipients' rights in the Source Code Form under this License.
189 |
190 | 3.3. Distribution of a Larger Work
191 |
192 | You may create and distribute a Larger Work under terms of Your choice,
193 | provided that You also comply with the requirements of this License for
194 | the Covered Software. If the Larger Work is a combination of Covered
195 | Software with a work governed by one or more Secondary Licenses, and the
196 | Covered Software is not Incompatible With Secondary Licenses, this
197 | License permits You to additionally distribute such Covered Software
198 | under the terms of such Secondary License(s), so that the recipient of
199 | the Larger Work may, at their option, further distribute the Covered
200 | Software under the terms of either this License or such Secondary
201 | License(s).
202 |
203 | 3.4. Notices
204 |
205 | You may not remove or alter the substance of any license notices
206 | (including copyright notices, patent notices, disclaimers of warranty, or
207 | limitations of liability) contained within the Source Code Form of the
208 | Covered Software, except that You may alter any license notices to the
209 | extent required to remedy known factual inaccuracies.
210 |
211 | 3.5. Application of Additional Terms
212 |
213 | You may choose to offer, and to charge a fee for, warranty, support,
214 | indemnity or liability obligations to one or more recipients of Covered
215 | Software. However, You may do so only on Your own behalf, and not on
216 | behalf of any Contributor. You must make it absolutely clear that any
217 | such warranty, support, indemnity, or liability obligation is offered by
218 | You alone, and You hereby agree to indemnify every Contributor for any
219 | liability incurred by such Contributor as a result of warranty, support,
220 | indemnity or liability terms You offer. You may include additional
221 | disclaimers of warranty and limitations of liability specific to any
222 | jurisdiction.
223 |
224 | 4. Inability to Comply Due to Statute or Regulation
225 |
226 | If it is impossible for You to comply with any of the terms of this License
227 | with respect to some or all of the Covered Software due to statute,
228 | judicial order, or regulation then You must: (a) comply with the terms of
229 | this License to the maximum extent possible; and (b) describe the
230 | limitations and the code they affect. Such description must be placed in a
231 | text file included with all distributions of the Covered Software under
232 | this License. Except to the extent prohibited by statute or regulation,
233 | such description must be sufficiently detailed for a recipient of ordinary
234 | skill to be able to understand it.
235 |
236 | 5. Termination
237 |
238 | 5.1. The rights granted under this License will terminate automatically if You
239 | fail to comply with any of its terms. However, if You become compliant,
240 | then the rights granted under this License from a particular Contributor
241 | are reinstated (a) provisionally, unless and until such Contributor
242 | explicitly and finally terminates Your grants, and (b) on an ongoing
243 | basis, if such Contributor fails to notify You of the non-compliance by
244 | some reasonable means prior to 60 days after You have come back into
245 | compliance. Moreover, Your grants from a particular Contributor are
246 | reinstated on an ongoing basis if such Contributor notifies You of the
247 | non-compliance by some reasonable means, this is the first time You have
248 | received notice of non-compliance with this License from such
249 | Contributor, and You become compliant prior to 30 days after Your receipt
250 | of the notice.
251 |
252 | 5.2. If You initiate litigation against any entity by asserting a patent
253 | infringement claim (excluding declaratory judgment actions,
254 | counter-claims, and cross-claims) alleging that a Contributor Version
255 | directly or indirectly infringes any patent, then the rights granted to
256 | You by any and all Contributors for the Covered Software under Section
257 | 2.1 of this License shall terminate.
258 |
259 | 5.3. In the event of termination under Sections 5.1 or 5.2 above, all end user
260 | license agreements (excluding distributors and resellers) which have been
261 | validly granted by You or Your distributors under this License prior to
262 | termination shall survive termination.
263 |
264 | 6. Disclaimer of Warranty
265 |
266 | Covered Software is provided under this License on an "as is" basis,
267 | without warranty of any kind, either expressed, implied, or statutory,
268 | including, without limitation, warranties that the Covered Software is free
269 | of defects, merchantable, fit for a particular purpose or non-infringing.
270 | The entire risk as to the quality and performance of the Covered Software
271 | is with You. Should any Covered Software prove defective in any respect,
272 | You (not any Contributor) assume the cost of any necessary servicing,
273 | repair, or correction. This disclaimer of warranty constitutes an essential
274 | part of this License. No use of any Covered Software is authorized under
275 | this License except under this disclaimer.
276 |
277 | 7. Limitation of Liability
278 |
279 | Under no circumstances and under no legal theory, whether tort (including
280 | negligence), contract, or otherwise, shall any Contributor, or anyone who
281 | distributes Covered Software as permitted above, be liable to You for any
282 | direct, indirect, special, incidental, or consequential damages of any
283 | character including, without limitation, damages for lost profits, loss of
284 | goodwill, work stoppage, computer failure or malfunction, or any and all
285 | other commercial damages or losses, even if such party shall have been
286 | informed of the possibility of such damages. This limitation of liability
287 | shall not apply to liability for death or personal injury resulting from
288 | such party's negligence to the extent applicable law prohibits such
289 | limitation. Some jurisdictions do not allow the exclusion or limitation of
290 | incidental or consequential damages, so this exclusion and limitation may
291 | not apply to You.
292 |
293 | 8. Litigation
294 |
295 | Any litigation relating to this License may be brought only in the courts
296 | of a jurisdiction where the defendant maintains its principal place of
297 | business and such litigation shall be governed by laws of that
298 | jurisdiction, without reference to its conflict-of-law provisions. Nothing
299 | in this Section shall prevent a party's ability to bring cross-claims or
300 | counter-claims.
301 |
302 | 9. Miscellaneous
303 |
304 | This License represents the complete agreement concerning the subject
305 | matter hereof. If any provision of this License is held to be
306 | unenforceable, such provision shall be reformed only to the extent
307 | necessary to make it enforceable. Any law or regulation which provides that
308 | the language of a contract shall be construed against the drafter shall not
309 | be used to construe this License against a Contributor.
310 |
311 |
312 | 10. Versions of the License
313 |
314 | 10.1. New Versions
315 |
316 | Mozilla Foundation is the license steward. Except as provided in Section
317 | 10.3, no one other than the license steward has the right to modify or
318 | publish new versions of this License. Each version will be given a
319 | distinguishing version number.
320 |
321 | 10.2. Effect of New Versions
322 |
323 | You may distribute the Covered Software under the terms of the version
324 | of the License under which You originally received the Covered Software,
325 | or under the terms of any subsequent version published by the license
326 | steward.
327 |
328 | 10.3. Modified Versions
329 |
330 | If you create software not governed by this License, and you want to
331 | create a new license for such software, you may create and use a
332 | modified version of this License if you rename the license and remove
333 | any references to the name of the license steward (except to note that
334 | such modified license differs from this License).
335 |
336 | 10.4. Distributing Source Code Form that is Incompatible With Secondary
337 | Licenses If You choose to distribute Source Code Form that is
338 | Incompatible With Secondary Licenses under the terms of this version of
339 | the License, the notice described in Exhibit B of this License must be
340 | attached.
341 |
342 | Exhibit A - Source Code Form License Notice
343 |
344 | This Source Code Form is subject to the
345 | terms of the Mozilla Public License, v.
346 | 2.0. If a copy of the MPL was not
347 | distributed with this file, You can
348 | obtain one at
349 | http://mozilla.org/MPL/2.0/.
350 |
351 | If it is not possible or desirable to put the notice in a particular file,
352 | then You may include the notice in a location (such as a LICENSE file in a
353 | relevant directory) where a recipient would be likely to look for such a
354 | notice.
355 |
356 | You may add additional accurate notices of copyright ownership.
357 |
358 | Exhibit B - "Incompatible With Secondary Licenses" Notice
359 |
360 | This Source Code Form is "Incompatible
361 | With Secondary Licenses", as defined by
362 | the Mozilla Public License, v. 2.0.
363 |
--------------------------------------------------------------------------------
/README.markdown:
--------------------------------------------------------------------------------
1 | HostAdmin
2 | =====================
3 | Saving your time when you switch domain-ip mapping between different environment
4 |
5 | Chrome APP Version
6 | ------------------
7 | Google banned NPAPI Please use [Chrome WebStore APP Version](https://chrome.google.com/webstore/detail/hostadmin-app/mfoaclfeiefiehgaojbmncmefhdnikeg) instead.
8 |
9 | It is true that is not easy to use than a menu bar edition. sad..
10 |
11 |
12 |
13 | Installing
14 | -----------------------------
15 | * [Chrome WebStore APP Version](https://chrome.google.com/webstore/detail/hostadmin-app/mfoaclfeiefiehgaojbmncmefhdnikeg)
16 | * [Firefox AddonSite](https://addons.mozilla.org/firefox/addon/hostadmin)
17 | * [Download from Google Code](http://code.google.com/p/fire-hostadmin/downloads/list)
18 |
19 |
20 | How HostAdmin analyze the Hosts file
21 | ------------------------------------
22 | [Syntax detail](http://code.google.com/p/fire-hostadmin/wiki/HOST_SYNTAX)
23 |
24 | * ``Common``
25 |
26 | IP DOMAIN [#COMMENT]
27 |
28 | *Example:*
29 |
30 | 127.0.0.1 localhost #comment here
31 |
32 | NOTE: A line with a comment, 'hide' (case-insensitive), would be hiden from HostAdmin.
33 |
34 | * ``Grouping``
35 |
36 | #==== Groupname
37 |
38 | # some mappings
39 |
40 | #====
41 |
42 | *Example:*
43 |
44 | #==== Project 1
45 | #127.0.0.1 localhost1
46 | 127.0.0.1 localhost2
47 | 127.0.0.1 localhost3
48 | #====
49 |
50 | #==== Project 2
51 | #127.0.0.1 localhost1
52 | #127.0.0.1 localhost2
53 | #127.0.0.1 localhost3
54 | #====
55 |
56 |
57 | * ``Bulk Hide``
58 |
59 |
60 | #hide_all_of_below
61 | ...
62 |
63 | #All text here will be parsed as comment
64 |
65 | ...
66 |
67 |
68 |
69 | WRITE Permission to Hosts File
70 | ------------------------------
71 | *WRITE Permission* to Hosts is needed, thus HostAdmin could modify your Host Files.
72 | XP users need NO additional setting.
73 | Here is a guide for you to gain write privilege for Vista/7/Linux/MacOS users
74 |
75 | http://code.google.com/p/fire-hostadmin/wiki/GAIN_HOSTS_WRITE_PERM
76 |
77 | DNS Auto refreshing
78 | -------------------
79 |
80 | * ``Firefox``
81 |
82 | HostAdmin borrowed code from [DNS flusher](https://addons.mozilla.org/en-US/firefox/addon/dns-flusher/)
83 | to refresh dns when hosts file is modified.
84 |
85 | * ``Chrome``
86 |
87 | Since Chrome 21, Chrome will auto refresh dns by itself.
88 | More info at this [ticket](http://code.google.com/p/chromium/issues/detail?id=125599)
89 |
90 | > _KNOWN ISSUE_
91 | >
92 | > DNS may not refresh as soon as hosts file changes due to a Chrome bug
93 | > reused socket pools by domain even if hosts changes
94 | >
95 | > To avoid this, open chrome://net-internals/#sockets and flush your host
96 | >
97 | > More info at Chrome Bug [152906](https://code.google.com/p/chromium/issues/detail?id=152906) [268059](https://code.google.com/p/chromium/issues/detail?id=268059) [288061](https://code.google.com/p/chromium/issues/detail?id=288061)
98 |
99 |
100 |
101 |
102 |
--------------------------------------------------------------------------------
/chrome.manifest:
--------------------------------------------------------------------------------
1 | content hostadmin-container container/firefox/
2 | content hostadmin core/
3 | content hostadmin-icons icons/
4 |
5 | style chrome://global/content/customizeToolbar.xul chrome://hostadmin-container/content/hostadmin.css
6 | overlay chrome://browser/content/browser.xul chrome://hostadmin-container/content/hostadmin.xul
7 |
--------------------------------------------------------------------------------
/container/chrome/background.html:
--------------------------------------------------------------------------------
1 |
2 |
Grouping "hosts lines" let you enable/disable all records in group just clicking group name into "quick edit tool" in the bottom. These lines will have also a tag that will display the group name of appurtenance.
120 |
121 |
122 |
Bulk Hide
123 |
124 | #hide_all_of_below
125 | ....
126 | #All text here will be parsed as comment
127 | ....
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
Hosts file
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
155 |
156 |
157 |
158 |
Host file has changed outside! Reload ?
159 |
160 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
--------------------------------------------------------------------------------
/core/editor.js:
--------------------------------------------------------------------------------
1 | run_from_glue(function(HostAdmin){
2 | var host_admin = HostAdmin.core;
3 | var event_host = HostAdmin.event_host;
4 |
5 | var container = HostAdmin.container;
6 | var opentab = container.opentab;
7 |
8 | var changed = false;
9 | var codeMirror = CodeMirror.fromTextArea(document.getElementById("code"), {
10 | lineNumbers: true,
11 | styleActiveLine: true
12 | });
13 |
14 | var save = $("#btnSave");
15 |
16 | codeMirror.on("change", function(){
17 | changed = true;
18 | save.attr("disabled", null);
19 | });
20 |
21 | codeMirror.setValue(host_admin.load());
22 |
23 | var move_cursor = function(cursorline){
24 | if(cursorline || cursorline === 0){
25 | codeMirror.setCursor(cursorline);
26 | codeMirror.scrollIntoView({line: cursorline}, 150);
27 | codeMirror.focus();
28 | }
29 | }
30 |
31 | move_cursor(HostAdmin.cursorline);
32 |
33 | var renew = function(){
34 | changed = false;
35 | save.attr("disabled", "disabled");
36 | $(".alert").hide('slow');
37 | };
38 |
39 | var reload = function(){
40 | var pos = codeMirror.getScrollInfo()
41 | codeMirror.setValue(host_admin.load());
42 | renew();
43 | codeMirror.scrollTo(pos.left, pos.top);
44 | };
45 |
46 | $("#mreload").click(function(){
47 | $("#contentchanged").modal('hide');
48 |
49 | reload();
50 | });
51 |
52 | event_host.addEventListener('HostAdminRefresh', function(e) {
53 | if(!changed){
54 | reload();
55 | }else{
56 | $("#contentchanged").modal('show');
57 | }
58 | }, false);
59 |
60 |
61 | event_host.addEventListener('HostAdminReqCursorLine', function(e) {
62 | move_cursor(e.detail.cursorline);
63 | }, false);
64 |
65 | save.click(function(e) {
66 | if(changed){
67 | changed = false;
68 |
69 | var pos = codeMirror.getScrollInfo()
70 |
71 | if(host_admin.save(codeMirror.getValue())){
72 | renew();
73 | codeMirror.scrollTo(pos.left, pos.top);
74 | }else{
75 | $(".alert").show('slow');
76 | }
77 | }
78 | });
79 |
80 | $(document).keydown(function(event){
81 | if (event.which == 83 && (event.ctrlKey||event.metaKey)) {
82 | event.preventDefault();
83 | save.click();
84 | return false;
85 | }
86 | return true;
87 | });
88 |
89 | $(".alert a").click(function(){
90 | opentab('PERMHELP');
91 | });
92 |
93 | renew();
94 |
95 | });
96 |
--------------------------------------------------------------------------------
/core/glue.js:
--------------------------------------------------------------------------------
1 | //
2 | // finding a method to be injected from container ...
3 | //
4 | window.run_from_glue = (function(){
5 |
6 | var HostAdmin = null;
7 |
8 | if(typeof(chrome) == 'object'){
9 | HostAdmin = chrome.extension.getBackgroundPage().HostAdmin;
10 | }else if(typeof(firefox) == 'object'){
11 | HostAdmin = firefox.HostAdmin;
12 | }
13 |
14 | var _inner = function(callback){
15 | callback(HostAdmin);
16 | };
17 |
18 | return function(_callback){
19 | _inner( _callback );
20 | };
21 | })();
22 |
--------------------------------------------------------------------------------
/core/hostadmin.js:
--------------------------------------------------------------------------------
1 | // HostAdmin
2 | // by T.G.(farmer1992@gmail.com)
3 | //
4 | // core module
5 | // implentment of hostadmin syntax
6 | // http://code.google.com/p/fire-hostadmin/wiki/HOST_SYNTAX
7 | //
8 | (function(HostAdmin){
9 |
10 | var host_file_wrapper = HostAdmin.host_file_wrapper;
11 | var event_host = HostAdmin.event_host;
12 |
13 | var host_admin = (function(){
14 | var ip_regx = /^((1?\d?\d|(2([0-4]\d|5[0-5])))\.){3}(1?\d?\d|(2([0-4]\d|5[0-5])))$/;
15 |
16 | // copy from http://forums.intermapper.com/viewtopic.php?t=452
17 | var ip6_regx = /^((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?$/ ;
18 |
19 | var lines = [];
20 | var hosts = {};
21 | var groups = {};
22 | var hostname_withoutcase = {};
23 |
24 | var cur_host_content = "";
25 |
26 | var loadhost = function() {
27 |
28 | lines = [];
29 | hosts = {};
30 | groups = {};
31 | hostname_withoutcase = {};
32 | //read
33 | var host = host_file_wrapper.get();
34 | cur_host_content = host;
35 |
36 | if (host && host.charAt(host.length - 1) != "\n"){ //fix no lf
37 | host += host_file_wrapper.splitchar;
38 | }
39 |
40 | var l_p = 0; //pointer to line
41 | var regx = /(.*?)\r?\n/mg;
42 | var group_id = 0;
43 | var group_c = 0;
44 | var ingroup = false;
45 | var bulk_hide = false;
46 | var group_hided = {};
47 |
48 | while(true){
49 | var l = regx.exec(host);
50 | if(!l){
51 | break;
52 | }
53 |
54 | var i;
55 | l = l[0];
56 |
57 | lines[l_p++] = l;
58 |
59 | l = l.replace(/^(\s*#)+/,"#");
60 | l = l.replace(/#/g," # ");
61 | l = l.replace(/^\s+|\s+$/g,"");
62 | l = l.replace(/\s+/g," ");
63 |
64 | var tks = l.split(" ");
65 |
66 | if (tks[0] == "#" && tks[1] == "===="){
67 | if(group_c === 0){
68 | group_id++;
69 | }
70 |
71 | if(group_c++ % 2 === 0){
72 | tks.splice(0,2);
73 | var group_name = "";
74 | for(i in tks){
75 | group_name += tks[i] + " ";
76 | }
77 |
78 | if( tks[i-1] === "#" && tks[i].toUpperCase() == 'HIDE' ){
79 | group_hided[group_id] = true;
80 | }
81 |
82 | if(group_name === ""){
83 | group_name = "Group " + group_id;
84 | }
85 |
86 | groups[group_id] = group_name;
87 | ingroup = true;
88 | }else{
89 | ingroup = false;
90 | group_id++;
91 | }
92 | continue;
93 |
94 | } else if (tks[0] == "#" && tks[1] && tks[1].toUpperCase() == "HIDE_ALL_OF_BELOW"){
95 | bulk_hide = true;
96 | }
97 |
98 | var using = true;
99 | if (tks[0] == "#"){
100 | using = false;
101 | tks.splice(0,1);
102 | }
103 |
104 | var ip = "";
105 | if (ip_regx.test(tks[0]) || ip6_regx.test(tks[0])){
106 | ip = tks[0];
107 | tks.splice(0,1);
108 | }else{
109 | continue;
110 | }
111 |
112 | var comment = "";
113 |
114 | var names = [];
115 | var findc = false;
116 | var findhide = false;
117 | for (i in tks){
118 | if(tks[i] == "#"){
119 | findc = true;
120 | continue;
121 | }
122 |
123 | findhide = tks[i].toUpperCase() == 'HIDE'
124 |
125 | if(findc){
126 | comment += tks[i] + " ";
127 | }else{
128 | names.push(tks[i]);
129 | }
130 | }
131 |
132 | if(typeof(comment) == "string"){
133 | comment = comment.replace(/^\s+|\s+$/g, '');
134 | }
135 |
136 | ip = {
137 | addr : ip,
138 | using : using ,
139 | line : l_p - 1,
140 | comment : comment,
141 | group : ingroup ? group_id : 0,
142 | hide : bulk_hide || findhide || (ingroup && group_hided[group_id] === true)
143 | };
144 |
145 | for (i in names){
146 | var name = names[i];
147 | if(typeof hosts[name] == "undefined"){
148 | hosts[name] = [];
149 | }
150 |
151 | hosts[name].push(ip);
152 | hostname_withoutcase[name.toUpperCase()] = name;
153 | }
154 | }
155 | };
156 |
157 | var line_enable = function(ip){
158 | if(!ip.using){
159 | lines[ip.line] = lines[ip.line].replace(/^(\s*#)+/,"");
160 | }
161 | ip.using = true;
162 | };
163 |
164 | var line_disable = function(ip){
165 | if(ip.using){
166 | lines[ip.line] = "#" + lines[ip.line];
167 | }
168 | ip.using = false;
169 | };
170 |
171 | var host_toggle = function(host_name, ip_p){
172 | if(hosts[host_name]){
173 | var addr = hosts[host_name][ip_p].addr;
174 | var using = hosts[host_name][ip_p].using;
175 | for (var i in hosts[host_name]){
176 | var ip = hosts[host_name][i];
177 |
178 | if(ip.addr == addr && !using){
179 | line_enable(ip);
180 | }else{
181 | line_disable(ip);
182 | }
183 | }
184 | }
185 | };
186 |
187 | var is_group_all_using = function(host_list, gp_p){
188 | for(var h in host_list){
189 | for (var i in hosts[host_list[h]]){
190 | var ip = hosts[host_list[h]][i];
191 | if(ip.group == gp_p && !ip.using){
192 | return false;
193 | }
194 | }
195 | }
196 | return true;
197 | };
198 |
199 | var group_toggle = function(host_list, gp_p){
200 | var using = is_group_all_using(host_list, gp_p);
201 |
202 | for(var h in host_list){
203 | for (var i in hosts[host_list[h]]){
204 | var ip = hosts[host_list[h]][i];
205 |
206 | if(ip.group == gp_p){
207 | if(using){
208 | line_disable(ip);
209 | }else{
210 | line_enable(ip);
211 | }
212 | }else if(ip.using){
213 | line_disable(ip);
214 | }
215 | }
216 | }
217 | };
218 |
219 | var mk_host = function(){
220 | var str = "";
221 | for (var i in lines){
222 | str += lines[i];
223 | }
224 | return str;
225 | };
226 |
227 | var last_modify = 0;
228 |
229 | // {{{
230 |
231 | var disp_refresh_event = function(){
232 | var e = event_host.createEvent('Events');
233 | e.initEvent('HostAdminRefresh', false, false);
234 | event_host.dispatchEvent(e);
235 | };
236 |
237 | var last_host_content;
238 | var refresh = function(){
239 | var t = host_file_wrapper.time();
240 |
241 | if( t != last_modify){
242 | loadhost();
243 |
244 | if(last_host_content != cur_host_content){
245 | // prevent from saving failed cause editor refresh
246 | last_host_content = cur_host_content;
247 | disp_refresh_event();
248 | }
249 |
250 | last_modify = t;
251 |
252 | return true;
253 | }
254 | return false;
255 | };
256 | // }}}
257 |
258 | return {
259 | get_hosts : function(){
260 | return hosts;
261 | },
262 | get_groups : function(){
263 | return groups;
264 | },
265 | host_toggle : host_toggle,
266 | group_toggle : group_toggle,
267 | group_checked : is_group_all_using,
268 | // mk_host : mk_host,
269 |
270 | host_toggle_and_save : function(host_name, ip_p){
271 | host_toggle(host_name, ip_p);
272 | return this.save();
273 | } ,
274 | group_toggle_and_save : function(host_list, gp_p){
275 | group_toggle(host_list, gp_p);
276 | return this.save();
277 | },
278 | save : function(hoststr){
279 | if(!hoststr){ hoststr = mk_host();}
280 |
281 | var succ = host_file_wrapper.set(hoststr);
282 |
283 | last_modify = 0;
284 | this.refresh();
285 | return succ;
286 | },
287 |
288 | load : function(){
289 | return cur_host_content;
290 | },
291 |
292 | refresh : refresh,
293 |
294 | real_hostname: function(hostname){
295 | if(hostname) return hostname_withoutcase[hostname.toUpperCase()];
296 | }
297 |
298 | };
299 |
300 | })();
301 |
302 | HostAdmin.core = host_admin;
303 | HostAdmin.PERM_HELP_URL = 'http://code.google.com/p/fire-hostadmin/wiki/GAIN_HOSTS_WRITE_PERM';
304 | })(window.HostAdmin);
305 |
306 |
--------------------------------------------------------------------------------
/core/init.js:
--------------------------------------------------------------------------------
1 | // HostAdmin
2 | // by T.G.(farmer1992@gmail.com)
3 | //
4 | // MPL v2
5 | // http://code.google.com/p/fire-hostadmin/
6 | window.HostAdmin = {};
7 |
8 | // event and cursor
9 | (function(HostAdmin){
10 | HostAdmin.event_host = document;
11 |
12 | HostAdmin.requestCursorLine = function(line){
13 | if(line || line === 0){
14 | var e = HostAdmin.event_host.createEvent('CustomEvent');
15 | e.initCustomEvent('HostAdminReqCursorLine', false, false, { cursorline : line });
16 | HostAdmin.event_host.dispatchEvent(e);
17 | }
18 | }
19 | })(window.HostAdmin);
20 |
21 |
--------------------------------------------------------------------------------
/core/lib/CodeMirror/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (C) 2012 by Marijn Haverbeke
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy
4 | of this software and associated documentation files (the "Software"), to deal
5 | in the Software without restriction, including without limitation the rights
6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 | copies of the Software, and to permit persons to whom the Software is
8 | furnished to do so, subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in
11 | all copies or substantial portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 | THE SOFTWARE.
20 |
21 | Please note that some subdirectories of the CodeMirror distribution
22 | include their own LICENSE files, and are released under different
23 | licences.
24 |
--------------------------------------------------------------------------------
/core/lib/CodeMirror/addon/selection/active-line.js:
--------------------------------------------------------------------------------
1 | // Because sometimes you need to style the cursor's line.
2 | //
3 | // Adds an option 'styleActiveLine' which, when enabled, gives the
4 | // active line's wrapping
the CSS class "CodeMirror-activeline",
5 | // and gives its background