├── .gitignore ├── circle.yml ├── lib ├── exec.js ├── is-on.js └── manage.js ├── .editorconfig ├── .gitattributes ├── test.js ├── package.json ├── CONTRIBUTING.md ├── README.md ├── index.js └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | # Dependencies are installed manually or using a build process, so they 2 | # can benefit from machine-specific compiling, etc. 3 | node_modules 4 | -------------------------------------------------------------------------------- /circle.yml: -------------------------------------------------------------------------------- 1 | machine: 2 | # Circle does not support setting Node version on macOS for some reason 3 | # node: 4 | # version: 8 5 | xcode: 6 | version: 9.0 7 | -------------------------------------------------------------------------------- /lib/exec.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const util = require('util'); 4 | const childProcess = require('child_process'); 5 | 6 | const execFile = util.promisify(childProcess.execFile); 7 | 8 | const exec = async (...args) => { 9 | const { stdout } = await execFile(...args); 10 | return stdout; 11 | }; 12 | 13 | module.exports = exec; 14 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # Standardized configuration for your text editor. 2 | # See: http://EditorConfig.org 3 | 4 | # This is the default for the whole project. 5 | root = true 6 | 7 | # Unix-style newlines with a newline ending every file. 8 | [*] 9 | charset = utf-8 10 | indent_style = space 11 | indent_size = 4 12 | end_of_line = lf 13 | trim_trailing_whitespace = true 14 | insert_final_newline = true 15 | 16 | [*.yml] 17 | indent_size = 2 18 | -------------------------------------------------------------------------------- /lib/is-on.js: -------------------------------------------------------------------------------- 1 | // This module exists to help determine the status of a 2 | // network device / service. 3 | 4 | 'use strict'; 5 | 6 | const isOn = (input) => { 7 | const onValues = [ 8 | true, 9 | 'true', 10 | 'yes', 11 | 'on', 12 | 'enabled' 13 | ]; 14 | 15 | return onValues.includes((input && typeof input === 'string') ? input.toLowerCase() : input); 16 | }; 17 | 18 | module.exports = isOn; 19 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Configuration for moving files between your working directory and the git database. 2 | 3 | * text=auto 4 | 5 | # Commit these with Unix line endings... 6 | 7 | # Source code. 8 | *.svg text 9 | *.json text 10 | *.js text eol=lf 11 | *.css text eol=lf diff=css 12 | *.html text eol=lf diff=html 13 | *.xml text diff=html 14 | *.sh text eol=lf 15 | *.bat text 16 | 17 | # Templates and lists. 18 | *.csv text 19 | 20 | # Documentation. 21 | *.md text 22 | *.txt text 23 | *.doc diff 24 | *.docx diff 25 | *.rtf diff 26 | *.pdf diff 27 | LICENSE text 28 | LICENSES text 29 | AUTHORS text 30 | CONTRIBUTORS text 31 | 32 | # Configuration files. 33 | .gitignore text 34 | .gitattributes text 35 | .editorconfig text 36 | 37 | # Leave line endings alone for these... 38 | 39 | # Multimedia and compressed storage. 40 | *.png binary 41 | *.jpg binary 42 | *.jpeg binary 43 | *.gif binary 44 | *.ico binary 45 | *.mov binary 46 | *.mp4 binary 47 | *.mp3 binary 48 | *.gz binary 49 | *.zip binary 50 | *.woff2 binary 51 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | import test from 'ava'; 2 | import osProxy from '.'; 3 | 4 | test('get()', async (t) => { 5 | const proxy = await osProxy.get(); 6 | t.is(typeof proxy, 'object'); 7 | t.is(typeof proxy.hostname, 'string'); 8 | t.is(typeof proxy.port, 'number'); 9 | t.is(typeof proxy.enabled, 'boolean'); 10 | t.deepEqual(Object.keys(proxy), ['hostname', 'port', 'enabled']); 11 | }); 12 | 13 | // Setting requires a password, which makes the tests fail in CI. 14 | 15 | // test('set()', async (t) => { 16 | // const previous = await osProxy.get(); 17 | 18 | // await osProxy.set({ 19 | // hostname : 'example.com', 20 | // port : 1234 21 | // }); 22 | 23 | // t.deepEqual(await osProxy.get(), { 24 | // hostname : 'example.com', 25 | // port : 1234, 26 | // enabled : true 27 | // }); 28 | 29 | // await osProxy.set(previous); 30 | // }); 31 | 32 | // test('enable()', async (t) => { 33 | 34 | // }); 35 | 36 | // test('disable()', async (t) => { 37 | 38 | // }); 39 | 40 | // test('toggle()', async (t) => { 41 | 42 | // }); 43 | 44 | // test('clear()', async (t) => { 45 | 46 | // }); 47 | 48 | // test('changed', async (t) => { 49 | 50 | // }); 51 | 52 | // test('watch()', async (t) => { 53 | 54 | // }); 55 | 56 | // test('unwatch()', async (t) => { 57 | 58 | // }); 59 | -------------------------------------------------------------------------------- /lib/manage.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const exec = require('./exec'); 4 | 5 | // CLI that manages network devices / services. 6 | const cli = { 7 | // OS X. 8 | darwin : 'networksetup', 9 | // Windows (32-bit or 64-bit) 10 | win32 : 'reg' 11 | // NOTE: We could also detect: freebsd, linux, sunos 12 | }[process.platform]; 13 | 14 | const cliArg = { 15 | darwin : { 16 | get : '-getwebproxy', 17 | set : '-setwebproxy', 18 | enable : '-setwebproxystate', 19 | disable : '-setwebproxystate', 20 | device : '-listallhardwareports' 21 | }, 22 | win32 : { 23 | get : '', 24 | set : '', 25 | enable : '', 26 | disable : [ 27 | 'add', 28 | '"HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"', 29 | '/v ProxyEnable', 30 | '/t REG_DWORD', 31 | '/d 0', 32 | '/f' 33 | ].join(' ') 34 | } 35 | }[process.platform]; 36 | 37 | const manage = (...args) => { 38 | return exec(cli, args); 39 | }; 40 | 41 | manage.get = manage.bind(null, cliArg.get); 42 | manage.set = manage.bind(null, cliArg.set); 43 | manage.enable = manage.bind(null, cliArg.enable); 44 | manage.disable = manage.bind(null, cliArg.disable); 45 | manage.device = manage.bind(null, cliArg.device); 46 | 47 | module.exports = manage; 48 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "os-proxy", 3 | "version": "0.7.0", 4 | "description": "Manage system-wide proxy settings", 5 | "homepage": "https://github.com/sholladay/os-proxy", 6 | "main": "index.js", 7 | "author": { 8 | "name": "Seth Holladay", 9 | "url": "https://seth-holladay.com", 10 | "email": "me@seth-holladay.com" 11 | }, 12 | "scripts": { 13 | "test": "xo && ava" 14 | }, 15 | "repository": { 16 | "type": "git", 17 | "url": "git@github.com:sholladay/os-proxy.git" 18 | }, 19 | "bugs": { 20 | "url": "https://github.com/sholladay/os-proxy/issues", 21 | "email": "me@seth-holladay.com" 22 | }, 23 | "engines": { 24 | "node": ">=7.6" 25 | }, 26 | "license": "MPL-2.0", 27 | "files": [ 28 | "lib", 29 | "index.js" 30 | ], 31 | "dependencies": { 32 | "adverb-signals": "^1.0.0", 33 | "chokidar": "^2.0.2", 34 | "joi": "^13.0.1", 35 | "yamljs": "^0.3.0" 36 | }, 37 | "devDependencies": { 38 | "ava": "^1.0.0-beta.3", 39 | "eslint-config-tidy": "^0.6.2", 40 | "xo": "^0.20.3" 41 | }, 42 | "keywords": [ 43 | "OS", 44 | "system", 45 | "network", 46 | "networking", 47 | "http", 48 | "https", 49 | "proxy", 50 | "tunnel", 51 | "state", 52 | "setting", 53 | "settings", 54 | "config", 55 | "configuration" 56 | ], 57 | "xo": { 58 | "extend": "tidy" 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | ## Issues 4 | 5 | **Ask questions** on [Stack Overflow](https://stackoverflow.com/ "Question and answer forum"). They will get more visibility and we can all enjoy an optimized Q&A experience. In the event that you don't get a satisfactory answer, it is okay to file an issue. Please post a link to your Stack Overflow question. 6 | 7 | **Bug reports** must include reproducible steps and supporting details, such as screenshots. We will be able to fix the problem faster if you supply a failing test case in a pull request. 8 | 9 | **Feature requests** must include use cases and details of the projects that would like to use them. Please keep these focussed on the user rather than the implementation. A pull request that proves the concept will be more effective if there are technical concerns. 10 | 11 | ## Pull Requests 12 | 13 | We love [PRs](https://help.github.com/articles/using-pull-requests/ "How to use pull requests on GitHub")! ❤️ The more the merrier, even for simple typos. 14 | 15 | Any non-trivial pull request may earn you commit privileges. 16 | 17 | An ideal patch brings reliability improvements, new tests, and improved code coverage. In general, these things are much more valuable than features. It takes a healthy system to make the user happy. 18 | 19 | ## Help 20 | 21 | **Still learning?** Check out how to [contribute to Open Source](https://egghead.io/series/how-to-contribute-to-an-open-source-project-on-github) projects. 22 | 23 | **Important work** comes in many forms. There are labels for [bugs](https://github.com/sholladay/os-proxy/labels/bug) and [easy](https://github.com/sholladay/os-proxy/labels/easy) vs [hard](https://github.com/sholladay/os-proxy/labels/hard) tasks. We also appreciate documentation, examples, tutorials, blogs, videos, books, and other supporting content. 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # os-proxy [![Build status for os-proxy](https://img.shields.io/circleci/project/sholladay/os-proxy/master.svg "Build Status")](https://circleci.com/gh/sholladay/os-proxy "Builds") 2 | 3 | > Manage system-wide proxy settings 4 | 5 | ## Why? 6 | 7 | - Cross-platform behavior. 8 | - Uses native APIs for managing config. 9 | - Can monitor external changes via events. 10 | 11 | ## Install 12 | 13 | ```sh 14 | npm install os-proxy --save 15 | ``` 16 | 17 | ## Usage 18 | 19 | Get it into your program. 20 | 21 | ```js 22 | const osProxy = require('os-proxy'); 23 | ``` 24 | 25 | Set the system proxy. 26 | 27 | **Tip**: This is a [`url.format()`](https://nodejs.org/api/url.html#url_url_format_urlobj "API documentation for the url.format method.") compatible object. 28 | 29 | ```js 30 | osProxy.set({ 31 | // Proxy configuration. 32 | hostname : 'example.com'. 33 | port : 1234 34 | }) 35 | .then(() => { 36 | console.log('Proxy onfiguration has finished saving.'); 37 | }); 38 | ``` 39 | 40 | At any time, you may retrieve the current proxy configuration. 41 | 42 | ```js 43 | osProxy.get({ 44 | device : 'Wi-Fi' 45 | }) 46 | .then((config) => { 47 | console.log('Proxy config:', config); 48 | }) 49 | ``` 50 | 51 | Because proxies can also be set through system menus, `osProxy` has been made aware of the platform-specific configuration store and knows how to monitor its changes at the file system level. All of that is abstracted away into opt-in [signals](https://github.com/millermedeiros/js-signals/wiki/Comparison-between-different-Observer-Pattern-implementations "Documentation for signals."). 52 | 53 | ```js 54 | // Register a listener for config store changes. 55 | osProxy.changed.always((event) => { 56 | console.log( 57 | 'Someone changed the proxy settings at:', event.path, 58 | 'That is where', process.platform, 'keeps them.' 59 | ); 60 | }); 61 | // Begin monitoring the config store. 62 | osProxy.watch(); 63 | ``` 64 | 65 | It is just as easy to stop monitoring the config store. 66 | 67 | ```js 68 | osProxy.unwatch(); 69 | ``` 70 | 71 | ## API 72 | 73 | ### get(option) 74 | 75 | Returns a promise for the current system configuration. 76 | 77 | #### option 78 | 79 | Type: `object` 80 | 81 | ##### device 82 | 83 | Type: `string`
84 | Default: `Wi-Fi` 85 | 86 | The device whose proxy configuration should be returned. 87 | 88 | ### set(option) 89 | 90 | Returns a promise for modifying the system configuration. 91 | 92 | #### option 93 | 94 | Type: `object` 95 | 96 | ##### hostname 97 | 98 | Type: `string` 99 | 100 | The hostname of the proxy to use. 101 | 102 | ##### port 103 | 104 | Type: `number` 105 | 106 | The port number of the proxy to use. 107 | 108 | ##### device 109 | 110 | Type: `string`
111 | Default: `Wi-Fi` 112 | 113 | The device that should use the proxy. 114 | 115 | ##### enabled 116 | 117 | Type: `boolean`
118 | Default: `true` 119 | 120 | Whether the proxy should be enabled or disabled after the configuration is saved. 121 | 122 | ### enable() 123 | 124 | Returns a promise for turning on proxy mode. 125 | 126 | ### disable() 127 | 128 | Returns a promise for turning off proxy mode. 129 | 130 | ### toggle() 131 | 132 | Returns a promise for reversing the on/off state of proxy mode. 133 | 134 | ### clear() 135 | 136 | Returns a promise for erasing the configuration data and disabling proxy mode. 137 | 138 | ### changed 139 | 140 | Type: [`Signal`](https://github.com/sholladay/adverb-signals) 141 | 142 | An event emitter with methods like `.always()` and `.never()` for adding and removing listeners that are called when changes to the system configuration are detected, either via this library or by other means. You must call `watch()` in order to begin receiving events. 143 | 144 | ### watch(path, option) 145 | 146 | Start monitoring for changes to the system configuration. Events will be emitted as a `changed` signal. 147 | 148 | Similar to [`chokidar.watch()`](https://github.com/paulmillr/chokidar#api), except `path` defaults to the operating system's proxy configuration file. 149 | 150 | ### unwatch(path) 151 | 152 | Stop monitoring for changes to the system configuration. Events will no longer be emitted. 153 | 154 | Similar to [`chokidar.unwatch()`](https://github.com/paulmillr/chokidar#api), except `path` defaults to the operating system's proxy configuration file. 155 | 156 | ## CLI 157 | 158 | See [os-proxy-cli](https://github.com/sholladay/os-proxy-cli) to use this on the command line. 159 | 160 | ## Contributing 161 | 162 | See our [contributing guidelines](https://github.com/sholladay/os-proxy/blob/master/CONTRIBUTING.md "Guidelines for participating in this project") for more details. 163 | 164 | 1. [Fork it](https://github.com/sholladay/os-proxy/fork). 165 | 2. Make a feature branch: `git checkout -b my-new-feature` 166 | 3. Commit your changes: `git commit -am 'Add some feature'` 167 | 4. Push to the branch: `git push origin my-new-feature` 168 | 5. [Submit a pull request](https://github.com/sholladay/os-proxy/compare "Submit code to this project for review"). 169 | 170 | ## License 171 | 172 | [MPL-2.0](https://github.com/sholladay/os-proxy/blob/master/LICENSE "License for os-proxy") © [Seth Holladay](https://seth-holladay.com "Author of os-proxy") 173 | 174 | Go make something, dang it. 175 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | // Modify your operating system's proxy settings. 2 | 3 | 'use strict'; 4 | 5 | const Signal = require('adverb-signals'); 6 | const yaml = require('yamljs'); 7 | const chokidar = require('chokidar'); 8 | const joi = require('joi'); 9 | const isOn = require('./lib/is-on'); 10 | const manage = require('./lib/manage'); 11 | 12 | const { platform } = process; 13 | 14 | // Inspiration for Windows support: 15 | // http://www.ehow.com/how_6887864_do-proxy-settings-command-prompt_.html 16 | // https://github.com/helloyou2012/system-proxy 17 | if (platform !== 'darwin') { 18 | throw new Error(`Support for ${platform} is not ready yet. Pull requests welcome!`); 19 | } 20 | 21 | // In these examples, "Wi-Fi" could be other devices like "Built-In Ethernet". 22 | 23 | // Determine whether a device is on. 24 | // networksetup -getnetworkserviceenabled Wi-Fi 25 | 26 | // Get a newline seperated list of devices. 27 | // networksetup -listallnetworkservices 28 | 29 | // Get the user's preferred network device 30 | const getDevice = async () => { 31 | const output = await manage.device(); 32 | return output.match(/: .+/)[0].substring(': '.length); 33 | }; 34 | 35 | // Turn on the currently configured proxy. 36 | const enable = async () => { 37 | return manage.enable(await getDevice(), 'on'); 38 | }; 39 | 40 | // Turn off the currently configured proxy, but keep it in the 41 | // operating system's database. 42 | const disable = async () => { 43 | return manage.disable(await getDevice(), 'off'); 44 | }; 45 | 46 | // Retrieve the currently configured proxy. 47 | const get = async (input) => { 48 | const option = Object.assign({}, input); 49 | option.device = option.device || await getDevice(); 50 | const config = joi.attempt(option, joi.object({ 51 | device : joi.string().required() 52 | }).required()); 53 | 54 | const output = await manage.get(config.device); 55 | 56 | if (!output) { 57 | throw new TypeError(`Unable to get proxy configuration. No output to parse.`); 58 | } 59 | 60 | const parsed = yaml.parse(output); 61 | 62 | // OS X answers with less than ideal property names. 63 | // We normalize them here before anyone sees it. 64 | return { 65 | hostname : parsed.Server, 66 | port : parsed.Port, 67 | enabled : isOn(parsed.Enabled) 68 | }; 69 | }; 70 | 71 | // Set and optionally turn on a new proxy configuration. 72 | const set = async (input) => { 73 | const option = Object.assign({}, input); 74 | option.device = option.device || await getDevice(); 75 | const config = joi.attempt(option, joi.object({ 76 | device : joi.string().required(), 77 | hostname : joi.string().required().hostname(), 78 | port : joi.number().required().positive().integer().min(0).max(65535), 79 | enabled : joi.boolean().optional().default(true) 80 | }).required()); 81 | 82 | await manage.set(config.device, config.hostname, config.port); 83 | 84 | // OS X turns on the proxy by default. But users may want to 85 | // do this at a later time or not at all. 86 | if (!config.enabled && typeof config.enabled !== 'undefined') { 87 | return disable(); 88 | } 89 | }; 90 | 91 | // Toggle the currently configured proxy between on and off. 92 | const toggle = async () => { 93 | const proxy = await get(); 94 | return proxy.enabled ? disable() : enable(); 95 | }; 96 | 97 | // Turn off and wipeout the currently configured proxy 98 | // from the operating system's database. 99 | const clear = () => { 100 | return set({ 101 | hostname : '', 102 | port : '', 103 | enabled : false 104 | }); 105 | }; 106 | 107 | // File system watching helpers. 108 | 109 | // Database for proxy configuration. These may get modified by any program at any time, 110 | // and so need to be watched to stay fully up to date. 111 | const configPath = { 112 | darwin : '/Library/Preferences/SystemConfiguration/preferences.plist', 113 | win32 : '' 114 | }[platform]; 115 | 116 | const changed = new Signal(); 117 | 118 | // File system watcher that is aware of changes to the system proxy settings 119 | // caused by any application. 120 | let watcher; 121 | 122 | // Activate a file system watcher, which will be notified about changes to the 123 | // OS preferences, regardless of who makes the change. 124 | const watch = (fp, ...rest) => { 125 | const filePath = typeof fp === 'undefined' ? configPath : fp; 126 | 127 | // If we are already watching, just add to the current set. 128 | if (watcher) { 129 | watcher.add(filePath, ...rest); 130 | } 131 | else { 132 | watcher = chokidar 133 | .watch(filePath, ...rest) 134 | .on('change', (pathStr) => { 135 | changed.emit({ path : pathStr }); 136 | }); 137 | } 138 | 139 | return watcher; 140 | }; 141 | 142 | // Deactivate an existing file system watcher. 143 | const unwatch = (fp, ...rest) => { 144 | if (watcher) { 145 | const filePath = typeof fp === 'undefined' ? configPath : fp; 146 | return watcher.unwatch(filePath, ...rest); 147 | } 148 | }; 149 | 150 | module.exports = { 151 | get, 152 | set, 153 | enable, 154 | disable, 155 | toggle, 156 | clear, 157 | changed, 158 | watch, 159 | unwatch 160 | }; 161 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright © 2016 Seth Holladay (https://seth-holladay.com) 2 | 3 | Mozilla Public License, version 2.0 4 | 5 | 1. Definitions 6 | 7 | 1.1. "Contributor" 8 | 9 | means each individual or legal entity that creates, contributes to the 10 | creation of, or owns Covered Software. 11 | 12 | 1.2. "Contributor Version" 13 | 14 | means the combination of the Contributions of others (if any) used by a 15 | Contributor and that particular Contributor's Contribution. 16 | 17 | 1.3. "Contribution" 18 | 19 | means Covered Software of a particular Contributor. 20 | 21 | 1.4. "Covered Software" 22 | 23 | means Source Code Form to which the initial Contributor has attached the 24 | notice in Exhibit A, the Executable Form of such Source Code Form, and 25 | Modifications of such Source Code Form, in each case including portions 26 | thereof. 27 | 28 | 1.5. "Incompatible With Secondary Licenses" 29 | means 30 | 31 | a. that the initial Contributor has attached the notice described in 32 | Exhibit B to the Covered Software; or 33 | 34 | b. that the Covered Software was made available under the terms of 35 | version 1.1 or earlier of the License, but not also under the terms of 36 | a Secondary License. 37 | 38 | 1.6. "Executable Form" 39 | 40 | means any form of the work other than Source Code Form. 41 | 42 | 1.7. "Larger Work" 43 | 44 | means a work that combines Covered Software with other material, in a 45 | separate file or files, that is not Covered Software. 46 | 47 | 1.8. "License" 48 | 49 | means this document. 50 | 51 | 1.9. "Licensable" 52 | 53 | means having the right to grant, to the maximum extent possible, whether 54 | at the time of the initial grant or subsequently, any and all of the 55 | rights conveyed by this License. 56 | 57 | 1.10. "Modifications" 58 | 59 | means any of the following: 60 | 61 | a. any file in Source Code Form that results from an addition to, 62 | deletion from, or modification of the contents of Covered Software; or 63 | 64 | b. any new file in Source Code Form that contains any Covered Software. 65 | 66 | 1.11. "Patent Claims" of a Contributor 67 | 68 | means any patent claim(s), including without limitation, method, 69 | process, and apparatus claims, in any patent Licensable by such 70 | Contributor that would be infringed, but for the grant of the License, 71 | by the making, using, selling, offering for sale, having made, import, 72 | or transfer of either its Contributions or its Contributor Version. 73 | 74 | 1.12. "Secondary License" 75 | 76 | means either the GNU General Public License, Version 2.0, the GNU Lesser 77 | General Public License, Version 2.1, the GNU Affero General Public 78 | License, Version 3.0, or any later versions of those licenses. 79 | 80 | 1.13. "Source Code Form" 81 | 82 | means the form of the work preferred for making modifications. 83 | 84 | 1.14. "You" (or "Your") 85 | 86 | means an individual or a legal entity exercising rights under this 87 | License. For legal entities, "You" includes any entity that controls, is 88 | controlled by, or is under common control with You. For purposes of this 89 | definition, "control" means (a) the power, direct or indirect, to cause 90 | the direction or management of such entity, whether by contract or 91 | otherwise, or (b) ownership of more than fifty percent (50%) of the 92 | outstanding shares or beneficial ownership of such entity. 93 | 94 | 95 | 2. License Grants and Conditions 96 | 97 | 2.1. Grants 98 | 99 | Each Contributor hereby grants You a world-wide, royalty-free, 100 | non-exclusive license: 101 | 102 | a. under intellectual property rights (other than patent or trademark) 103 | Licensable by such Contributor to use, reproduce, make available, 104 | modify, display, perform, distribute, and otherwise exploit its 105 | Contributions, either on an unmodified basis, with Modifications, or 106 | as part of a Larger Work; and 107 | 108 | b. under Patent Claims of such Contributor to make, use, sell, offer for 109 | sale, have made, import, and otherwise transfer either its 110 | Contributions or its Contributor Version. 111 | 112 | 2.2. Effective Date 113 | 114 | The licenses granted in Section 2.1 with respect to any Contribution 115 | become effective for each Contribution on the date the Contributor first 116 | distributes such Contribution. 117 | 118 | 2.3. Limitations on Grant Scope 119 | 120 | The licenses granted in this Section 2 are the only rights granted under 121 | this License. No additional rights or licenses will be implied from the 122 | distribution or licensing of Covered Software under this License. 123 | Notwithstanding Section 2.1(b) above, no patent license is granted by a 124 | Contributor: 125 | 126 | a. for any code that a Contributor has removed from Covered Software; or 127 | 128 | b. for infringements caused by: (i) Your and any other third party's 129 | modifications of Covered Software, or (ii) the combination of its 130 | Contributions with other software (except as part of its Contributor 131 | Version); or 132 | 133 | c. under Patent Claims infringed by Covered Software in the absence of 134 | its Contributions. 135 | 136 | This License does not grant any rights in the trademarks, service marks, 137 | or logos of any Contributor (except as may be necessary to comply with 138 | the notice requirements in Section 3.4). 139 | 140 | 2.4. Subsequent Licenses 141 | 142 | No Contributor makes additional grants as a result of Your choice to 143 | distribute the Covered Software under a subsequent version of this 144 | License (see Section 10.2) or under the terms of a Secondary License (if 145 | permitted under the terms of Section 3.3). 146 | 147 | 2.5. Representation 148 | 149 | Each Contributor represents that the Contributor believes its 150 | Contributions are its original creation(s) or it has sufficient rights to 151 | grant the rights to its Contributions conveyed by this License. 152 | 153 | 2.6. Fair Use 154 | 155 | This License is not intended to limit any rights You have under 156 | applicable copyright doctrines of fair use, fair dealing, or other 157 | equivalents. 158 | 159 | 2.7. Conditions 160 | 161 | Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted in 162 | Section 2.1. 163 | 164 | 165 | 3. Responsibilities 166 | 167 | 3.1. Distribution of Source Form 168 | 169 | All distribution of Covered Software in Source Code Form, including any 170 | Modifications that You create or to which You contribute, must be under 171 | the terms of this License. You must inform recipients that the Source 172 | Code Form of the Covered Software is governed by the terms of this 173 | License, and how they can obtain a copy of this License. You may not 174 | attempt to alter or restrict the recipients' rights in the Source Code 175 | Form. 176 | 177 | 3.2. Distribution of Executable Form 178 | 179 | If You distribute Covered Software in Executable Form then: 180 | 181 | a. such Covered Software must also be made available in Source Code Form, 182 | as described in Section 3.1, and You must inform recipients of the 183 | Executable Form how they can obtain a copy of such Source Code Form by 184 | reasonable means in a timely manner, at a charge no more than the cost 185 | of distribution to the recipient; and 186 | 187 | b. You may distribute such Executable Form under the terms of this 188 | License, or sublicense it under different terms, provided that the 189 | license for the Executable Form does not attempt to limit or alter the 190 | recipients' rights in the Source Code Form under this License. 191 | 192 | 3.3. Distribution of a Larger Work 193 | 194 | You may create and distribute a Larger Work under terms of Your choice, 195 | provided that You also comply with the requirements of this License for 196 | the Covered Software. If the Larger Work is a combination of Covered 197 | Software with a work governed by one or more Secondary Licenses, and the 198 | Covered Software is not Incompatible With Secondary Licenses, this 199 | License permits You to additionally distribute such Covered Software 200 | under the terms of such Secondary License(s), so that the recipient of 201 | the Larger Work may, at their option, further distribute the Covered 202 | Software under the terms of either this License or such Secondary 203 | License(s). 204 | 205 | 3.4. Notices 206 | 207 | You may not remove or alter the substance of any license notices 208 | (including copyright notices, patent notices, disclaimers of warranty, or 209 | limitations of liability) contained within the Source Code Form of the 210 | Covered Software, except that You may alter any license notices to the 211 | extent required to remedy known factual inaccuracies. 212 | 213 | 3.5. Application of Additional Terms 214 | 215 | You may choose to offer, and to charge a fee for, warranty, support, 216 | indemnity or liability obligations to one or more recipients of Covered 217 | Software. However, You may do so only on Your own behalf, and not on 218 | behalf of any Contributor. You must make it absolutely clear that any 219 | such warranty, support, indemnity, or liability obligation is offered by 220 | You alone, and You hereby agree to indemnify every Contributor for any 221 | liability incurred by such Contributor as a result of warranty, support, 222 | indemnity or liability terms You offer. You may include additional 223 | disclaimers of warranty and limitations of liability specific to any 224 | jurisdiction. 225 | 226 | 4. Inability to Comply Due to Statute or Regulation 227 | 228 | If it is impossible for You to comply with any of the terms of this License 229 | with respect to some or all of the Covered Software due to statute, 230 | judicial order, or regulation then You must: (a) comply with the terms of 231 | this License to the maximum extent possible; and (b) describe the 232 | limitations and the code they affect. Such description must be placed in a 233 | text file included with all distributions of the Covered Software under 234 | this License. Except to the extent prohibited by statute or regulation, 235 | such description must be sufficiently detailed for a recipient of ordinary 236 | skill to be able to understand it. 237 | 238 | 5. Termination 239 | 240 | 5.1. The rights granted under this License will terminate automatically if You 241 | fail to comply with any of its terms. However, if You become compliant, 242 | then the rights granted under this License from a particular Contributor 243 | are reinstated (a) provisionally, unless and until such Contributor 244 | explicitly and finally terminates Your grants, and (b) on an ongoing 245 | basis, if such Contributor fails to notify You of the non-compliance by 246 | some reasonable means prior to 60 days after You have come back into 247 | compliance. Moreover, Your grants from a particular Contributor are 248 | reinstated on an ongoing basis if such Contributor notifies You of the 249 | non-compliance by some reasonable means, this is the first time You have 250 | received notice of non-compliance with this License from such 251 | Contributor, and You become compliant prior to 30 days after Your receipt 252 | of the notice. 253 | 254 | 5.2. If You initiate litigation against any entity by asserting a patent 255 | infringement claim (excluding declaratory judgment actions, 256 | counter-claims, and cross-claims) alleging that a Contributor Version 257 | directly or indirectly infringes any patent, then the rights granted to 258 | You by any and all Contributors for the Covered Software under Section 259 | 2.1 of this License shall terminate. 260 | 261 | 5.3. In the event of termination under Sections 5.1 or 5.2 above, all end user 262 | license agreements (excluding distributors and resellers) which have been 263 | validly granted by You or Your distributors under this License prior to 264 | termination shall survive termination. 265 | 266 | 6. Disclaimer of Warranty 267 | 268 | Covered Software is provided under this License on an "as is" basis, 269 | without warranty of any kind, either expressed, implied, or statutory, 270 | including, without limitation, warranties that the Covered Software is free 271 | of defects, merchantable, fit for a particular purpose or non-infringing. 272 | The entire risk as to the quality and performance of the Covered Software 273 | is with You. Should any Covered Software prove defective in any respect, 274 | You (not any Contributor) assume the cost of any necessary servicing, 275 | repair, or correction. This disclaimer of warranty constitutes an essential 276 | part of this License. No use of any Covered Software is authorized under 277 | this License except under this disclaimer. 278 | 279 | 7. Limitation of Liability 280 | 281 | Under no circumstances and under no legal theory, whether tort (including 282 | negligence), contract, or otherwise, shall any Contributor, or anyone who 283 | distributes Covered Software as permitted above, be liable to You for any 284 | direct, indirect, special, incidental, or consequential damages of any 285 | character including, without limitation, damages for lost profits, loss of 286 | goodwill, work stoppage, computer failure or malfunction, or any and all 287 | other commercial damages or losses, even if such party shall have been 288 | informed of the possibility of such damages. This limitation of liability 289 | shall not apply to liability for death or personal injury resulting from 290 | such party's negligence to the extent applicable law prohibits such 291 | limitation. Some jurisdictions do not allow the exclusion or limitation of 292 | incidental or consequential damages, so this exclusion and limitation may 293 | not apply to You. 294 | 295 | 8. Litigation 296 | 297 | Any litigation relating to this License may be brought only in the courts 298 | of a jurisdiction where the defendant maintains its principal place of 299 | business and such litigation shall be governed by laws of that 300 | jurisdiction, without reference to its conflict-of-law provisions. Nothing 301 | in this Section shall prevent a party's ability to bring cross-claims or 302 | counter-claims. 303 | 304 | 9. Miscellaneous 305 | 306 | This License represents the complete agreement concerning the subject 307 | matter hereof. If any provision of this License is held to be 308 | unenforceable, such provision shall be reformed only to the extent 309 | necessary to make it enforceable. Any law or regulation which provides that 310 | the language of a contract shall be construed against the drafter shall not 311 | be used to construe this License against a Contributor. 312 | 313 | 314 | 10. Versions of the License 315 | 316 | 10.1. New Versions 317 | 318 | Mozilla Foundation is the license steward. Except as provided in Section 319 | 10.3, no one other than the license steward has the right to modify or 320 | publish new versions of this License. Each version will be given a 321 | distinguishing version number. 322 | 323 | 10.2. Effect of New Versions 324 | 325 | You may distribute the Covered Software under the terms of the version 326 | of the License under which You originally received the Covered Software, 327 | or under the terms of any subsequent version published by the license 328 | steward. 329 | 330 | 10.3. Modified Versions 331 | 332 | If you create software not governed by this License, and you want to 333 | create a new license for such software, you may create and use a 334 | modified version of this License if you rename the license and remove 335 | any references to the name of the license steward (except to note that 336 | such modified license differs from this License). 337 | 338 | 10.4. Distributing Source Code Form that is Incompatible With Secondary 339 | Licenses If You choose to distribute Source Code Form that is 340 | Incompatible With Secondary Licenses under the terms of this version of 341 | the License, the notice described in Exhibit B of this License must be 342 | attached. 343 | 344 | Exhibit A - Source Code Form License Notice 345 | 346 | This Source Code Form is subject to the 347 | terms of the Mozilla Public License, v. 348 | 2.0. If a copy of the MPL was not 349 | distributed with this file, You can 350 | obtain one at 351 | https://mozilla.org/MPL/2.0/. 352 | 353 | If it is not possible or desirable to put the notice in a particular file, 354 | then You may include the notice in a location (such as a LICENSE file in a 355 | relevant directory) where a recipient would be likely to look for such a 356 | notice. 357 | 358 | You may add additional accurate notices of copyright ownership. 359 | 360 | Exhibit B - "Incompatible With Secondary Licenses" Notice 361 | 362 | This Source Code Form is "Incompatible 363 | With Secondary Licenses", as defined by 364 | the Mozilla Public License, v. 2.0. 365 | --------------------------------------------------------------------------------