├── .gitignore ├── LICENSE ├── Makefile ├── README.md ├── doc └── index.html ├── examples ├── basic.fallback.js └── basic.js ├── index.js ├── package.json └── tests ├── ssl ├── ssl.crt └── ssl.private.key └── unit.test.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2011 Arnout Kazemier,3rd-Eden 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. -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | doc: 2 | dox --title "FlashPolicyFileServer" lib/* > doc/index.html 3 | 4 | test: 5 | expresso -I lib $(TESTFLAGS) tests/*.test.js 6 | 7 | .PHONY: test doc -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## LOL, WUT? 2 | It basically allows you to allow or disallow Flash Player sockets from accessing your site. 3 | 4 | ## Installation 5 | 6 | ```bash 7 | npm install policyfile 8 | ``` 9 | ## Usage 10 | 11 | The server is based on the regular and know `net` and `http` server patterns. So it you can just listen 12 | for all the events that a `net` based server emits etc. But there is one extra event, the `connect_failed` 13 | event. This event is triggered when we are unable to listen on the supplied port number. 14 | 15 | ### createServer 16 | Creates a new server instance and accepts 2 optional arguments: 17 | 18 | - `options` **Object** Options to configure the server instance 19 | - `log` **Boolean** Enable logging to STDOUT and STDERR (defaults to true) 20 | - `origins` **Array** An Array of origins that are allowed by the server (defaults to *:*) 21 | 22 | ```js 23 | var pf = require('policyfile').createServer(); 24 | 25 | pf.listen(); 26 | ``` 27 | 28 | #### server.listen 29 | Start listening on the server and it takes 3 optional arguments 30 | 31 | - `port` **Number** On which port number should we listen? (defaults to 843, which is the first port number the FlashPlayer checks) 32 | - `server` **Server** A http server, if we are unable to accept requests or run the server we can also answer the policy requests inline over the supplied HTTP server. 33 | - `callback` **Function** A callback function that is called when listening to the server was successful. 34 | 35 | ```js 36 | var pf = require('policyfile').createServer(); 37 | 38 | pf.listen(1337, function(){ 39 | console.log(':3 yay') 40 | }); 41 | ``` 42 | 43 | Changing port numbers can be handy if you do not want to run your server as root and have port 843 forward to a non root port number (aka a number above 1024). 44 | 45 | ```js 46 | var pf = require('policyfile').createServer() 47 | , http = require('http'); 48 | 49 | server = http.createServer(function(q,r){r.writeHead(200);r.end('hello world')}); 50 | server.listen(80); 51 | 52 | pf.listen(1337, server, function(){ 53 | console.log(':3 yay') 54 | }); 55 | ``` 56 | 57 | Support for serving inline requests over a existing HTTP connection as the FlashPlayer will first check port 843, but if it's unable to get a response there it will send a policy file request over port 80, which is usually your http server. 58 | 59 | #### server.add 60 | Adds more origins to the policy file you can add as many arguments as you like. 61 | 62 | ```js 63 | var pf = require('policyfile').createServer(['google.com:80']); 64 | 65 | pf.listen(); 66 | pf.add('blog.3rd-Eden.com:80', 'blog.3rd-Eden.com:8080'); // now has 3 origins 67 | ``` 68 | 69 | #### server.remove 70 | Removes added origins from the policy file - you can add as many arguments as you like. 71 | 72 | ```js 73 | var pf = require('policyfile').createServer(['blog.3rd-Eden.com:80', 'blog.3rd-Eden.com:8080']); 74 | 75 | pf.listen(); 76 | pf.remove('blog.3rd-Eden.com:8080'); // only contains the :80 version now 77 | ``` 78 | 79 | #### server.close 80 | Shuts down the server 81 | 82 | ```js 83 | var pf = require('policyfile').createServer(); 84 | 85 | pf.listen(); 86 | pf.close(); // OH NVM. 87 | ``` 88 | 89 | ## API 90 | http://3rd-eden.com/FlashPolicyFileServer/ 91 | 92 | ## Examples 93 | See https://github.com/3rd-Eden/FlashPolicyFileServer/tree/master/examples for examples 94 | 95 | ## Licence 96 | 97 | MIT see LICENSE file in the repository -------------------------------------------------------------------------------- /doc/index.html: -------------------------------------------------------------------------------- 1 | 2 |
3 |FlashPolicyFileServer | |
server | lib/server.js |
113 | Module dependencies and cached references. 114 | 115 | |
116 |
117 |
119 | |
120 |
123 | The server that does the Policy File severing 124 | 125 |Options126 | 127 |
|
133 |
134 |
195 | |
196 |
199 | Start listening for requests 200 | 201 | 202 | 203 |
|
205 |
206 |
258 | |
259 |
262 | Adds a new origin to the Flash Policy File. 263 | 264 | 265 | 266 |
|
268 |
269 |
292 | |
293 |
296 | Removes a origin from the Flash Policy File. 297 | 298 | 299 | 300 |
|
302 |
303 |
314 | |
315 |
318 | Closes and cleans up the server 319 | 320 |
|
322 |
323 |
330 | |
331 |
334 | Proxy the event listener requests to the created Net server 335 | 336 | |
337 |
338 |
347 | |
348 |
351 | Creates a new server instance. 352 | 353 | 354 | 355 |
|
357 |
358 |
369 | |
370 |
373 | Provide a hook to the original server, so it can be extended if needed. 374 | 375 | 376 | 377 |
|
379 |
380 |
381 | |
382 |
385 | Module version 386 | 387 | 388 | 389 |
|
391 |
392 |
394 | |
395 |