Marek Piasecki
7 years ago
commit
743cd33b48
121 changed files with 10493 additions and 0 deletions
@ -0,0 +1,11 @@ |
|||||
|
nodes.conf |
||||
|
config.yml |
||||
|
node_modules/* |
||||
|
*.log* |
||||
|
services/init.coffee |
||||
|
public/* |
||||
|
.byebug_history |
||||
|
.vagrant |
||||
|
_site |
||||
|
docker-compose.yml |
||||
|
Dockerfile.* |
@ -0,0 +1,8 @@ |
|||||
|
require '../components/router/router_tag' |
||||
|
# Router.init :name_of_root_view |
||||
|
|
||||
|
tag #app |
||||
|
|
||||
|
def render |
||||
|
<self> # <router> |
||||
|
'Pro is running' |
@ -0,0 +1,10 @@ |
|||||
|
<!DOCTYPE html> |
||||
|
<html> |
||||
|
<head> |
||||
|
<meta charset="UTF-8"> |
||||
|
</head> |
||||
|
<body> |
||||
|
<div id="app"></div> |
||||
|
<script src="/bundle.js" charset="utf-8"></script> |
||||
|
</body> |
||||
|
</html> |
@ -0,0 +1,5 @@ |
|||||
|
tag not_found |
||||
|
|
||||
|
def render |
||||
|
<self> |
||||
|
<h1> 'Page not found' |
@ -0,0 +1,10 @@ |
|||||
|
<html> |
||||
|
<body> |
||||
|
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.4/lodash.min.js'></script> |
||||
|
<script src='https://unpkg.com/pro-router@3.2.0/pro-router-standalone.min.js'></script> |
||||
|
<script> |
||||
|
window.render = function(){ console.log(R.view); console.log(JSON.stringify(R.params)) } |
||||
|
R.init({helpers: _}) |
||||
|
</script> |
||||
|
</body> |
||||
|
</html> |
@ -0,0 +1,20 @@ |
|||||
|
{ |
||||
|
"name": "pro-router", |
||||
|
"description": "Fully automated singleton router service for frontend. Use url as data store", |
||||
|
"version": "4.3.0", |
||||
|
"main": "router.js", |
||||
|
"repository": { |
||||
|
"type": "git", |
||||
|
"url": "git+https://github.com/madmaniak/pro.git" |
||||
|
}, |
||||
|
"keywords": [ |
||||
|
"frontend", |
||||
|
"router" |
||||
|
], |
||||
|
"author": "Marek Piasecki", |
||||
|
"license": "ISC", |
||||
|
"bugs": { |
||||
|
"url": "https://github.com/madmaniak/pro/issues" |
||||
|
}, |
||||
|
"homepage": "https://github.com/madmaniak/pro/framework/components/router/npm_router_service" |
||||
|
} |
@ -0,0 +1 @@ |
|||||
|
window.R={_l:location,_r:history.replaceState.bind(history),_p:history.pushState.bind(history),_d:decodeURIComponent,_e:encodeURIComponent,init:function(o){if(o==null){o={}}this.root||(this.root=o.root||"root");this.views||(this.views=o.views||window.Views||[this.root]);this.render||(this.render=o.render||window.render);this.h||(this.h=o.helpers||window._);window.onpopstate=this.url_changed.bind(this);this.read()},cache:{},getters:{},setters:{},param:function(k){var base;if(this.getters[k]){return(base=this.cache)[k]||(base[k]=this.getters[k](this._d(this.params[k]||"")))}else{return this._d(this.params[k]||"")}},write:function(){var i,j,k,l,v;for(i=j=0,l=arguments.length;j<l;i=++j){k=arguments[i];if(!(i%2)){v=arguments[i+1];this._write(k,v)}}this._r({},this._l.pathname,this.to_path(this.view,this.params));this.url_changed()},_write:function(k,v){var _v=this.setters[k]?this.setters[k](v):v;_v?this.params[k]=this._e(_v):delete this.params[k]},toggle:function(f,s){this.write(f,s!=null?s?1:void 0:!this.params[f]?1:void 0)},go:function(p){this._p({},null,p);this.url_changed()},read:function(){var ref;ref=this.split_path(this._l.hash),this.view=ref[0],this.params=ref[1];this._safe_params()},split_path:function(p){p=p.slice(2);if(!p.length){return [this.root,{}]}var list,params,view;list=this.h.compact(p.split("/"));view=this._existance(list.shift());params=this.h.fromPairs(this.h.chunk(list,2));return[view,params]},_existance:function(v){if(this.h.includes(this.views,v)){return v}else{return"not_found"}},_safe_params:function(){return this.safe_params=this.h.fromPairs(this.h.reject(this.h.toPairs(this.params),function(p){return/^_/.test(p[0])}))},to_path:function(v,p){var a;if(v==null){v=this.view}if(p==null){p=this.safe_params}a=this.h.flatten(this.h.reject(this.h.toPairs(p),function(p){return!p[1]}));return"#/"+v+"/"+a.join("/")},url_changed:function(){this.cache={};this.read();this.render()}}; |
@ -0,0 +1 @@ |
|||||
|
window.R={_l:location,_r:history.replaceState.bind(history),_p:history.pushState.bind(history),_d:decodeURIComponent,_e:encodeURIComponent,init:function(o){if(o==null){o={}}this.root||(this.root=o.root||"root");this.views||(this.views=o.views||window.Views||[this.root]);this.render||(this.render=o.render||window.render);this.h||(this.h=o.helpers||window._);window.onpopstate=this.url_changed.bind(this);this.read()},cache:{},getters:{},setters:{},param:function(k){var base;if(this.getters[k]){return(base=this.cache)[k]||(base[k]=this.getters[k](this._d(this.params[k]||"")))}else{return this._d(this.params[k]||"")}},write:function(){var i,j,k,l,v;for(i=j=0,l=arguments.length;j<l;i=++j){k=arguments[i];if(!(i%2)){v=arguments[i+1];this._write(k,v)}}this._r({},this._l.pathname,this.to_path(this.view,this.params));this.url_changed()},_write:function(k,v){var _v=this.setters[k]?this.setters[k](v):v;_v?this.params[k]=this._e(_v):delete this.params[k]},toggle:function(f,s){this.write(f,s!=null?s?1:void 0:!this.params[f]?1:void 0)},go:function(p){this._p({},null,p);this.url_changed()},read:function(){var ref;ref=this.split_path(this._l.pathname),this.view=ref[0],this.params=ref[1];this._safe_params()},split_path:function(p){if(p.length==1){return [this.root,{}]}var list,params,view;list=this.h.compact(p.split("/"));view=this._existance(list.shift());params=this.h.fromPairs(this.h.chunk(list,2));return[view,params]},_existance:function(v){if(this.h.includes(this.views,v)){return v}else{return"not_found"}},_safe_params:function(){return this.safe_params=this.h.fromPairs(this.h.reject(this.h.toPairs(this.params),function(p){return/^_/.test(p[0])}))},to_path:function(v,p){var a;if(v==null){v=this.view}if(p==null){p=this.safe_params}a=this.h.flatten(this.h.reject(this.h.toPairs(p),function(p){return!p[1]}));return"/"+v+"/"+a.join("/")},url_changed:function(){this.cache={};this.read();this.render()}}; |
@ -0,0 +1,84 @@ |
|||||
|
module.exports = window.R = |
||||
|
|
||||
|
# local cache |
||||
|
_location: location |
||||
|
_replaceState: history.replaceState.bind(history) |
||||
|
_pushState: history.pushState.bind(history) |
||||
|
_decodeURIComponent: decodeURIComponent |
||||
|
_encodeURIComponent: encodeURIComponent |
||||
|
|
||||
|
init: (opts = {}) -> |
||||
|
@root ||= opts.root || 'root' |
||||
|
@views ||= opts.views || window.Views || [@root] |
||||
|
@render ||= opts.render || window.render |
||||
|
@h ||= opts.helpers || window._ |
||||
|
window.onpopstate = @url_changed.bind(@) |
||||
|
@read() |
||||
|
|
||||
|
cache: {} |
||||
|
getters: {} |
||||
|
setters: {} |
||||
|
|
||||
|
# <MAIN API> |
||||
|
|
||||
|
param: (key) -> |
||||
|
if @getters[key] |
||||
|
then @cache[key] ||= @getters[key]( @_decodeURIComponent(@params[key] || '') ) |
||||
|
else @_decodeURIComponent(@params[key] || '') |
||||
|
|
||||
|
write: -> |
||||
|
# accept arguments keeping key, value, key, value order |
||||
|
# serialize using setters |
||||
|
# if no argument given just refresh url and rerender |
||||
|
for k, i in arguments |
||||
|
unless i % 2 |
||||
|
v = arguments[i+1] |
||||
|
@_write(k,v) |
||||
|
|
||||
|
@_replaceState {}, |
||||
|
@_location.pathname, @to_path(@view, @params) |
||||
|
@url_changed() |
||||
|
|
||||
|
_write: (k,v) -> |
||||
|
value = if @setters[k] then @setters[k](v) else v |
||||
|
if value |
||||
|
then @params[k] = @_encodeURIComponent(value) |
||||
|
else delete @params[k] |
||||
|
|
||||
|
toggle: (flag, state) -> |
||||
|
@write flag, if state? |
||||
|
then ( 1 if state ) |
||||
|
else ( 1 if !@params[flag] ) |
||||
|
|
||||
|
go: (path) -> |
||||
|
@_pushState {}, null, path |
||||
|
@url_changed() |
||||
|
|
||||
|
# </MAIN API> |
||||
|
|
||||
|
read: -> |
||||
|
[@view, @params] = @split_path @_location.pathname |
||||
|
@_safe_params() |
||||
|
|
||||
|
split_path: (path) -> |
||||
|
return [ @root, {} ] if path.length == 1 |
||||
|
list = @h.compact path.split("/") |
||||
|
view = @_existance list.shift() |
||||
|
params = @h.fromPairs @h.chunk(list, 2) |
||||
|
[ view, params ] |
||||
|
|
||||
|
_existance: (view) -> |
||||
|
if @h.includes(@views, view) then view else 'not_found' |
||||
|
|
||||
|
_safe_params: -> |
||||
|
@safe_params = @h.fromPairs @h.reject @h.toPairs(@params), (pair) -> |
||||
|
/^_/.test pair[0] |
||||
|
|
||||
|
to_path: (view = @view, params = @safe_params) -> |
||||
|
array = @h.flatten @h.toPairs(params) |
||||
|
'/' + view + '/' + array.join('/') |
||||
|
|
||||
|
url_changed: -> |
||||
|
@cache = {} |
||||
|
@read() |
||||
|
@render() |
@ -0,0 +1,96 @@ |
|||||
|
module.exports = window.R = { |
||||
|
_location: location, |
||||
|
_replaceState: history.replaceState.bind(history), |
||||
|
_pushState: history.pushState.bind(history), |
||||
|
_decodeURIComponent: decodeURIComponent, |
||||
|
_encodeURIComponent: encodeURIComponent, |
||||
|
init: function(opts) { |
||||
|
if (opts == null) { |
||||
|
opts = {}; |
||||
|
} |
||||
|
this.root || (this.root = opts.root || 'root'); |
||||
|
this.views || (this.views = opts.views || window.Views || [this.root]); |
||||
|
this.render || (this.render = opts.render || window.render); |
||||
|
this.h || (this.h = opts.helpers || window._); |
||||
|
window.onpopstate = this.url_changed.bind(this) |
||||
|
this.read(); |
||||
|
}, |
||||
|
cache: {}, |
||||
|
getters: {}, |
||||
|
setters: {}, |
||||
|
param: function(key) { |
||||
|
var base; |
||||
|
if (this.getters[key]) { |
||||
|
return (base = this.cache)[key] || (base[key] = this.getters[key](this._decodeURIComponent(this.params[key] || ''))); |
||||
|
} else { |
||||
|
return this._decodeURIComponent(this.params[key] || ''); |
||||
|
} |
||||
|
}, |
||||
|
write: function() { |
||||
|
var i, j, k, len, v; |
||||
|
for (i = j = 0, len = arguments.length; j < len; i = ++j) { |
||||
|
k = arguments[i]; |
||||
|
if (!(i % 2)) { |
||||
|
v = arguments[i + 1]; |
||||
|
this._write(k, v); |
||||
|
} |
||||
|
} |
||||
|
this._replaceState({}, this._location.pathname, this.to_path(this.view, this.params)); |
||||
|
this.url_changed(); |
||||
|
}, |
||||
|
_write: function(k, v) { |
||||
|
var value = this.setters[k] ? this.setters[k](v) : v; |
||||
|
value ? this.params[k] = this._encodeURIComponent(value) : delete this.params[k]; |
||||
|
}, |
||||
|
toggle: function(flag, state) { |
||||
|
this.write(flag, state != null ? (state ? 1 : void 0) : (!this.params[flag] ? 1 : void 0)); |
||||
|
}, |
||||
|
go: function(path) { |
||||
|
this._pushState({}, null, path); |
||||
|
this.url_changed(); |
||||
|
}, |
||||
|
read: function() { |
||||
|
var ref; |
||||
|
ref = this.split_path(this._location.pathname), this.view = ref[0], this.params = ref[1]; |
||||
|
this._safe_params(); |
||||
|
}, |
||||
|
split_path: function(path) { |
||||
|
if (path.length == 1) { |
||||
|
return [this.root, {}]; |
||||
|
} |
||||
|
var list, params, view; |
||||
|
list = this.h.compact(path.split("/")); |
||||
|
view = this._existance(list.shift()); |
||||
|
params = this.h.fromPairs(this.h.chunk(list, 2)); |
||||
|
return [view, params]; |
||||
|
}, |
||||
|
_existance: function(view) { |
||||
|
if (this.h.includes(this.views, view)) { |
||||
|
return view; |
||||
|
} else { |
||||
|
return 'not_found'; |
||||
|
} |
||||
|
}, |
||||
|
_safe_params: function() { |
||||
|
return this.safe_params = this.h.fromPairs(this.h.reject(this.h.toPairs(this.params), function(pair) { |
||||
|
return /^_/.test(pair[0]); |
||||
|
})); |
||||
|
}, |
||||
|
to_path: function(view, params) { |
||||
|
var array; |
||||
|
if (view == null) { |
||||
|
view = this.view; |
||||
|
} |
||||
|
if (params == null) { |
||||
|
params = this.safe_params; |
||||
|
} |
||||
|
array = this.h.flatten(this.h.toPairs(params)); |
||||
|
return '/' + view + '/' + array.join('/'); |
||||
|
}, |
||||
|
url_changed: function() { |
||||
|
this.cache = {}; |
||||
|
this.read(); |
||||
|
this.render(); |
||||
|
} |
||||
|
|
||||
|
}; |
@ -0,0 +1,85 @@ |
|||||
|
module.exports = window.R = |
||||
|
|
||||
|
# local cache |
||||
|
_location: location |
||||
|
_replaceState: history.replaceState.bind(history) |
||||
|
_pushState: history.pushState.bind(history) |
||||
|
_decodeURIComponent: decodeURIComponent |
||||
|
_encodeURIComponent: encodeURIComponent |
||||
|
|
||||
|
init: (opts = {}) -> |
||||
|
@root ||= opts.root || 'root' |
||||
|
@views ||= opts.views || window.Views || [@root] |
||||
|
@render ||= opts.render || window.render |
||||
|
@h ||= opts.helpers || window._ |
||||
|
window.onpopstate = @url_changed.bind(@) |
||||
|
@read() |
||||
|
|
||||
|
cache: {} |
||||
|
getters: {} |
||||
|
setters: {} |
||||
|
|
||||
|
# <MAIN API> |
||||
|
|
||||
|
param: (key) -> |
||||
|
if @getters[key] |
||||
|
then @cache[key] ||= @getters[key]( @_decodeURIComponent(@params[key] || '') ) |
||||
|
else @_decodeURIComponent(@params[key] || '') |
||||
|
|
||||
|
write: -> |
||||
|
# accept arguments keeping key, value, key, value order |
||||
|
# serialize using setters |
||||
|
# if no argument given just refresh url and rerender |
||||
|
for k, i in arguments |
||||
|
unless i % 2 |
||||
|
v = arguments[i+1] |
||||
|
@_write(k,v) |
||||
|
|
||||
|
@_replaceState {}, |
||||
|
@_location.pathname, @to_path(@view, @params) |
||||
|
@url_changed() |
||||
|
|
||||
|
_write: (k,v) -> |
||||
|
value = if @setters[k] then @setters[k](v) else v |
||||
|
if value |
||||
|
then @params[k] = @_encodeURIComponent(value) |
||||
|
else delete @params[k] |
||||
|
|
||||
|
toggle: (flag, state) -> |
||||
|
@write flag, if state? |
||||
|
then ( 1 if state ) |
||||
|
else ( 1 if !@params[flag] ) |
||||
|
|
||||
|
go: (path) -> |
||||
|
@_pushState {}, null, path |
||||
|
@url_changed() |
||||
|
|
||||
|
# </MAIN API> |
||||
|
|
||||
|
read: -> |
||||
|
[@view, @params] = @split_path @_location.hash |
||||
|
@_safe_params() |
||||
|
|
||||
|
split_path: (path) -> |
||||
|
path = path.slice(2) |
||||
|
return [ @root, {} ] unless path.length |
||||
|
list = @h.compact path.split("/") |
||||
|
view = @_existance list.shift() |
||||
|
params = @h.fromPairs @h.chunk(list, 2) |
||||
|
[ view, params ] |
||||
|
|
||||
|
_existance: (view) -> |
||||
|
if @h.includes(@views, view) then view else 'not_found' |
||||
|
|
||||
|
_safe_params: -> |
||||
|
@safe_params = @h.fromPairs @h.reject @h.toPairs(@params), (pair) -> |
||||
|
/^_/.test pair[0] |
||||
|
|
||||
|
to_path: (view = @view, params = @safe_params) -> |
||||
|
array = @h.flatten @h.toPairs(params) |
||||
|
'#/' + view + '/' + array.join('/') |
||||
|
|
||||
|
url_changed: -> |
||||
|
@cache = {} |
||||
|
@read() |
||||
|
@render() |
@ -0,0 +1,97 @@ |
|||||
|
module.exports = window.R = { |
||||
|
_location: location, |
||||
|
_replaceState: history.replaceState.bind(history), |
||||
|
_pushState: history.pushState.bind(history), |
||||
|
_decodeURIComponent: decodeURIComponent, |
||||
|
_encodeURIComponent: encodeURIComponent, |
||||
|
init: function(opts) { |
||||
|
if (opts == null) { |
||||
|
opts = {}; |
||||
|
} |
||||
|
this.root || (this.root = opts.root || 'root'); |
||||
|
this.views || (this.views = opts.views || window.Views || [this.root]); |
||||
|
this.render || (this.render = opts.render || window.render); |
||||
|
this.h || (this.h = opts.helpers || window._); |
||||
|
window.onpopstate = this.url_changed.bind(this) |
||||
|
this.read(); |
||||
|
}, |
||||
|
cache: {}, |
||||
|
getters: {}, |
||||
|
setters: {}, |
||||
|
param: function(key) { |
||||
|
var base; |
||||
|
if (this.getters[key]) { |
||||
|
return (base = this.cache)[key] || (base[key] = this.getters[key](this._decodeURIComponent(this.params[key] || ''))); |
||||
|
} else { |
||||
|
return this._decodeURIComponent(this.params[key] || ''); |
||||
|
} |
||||
|
}, |
||||
|
write: function() { |
||||
|
var i, j, k, len, v; |
||||
|
for (i = j = 0, len = arguments.length; j < len; i = ++j) { |
||||
|
k = arguments[i]; |
||||
|
if (!(i % 2)) { |
||||
|
v = arguments[i + 1]; |
||||
|
this._write(k, v); |
||||
|
} |
||||
|
} |
||||
|
this._replaceState({}, this._location.pathname, this.to_path(this.view, this.params)); |
||||
|
this.url_changed(); |
||||
|
}, |
||||
|
_write: function(k, v) { |
||||
|
var value = this.setters[k] ? this.setters[k](v) : v; |
||||
|
value ? this.params[k] = this._encodeURIComponent(value) : delete this.params[k]; |
||||
|
}, |
||||
|
toggle: function(flag, state) { |
||||
|
this.write(flag, state != null ? (state ? 1 : void 0) : (!this.params[flag] ? 1 : void 0)); |
||||
|
}, |
||||
|
go: function(path) { |
||||
|
this._pushState({}, null, path); |
||||
|
this.url_changed(); |
||||
|
}, |
||||
|
read: function() { |
||||
|
var ref; |
||||
|
ref = this.split_path(this._location.hash), this.view = ref[0], this.params = ref[1]; |
||||
|
this._safe_params(); |
||||
|
}, |
||||
|
split_path: function(path) { |
||||
|
path = path.slice(2); |
||||
|
if (!path.length) { |
||||
|
return [this.root, {}]; |
||||
|
} |
||||
|
var list, params, view; |
||||
|
list = this.h.compact(path.split("/")); |
||||
|
view = this._existance(list.shift()); |
||||
|
params = this.h.fromPairs(this.h.chunk(list, 2)); |
||||
|
return [view, params]; |
||||
|
}, |
||||
|
_existance: function(view) { |
||||
|
if (this.h.includes(this.views, view)) { |
||||
|
return view; |
||||
|
} else { |
||||
|
return 'not_found'; |
||||
|
} |
||||
|
}, |
||||
|
_safe_params: function() { |
||||
|
return this.safe_params = this.h.fromPairs(this.h.reject(this.h.toPairs(this.params), function(pair) { |
||||
|
return /^_/.test(pair[0]); |
||||
|
})); |
||||
|
}, |
||||
|
to_path: function(view, params) { |
||||
|
var array; |
||||
|
if (view == null) { |
||||
|
view = this.view; |
||||
|
} |
||||
|
if (params == null) { |
||||
|
params = this.safe_params; |
||||
|
} |
||||
|
array = this.h.flatten(this.h.toPairs(params)); |
||||
|
return '#/' + view + '/' + array.join('/'); |
||||
|
}, |
||||
|
url_changed: function() { |
||||
|
this.cache = {}; |
||||
|
this.read(); |
||||
|
this.render(); |
||||
|
} |
||||
|
|
||||
|
}; |
@ -0,0 +1,33 @@ |
|||||
|
tag ref < a |
||||
|
|
||||
|
prop view |
||||
|
prop target |
||||
|
prop go |
||||
|
|
||||
|
attr onclick |
||||
|
|
||||
|
def setup |
||||
|
@r = R |
||||
|
|
||||
|
def render |
||||
|
<self.active=is_active href=link onclick='return false'> |
||||
|
|
||||
|
def is_active |
||||
|
var view, params |
||||
|
[ view, params ] = @r.split_path(link) |
||||
|
view == @r:view && L.isEqual params, @r:params |
||||
|
|
||||
|
def ontap e |
||||
|
return if is_active |
||||
|
@r.go dom:href |
||||
|
window.scrollTo 0, 0 |
||||
|
|
||||
|
def link |
||||
|
@go || url |
||||
|
|
||||
|
def url |
||||
|
if @target |
||||
|
var attributes = L.reduce L.concat({}, @target), do |map, el| |
||||
|
map[el:type] = el:id |
||||
|
map |
||||
|
@r.to_path @view, L.defaults attributes || {}, @r:safe_params |
@ -0,0 +1,13 @@ |
|||||
|
global:Router = require('pro-router') |
||||
|
require './ref/ref' |
||||
|
require './switch/switch' |
||||
|
require './not_found/not_found' |
||||
|
|
||||
|
tag router |
||||
|
|
||||
|
def setup |
||||
|
@r = R |
||||
|
|
||||
|
def render |
||||
|
self:__:A = self:__:A || {} |
||||
|
<self> ( self:__:A[@r:view] || self:__:A[@r:view] = global:_T[@r:view.toUpperCase]() ).end |
@ -0,0 +1,18 @@ |
|||||
|
require './switch.scss' |
||||
|
|
||||
|
tag switch |
||||
|
|
||||
|
prop key |
||||
|
prop disable |
||||
|
|
||||
|
def setup |
||||
|
@r = R |
||||
|
|
||||
|
def render |
||||
|
<self.is_on=is_on .disabled=@disable> |
||||
|
|
||||
|
def is_on |
||||
|
@r:params[@key] |
||||
|
|
||||
|
def ontap |
||||
|
@r.toggle key unless @disable |
@ -0,0 +1 @@ |
|||||
|
._switch{ cursor: pointer } |
@ -0,0 +1 @@ |
|||||
|
|
@ -0,0 +1 @@ |
|||||
|
global.Dispatcher = require("backbone-events-standalone") |
@ -0,0 +1,35 @@ |
|||||
|
L.mixin compose: (base, layers...) -> |
||||
|
L.reduce L.uniq(L.flatten(L.map(layers, L.functions))), (object, method) -> |
||||
|
object[method] = L.pipe base, L.compact L.map( layers, method ) |
||||
|
object |
||||
|
, base |
||||
|
|
||||
|
# namespacer |
||||
|
L.mixin ns: (path, action) -> |
||||
|
rm_dots = path.split('../') |
||||
|
framework = if rm_dots.length == 4 then 'framework/' else '' |
||||
|
"#{framework}#{rm_dots[rm_dots.length - 1]}/#{action}" |
||||
|
|
||||
|
L.mixin pipe: (context, methods) -> |
||||
|
-> |
||||
|
result = arguments |
||||
|
L.each methods, (method) -> |
||||
|
if method.length |
||||
|
result = method.apply(context, result) |
||||
|
else |
||||
|
method.call(context) |
||||
|
result |
||||
|
|
||||
|
L.mixin reference: (object) -> [object.type, object.id] |
||||
|
|
||||
|
L.mixin stringify: (hash) -> |
||||
|
L.reduce(hash, (array, k,v) -> |
||||
|
array.push "#{k}#{v}" |
||||
|
array |
||||
|
, []).sort().join() |
||||
|
|
||||
|
L.mixin tmp_id: (object) -> /tmp/.exec object.id |
||||
|
|
||||
|
L.mixin wait_for_real_id: (objects, action) -> |
||||
|
!if object = L.find objects, L.tmp_id |
||||
|
Dispatcher.once "#{object.id}_to_id", action |
@ -0,0 +1,4 @@ |
|||||
|
require './dispatcher' |
||||
|
require './helpers' |
||||
|
require './requests' |
||||
|
require './store' |
@ -0,0 +1,7 @@ |
|||||
|
global.Cache = |
||||
|
|
||||
|
get: (request_key) -> |
||||
|
localStorage.getItem(request_key) |
||||
|
|
||||
|
set: (request_key, data) -> |
||||
|
localStorage.setItem request_key, data |
@ -0,0 +1,27 @@ |
|||||
|
class Collection.Dynamic extends Collection.Static |
||||
|
|
||||
|
prev: -> |
||||
|
if @dynamic_prev |
||||
|
then @go dynamic: @scope, @dynamic |
||||
|
else super |
||||
|
|
||||
|
next: -> |
||||
|
if @dynamic_next |
||||
|
then @go dynamic: @scope, @dynamic |
||||
|
else super |
||||
|
|
||||
|
dynamic: (scope) -> |
||||
|
L.each scope, (id) => @add_id(id) |
||||
|
@_dynamic_flags(scope) |
||||
|
|
||||
|
_dynamic_flags: (scope) -> |
||||
|
@dynamic_prev = false if L.includes scope, @scope[0] |
||||
|
@dynamic_next = false if L.includes scope, L.last(@scope) |
||||
|
|
||||
|
reorder: (i) -> |
||||
|
i = super(i) |
||||
|
if i == @elements().length - 1 |
||||
|
@dynamic_next = true |
||||
|
else if i == 0 |
||||
|
@dynamic_prev = true |
||||
|
i |
@ -0,0 +1,131 @@ |
|||||
|
class global.Collection |
||||
|
|
||||
|
@list: {} |
||||
|
|
||||
|
constructor: (@scope = [], @params = {}, @belongs_to) -> |
||||
|
@v = 0 |
||||
|
Dispatcher.on "#{@constructor.base}_change", @change |
||||
|
unless @belongs_to |
||||
|
# root in Store |
||||
|
@belongs_to = id: 1, type: @constructor.path |
||||
|
@belongs_to[@constructor.base] = @ |
||||
|
Store.collections[@constructor.path] = 1: @belongs_to |
||||
|
|
||||
|
load: -> @go {}, (scope) => @scope = scope |
||||
|
|
||||
|
elements: -> |
||||
|
if @_v == @v |
||||
|
then @_collection |
||||
|
else @_v = @v; @_collection = Store.get @constructor.base, @scope |
||||
|
|
||||
|
add: (object, relations = []) -> |
||||
|
Store.add @constructor.base, object, relations.concat @belongs_to |
||||
|
render() |
||||
|
|
||||
|
add_id: (id) -> |
||||
|
@scope.push(id); @v++ |
||||
|
i = @reorder(@scope.length - 1) |
||||
|
object = @_object(id) |
||||
|
L.wait_for_real_id [object], => |
||||
|
if @scope[i] != id |
||||
|
i = @index_of(object, id) |
||||
|
@scope.splice(i, true, object.id); @v++ |
||||
|
@_create_relations(id) |
||||
|
|
||||
|
_create_relations: (id) -> |
||||
|
object = @_object(id) |
||||
|
L.each @constructor.relations, (ns, relation) -> |
||||
|
if !object[relation] or L.isArray object[relation] |
||||
|
object[relation] = new Collection.list[ns](object[relation], {}, object) |
||||
|
|
||||
|
change: (id) => |
||||
|
if object = @_object(id) |
||||
|
# still exists? |
||||
|
# id in scope? |
||||
|
if (i = @index_of(object)) != -1 |
||||
|
then @reorder(i) |
||||
|
else @scope.splice(i, 1); @v++ |
||||
|
else |
||||
|
# don't exist at all? |
||||
|
# was in scope? |
||||
|
if (i = L.indexOf(@scope, id)) != -1 |
||||
|
@scope.splice(i, 1); @v++ |
||||
|
|
||||
|
reorder: (i) -> |
||||
|
c = @elements() |
||||
|
if direction = @_direction c[i-1], c[i], c[i+1] |
||||
|
# wrong order? |
||||
|
split = i + direction |
||||
|
destination = |
||||
|
if direction < 0 |
||||
|
then @proper_index(c[i], c, 0, split-1) |
||||
|
else i + @proper_index(c[i], c, split) |
||||
|
@move i, destination |
||||
|
destination || i |
||||
|
|
||||
|
# which way unsorted element should go |
||||
|
_direction: (left, object, right) -> |
||||
|
if right and @compare(object, right) then 1 |
||||
|
else if left and @compare(left, object) then -1 |
||||
|
else 0 |
||||
|
|
||||
|
move: (from, to) -> |
||||
|
@scope.splice to, 0, @scope.splice(from, 1)[0]; @v++ |
||||
|
|
||||
|
# is a >= b considering [attribute, boolean:descending]? |
||||
|
compare: (a, b) -> |
||||
|
for order in @constructor.order |
||||
|
return !order[1] if a[order[0]] > b[order[0]] |
||||
|
return order[1] if a[order[0]] < b[order[0]] |
||||
|
return !order[1] if L.isString(a[order[0]]) && L.isInteger(b[order[0]]) |
||||
|
return order[1] if L.isString(b[order[0]]) && L.isInteger(a[order[0]]) |
||||
|
true |
||||
|
|
||||
|
# binary search for proper index |
||||
|
proper_index: (object, collection, left, right) -> |
||||
|
collection ||= @elements() |
||||
|
l = left || 0 |
||||
|
r = right || collection.length - 1 |
||||
|
m = H.half_way(l, r) |
||||
|
while true |
||||
|
return l if @compare(collection[l], object) |
||||
|
return r+1 if @compare(object, collection[r]) |
||||
|
if @compare(collection[m], object) |
||||
|
then r = m - 1 |
||||
|
else l = m + 1 |
||||
|
m = H.half_way(l, r) |
||||
|
|
||||
|
index_of: (object, id = object.id) -> |
||||
|
i = @proper_index object |
||||
|
return i if @scope[i] == id |
||||
|
j = 1 |
||||
|
while (i2 = i+j) < @scope.length |
||||
|
return i2 if @scope[i2] == id or @scope[i-j] == id |
||||
|
j++ |
||||
|
while (i2 = i-j) >= 0 |
||||
|
return i2 if @scope[i2] == id |
||||
|
j++ |
||||
|
-1 |
||||
|
|
||||
|
_object: (id) -> Store.get(@constructor.base, id)[0] |
||||
|
|
||||
|
go: (params, scope_f) -> |
||||
|
@done = false |
||||
|
query = L.merge(params, @params) |
||||
|
rk = @constructor.path + L.stringify(query) |
||||
|
|
||||
|
Dispatcher.once Requests.perform(@constructor.path, query), (reply) => |
||||
|
# Cache.set rk, reply.raw |
||||
|
scope_f?.call(@, reply.scope); @v++ |
||||
|
if @constructor.relations |
||||
|
L.each Store.get(@constructor.base, reply.scope), (object) => |
||||
|
@_create_relations(object.id) |
||||
|
@done = true |
||||
|
@ |
||||
|
|
||||
|
H = |
||||
|
half_way: (l, r) -> |
||||
|
l + Math.floor (r - l)/2 |
||||
|
|
||||
|
require './static' |
||||
|
require './dynamic' |
@ -0,0 +1,23 @@ |
|||||
|
class Collection.Static extends Collection |
||||
|
|
||||
|
constructor: -> |
||||
|
super |
||||
|
@key_values = L.map @constructor.order, 0 |
||||
|
|
||||
|
more: -> @go ids: @scope |
||||
|
page: (i, params = {}) -> |
||||
|
new @constructor undefined, L.merge(params, page: i), @belongs_to |
||||
|
|
||||
|
prev: -> |
||||
|
key = @_get_key L.first(@scope) |
||||
|
@go before: key, (scope) => @scope = L.reverse(scope).concat @scope |
||||
|
|
||||
|
next: -> |
||||
|
key = @_get_key L.last(@scope) |
||||
|
@go after: key, (scope) => @scope = @scope.concat scope |
||||
|
|
||||
|
_get_key: (id) -> |
||||
|
object = @_object(id); key = [] |
||||
|
for attr in @key_values |
||||
|
if v = object[attr] then key.push(v) else return id |
||||
|
key |
@ -0,0 +1,28 @@ |
|||||
|
Primus = require('../../tools/communication/primus/primus') |
||||
|
|
||||
|
global.Dialog = |
||||
|
|
||||
|
init: -> |
||||
|
url = "#{location.protocol}//#{location.hostname}" |
||||
|
@primusI = Primus.connect "#{url}:8090" |
||||
|
@primusO = Primus.connect "#{url}:8091" |
||||
|
@pair_connections() |
||||
|
@listen_to_data() |
||||
|
|
||||
|
pair_connections: -> |
||||
|
@primusI.on 'open', => |
||||
|
@primusI.id (id) => |
||||
|
@primusO.write id |
||||
|
render() |
||||
|
|
||||
|
listen_to_data: -> |
||||
|
@primusO.on 'data', (data) -> |
||||
|
return if /primus::ping/.exec(data) |
||||
|
console.log data |
||||
|
Requests.receive data |
||||
|
|
||||
|
send: (data) -> |
||||
|
console.log data |
||||
|
@primusI.write data |
||||
|
|
||||
|
Dialog.init() |
@ -0,0 +1,22 @@ |
|||||
|
require './dialog' |
||||
|
require './cache' |
||||
|
require './collection' |
||||
|
|
||||
|
global.Requests = |
||||
|
|
||||
|
counter: 1 |
||||
|
|
||||
|
perform: (event, params = {}) -> |
||||
|
params.event = event |
||||
|
params.r = @counter++ |
||||
|
Dialog.send params |
||||
|
"#{params.r}_request" |
||||
|
|
||||
|
receive: (data) -> |
||||
|
parsed = JSON.parse(data) |
||||
|
parsed.raw = data |
||||
|
Store.patch parsed.data if parsed.data |
||||
|
Dispatcher.trigger parsed.event, parsed if parsed.event |
||||
|
Dispatcher.trigger("#{parsed.r}_request", parsed) if parsed.r |
||||
|
render() |
||||
|
parsed |
@ -0,0 +1,2 @@ |
|||||
|
var render = do this.render |
||||
|
global:render = L.throttle render.bind(#app), 17 # 60 fps |
@ -0,0 +1,9 @@ |
|||||
|
global.Actions = {} |
||||
|
|
||||
|
Dispatcher.on L.ns(__dirname, "update"), (data) -> |
||||
|
if object = Store.get_ref(data.ref) |
||||
|
object.v = data.v - 1 |
||||
|
LocalStore.update object, data.transition, data.params |
||||
|
|
||||
|
Dispatcher.on L.ns(__dirname, "delete"), (data) -> |
||||
|
LocalStore.delete object if object = Store.get_ref(data.ref) |
@ -0,0 +1,44 @@ |
|||||
|
Service __FILE__ do |
||||
|
|
||||
|
def perform(data) |
||||
|
collection = data[:object][:type].to_sym |
||||
|
|
||||
|
# insert |
||||
|
id = $models[collection].insert \ |
||||
|
sql_relations(collection, data[:relations]).merge \ |
||||
|
data: Sequel.pg_jsonb(data[:object].reject{ |k,_| [:id, :type].include? k }) |
||||
|
|
||||
|
# broadcast |
||||
|
serialized = {} |
||||
|
serialized[collection] = [ data[:object].reject{ |k| k == :type }.merge!(id: id) ] |
||||
|
serialized.merge! json_relations(collection, id, data[:relations]) |
||||
|
broadcast data, data: serialized |
||||
|
|
||||
|
# fix tmp_id in origin client |
||||
|
reply data, |
||||
|
change: { |
||||
|
collection: collection, |
||||
|
tmp_id: data[:object][:id], |
||||
|
id: id |
||||
|
} |
||||
|
end |
||||
|
|
||||
|
private |
||||
|
|
||||
|
def sql_relations(collection, references) |
||||
|
references.inject({}) { |h, (type, id)| |
||||
|
if model = $models[type.to_sym] |
||||
|
foreign_key = model.association_reflections[collection][:key] |
||||
|
h[foreign_key] = id |
||||
|
end |
||||
|
h |
||||
|
} |
||||
|
end |
||||
|
|
||||
|
def json_relations(collection, object_id, references) |
||||
|
references.inject(Hash.new([])) { |h, (type, id)| |
||||
|
h[type] += [{ id: id, collection => [object_id] }]; h |
||||
|
} |
||||
|
end |
||||
|
|
||||
|
end |
@ -0,0 +1,11 @@ |
|||||
|
Service __FILE__ do |
||||
|
|
||||
|
def perform(data) |
||||
|
effect = $models[data[:ref][0].to_sym] |
||||
|
.where(id: data[:ref][1]) |
||||
|
.delete |
||||
|
|
||||
|
broadcast data unless effect.zero? |
||||
|
end |
||||
|
|
||||
|
end |
@ -0,0 +1,17 @@ |
|||||
|
require './actions' |
||||
|
require './local' |
||||
|
|
||||
|
TmpIdsCheck = require './tmp_ids_check' |
||||
|
Remote = require './remote' |
||||
|
|
||||
|
global.Store = L.compose |
||||
|
|
||||
|
collections: {} |
||||
|
|
||||
|
get: (name, ids) -> |
||||
|
return [] unless name and ids |
||||
|
L.compact L.at(@collections[name], ids) |
||||
|
|
||||
|
get_ref: (reference) -> @get.apply(@, reference)[0] |
||||
|
|
||||
|
, TmpIdsCheck, Remote, LocalStore |
@ -0,0 +1,3 @@ |
|||||
|
require_relative './add' |
||||
|
require_relative './delete' |
||||
|
require_relative './update' |
@ -0,0 +1,31 @@ |
|||||
|
global.LocalStore = |
||||
|
|
||||
|
add: (name, object, relations) -> |
||||
|
Store.collections[name] ||= {} |
||||
|
Store.collections[name][object.id] = object |
||||
|
L.each relations, (relation) -> |
||||
|
relation[name].add_id(object.id) |
||||
|
|
||||
|
update: (object, transition, params) -> |
||||
|
Actions[transition](object, params) |
||||
|
object.v = (object.v || 0) + 1 |
||||
|
@_change(object) |
||||
|
render() |
||||
|
|
||||
|
delete: (object) -> |
||||
|
delete Store.collections[object.type][object.id] |
||||
|
@_change(object) |
||||
|
render() |
||||
|
|
||||
|
patch: (collections) -> |
||||
|
L.each collections, (objects, type) -> |
||||
|
collection = Store.collections[type] ||= {} |
||||
|
L.each objects, (object) -> |
||||
|
object.type ||= type |
||||
|
L.mergeWith (collection[object.id] ||= {}), object, (prev, next) -> |
||||
|
if prev and L.isArray(next) |
||||
|
L.each next, (n) -> prev.add_id(n) |
||||
|
prev |
||||
|
|
||||
|
_change: (object) -> |
||||
|
Dispatcher.trigger "#{object.type}_change", object.id |
@ -0,0 +1,32 @@ |
|||||
|
module.exports = |
||||
|
add: (name, object, relations) -> |
||||
|
object['id'] = L.uniqueId("tmp") |
||||
|
object['type'] = name |
||||
|
|
||||
|
Dispatcher.once Requests.perform(L.ns(__dirname, 'add'), |
||||
|
object: L.assign {}, object |
||||
|
relations: L.map(relations, L.reference) |
||||
|
), (data) -> |
||||
|
change = data.change |
||||
|
# find object with tmp_id |
||||
|
object = Store.get(change.collection, change.tmp_id)[0] |
||||
|
old_id = object.id |
||||
|
object.id = change.id |
||||
|
# store object with real id |
||||
|
Store.collections[change.collection][change.id] = object |
||||
|
delete Store.collections[change.collection][change.tmp_id] |
||||
|
Dispatcher.trigger "#{change.tmp_id}_to_id" |
||||
|
arguments |
||||
|
|
||||
|
update: (object, transition, params) -> |
||||
|
Requests.perform L.ns(__dirname, 'update'), { |
||||
|
params |
||||
|
transition |
||||
|
ref: L.reference(object) |
||||
|
v: object.v |
||||
|
} |
||||
|
arguments |
||||
|
|
||||
|
delete: (object) -> |
||||
|
Requests.perform L.ns(__dirname, 'delete'), ref: L.reference(object) |
||||
|
arguments |
@ -0,0 +1,19 @@ |
|||||
|
H = |
||||
|
all: (objects, action, args) -> |
||||
|
L.wait_for_real_id objects, -> action.apply(null, args) |
||||
|
|
||||
|
module.exports = |
||||
|
add: (name, object, relations) -> |
||||
|
if H.all relations, @add, arguments |
||||
|
arguments |
||||
|
else false |
||||
|
|
||||
|
update: (object) -> |
||||
|
if H.all [object], @update, arguments |
||||
|
arguments |
||||
|
else false |
||||
|
|
||||
|
delete: (object) -> |
||||
|
if H.all [object], @delete, arguments |
||||
|
arguments |
||||
|
else false |
@ -0,0 +1,18 @@ |
|||||
|
Service __FILE__ do |
||||
|
|
||||
|
def perform(data) |
||||
|
model = $models[data[:ref][0].to_sym] |
||||
|
|
||||
|
unless model.immutable |
||||
|
function = data[:transition].gsub('/', '_') |
||||
|
data[:v] = data[:v].to_i |
||||
|
inc_v = data[:v] + 1 |
||||
|
effect = model |
||||
|
.where(id: data[:ref][1], v: data[:v]) |
||||
|
.update("data = #{function}('#{data[:ref].to_json}', '#{data[:params].to_json}'), |
||||
|
v = #{inc_v}") |
||||
|
broadcast data.merge v: inc_v unless effect.zero? |
||||
|
end |
||||
|
end |
||||
|
|
||||
|
end |
@ -0,0 +1,10 @@ |
|||||
|
FROM node |
||||
|
|
||||
|
RUN mkdir -p /pro/node_modules |
||||
|
WORKDIR /pro |
||||
|
|
||||
|
RUN npm install -g webpack@3.5.5 |
||||
|
|
||||
|
ADD framework/tools/bundler/webpack/package.json package.json |
||||
|
RUN npm install |
||||
|
RUN rm package.json |
@ -0,0 +1,24 @@ |
|||||
|
## Role |
||||
|
|
||||
|
Bundling static files and serving them for development - HTML, JS, CSS, |
||||
|
images. |
||||
|
|
||||
|
## Setup |
||||
|
|
||||
|
``` |
||||
|
npm install webpack -g |
||||
|
``` |
||||
|
|
||||
|
``` |
||||
|
cd tools/webpack |
||||
|
npm install |
||||
|
``` |
||||
|
|
||||
|
## Procfile |
||||
|
|
||||
|
``` |
||||
|
static-files: sh -c 'cd ./tools/webpack && exec npm start' |
||||
|
``` |
||||
|
## Documentation |
||||
|
|
||||
|
[http://webpack.github.io/docs/tutorials/getting-started](http://webpack.github.io/docs/tutorials/getting-started/) |
@ -0,0 +1,11 @@ |
|||||
|
assets: |
||||
|
build: |
||||
|
context: . |
||||
|
dockerfile: ./Dockerfile.assets |
||||
|
volumes: |
||||
|
- .:/pro |
||||
|
- /pro/node_modules |
||||
|
ports: |
||||
|
- "8080:8080" |
||||
|
working_dir: /pro/framework/tools/bundler/webpack |
||||
|
command: webpack --watch --config webpack.prod.config.js |
@ -0,0 +1 @@ |
|||||
|
../../../../node_modules |
@ -0,0 +1,34 @@ |
|||||
|
{ |
||||
|
"name": "webpack", |
||||
|
"version": "1.0.0", |
||||
|
"description": "", |
||||
|
"main": "webpack.config.js", |
||||
|
"scripts": { |
||||
|
"test": "echo \"Error: no test specified\" && exit 1", |
||||
|
"webpack-server": "webpack --watch" |
||||
|
}, |
||||
|
"author": "", |
||||
|
"license": "ISC", |
||||
|
"dependencies": { |
||||
|
"autoprefixer-loader": "^3.2.0", |
||||
|
"coffee-loader": "^0.7.2", |
||||
|
"coffee-script": "^1.10.0", |
||||
|
"css-loader": "^0.23.1", |
||||
|
"file-loader": "^0.8.5", |
||||
|
"http-server": "^0.9.0", |
||||
|
"img-loader": "^1.2.2", |
||||
|
"node-sass": "^3.4.2", |
||||
|
"postcss-loader": "^0.8.2", |
||||
|
"sass-loader": "^3.2.0", |
||||
|
"style-loader": "^0.13.1", |
||||
|
"svgo": "^0.6.4", |
||||
|
"svgo-loader": "^1.1.0", |
||||
|
"url-loader": "^0.5.7", |
||||
|
"backbone-events-standalone": "^0.2.7", |
||||
|
"imba": "somebee/imba", |
||||
|
"lodash": "^4.11.1", |
||||
|
"pro-router": "^4.3.0", |
||||
|
"compression-webpack-plugin": "^1.0.0", |
||||
|
"webpack": "^3.5.5" |
||||
|
} |
||||
|
} |
@ -0,0 +1,43 @@ |
|||||
|
const path = require('path'); |
||||
|
module.exports = { |
||||
|
context: __dirname, |
||||
|
entry: '../../../services/init', |
||||
|
node: { |
||||
|
__dirname: true |
||||
|
}, |
||||
|
output: { |
||||
|
path: __dirname + '/../../../public', |
||||
|
filename: 'bundle.js' |
||||
|
}, |
||||
|
devtool: 'eval', |
||||
|
module: { |
||||
|
rules: [ |
||||
|
{ |
||||
|
test: /\.s(c|a)ss$/, |
||||
|
use: [ |
||||
|
{ loader: 'style-loader' }, |
||||
|
{ loader: 'css-loader' }, |
||||
|
{ loader: 'autoprefixer-loader', options: { browsers: 'last 3 versions' } }, |
||||
|
{ loader: 'sass-loader', options: { outputStyle: 'expanded' } } |
||||
|
] |
||||
|
}, |
||||
|
{ |
||||
|
test: /\.(jpe?g|png|gif|svg)$/i, |
||||
|
use: [ |
||||
|
{ loader: 'url-loader', options: { limit: 8192 } }, |
||||
|
{ loader: 'img-loader' } |
||||
|
] |
||||
|
}, |
||||
|
{ test: /\.woff$/, use: [ { loader: 'url-loader', options: { limit: 65000, mimetype: 'application/font-woff', name: 'public/fonts/[name].[ext]' } } ] }, |
||||
|
{ test: /\.woff2$/, use: [ { loader: 'url-loader', options: { limit: 65000, mimetype: 'application/font-woff2', name: 'public/fonts/[name].[ext]' } } ] }, |
||||
|
{ test: /\.[ot]tf$/, use: [ { loader: 'url-loader', options: { limit: 65000, mimetype: 'application/octet-stream', name: 'public/fonts/[name].[ext]' } } ] }, |
||||
|
{ test: /\.eot$/, use: [ { loader: 'url-loader', options: { limit: 65000, mimetype: 'application/vnd.ms-fontobject', name: 'public/fonts/[name].[ext]' } } ] }, |
||||
|
|
||||
|
{ test: /\.imba/, use: [ 'imba/loader' ]}, |
||||
|
{ test: /\.coffee/, use: [ 'coffee-loader' ]} |
||||
|
] |
||||
|
}, |
||||
|
resolve: { |
||||
|
extensions: ['.imba', '.js', '.coffee' ] |
||||
|
} |
||||
|
}; |
@ -0,0 +1,74 @@ |
|||||
|
const webpack = require('webpack'); |
||||
|
const CompressionPlugin = require("compression-webpack-plugin"); |
||||
|
const path = require('path'); |
||||
|
module.exports = { |
||||
|
cache: false, |
||||
|
context: __dirname, |
||||
|
entry: '../../../services/init', |
||||
|
node: { |
||||
|
__dirname: true |
||||
|
}, |
||||
|
output: { |
||||
|
path: __dirname + '/../../../public', |
||||
|
filename: 'bundle.js' |
||||
|
}, |
||||
|
devtool: 'cheap-module-source-map', |
||||
|
plugins: [ |
||||
|
new webpack.DefinePlugin({ |
||||
|
'process.env.NODE_ENV': '"production"' |
||||
|
}), |
||||
|
new webpack.optimize.UglifyJsPlugin({ |
||||
|
mangle: true, |
||||
|
compress: { |
||||
|
warnings: false, // Suppress uglification warnings
|
||||
|
pure_getters: true, |
||||
|
unsafe: true, |
||||
|
unsafe_comps: true, |
||||
|
screw_ie8: true |
||||
|
}, |
||||
|
output: { |
||||
|
comments: false, |
||||
|
}, |
||||
|
exclude: [/\.min\.js$/gi] // skip pre-minified libs
|
||||
|
}), |
||||
|
new webpack.IgnorePlugin(/^\.\/locale$/, [/moment$/]), |
||||
|
new webpack.NoEmitOnErrorsPlugin(), |
||||
|
new CompressionPlugin({ |
||||
|
asset: "[path].gz[query]", |
||||
|
algorithm: "gzip", |
||||
|
test: /\.js$|\.css$|\.html$/, |
||||
|
threshold: 10240, |
||||
|
minRatio: 0 |
||||
|
}) |
||||
|
], |
||||
|
module: { |
||||
|
rules: [ |
||||
|
{ |
||||
|
test: /\.s(c|a)ss$/, |
||||
|
use: [ |
||||
|
{ loader: 'style-loader' }, |
||||
|
{ loader: 'css-loader' }, |
||||
|
{ loader: 'autoprefixer-loader', options: { browsers: 'last 3 versions' } }, |
||||
|
{ loader: 'sass-loader', options: { outputStyle: 'expanded' } } |
||||
|
] |
||||
|
}, |
||||
|
{ |
||||
|
test: /\.(jpe?g|png|gif|svg)$/i, |
||||
|
use: [ |
||||
|
{ loader: 'url-loader', options: { limit: 8192 } }, |
||||
|
{ loader: 'img-loader' } |
||||
|
] |
||||
|
}, |
||||
|
{ test: /\.woff$/, use: [ { loader: 'url-loader', options: { limit: 65000, mimetype: 'application/font-woff', name: 'public/fonts/[name].[ext]' } } ] }, |
||||
|
{ test: /\.woff2$/, use: [ { loader: 'url-loader', options: { limit: 65000, mimetype: 'application/font-woff2', name: 'public/fonts/[name].[ext]' } } ] }, |
||||
|
{ test: /\.[ot]tf$/, use: [ { loader: 'url-loader', options: { limit: 65000, mimetype: 'application/octet-stream', name: 'public/fonts/[name].[ext]' } } ] }, |
||||
|
{ test: /\.eot$/, use: [ { loader: 'url-loader', options: { limit: 65000, mimetype: 'application/vnd.ms-fontobject', name: 'public/fonts/[name].[ext]' } } ] }, |
||||
|
|
||||
|
{ test: /\.imba/, use: [ 'imba/loader' ]}, |
||||
|
{ test: /\.coffee/, use: [ 'coffee-loader' ]} |
||||
|
] |
||||
|
}, |
||||
|
resolve: { |
||||
|
extensions: ['.imba', '.js', '.coffee' ] |
||||
|
} |
||||
|
}; |
@ -0,0 +1,7 @@ |
|||||
|
FROM debian:latest |
||||
|
|
||||
|
RUN mkdir -p /tmp/disque-deb |
||||
|
|
||||
|
ADD disque-1.0-rc1-0192ba7e-amd64.deb /tmp/disque-deb/disque-1.0-rc1-0192ba7e-amd64.deb |
||||
|
|
||||
|
RUN dpkg -i /tmp/disque-deb/disque-1.0-rc1-0192ba7e-amd64.deb |
@ -0,0 +1,14 @@ |
|||||
|
## Role |
||||
|
|
||||
|
Communication bus. |
||||
|
|
||||
|
|
||||
|
## Setup |
||||
|
|
||||
|
[https://github.com/antirez/disque#setup](https://github.com/antirez/disque#setup) |
||||
|
|
||||
|
## Procfile |
||||
|
|
||||
|
``` |
||||
|
bus: disque-server |
||||
|
``` |
@ -0,0 +1,2 @@ |
|||||
|
disque_host: bus |
||||
|
disque_port: '7711' |
Binary file not shown.
@ -0,0 +1,8 @@ |
|||||
|
bus: |
||||
|
build: framework/tools/bus/disque |
||||
|
extends: |
||||
|
file: framework/tools/containers/docker/common.yml |
||||
|
service: pro |
||||
|
command: disque-server |
||||
|
ports: |
||||
|
- "7711:7711" |
@ -0,0 +1,31 @@ |
|||||
|
## Role |
||||
|
|
||||
|
Mobile versions of application. |
||||
|
|
||||
|
## Install |
||||
|
|
||||
|
``` |
||||
|
npm install cordova -g |
||||
|
``` |
||||
|
|
||||
|
## Setup |
||||
|
|
||||
|
You need to add a platform for which you want to build your app. |
||||
|
For example: |
||||
|
|
||||
|
``` |
||||
|
cordova platform add browser |
||||
|
``` |
||||
|
|
||||
|
## Run |
||||
|
|
||||
|
``` |
||||
|
# application is already running (foreman start) |
||||
|
|
||||
|
cd tools/cordova |
||||
|
cordova run browser |
||||
|
``` |
||||
|
|
||||
|
## Documentation |
||||
|
|
||||
|
[https://cordova.apache.org/docs/en/latest](https://cordova.apache.org/docs/en/latest) |
@ -0,0 +1,26 @@ |
|||||
|
<?xml version='1.0' encoding='utf-8'?> |
||||
|
<widget id="io.cordova.hellocordova" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0"> |
||||
|
<name>HelloCordova</name> |
||||
|
<description> |
||||
|
A sample Apache Cordova application that responds to the deviceready event. |
||||
|
</description> |
||||
|
<author email="dev@cordova.apache.org" href="http://cordova.io"> |
||||
|
Apache Cordova Team |
||||
|
</author> |
||||
|
<content src="index.html" /> |
||||
|
<plugin name="cordova-plugin-whitelist" spec="1" /> |
||||
|
<access origin="*" /> |
||||
|
<allow-intent href="http://*/*" /> |
||||
|
<allow-intent href="https://*/*" /> |
||||
|
<allow-intent href="tel:*" /> |
||||
|
<allow-intent href="sms:*" /> |
||||
|
<allow-intent href="mailto:*" /> |
||||
|
<allow-intent href="geo:*" /> |
||||
|
<platform name="android"> |
||||
|
<allow-intent href="market:*" /> |
||||
|
</platform> |
||||
|
<platform name="ios"> |
||||
|
<allow-intent href="itms:*" /> |
||||
|
<allow-intent href="itms-apps:*" /> |
||||
|
</platform> |
||||
|
</widget> |
@ -0,0 +1,23 @@ |
|||||
|
<!-- |
||||
|
# |
||||
|
# Licensed to the Apache Software Foundation (ASF) under one |
||||
|
# or more contributor license agreements. See the NOTICE file |
||||
|
# distributed with this work for additional information |
||||
|
# regarding copyright ownership. The ASF licenses this file |
||||
|
# to you under the Apache License, Version 2.0 (the |
||||
|
# "License"); you may not use this file except in compliance |
||||
|
# with the License. You may obtain a copy of the License at |
||||
|
# |
||||
|
# http://www.apache.org/licenses/LICENSE-2.0 |
||||
|
# |
||||
|
# Unless required by applicable law or agreed to in writing, |
||||
|
# software distributed under the License is distributed on an |
||||
|
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
||||
|
# KIND, either express or implied. See the License for the |
||||
|
# specific language governing permissions and limitations |
||||
|
# under the License. |
||||
|
# |
||||
|
--> |
||||
|
# Cordova Hooks |
||||
|
|
||||
|
Cordova Hooks represent special scripts which could be added by application and plugin developers or even by your own build system to customize cordova commands. See Hooks Guide for more details: http://cordova.apache.org/docs/en/edge/guide_appdev_hooks_index.md.html#Hooks%20Guide. |
@ -0,0 +1 @@ |
|||||
|
{} |
@ -0,0 +1,37 @@ |
|||||
|
<!-- |
||||
|
# |
||||
|
# Licensed to the Apache Software Foundation (ASF) under one |
||||
|
# or more contributor license agreements. See the NOTICE file |
||||
|
# distributed with this work for additional information |
||||
|
# regarding copyright ownership. The ASF licenses this file |
||||
|
# to you under the Apache License, Version 2.0 (the |
||||
|
# "License"); you may not use this file except in compliance |
||||
|
# with the License. You may obtain a copy of the License at |
||||
|
# |
||||
|
# http://www.apache.org/licenses/LICENSE-2.0 |
||||
|
# |
||||
|
# Unless required by applicable law or agreed to in writing, |
||||
|
# software distributed under the License is distributed on an |
||||
|
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
||||
|
# KIND, either express or implied. See the License for the |
||||
|
# specific language governing permissions and limitations |
||||
|
# under the License. |
||||
|
# |
||||
|
--> |
||||
|
|
||||
|
# Contributing to Apache Cordova |
||||
|
|
||||
|
Anyone can contribute to Cordova. And we need your contributions. |
||||
|
|
||||
|
There are multiple ways to contribute: report bugs, improve the docs, and |
||||
|
contribute code. |
||||
|
|
||||
|
For instructions on this, start with the |
||||
|
[contribution overview](http://cordova.apache.org/contribute/). |
||||
|
|
||||
|
The details are explained there, but the important items are: |
||||
|
- Sign and submit an Apache ICLA (Contributor License Agreement). |
||||
|
- Have a Jira issue open that corresponds to your contribution. |
||||
|
- Run the tests so your patch doesn't break existing functionality. |
||||
|
|
||||
|
We look forward to your contributions! |
@ -0,0 +1,202 @@ |
|||||
|
|
||||
|
Apache License |
||||
|
Version 2.0, January 2004 |
||||
|
http://www.apache.org/licenses/ |
||||
|
|
||||
|
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION |
||||
|
|
||||
|
1. Definitions. |
||||
|
|
||||
|
"License" shall mean the terms and conditions for use, reproduction, |
||||
|
and distribution as defined by Sections 1 through 9 of this document. |
||||
|
|
||||
|
"Licensor" shall mean the copyright owner or entity authorized by |
||||
|
the copyright owner that is granting the License. |
||||
|
|
||||
|
"Legal Entity" shall mean the union of the acting entity and all |
||||
|
other entities that control, are controlled by, or are under common |
||||
|
control with that entity. For the purposes of this definition, |
||||
|
"control" means (i) the power, direct or indirect, to cause the |
||||
|
direction or management of such entity, whether by contract or |
||||
|
otherwise, or (ii) ownership of fifty percent (50%) or more of the |
||||
|
outstanding shares, or (iii) beneficial ownership of such entity. |
||||
|
|
||||
|
"You" (or "Your") shall mean an individual or Legal Entity |
||||
|
exercising permissions granted by this License. |
||||
|
|
||||
|
"Source" form shall mean the preferred form for making modifications, |
||||
|
including but not limited to software source code, documentation |
||||
|
source, and configuration files. |
||||
|
|
||||
|
"Object" form shall mean any form resulting from mechanical |
||||
|
transformation or translation of a Source form, including but |
||||
|
not limited to compiled object code, generated documentation, |
||||
|
and conversions to other media types. |
||||
|
|
||||
|
"Work" shall mean the work of authorship, whether in Source or |
||||
|
Object form, made available under the License, as indicated by a |
||||
|
copyright notice that is included in or attached to the work |
||||
|
(an example is provided in the Appendix below). |
||||
|
|
||||
|
"Derivative Works" shall mean any work, whether in Source or Object |
||||
|
form, that is based on (or derived from) the Work and for which the |
||||
|
editorial revisions, annotations, elaborations, or other modifications |
||||
|
represent, as a whole, an original work of authorship. For the purposes |
||||
|
of this License, Derivative Works shall not include works that remain |
||||
|
separable from, or merely link (or bind by name) to the interfaces of, |
||||
|
the Work and Derivative Works thereof. |
||||
|
|
||||
|
"Contribution" shall mean any work of authorship, including |
||||
|
the original version of the Work and any modifications or additions |
||||
|
to that Work or Derivative Works thereof, that is intentionally |
||||
|
submitted to Licensor for inclusion in the Work by the copyright owner |
||||
|
or by an individual or Legal Entity authorized to submit on behalf of |
||||
|
the copyright owner. For the purposes of this definition, "submitted" |
||||
|
means any form of electronic, verbal, or written communication sent |
||||
|
to the Licensor or its representatives, including but not limited to |
||||
|
communication on electronic mailing lists, source code control systems, |
||||
|
and issue tracking systems that are managed by, or on behalf of, the |
||||
|
Licensor for the purpose of discussing and improving the Work, but |
||||
|
excluding communication that is conspicuously marked or otherwise |
||||
|
designated in writing by the copyright owner as "Not a Contribution." |
||||
|
|
||||
|
"Contributor" shall mean Licensor and any individual or Legal Entity |
||||
|
on behalf of whom a Contribution has been received by Licensor and |
||||
|
subsequently incorporated within the Work. |
||||
|
|
||||
|
2. Grant of Copyright License. Subject to the terms and conditions of |
||||
|
this License, each Contributor hereby grants to You a perpetual, |
||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable |
||||
|
copyright license to reproduce, prepare Derivative Works of, |
||||
|
publicly display, publicly perform, sublicense, and distribute the |
||||
|
Work and such Derivative Works in Source or Object form. |
||||
|
|
||||
|
3. Grant of Patent License. Subject to the terms and conditions of |
||||
|
this License, each Contributor hereby grants to You a perpetual, |
||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable |
||||
|
(except as stated in this section) patent license to make, have made, |
||||
|
use, offer to sell, sell, import, and otherwise transfer the Work, |
||||
|
where such license applies only to those patent claims licensable |
||||
|
by such Contributor that are necessarily infringed by their |
||||
|
Contribution(s) alone or by combination of their Contribution(s) |
||||
|
with the Work to which such Contribution(s) was submitted. If You |
||||
|
institute patent litigation against any entity (including a |
||||
|
cross-claim or counterclaim in a lawsuit) alleging that the Work |
||||
|
or a Contribution incorporated within the Work constitutes direct |
||||
|
or contributory patent infringement, then any patent licenses |
||||
|
granted to You under this License for that Work shall terminate |
||||
|
as of the date such litigation is filed. |
||||
|
|
||||
|
4. Redistribution. You may reproduce and distribute copies of the |
||||
|
Work or Derivative Works thereof in any medium, with or without |
||||
|
modifications, and in Source or Object form, provided that You |
||||
|
meet the following conditions: |
||||
|
|
||||
|
(a) You must give any other recipients of the Work or |
||||
|
Derivative Works a copy of this License; and |
||||
|
|
||||
|
(b) You must cause any modified files to carry prominent notices |
||||
|
stating that You changed the files; and |
||||
|
|
||||
|
(c) You must retain, in the Source form of any Derivative Works |
||||
|
that You distribute, all copyright, patent, trademark, and |
||||
|
attribution notices from the Source form of the Work, |
||||
|
excluding those notices that do not pertain to any part of |
||||
|
the Derivative Works; and |
||||
|
|
||||
|
(d) If the Work includes a "NOTICE" text file as part of its |
||||
|
distribution, then any Derivative Works that You distribute must |
||||
|
include a readable copy of the attribution notices contained |
||||
|
within such NOTICE file, excluding those notices that do not |
||||
|
pertain to any part of the Derivative Works, in at least one |
||||
|
of the following places: within a NOTICE text file distributed |
||||
|
as part of the Derivative Works; within the Source form or |
||||
|
documentation, if provided along with the Derivative Works; or, |
||||
|
within a display generated by the Derivative Works, if and |
||||
|
wherever such third-party notices normally appear. The contents |
||||
|
of the NOTICE file are for informational purposes only and |
||||
|
do not modify the License. You may add Your own attribution |
||||
|
notices within Derivative Works that You distribute, alongside |
||||
|
or as an addendum to the NOTICE text from the Work, provided |
||||
|
that such additional attribution notices cannot be construed |
||||
|
as modifying the License. |
||||
|
|
||||
|
You may add Your own copyright statement to Your modifications and |
||||
|
may provide additional or different license terms and conditions |
||||
|
for use, reproduction, or distribution of Your modifications, or |
||||
|
for any such Derivative Works as a whole, provided Your use, |
||||
|
reproduction, and distribution of the Work otherwise complies with |
||||
|
the conditions stated in this License. |
||||
|
|
||||
|
5. Submission of Contributions. Unless You explicitly state otherwise, |
||||
|
any Contribution intentionally submitted for inclusion in the Work |
||||
|
by You to the Licensor shall be under the terms and conditions of |
||||
|
this License, without any additional terms or conditions. |
||||
|
Notwithstanding the above, nothing herein shall supersede or modify |
||||
|
the terms of any separate license agreement you may have executed |
||||
|
with Licensor regarding such Contributions. |
||||
|
|
||||
|
6. Trademarks. This License does not grant permission to use the trade |
||||
|
names, trademarks, service marks, or product names of the Licensor, |
||||
|
except as required for reasonable and customary use in describing the |
||||
|
origin of the Work and reproducing the content of the NOTICE file. |
||||
|
|
||||
|
7. Disclaimer of Warranty. Unless required by applicable law or |
||||
|
agreed to in writing, Licensor provides the Work (and each |
||||
|
Contributor provides its Contributions) on an "AS IS" BASIS, |
||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
||||
|
implied, including, without limitation, any warranties or conditions |
||||
|
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A |
||||
|
PARTICULAR PURPOSE. You are solely responsible for determining the |
||||
|
appropriateness of using or redistributing the Work and assume any |
||||
|
risks associated with Your exercise of permissions under this License. |
||||
|
|
||||
|
8. Limitation of Liability. In no event and under no legal theory, |
||||
|
whether in tort (including negligence), contract, or otherwise, |
||||
|
unless required by applicable law (such as deliberate and grossly |
||||
|
negligent acts) or agreed to in writing, shall any Contributor be |
||||
|
liable to You for damages, including any direct, indirect, special, |
||||
|
incidental, or consequential damages of any character arising as a |
||||
|
result of this License or out of the use or inability to use the |
||||
|
Work (including but not limited to damages for loss of goodwill, |
||||
|
work stoppage, computer failure or malfunction, or any and all |
||||
|
other commercial damages or losses), even if such Contributor |
||||
|
has been advised of the possibility of such damages. |
||||
|
|
||||
|
9. Accepting Warranty or Additional Liability. While redistributing |
||||
|
the Work or Derivative Works thereof, You may choose to offer, |
||||
|
and charge a fee for, acceptance of support, warranty, indemnity, |
||||
|
or other liability obligations and/or rights consistent with this |
||||
|
License. However, in accepting such obligations, You may act only |
||||
|
on Your own behalf and on Your sole responsibility, not on behalf |
||||
|
of any other Contributor, and only if You agree to indemnify, |
||||
|
defend, and hold each Contributor harmless for any liability |
||||
|
incurred by, or claims asserted against, such Contributor by reason |
||||
|
of your accepting any such warranty or additional liability. |
||||
|
|
||||
|
END OF TERMS AND CONDITIONS |
||||
|
|
||||
|
APPENDIX: How to apply the Apache License to your work. |
||||
|
|
||||
|
To apply the Apache License to your work, attach the following |
||||
|
boilerplate notice, with the fields enclosed by brackets "[]" |
||||
|
replaced with your own identifying information. (Don't include |
||||
|
the brackets!) The text should be enclosed in the appropriate |
||||
|
comment syntax for the file format. We also recommend that a |
||||
|
file or class name and description of purpose be included on the |
||||
|
same "printed page" as the copyright notice for easier |
||||
|
identification within third-party archives. |
||||
|
|
||||
|
Copyright [yyyy] [name of copyright owner] |
||||
|
|
||||
|
Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
you may not use this file except in compliance with the License. |
||||
|
You may obtain a copy of the License at |
||||
|
|
||||
|
http://www.apache.org/licenses/LICENSE-2.0 |
||||
|
|
||||
|
Unless required by applicable law or agreed to in writing, software |
||||
|
distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
See the License for the specific language governing permissions and |
||||
|
limitations under the License. |
@ -0,0 +1,5 @@ |
|||||
|
Apache Cordova |
||||
|
Copyright 2012 The Apache Software Foundation |
||||
|
|
||||
|
This product includes software developed at |
||||
|
The Apache Software Foundation (http://www.apache.org/). |
@ -0,0 +1,151 @@ |
|||||
|
<!-- |
||||
|
# license: Licensed to the Apache Software Foundation (ASF) under one |
||||
|
# or more contributor license agreements. See the NOTICE file |
||||
|
# distributed with this work for additional information |
||||
|
# regarding copyright ownership. The ASF licenses this file |
||||
|
# to you under the Apache License, Version 2.0 (the |
||||
|
# "License"); you may not use this file except in compliance |
||||
|
# with the License. You may obtain a copy of the License at |
||||
|
# |
||||
|
# http://www.apache.org/licenses/LICENSE-2.0 |
||||
|
# |
||||
|
# Unless required by applicable law or agreed to in writing, |
||||
|
# software distributed under the License is distributed on an |
||||
|
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
||||
|
# KIND, either express or implied. See the License for the |
||||
|
# specific language governing permissions and limitations |
||||
|
# under the License. |
||||
|
--> |
||||
|
|
||||
|
# cordova-plugin-whitelist |
||||
|
|
||||
|
This plugin implements a whitelist policy for navigating the application webview on Cordova 4.0 |
||||
|
|
||||
|
:warning: Report issues on the [Apache Cordova issue tracker](https://issues.apache.org/jira/issues/?jql=project%20%3D%20CB%20AND%20status%20in%20%28Open%2C%20%22In%20Progress%22%2C%20Reopened%29%20AND%20resolution%20%3D%20Unresolved%20AND%20component%20%3D%20%22Plugin%20Whitelist%22%20ORDER%20BY%20priority%20DESC%2C%20summary%20ASC%2C%20updatedDate%20DESC) |
||||
|
|
||||
|
|
||||
|
## Supported Cordova Platforms |
||||
|
|
||||
|
* Android 4.0.0 or above |
||||
|
|
||||
|
## Navigation Whitelist |
||||
|
Controls which URLs the WebView itself can be navigated to. Applies to |
||||
|
top-level navigations only. |
||||
|
|
||||
|
Quirks: on Android it also applies to iframes for non-http(s) schemes. |
||||
|
|
||||
|
By default, navigations only to `file://` URLs, are allowed. To allow others URLs, you must add `<allow-navigation>` tags to your `config.xml`: |
||||
|
|
||||
|
<!-- Allow links to example.com --> |
||||
|
<allow-navigation href="http://example.com/*" /> |
||||
|
|
||||
|
<!-- Wildcards are allowed for the protocol, as a prefix |
||||
|
to the host, or as a suffix to the path --> |
||||
|
<allow-navigation href="*://*.example.com/*" /> |
||||
|
|
||||
|
<!-- A wildcard can be used to whitelist the entire network, |
||||
|
over HTTP and HTTPS. |
||||
|
*NOT RECOMMENDED* --> |
||||
|
<allow-navigation href="*" /> |
||||
|
|
||||
|
<!-- The above is equivalent to these three declarations --> |
||||
|
<allow-navigation href="http://*/*" /> |
||||
|
<allow-navigation href="https://*/*" /> |
||||
|
<allow-navigation href="data:*" /> |
||||
|
|
||||
|
## Intent Whitelist |
||||
|
Controls which URLs the app is allowed to ask the system to open. |
||||
|
By default, no external URLs are allowed. |
||||
|
|
||||
|
On Android, this equates to sending an intent of type BROWSEABLE. |
||||
|
|
||||
|
This whitelist does not apply to plugins, only hyperlinks and calls to `window.open()`. |
||||
|
|
||||
|
In `config.xml`, add `<allow-intent>` tags, like this: |
||||
|
|
||||
|
<!-- Allow links to web pages to open in a browser --> |
||||
|
<allow-intent href="http://*/*" /> |
||||
|
<allow-intent href="https://*/*" /> |
||||
|
|
||||
|
<!-- Allow links to example.com to open in a browser --> |
||||
|
<allow-intent href="http://example.com/*" /> |
||||
|
|
||||
|
<!-- Wildcards are allowed for the protocol, as a prefix |
||||
|
to the host, or as a suffix to the path --> |
||||
|
<allow-intent href="*://*.example.com/*" /> |
||||
|
|
||||
|
<!-- Allow SMS links to open messaging app --> |
||||
|
<allow-intent href="sms:*" /> |
||||
|
|
||||
|
<!-- Allow tel: links to open the dialer --> |
||||
|
<allow-intent href="tel:*" /> |
||||
|
|
||||
|
<!-- Allow geo: links to open maps --> |
||||
|
<allow-intent href="geo:*" /> |
||||
|
|
||||
|
<!-- Allow all unrecognized URLs to open installed apps |
||||
|
*NOT RECOMMENDED* --> |
||||
|
<allow-intent href="*" /> |
||||
|
|
||||
|
## Network Request Whitelist |
||||
|
Controls which network requests (images, XHRs, etc) are allowed to be made (via cordova native hooks). |
||||
|
|
||||
|
Note: We suggest you use a Content Security Policy (see below), which is more secure. This whitelist is mostly historical for webviews which do not support CSP. |
||||
|
|
||||
|
In `config.xml`, add `<access>` tags, like this: |
||||
|
|
||||
|
<!-- Allow images, xhrs, etc. to google.com --> |
||||
|
<access origin="http://google.com" /> |
||||
|
<access origin="https://google.com" /> |
||||
|
|
||||
|
<!-- Access to the subdomain maps.google.com --> |
||||
|
<access origin="http://maps.google.com" /> |
||||
|
|
||||
|
<!-- Access to all the subdomains on google.com --> |
||||
|
<access origin="http://*.google.com" /> |
||||
|
|
||||
|
<!-- Enable requests to content: URLs --> |
||||
|
<access origin="content:///*" /> |
||||
|
|
||||
|
<!-- Don't block any requests --> |
||||
|
<access origin="*" /> |
||||
|
|
||||
|
Without any `<access>` tags, only requests to `file://` URLs are allowed. However, the default Cordova application includes `<access origin="*">` by default. |
||||
|
|
||||
|
|
||||
|
Note: Whitelist cannot block network redirects from a whitelisted remote website (i.e. http or https) to a non-whitelisted website. Use CSP rules to mitigate redirects to non-whitelisted websites for webviews that support CSP. |
||||
|
|
||||
|
Quirk: Android also allows requests to https://ssl.gstatic.com/accessibility/javascript/android/ by default, since this is required for TalkBack to function properly. |
||||
|
|
||||
|
### Content Security Policy |
||||
|
Controls which network requests (images, XHRs, etc) are allowed to be made (via webview directly). |
||||
|
|
||||
|
On Android and iOS, the network request whitelist (see above) is not able to filter all types of requests (e.g. `<video>` & WebSockets are not blocked). So, in addition to the whitelist, you should use a [Content Security Policy](http://content-security-policy.com/) `<meta>` tag on all of your pages. |
||||
|
|
||||
|
On Android, support for CSP within the system webview starts with KitKat (but is available on all versions using Crosswalk WebView). |
||||
|
|
||||
|
Here are some example CSP declarations for your `.html` pages: |
||||
|
|
||||
|
<!-- Good default declaration: |
||||
|
* gap: is required only on iOS (when using UIWebView) and is needed for JS->native communication |
||||
|
* https://ssl.gstatic.com is required only on Android and is needed for TalkBack to function properly |
||||
|
* Disables use of eval() and inline scripts in order to mitigate risk of XSS vulnerabilities. To change this: |
||||
|
* Enable inline JS: add 'unsafe-inline' to default-src |
||||
|
* Enable eval(): add 'unsafe-eval' to default-src |
||||
|
--> |
||||
|
<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com; style-src 'self' 'unsafe-inline'; media-src *"> |
||||
|
|
||||
|
<!-- Allow everything but only from the same origin and foo.com --> |
||||
|
<meta http-equiv="Content-Security-Policy" content="default-src 'self' foo.com"> |
||||
|
|
||||
|
<!-- This policy allows everything (eg CSS, AJAX, object, frame, media, etc) except that |
||||
|
* CSS only from the same origin and inline styles, |
||||
|
* scripts only from the same origin and inline styles, and eval() |
||||
|
--> |
||||
|
<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'"> |
||||
|
|
||||
|
<!-- Allows XHRs only over HTTPS on the same domain. --> |
||||
|
<meta http-equiv="Content-Security-Policy" content="default-src 'self' https:"> |
||||
|
|
||||
|
<!-- Allow iframe to https://cordova.apache.org/ --> |
||||
|
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; frame-src 'self' https://cordova.apache.org"> |
@ -0,0 +1,55 @@ |
|||||
|
<!-- |
||||
|
# |
||||
|
# Licensed to the Apache Software Foundation (ASF) under one |
||||
|
# or more contributor license agreements. See the NOTICE file |
||||
|
# distributed with this work for additional information |
||||
|
# regarding copyright ownership. The ASF licenses this file |
||||
|
# to you under the Apache License, Version 2.0 (the |
||||
|
# "License"); you may not use this file except in compliance |
||||
|
# with the License. You may obtain a copy of the License at |
||||
|
# |
||||
|
# http://www.apache.org/licenses/LICENSE-2.0 |
||||
|
# |
||||
|
# Unless required by applicable law or agreed to in writing, |
||||
|
# software distributed under the License is distributed on an |
||||
|
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
||||
|
# KIND, either express or implied. See the License for the |
||||
|
# specific language governing permissions and limitations |
||||
|
# under the License. |
||||
|
# |
||||
|
--> |
||||
|
# Release Notes |
||||
|
|
||||
|
### 1.2.2 (Apr 15, 2016) |
||||
|
* add note about redirects |
||||
|
* CB-10624 remove error message from `whitelist.js`, which leaves it empty |
||||
|
|
||||
|
### 1.2.1 (Jan 15, 2016) |
||||
|
* CB-10194 info tag prints for ios when not applicable |
||||
|
|
||||
|
### 1.2.0 (Nov 18, 2015) |
||||
|
* removed **iOS** engine check from `plugin.xml` |
||||
|
* [CB-10035](https://issues.apache.org/jira/browse/CB-10035) Updated `RELEASENOTES` to be newest to oldest |
||||
|
* [CB-9972](https://issues.apache.org/jira/browse/CB-9972) - Remove **iOS** whitelist |
||||
|
* Updated the text, it should read 4.0.x and greater, since this plugin will be required for `cordova-android 5.0` |
||||
|
* Fixing contribute link. |
||||
|
* Updated `plugin.xml <info>` tag to remove warning about not needing this plugin if you are using the **iOS 9 SDK** |
||||
|
* [CB-9738](https://issues.apache.org/jira/browse/CB-9738) - Disable whitelist use when runtime environment is **iOS 9** |
||||
|
* [CB-9740](https://issues.apache.org/jira/browse/CB-9740) - Add `<info>` tag describing whitelist plugin not needed on `cordova-ios` and cordova-android 3.x` |
||||
|
* [CB-9568](https://issues.apache.org/jira/browse/CB-9568) - Update whitelist plugin to allow all network access by default |
||||
|
* [CB-9337](https://issues.apache.org/jira/browse/CB-9337) - enable use of `<access>` tags for native code network requests |
||||
|
|
||||
|
### 1.1.0 (Jun 17, 2015) |
||||
|
* [CB-9128](https://issues.apache.org/jira/browse/CB-9128) cordova-plugin-whitelist documentation translation: cordova-plugin-whitelist |
||||
|
* fix npm md issue |
||||
|
* Usage of CDVURLRequestFilter protocol. |
||||
|
* [CB-9089](https://issues.apache.org/jira/browse/CB-9089) - iOS whitelist plugin does not compile |
||||
|
* [CB-9090](https://issues.apache.org/jira/browse/CB-9090) - Enable whitelist plugin for cordova-ios 4.0.0 |
||||
|
* Fixed error in Content-Security-Policy example |
||||
|
|
||||
|
### 1.0.0 (Mar 25, 2015) |
||||
|
* [CB-8739](https://issues.apache.org/jira/browse/CB-8739) added missing license headers |
||||
|
* Add @Override to CustomConfigXmlParser methods |
||||
|
* Change ID to cordova-plugin-whitelist rather than reverse-DNS-style |
||||
|
* Tweak CSP examples in README |
||||
|
* [CB-8660](https://issues.apache.org/jira/browse/CB-8660) remove extra commas from package.json |
@ -0,0 +1,148 @@ |
|||||
|
<!-- |
||||
|
# license: Licensed to the Apache Software Foundation (ASF) under one |
||||
|
# or more contributor license agreements. See the NOTICE file |
||||
|
# distributed with this work for additional information |
||||
|
# regarding copyright ownership. The ASF licenses this file |
||||
|
# to you under the Apache License, Version 2.0 (the |
||||
|
# "License"); you may not use this file except in compliance |
||||
|
# with the License. You may obtain a copy of the License at |
||||
|
# |
||||
|
# http://www.apache.org/licenses/LICENSE-2.0 |
||||
|
# |
||||
|
# Unless required by applicable law or agreed to in writing, |
||||
|
# software distributed under the License is distributed on an |
||||
|
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
||||
|
# KIND, either express or implied. See the License for the |
||||
|
# specific language governing permissions and limitations |
||||
|
# under the License. |
||||
|
--> |
||||
|
|
||||
|
# cordova-plugin-whitelist |
||||
|
|
||||
|
Dieses Plugin implementiert eine Whitelist-Politik für die Navigation in der Anwendung Webview Cordova 4.0 |
||||
|
|
||||
|
## Cordova unterstützte Plattformen |
||||
|
|
||||
|
* Android 4.0.0 oder höher |
||||
|
* iOS 4.0.0 oder höher |
||||
|
|
||||
|
## Navigation-Whitelist |
||||
|
|
||||
|
Steuert, welche URLs die WebView selbst zu navigiert werden kann. Bezieht sich auf der obersten Ebene Navigationen nur. |
||||
|
|
||||
|
Macken: auf Android es gilt auch für Iframes für nicht-http(s) Systeme. |
||||
|
|
||||
|
In der Standardeinstellung Navigationen nur auf `file://` URLs, sind zulässig. Wenn andere andere URLs zulassen möchten, müssen Sie Ihre `"config.xml"` `<allow-navigation>` Markierungen hinzufügen: |
||||
|
|
||||
|
<!-- Allow links to example.com --> |
||||
|
<allow-navigation href="http://example.com/*" /> |
||||
|
|
||||
|
<!-- Wildcards are allowed for the protocol, as a prefix |
||||
|
to the host, or as a suffix to the path --> |
||||
|
<allow-navigation href="*://*.example.com/*" /> |
||||
|
|
||||
|
<!-- A wildcard can be used to whitelist the entire network, |
||||
|
over HTTP and HTTPS. |
||||
|
*NOT RECOMMENDED* --> |
||||
|
<allow-navigation href="*" /> |
||||
|
|
||||
|
<!-- The above is equivalent to these three declarations --> |
||||
|
<allow-navigation href="http://*/*" /> |
||||
|
<allow-navigation href="https://*/*" /> |
||||
|
<allow-navigation href="data:*" /> |
||||
|
|
||||
|
|
||||
|
## Vorsatz-Whitelist |
||||
|
|
||||
|
Steuert, welche URLs die app zulässig ist, um das System zu öffnen Fragen. Standardmäßig dürfen keine externe URLs. |
||||
|
|
||||
|
Das entspricht auf Android eine Absicht des Typs BROWSEABLE senden. |
||||
|
|
||||
|
Diese Whitelist gilt nicht für Plugins, nur Hyperlinks und Aufrufe von `window.open()`. |
||||
|
|
||||
|
Fügen Sie in `"config.xml"` `<allow-intent>` Tags hinzu, wie folgt: |
||||
|
|
||||
|
<!-- Allow links to web pages to open in a browser --> |
||||
|
<allow-intent href="http://*/*" /> |
||||
|
<allow-intent href="https://*/*" /> |
||||
|
|
||||
|
<!-- Allow links to example.com to open in a browser --> |
||||
|
<allow-intent href="http://example.com/*" /> |
||||
|
|
||||
|
<!-- Wildcards are allowed for the protocol, as a prefix |
||||
|
to the host, or as a suffix to the path --> |
||||
|
<allow-intent href="*://*.example.com/*" /> |
||||
|
|
||||
|
<!-- Allow SMS links to open messaging app --> |
||||
|
<allow-intent href="sms:*" /> |
||||
|
|
||||
|
<!-- Allow tel: links to open the dialer --> |
||||
|
<allow-intent href="tel:*" /> |
||||
|
|
||||
|
<!-- Allow geo: links to open maps --> |
||||
|
<allow-intent href="geo:*" /> |
||||
|
|
||||
|
<!-- Allow all unrecognized URLs to open installed apps |
||||
|
*NOT RECOMMENDED* --> |
||||
|
<allow-intent href="*" /> |
||||
|
|
||||
|
|
||||
|
## Netzwerk-Anforderung-Whitelist |
||||
|
|
||||
|
Steuert, welche-Anforderungen Netzwerk (Bilder, XHRs, etc.) dürfen (über Cordova native Haken) erfolgen. |
||||
|
|
||||
|
Hinweis: Wir empfehlen Ihnen eine Content Security Policy (siehe unten), das ist sicherer. Diese Whitelist ist vor allem historisch für Webansichten für die CSP nicht unterstützen. |
||||
|
|
||||
|
Fügen Sie in `"config.xml"` `<access>` Tags hinzu, wie folgt: |
||||
|
|
||||
|
<!-- Allow images, xhrs, etc. to google.com --> |
||||
|
<access origin="http://google.com" /> |
||||
|
<access origin="https://google.com" /> |
||||
|
|
||||
|
<!-- Access to the subdomain maps.google.com --> |
||||
|
<access origin="http://maps.google.com" /> |
||||
|
|
||||
|
<!-- Access to all the subdomains on google.com --> |
||||
|
<access origin="http://*.google.com" /> |
||||
|
|
||||
|
<!-- Enable requests to content: URLs --> |
||||
|
<access origin="content:///*" /> |
||||
|
|
||||
|
<!-- Don't block any requests --> |
||||
|
<access origin="*" /> |
||||
|
|
||||
|
|
||||
|
Ohne `<access>` -Tags dürfen nur Anforderungen an `file://` URLs. Enthält jedoch die Standardanwendung Cordova `<access origin="*">` standardmäßig. |
||||
|
|
||||
|
Eigenart: Android kann auch Anforderungen an https://ssl.gstatic.com/accessibility/javascript/android/ standardmäßig, da dies für TalkBack ordnungsgemäß erforderlich ist. |
||||
|
|
||||
|
### Content-Security-Policy |
||||
|
|
||||
|
Steuert, welche-Anforderungen Netzwerk (Bilder, XHRs, etc.) dürfen (über Webview direkt) erfolgen. |
||||
|
|
||||
|
Auf Android und iOS ist die Netzwerk Anfrage Whitelist (s.o.) nicht in der Lage, alle Arten von Anfragen (z.B. `< video >` & WebSockets nicht blockiert) filtern. Also, sollten Sie neben der Whitelist, [Content Security Policy](http://content-security-policy.com/) `< Meta >` -Tags auf allen Ihren Seiten verwenden. |
||||
|
|
||||
|
Auf Android Unterstützung für CSP innerhalb der System-Webview beginnt mit KitKat (aber ist in allen Versionen mit Crosswalk WebView verfügbar). |
||||
|
|
||||
|
Hier sind einige Beispiel-CSP-Deklarationen für Ihre `HTML` -Seiten: |
||||
|
|
||||
|
<!-- Good default declaration: |
||||
|
* gap: is required only on iOS (when using UIWebView) and is needed for JS->native communication |
||||
|
* https://ssl.gstatic.com is required only on Android and is needed for TalkBack to function properly |
||||
|
* Disables use of eval() and inline scripts in order to mitigate risk of XSS vulnerabilities. To change this: |
||||
|
* Enable inline JS: add 'unsafe-inline' to default-src |
||||
|
* Enable eval(): add 'unsafe-eval' to default-src |
||||
|
--> |
||||
|
<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com; style-src 'self' 'unsafe-inline'; media-src *"> |
||||
|
|
||||
|
<!-- Allow requests to foo.com --> |
||||
|
<meta http-equiv="Content-Security-Policy" content="default-src 'self' foo.com"> |
||||
|
|
||||
|
<!-- Enable all requests, inline styles, and eval() --> |
||||
|
<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'"> |
||||
|
|
||||
|
<!-- Allow XHRs via https only --> |
||||
|
<meta http-equiv="Content-Security-Policy" content="default-src 'self' https:"> |
||||
|
|
||||
|
<!-- Allow iframe to https://cordova.apache.org/ --> |
||||
|
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; frame-src 'self' https://cordova.apache.org"> |
@ -0,0 +1,148 @@ |
|||||
|
<!-- |
||||
|
# license: Licensed to the Apache Software Foundation (ASF) under one |
||||
|
# or more contributor license agreements. See the NOTICE file |
||||
|
# distributed with this work for additional information |
||||
|
# regarding copyright ownership. The ASF licenses this file |
||||
|
# to you under the Apache License, Version 2.0 (the |
||||
|
# "License"); you may not use this file except in compliance |
||||
|
# with the License. You may obtain a copy of the License at |
||||
|
# |
||||
|
# http://www.apache.org/licenses/LICENSE-2.0 |
||||
|
# |
||||
|
# Unless required by applicable law or agreed to in writing, |
||||
|
# software distributed under the License is distributed on an |
||||
|
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
||||
|
# KIND, either express or implied. See the License for the |
||||
|
# specific language governing permissions and limitations |
||||
|
# under the License. |
||||
|
--> |
||||
|
|
||||
|
# cordova-plugin-whitelist |
||||
|
|
||||
|
Este plugin implementa una política de lista blanca para navegar la aplicación webview en Cordova 4.0 |
||||
|
|
||||
|
## Plataformas soportadas Cordova |
||||
|
|
||||
|
* Android 4.0 o superior |
||||
|
* iOS 4.0.0 o superior |
||||
|
|
||||
|
## Lista blanca de navegación |
||||
|
|
||||
|
Controla que las URLs del WebView se puede navegar a. Se aplica a nivel superior navegaciones solo. |
||||
|
|
||||
|
Peculiaridades: en Android también se aplica a iframes para esquemas que son de http (s). |
||||
|
|
||||
|
Por defecto, navegaciones solo a direcciones URL `file://` , son permitidas. Para permitir que otros otras URL, debe agregar `< allow-navegación >` etiquetas en el `archivo config.xml`: |
||||
|
|
||||
|
<!-- Allow links to example.com --> |
||||
|
<allow-navigation href="http://example.com/*" /> |
||||
|
|
||||
|
<!-- Wildcards are allowed for the protocol, as a prefix |
||||
|
to the host, or as a suffix to the path --> |
||||
|
<allow-navigation href="*://*.example.com/*" /> |
||||
|
|
||||
|
<!-- A wildcard can be used to whitelist the entire network, |
||||
|
over HTTP and HTTPS. |
||||
|
*NOT RECOMMENDED* --> |
||||
|
<allow-navigation href="*" /> |
||||
|
|
||||
|
<!-- The above is equivalent to these three declarations --> |
||||
|
<allow-navigation href="http://*/*" /> |
||||
|
<allow-navigation href="https://*/*" /> |
||||
|
<allow-navigation href="data:*" /> |
||||
|
|
||||
|
|
||||
|
## Intención de lista blanca |
||||
|
|
||||
|
Controla qué URLs de la aplicación se permite hacer el sistema para abrir. De forma predeterminada, se permiten ninguÌ n external URLs. |
||||
|
|
||||
|
En Android, esto equivale a enviar una intención de tipo BROWSEABLE. |
||||
|
|
||||
|
Esta lista blanca no se aplica a plugins, sólo los hipervínculos y las llamadas a `window.Open)`. |
||||
|
|
||||
|
En `config.xml`, agregar etiquetas `< allow-intent >` , como este: |
||||
|
|
||||
|
<!-- Allow links to web pages to open in a browser --> |
||||
|
<allow-intent href="http://*/*" /> |
||||
|
<allow-intent href="https://*/*" /> |
||||
|
|
||||
|
<!-- Allow links to example.com to open in a browser --> |
||||
|
<allow-intent href="http://example.com/*" /> |
||||
|
|
||||
|
<!-- Wildcards are allowed for the protocol, as a prefix |
||||
|
to the host, or as a suffix to the path --> |
||||
|
<allow-intent href="*://*.example.com/*" /> |
||||
|
|
||||
|
<!-- Allow SMS links to open messaging app --> |
||||
|
<allow-intent href="sms:*" /> |
||||
|
|
||||
|
<!-- Allow tel: links to open the dialer --> |
||||
|
<allow-intent href="tel:*" /> |
||||
|
|
||||
|
<!-- Allow geo: links to open maps --> |
||||
|
<allow-intent href="geo:*" /> |
||||
|
|
||||
|
<!-- Allow all unrecognized URLs to open installed apps |
||||
|
*NOT RECOMMENDED* --> |
||||
|
<allow-intent href="*" /> |
||||
|
|
||||
|
|
||||
|
## Solicitud de red blanca |
||||
|
|
||||
|
Controles que las peticiones de la red (imágenes, XHRs, etc.) se les permite hacer (a través de ganchos nativa de Córdoba). |
||||
|
|
||||
|
Nota: Le sugerimos que utilice una política de seguridad de contenido (véase abajo), que es más seguro. Esta lista blanca es sobre todo histórico para webviews que no admiten la CSP. |
||||
|
|
||||
|
En `config.xml`, agregue etiquetas de `< access >` , como este: |
||||
|
|
||||
|
<!-- Allow images, xhrs, etc. to google.com --> |
||||
|
<access origin="http://google.com" /> |
||||
|
<access origin="https://google.com" /> |
||||
|
|
||||
|
<!-- Access to the subdomain maps.google.com --> |
||||
|
<access origin="http://maps.google.com" /> |
||||
|
|
||||
|
<!-- Access to all the subdomains on google.com --> |
||||
|
<access origin="http://*.google.com" /> |
||||
|
|
||||
|
<!-- Enable requests to content: URLs --> |
||||
|
<access origin="content:///*" /> |
||||
|
|
||||
|
<!-- Don't block any requests --> |
||||
|
<access origin="*" /> |
||||
|
|
||||
|
|
||||
|
Sin las etiquetas `< access >` , se admiten sólo las solicitudes a direcciones URL `file://` . Sin embargo, la aplicación por defecto de Cordova incluye `< access origin = "*" >` por defecto. |
||||
|
|
||||
|
Quirk: Android también permite las solicitudes de https://ssl.gstatic.com/accessibility/javascript/android/ por defecto, puesto que es necesario para TalkBack funcionar correctamente. |
||||
|
|
||||
|
### Política de seguridad de contenido |
||||
|
|
||||
|
Controles que las peticiones de la red (imágenes, XHRs, etc.) se les permite hacer (vía webview directamente). |
||||
|
|
||||
|
En iOS y Android, la red solicitud lista blanca (véase arriba) no es capaz de filtrar todos los tipos de solicitudes (por ejemplo, `< video >` y WebSockets no estén bloqueadas). Así, además de la lista blanca, usted debe utilizar una etiqueta `< meta >` de [Contenido la política de seguridad](http://content-security-policy.com/) en todas las páginas. |
||||
|
|
||||
|
En Android, soporte para CSP en el sistema webview comienza con KitKat (pero está disponible en todas las versiones con WebView de paso de peatones). |
||||
|
|
||||
|
Aquí están algunas declaraciones de CSP de ejemplo para las páginas `.html` : |
||||
|
|
||||
|
<!-- Good default declaration: |
||||
|
* gap: is required only on iOS (when using UIWebView) and is needed for JS->native communication |
||||
|
* https://ssl.gstatic.com is required only on Android and is needed for TalkBack to function properly |
||||
|
* Disables use of eval() and inline scripts in order to mitigate risk of XSS vulnerabilities. To change this: |
||||
|
* Enable inline JS: add 'unsafe-inline' to default-src |
||||
|
* Enable eval(): add 'unsafe-eval' to default-src |
||||
|
--> |
||||
|
<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com; style-src 'self' 'unsafe-inline'; media-src *"> |
||||
|
|
||||
|
<!-- Allow requests to foo.com --> |
||||
|
<meta http-equiv="Content-Security-Policy" content="default-src 'self' foo.com"> |
||||
|
|
||||
|
<!-- Enable all requests, inline styles, and eval() --> |
||||
|
<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'"> |
||||
|
|
||||
|
<!-- Allow XHRs via https only --> |
||||
|
<meta http-equiv="Content-Security-Policy" content="default-src 'self' https:"> |
||||
|
|
||||
|
<!-- Allow iframe to https://cordova.apache.org/ --> |
||||
|
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; frame-src 'self' https://cordova.apache.org"> |
@ -0,0 +1,148 @@ |
|||||
|
<!-- |
||||
|
# license: Licensed to the Apache Software Foundation (ASF) under one |
||||
|
# or more contributor license agreements. See the NOTICE file |
||||
|
# distributed with this work for additional information |
||||
|
# regarding copyright ownership. The ASF licenses this file |
||||
|
# to you under the Apache License, Version 2.0 (the |
||||
|
# "License"); you may not use this file except in compliance |
||||
|
# with the License. You may obtain a copy of the License at |
||||
|
# |
||||
|
# http://www.apache.org/licenses/LICENSE-2.0 |
||||
|
# |
||||
|
# Unless required by applicable law or agreed to in writing, |
||||
|
# software distributed under the License is distributed on an |
||||
|
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
||||
|
# KIND, either express or implied. See the License for the |
||||
|
# specific language governing permissions and limitations |
||||
|
# under the License. |
||||
|
--> |
||||
|
|
||||
|
# cordova-plugin-whitelist |
||||
|
|
||||
|
Ce plugin met en œuvre une politique de liste blanche pour naviguer le webview application sur Cordova 4.0 |
||||
|
|
||||
|
## Plates-formes prises en charge Cordova |
||||
|
|
||||
|
* 4.0.0 Android ou supérieur |
||||
|
* iOS 4.0.0 ou supérieur |
||||
|
|
||||
|
## Navigation liste blanche |
||||
|
|
||||
|
Contrôle quels URL le WebView lui-même peut être parcourus à. S'applique à des navigations niveau supérieur seulement. |
||||
|
|
||||
|
Particularités : sur Android il s'applique également aux iframes pour non-schémas http (s). |
||||
|
|
||||
|
Par défaut, navigations qu'aux URL `file://` , sont autorisés. Pour permettre aux autres d'autres URL, vous devez ajouter des balises `<allow-navigation>` à votre `fichier config.xml`: |
||||
|
|
||||
|
<!-- Allow links to example.com --> |
||||
|
<allow-navigation href="http://example.com/*" /> |
||||
|
|
||||
|
<!-- Wildcards are allowed for the protocol, as a prefix |
||||
|
to the host, or as a suffix to the path --> |
||||
|
<allow-navigation href="*://*.example.com/*" /> |
||||
|
|
||||
|
<!-- A wildcard can be used to whitelist the entire network, |
||||
|
over HTTP and HTTPS. |
||||
|
*NOT RECOMMENDED* --> |
||||
|
<allow-navigation href="*" /> |
||||
|
|
||||
|
<!-- The above is equivalent to these three declarations --> |
||||
|
<allow-navigation href="http://*/*" /> |
||||
|
<allow-navigation href="https://*/*" /> |
||||
|
<allow-navigation href="data:*" /> |
||||
|
|
||||
|
|
||||
|
## Intent Whitelist |
||||
|
|
||||
|
Contrôle quels URL l'app n'est autorisé à poser le système d'ouverture. Par défaut, aucun external URL est autorisés. |
||||
|
|
||||
|
Sur Android, cela équivaut à envoyer une intention de type BROWSEABLE. |
||||
|
|
||||
|
Cette autorisation ne s'applique pas aux plugins, uniquement les liens hypertexte et les appels à `window.open()`. |
||||
|
|
||||
|
Dans le `fichier config.xml`, ajouter des balises `<allow-intent>` , comme ceci : |
||||
|
|
||||
|
<!-- Allow links to web pages to open in a browser --> |
||||
|
<allow-intent href="http://*/*" /> |
||||
|
<allow-intent href="https://*/*" /> |
||||
|
|
||||
|
<!-- Allow links to example.com to open in a browser --> |
||||
|
<allow-intent href="http://example.com/*" /> |
||||
|
|
||||
|
<!-- Wildcards are allowed for the protocol, as a prefix |
||||
|
to the host, or as a suffix to the path --> |
||||
|
<allow-intent href="*://*.example.com/*" /> |
||||
|
|
||||
|
<!-- Allow SMS links to open messaging app --> |
||||
|
<allow-intent href="sms:*" /> |
||||
|
|
||||
|
<!-- Allow tel: links to open the dialer --> |
||||
|
<allow-intent href="tel:*" /> |
||||
|
|
||||
|
<!-- Allow geo: links to open maps --> |
||||
|
<allow-intent href="geo:*" /> |
||||
|
|
||||
|
<!-- Allow all unrecognized URLs to open installed apps |
||||
|
*NOT RECOMMENDED* --> |
||||
|
<allow-intent href="*" /> |
||||
|
|
||||
|
|
||||
|
## Réseau demande liste blanche |
||||
|
|
||||
|
Les contrôles dont les demandes de réseau (images, XHRs, etc.) sont autorisés à effectuer (via cordova natif crochets). |
||||
|
|
||||
|
Remarque : Nous vous suggérons de qu'utiliser un contenu politique de sécurité (voir ci-dessous), qui est plus sûr. Cette liste blanche est surtout historique pour webviews qui ne prennent pas en charge les CSP. |
||||
|
|
||||
|
Dans le `fichier config.xml`, ajouter des balises `<access>` , comme ceci : |
||||
|
|
||||
|
<!-- Allow images, xhrs, etc. to google.com --> |
||||
|
<access origin="http://google.com" /> |
||||
|
<access origin="https://google.com" /> |
||||
|
|
||||
|
<!-- Access to the subdomain maps.google.com --> |
||||
|
<access origin="http://maps.google.com" /> |
||||
|
|
||||
|
<!-- Access to all the subdomains on google.com --> |
||||
|
<access origin="http://*.google.com" /> |
||||
|
|
||||
|
<!-- Enable requests to content: URLs --> |
||||
|
<access origin="content:///*" /> |
||||
|
|
||||
|
<!-- Don't block any requests --> |
||||
|
<access origin="*" /> |
||||
|
|
||||
|
|
||||
|
Sans les balises `<access>` , seules les demandes d'URL `file://` sont autorisés. Toutefois, l'application de Cordoue par défaut inclut `<access origin="*" >` par défaut. |
||||
|
|
||||
|
Bizarrerie : Android permet également aux requêtes à https://ssl.gstatic.com/accessibility/javascript/android/ par défaut, puisque c'est nécessaire pour TalkBack fonctionner correctement. |
||||
|
|
||||
|
### Politique de sécurité du contenu |
||||
|
|
||||
|
Les contrôles dont les demandes de réseau (images, XHRs, etc.) sont autorisés à effectuer (via webview directement). |
||||
|
|
||||
|
Sur Android et iOS, la réseau demande liste blanche (voir ci-dessus) n'est pas en mesure de filtrer tous les types de demandes (p. ex. `< video >` & WebSockets ne sont pas bloquées). Ainsi, en plus de la liste blanche, vous devez utiliser une balise `< meta >` de [Contenu politique de sécurité](http://content-security-policy.com/) sur toutes vos pages. |
||||
|
|
||||
|
Sur Android, support pour le CSP dans le système webview commence par KitKat (mais n'est disponible sur toutes les versions à l'aide du tableau de concordance WebView). |
||||
|
|
||||
|
Voici quelques exemples de déclarations de CSP pour vos pages `.html` : |
||||
|
|
||||
|
<!-- Good default declaration: |
||||
|
* gap: is required only on iOS (when using UIWebView) and is needed for JS->native communication |
||||
|
* https://ssl.gstatic.com is required only on Android and is needed for TalkBack to function properly |
||||
|
* Disables use of eval() and inline scripts in order to mitigate risk of XSS vulnerabilities. To change this: |
||||
|
* Enable inline JS: add 'unsafe-inline' to default-src |
||||
|
* Enable eval(): add 'unsafe-eval' to default-src |
||||
|
--> |
||||
|
<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com; style-src 'self' 'unsafe-inline'; media-src *"> |
||||
|
|
||||
|
<!-- Allow requests to foo.com --> |
||||
|
<meta http-equiv="Content-Security-Policy" content="default-src 'self' foo.com"> |
||||
|
|
||||
|
<!-- Enable all requests, inline styles, and eval() --> |
||||
|
<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'"> |
||||
|
|
||||
|
<!-- Allow XHRs via https only --> |
||||
|
<meta http-equiv="Content-Security-Policy" content="default-src 'self' https:"> |
||||
|
|
||||
|
<!-- Allow iframe to https://cordova.apache.org/ --> |
||||
|
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; frame-src 'self' https://cordova.apache.org"> |
@ -0,0 +1,148 @@ |
|||||
|
<!-- |
||||
|
# license: Licensed to the Apache Software Foundation (ASF) under one |
||||
|
# or more contributor license agreements. See the NOTICE file |
||||
|
# distributed with this work for additional information |
||||
|
# regarding copyright ownership. The ASF licenses this file |
||||
|
# to you under the Apache License, Version 2.0 (the |
||||
|
# "License"); you may not use this file except in compliance |
||||
|
# with the License. You may obtain a copy of the License at |
||||
|
# |
||||
|
# http://www.apache.org/licenses/LICENSE-2.0 |
||||
|
# |
||||
|
# Unless required by applicable law or agreed to in writing, |
||||
|
# software distributed under the License is distributed on an |
||||
|
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
||||
|
# KIND, either express or implied. See the License for the |
||||
|
# specific language governing permissions and limitations |
||||
|
# under the License. |
||||
|
--> |
||||
|
|
||||
|
# cordova-plugin-whitelist |
||||
|
|
||||
|
Questo plugin attua una politica di whitelist per spostarsi all'interno dell'applicazione webview in Cordova 4.0 |
||||
|
|
||||
|
## Piattaforme supportate Cordova |
||||
|
|
||||
|
* Android 4.0.0 o superiore |
||||
|
* iOS 4.0.0 o superiore |
||||
|
|
||||
|
## Navigazione Whitelist |
||||
|
|
||||
|
Controlla quali URL WebView stessa può essere esplorato. Si applica al solo primo livello navigazioni. |
||||
|
|
||||
|
Stranezze: su Android vale anche per gli iframe per non-schemi di http (s). |
||||
|
|
||||
|
Per impostazione predefinita, navigazioni solo agli URL `file://` , sono ammessi. Per consentire altri altri URL, è necessario aggiungere `<allow-navigation>` tag per il tuo `config. XML`: |
||||
|
|
||||
|
<!-- Allow links to example.com --> |
||||
|
<allow-navigation href="http://example.com/*" /> |
||||
|
|
||||
|
<!-- Wildcards are allowed for the protocol, as a prefix |
||||
|
to the host, or as a suffix to the path --> |
||||
|
<allow-navigation href="*://*.example.com/*" /> |
||||
|
|
||||
|
<!-- A wildcard can be used to whitelist the entire network, |
||||
|
over HTTP and HTTPS. |
||||
|
*NOT RECOMMENDED* --> |
||||
|
<allow-navigation href="*" /> |
||||
|
|
||||
|
<!-- The above is equivalent to these three declarations --> |
||||
|
<allow-navigation href="http://*/*" /> |
||||
|
<allow-navigation href="https://*/*" /> |
||||
|
<allow-navigation href="data:*" /> |
||||
|
|
||||
|
|
||||
|
## Whitelist intento |
||||
|
|
||||
|
Controlla quali URL app è consentito richiedere il sistema di apertura. Per impostazione predefinita, nessun esterno URL sono ammessi. |
||||
|
|
||||
|
Su Android, ciò equivale all'invio di un intento di tipo BROWSEABLE. |
||||
|
|
||||
|
Questa whitelist non si applica ai plugin, solo i collegamenti ipertestuali e chiamate a `Window`. |
||||
|
|
||||
|
In `config. XML`, aggiungere tag `<allow-intent>` , simile al seguente: |
||||
|
|
||||
|
<!-- Allow links to web pages to open in a browser --> |
||||
|
<allow-intent href="http://*/*" /> |
||||
|
<allow-intent href="https://*/*" /> |
||||
|
|
||||
|
<!-- Allow links to example.com to open in a browser --> |
||||
|
<allow-intent href="http://example.com/*" /> |
||||
|
|
||||
|
<!-- Wildcards are allowed for the protocol, as a prefix |
||||
|
to the host, or as a suffix to the path --> |
||||
|
<allow-intent href="*://*.example.com/*" /> |
||||
|
|
||||
|
<!-- Allow SMS links to open messaging app --> |
||||
|
<allow-intent href="sms:*" /> |
||||
|
|
||||
|
<!-- Allow tel: links to open the dialer --> |
||||
|
<allow-intent href="tel:*" /> |
||||
|
|
||||
|
<!-- Allow geo: links to open maps --> |
||||
|
<allow-intent href="geo:*" /> |
||||
|
|
||||
|
<!-- Allow all unrecognized URLs to open installed apps |
||||
|
*NOT RECOMMENDED* --> |
||||
|
<allow-intent href="*" /> |
||||
|
|
||||
|
|
||||
|
## Rete richiesta Whitelist |
||||
|
|
||||
|
Controlli che le richieste di rete (immagini, XHRs, ecc.) sono consentiti (tramite ganci nativo di cordova). |
||||
|
|
||||
|
Nota: Si consiglia di che utilizzare un criterio di protezione contenuti (Vedi sotto), che è più sicuro. La whitelist è principalmente storico per visualizzazioni Web che non supportano la CSP. |
||||
|
|
||||
|
In `config. XML`, aggiungere tag `< access >` , simile al seguente: |
||||
|
|
||||
|
<!-- Allow images, xhrs, etc. to google.com --> |
||||
|
<access origin="http://google.com" /> |
||||
|
<access origin="https://google.com" /> |
||||
|
|
||||
|
<!-- Access to the subdomain maps.google.com --> |
||||
|
<access origin="http://maps.google.com" /> |
||||
|
|
||||
|
<!-- Access to all the subdomains on google.com --> |
||||
|
<access origin="http://*.google.com" /> |
||||
|
|
||||
|
<!-- Enable requests to content: URLs --> |
||||
|
<access origin="content:///*" /> |
||||
|
|
||||
|
<!-- Don't block any requests --> |
||||
|
<access origin="*" /> |
||||
|
|
||||
|
|
||||
|
Senza qualsiasi tag `< access >` , sono consentite solo le richieste di URL `file://` . Tuttavia, l'applicazione di Cordova predefinito include `< access origin = "*" >` per impostazione predefinita. |
||||
|
|
||||
|
Stranezza: Android consente anche alle richieste di https://ssl.gstatic.com/accessibility/javascript/android/ per impostazione predefinita, poiché questa operazione è necessaria per TalkBack funzionare correttamente. |
||||
|
|
||||
|
### Politica di sicurezza del contenuto |
||||
|
|
||||
|
Controlli che le richieste di rete (immagini, XHRs, ecc.) possono essere effettuate (via webview direttamente). |
||||
|
|
||||
|
Su Android e iOS, la rete richiesta whitelist (Vedi sopra) non è in grado di filtrare tutti i tipi di richieste (ad esempio non sono bloccate `< video >` & WebSockets). Così, oltre alla whitelist, è necessario utilizzare un tag `< meta >` [Content Security Policy](http://content-security-policy.com/) su tutte le pagine. |
||||
|
|
||||
|
Su Android, supporto per CSP all'interno webview sistema inizia con KitKat (ma è disponibile su tutte le versioni usando Crosswalk WebView). |
||||
|
|
||||
|
Ecco alcuni esempi di dichiarazioni di CSP per le pagine `HTML` : |
||||
|
|
||||
|
<!-- Good default declaration: |
||||
|
* gap: is required only on iOS (when using UIWebView) and is needed for JS->native communication |
||||
|
* https://ssl.gstatic.com is required only on Android and is needed for TalkBack to function properly |
||||
|
* Disables use of eval() and inline scripts in order to mitigate risk of XSS vulnerabilities. To change this: |
||||
|
* Enable inline JS: add 'unsafe-inline' to default-src |
||||
|
* Enable eval(): add 'unsafe-eval' to default-src |
||||
|
--> |
||||
|
<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com; style-src 'self' 'unsafe-inline'; media-src *"> |
||||
|
|
||||
|
<!-- Allow requests to foo.com --> |
||||
|
<meta http-equiv="Content-Security-Policy" content="default-src 'self' foo.com"> |
||||
|
|
||||
|
<!-- Enable all requests, inline styles, and eval() --> |
||||
|
<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'"> |
||||
|
|
||||
|
<!-- Allow XHRs via https only --> |
||||
|
<meta http-equiv="Content-Security-Policy" content="default-src 'self' https:"> |
||||
|
|
||||
|
<!-- Allow iframe to https://cordova.apache.org/ --> |
||||
|
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; frame-src 'self' https://cordova.apache.org"> |
@ -0,0 +1,148 @@ |
|||||
|
<!-- |
||||
|
# license: Licensed to the Apache Software Foundation (ASF) under one |
||||
|
# or more contributor license agreements. See the NOTICE file |
||||
|
# distributed with this work for additional information |
||||
|
# regarding copyright ownership. The ASF licenses this file |
||||
|
# to you under the Apache License, Version 2.0 (the |
||||
|
# "License"); you may not use this file except in compliance |
||||
|
# with the License. You may obtain a copy of the License at |
||||
|
# |
||||
|
# http://www.apache.org/licenses/LICENSE-2.0 |
||||
|
# |
||||
|
# Unless required by applicable law or agreed to in writing, |
||||
|
# software distributed under the License is distributed on an |
||||
|
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
||||
|
# KIND, either express or implied. See the License for the |
||||
|
# specific language governing permissions and limitations |
||||
|
# under the License. |
||||
|
--> |
||||
|
|
||||
|
# cordova-plugin-whitelist |
||||
|
|
||||
|
このプラグイン実装コルドバ 4.0 アプリケーション webview をナビゲートするためのホワイト リスト ポリシー |
||||
|
|
||||
|
## サポートされているコルドバのプラットフォーム |
||||
|
|
||||
|
* アンドロイド 4.0.0 以上 |
||||
|
* iOS 4.0.0 以上 |
||||
|
|
||||
|
## ナビゲーションのホワイト リスト |
||||
|
|
||||
|
WebView 自体に移動に Url を制御します。最上位ナビゲーションのみに適用されます。 |
||||
|
|
||||
|
癖: Android にもに適用されますの iframe 非-[http スキーム。 |
||||
|
|
||||
|
既定では、ナビゲーション、 `file://`の Url にのみ許可されます。その他の他の Url を許可するように、 `config.xml`に`<allow-navigation>`タグを追加する必要があります。 |
||||
|
|
||||
|
<!-- Allow links to example.com --> |
||||
|
<allow-navigation href="http://example.com/*" /> |
||||
|
|
||||
|
<!-- Wildcards are allowed for the protocol, as a prefix |
||||
|
to the host, or as a suffix to the path --> |
||||
|
<allow-navigation href="*://*.example.com/*" /> |
||||
|
|
||||
|
<!-- A wildcard can be used to whitelist the entire network, |
||||
|
over HTTP and HTTPS. |
||||
|
*NOT RECOMMENDED* --> |
||||
|
<allow-navigation href="*" /> |
||||
|
|
||||
|
<!-- The above is equivalent to these three declarations --> |
||||
|
<allow-navigation href="http://*/*" /> |
||||
|
<allow-navigation href="https://*/*" /> |
||||
|
<allow-navigation href="data:*" /> |
||||
|
|
||||
|
|
||||
|
## インテントのホワイト リスト |
||||
|
|
||||
|
どの Url を開くようにシステムを聞いて、アプリに許可を制御します。 既定では、外部 Url 許可されません。 |
||||
|
|
||||
|
人造人間、これは型 BROWSEABLE の意図を送信することに相当します。 |
||||
|
|
||||
|
このホワイト リストはプラグインのみハイパーリンクおよび`window.open()`への呼び出しには適用されません。. |
||||
|
|
||||
|
`Config.xml`内の`<allow-intent>`タグは、このようなを追加します。 |
||||
|
|
||||
|
<!-- Allow links to web pages to open in a browser --> |
||||
|
<allow-intent href="http://*/*" /> |
||||
|
<allow-intent href="https://*/*" /> |
||||
|
|
||||
|
<!-- Allow links to example.com to open in a browser --> |
||||
|
<allow-intent href="http://example.com/*" /> |
||||
|
|
||||
|
<!-- Wildcards are allowed for the protocol, as a prefix |
||||
|
to the host, or as a suffix to the path --> |
||||
|
<allow-intent href="*://*.example.com/*" /> |
||||
|
|
||||
|
<!-- Allow SMS links to open messaging app --> |
||||
|
<allow-intent href="sms:*" /> |
||||
|
|
||||
|
<!-- Allow tel: links to open the dialer --> |
||||
|
<allow-intent href="tel:*" /> |
||||
|
|
||||
|
<!-- Allow geo: links to open maps --> |
||||
|
<allow-intent href="geo:*" /> |
||||
|
|
||||
|
<!-- Allow all unrecognized URLs to open installed apps |
||||
|
*NOT RECOMMENDED* --> |
||||
|
<allow-intent href="*" /> |
||||
|
|
||||
|
|
||||
|
## ネットワーク要求のホワイト リスト |
||||
|
|
||||
|
ネットワーク要求コントロール (画像、XHRs 等) (コルドバ ネイティブ フック) を介して行われることが。 |
||||
|
|
||||
|
注: より安全なコンテンツ セキュリティ ポリシー (下記参照) を使用してお勧めします。 このホワイト リストほとんどの CSP をサポートしていない web 表示のために歴史的です。 |
||||
|
|
||||
|
`Config.xml`内のこのような`<access>`タグを追加します。 |
||||
|
|
||||
|
<!-- Allow images, xhrs, etc. to google.com --> |
||||
|
<access origin="http://google.com" /> |
||||
|
<access origin="https://google.com" /> |
||||
|
|
||||
|
<!-- Access to the subdomain maps.google.com --> |
||||
|
<access origin="http://maps.google.com" /> |
||||
|
|
||||
|
<!-- Access to all the subdomains on google.com --> |
||||
|
<access origin="http://*.google.com" /> |
||||
|
|
||||
|
<!-- Enable requests to content: URLs --> |
||||
|
<access origin="content:///*" /> |
||||
|
|
||||
|
<!-- Don't block any requests --> |
||||
|
<access origin="*" /> |
||||
|
|
||||
|
|
||||
|
`<access>`タグ、なし`file://` Url に要求のみを許可します。 ただし、既定のコルドバ アプリケーションが含まれています`<access origin="*">`デフォルトで。 |
||||
|
|
||||
|
気まぐれ: アンドロイドも要求できます https://ssl.gstatic.com/accessibility/javascript/android/デフォルトでは、トークが正常に機能するために必要ですので。 |
||||
|
|
||||
|
### コンテンツのセキュリティ ポリシー |
||||
|
|
||||
|
ネットワーク要求コントロール (画像、XHRs 等) (直接 webview) を介して行われることが。 |
||||
|
|
||||
|
Android と iOS は、ネットワーク要求ホワイト リスト (上記参照) はすべての種類の要求 (例: `< ビデオ >` & Websocket がふさがれていない) をフィルター処理できません。 だから、ホワイト リストに加えてすべてのページに[コンテンツ セキュリティ ポリシー](http://content-security-policy.com/) `< meta >`タグを使用する必要があります。 |
||||
|
|
||||
|
Android 上システム webview 内 CSP サポート キットカットから始まります (しかし横断歩道 WebView を使用してすべてのバージョンで利用可能です)。 |
||||
|
|
||||
|
`.Html`ページのいくつかの例 CSP の宣言は次のとおりです。 |
||||
|
|
||||
|
<!-- Good default declaration: |
||||
|
* gap: is required only on iOS (when using UIWebView) and is needed for JS->native communication |
||||
|
* https://ssl.gstatic.com is required only on Android and is needed for TalkBack to function properly |
||||
|
* Disables use of eval() and inline scripts in order to mitigate risk of XSS vulnerabilities. To change this: |
||||
|
* Enable inline JS: add 'unsafe-inline' to default-src |
||||
|
* Enable eval(): add 'unsafe-eval' to default-src |
||||
|
--> |
||||
|
<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com; style-src 'self' 'unsafe-inline'; media-src *"> |
||||
|
|
||||
|
<!-- Allow requests to foo.com --> |
||||
|
<meta http-equiv="Content-Security-Policy" content="default-src 'self' foo.com"> |
||||
|
|
||||
|
<!-- Enable all requests, inline styles, and eval() --> |
||||
|
<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'"> |
||||
|
|
||||
|
<!-- Allow XHRs via https only --> |
||||
|
<meta http-equiv="Content-Security-Policy" content="default-src 'self' https:"> |
||||
|
|
||||
|
<!-- Allow iframe to https://cordova.apache.org/ --> |
||||
|
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; frame-src 'self' https://cordova.apache.org"> |
@ -0,0 +1,148 @@ |
|||||
|
<!-- |
||||
|
# license: Licensed to the Apache Software Foundation (ASF) under one |
||||
|
# or more contributor license agreements. See the NOTICE file |
||||
|
# distributed with this work for additional information |
||||
|
# regarding copyright ownership. The ASF licenses this file |
||||
|
# to you under the Apache License, Version 2.0 (the |
||||
|
# "License"); you may not use this file except in compliance |
||||
|
# with the License. You may obtain a copy of the License at |
||||
|
# |
||||
|
# http://www.apache.org/licenses/LICENSE-2.0 |
||||
|
# |
||||
|
# Unless required by applicable law or agreed to in writing, |
||||
|
# software distributed under the License is distributed on an |
||||
|
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
||||
|
# KIND, either express or implied. See the License for the |
||||
|
# specific language governing permissions and limitations |
||||
|
# under the License. |
||||
|
--> |
||||
|
|
||||
|
# cordova-plugin-whitelist |
||||
|
|
||||
|
이 플러그인 구현 코르도바 4.0 응용 프로그램 webview를 탐색에 대 한 허용 정책 |
||||
|
|
||||
|
## 지원된 코르도바 플랫폼 |
||||
|
|
||||
|
* 안 드 로이드 4.0.0 이상 |
||||
|
* iOS 4.0.0 이상 |
||||
|
|
||||
|
## 탐색 허용 |
||||
|
|
||||
|
WebView 자체가 탐색할 수 있는 Url을 제어 합니다. 최상위 탐색에만 적용 됩니다. |
||||
|
|
||||
|
단점: 안 드 로이드에도 적용 됩니다 iframe에 대 한 비-프로토콜인 계획. |
||||
|
|
||||
|
기본적으로 탐색 `file://` Url에만 사용할 수 있습니다. 다른 다른 Url을 허용 하려면 `config.xml`에 `< allow-navigation >` 태그를 추가 해야 합니다. |
||||
|
|
||||
|
<!-- Allow links to example.com --> |
||||
|
<allow-navigation href="http://example.com/*" /> |
||||
|
|
||||
|
<!-- Wildcards are allowed for the protocol, as a prefix |
||||
|
to the host, or as a suffix to the path --> |
||||
|
<allow-navigation href="*://*.example.com/*" /> |
||||
|
|
||||
|
<!-- A wildcard can be used to whitelist the entire network, |
||||
|
over HTTP and HTTPS. |
||||
|
*NOT RECOMMENDED* --> |
||||
|
<allow-navigation href="*" /> |
||||
|
|
||||
|
<!-- The above is equivalent to these three declarations --> |
||||
|
<allow-navigation href="http://*/*" /> |
||||
|
<allow-navigation href="https://*/*" /> |
||||
|
<allow-navigation href="data:*" /> |
||||
|
|
||||
|
|
||||
|
## 의도 허용 |
||||
|
|
||||
|
App 시스템 열을 게 허용 되는 Url을 제어 합니다. 기본적으로 외부 Url은 사용할 수 있습니다. |
||||
|
|
||||
|
안 드 로이드에이 형식의 BROWSEABLE 의도 보내는 것 같습니다. |
||||
|
|
||||
|
이 허용 된 플러그인, 하이퍼링크 및 `window.open ()` 호출에 적용 되지 않습니다.. |
||||
|
|
||||
|
`Config.xml`에이 같은 `< allow-intent >` 태그를 추가 합니다. |
||||
|
|
||||
|
<!-- Allow links to web pages to open in a browser --> |
||||
|
<allow-intent href="http://*/*" /> |
||||
|
<allow-intent href="https://*/*" /> |
||||
|
|
||||
|
<!-- Allow links to example.com to open in a browser --> |
||||
|
<allow-intent href="http://example.com/*" /> |
||||
|
|
||||
|
<!-- Wildcards are allowed for the protocol, as a prefix |
||||
|
to the host, or as a suffix to the path --> |
||||
|
<allow-intent href="*://*.example.com/*" /> |
||||
|
|
||||
|
<!-- Allow SMS links to open messaging app --> |
||||
|
<allow-intent href="sms:*" /> |
||||
|
|
||||
|
<!-- Allow tel: links to open the dialer --> |
||||
|
<allow-intent href="tel:*" /> |
||||
|
|
||||
|
<!-- Allow geo: links to open maps --> |
||||
|
<allow-intent href="geo:*" /> |
||||
|
|
||||
|
<!-- Allow all unrecognized URLs to open installed apps |
||||
|
*NOT RECOMMENDED* --> |
||||
|
<allow-intent href="*" /> |
||||
|
|
||||
|
|
||||
|
## 네트워크 요청 허용 |
||||
|
|
||||
|
요청을 네트워크 컨트롤 (이미지, XHRs, 등) (코르도바 네이티브 후크)를 통해 할 수 있습니다. |
||||
|
|
||||
|
참고: 당신이 사용 콘텐츠 보안 정책 (아래 참조), 더 안전한 것이 좋습니다. 이 허용은 CSP를 지원 하지 않는 webviews에 대 한 역사적. |
||||
|
|
||||
|
`Config.xml`에이 같은 `< access >` 태그를 추가 합니다. |
||||
|
|
||||
|
<!-- Allow images, xhrs, etc. to google.com --> |
||||
|
<access origin="http://google.com" /> |
||||
|
<access origin="https://google.com" /> |
||||
|
|
||||
|
<!-- Access to the subdomain maps.google.com --> |
||||
|
<access origin="http://maps.google.com" /> |
||||
|
|
||||
|
<!-- Access to all the subdomains on google.com --> |
||||
|
<access origin="http://*.google.com" /> |
||||
|
|
||||
|
<!-- Enable requests to content: URLs --> |
||||
|
<access origin="content:///*" /> |
||||
|
|
||||
|
<!-- Don't block any requests --> |
||||
|
<access origin="*" /> |
||||
|
|
||||
|
|
||||
|
어떤 `< access >` 태그 없이 요청 `file://` Url 사용할 수 있습니다. 그러나 기본 코르도바 응용 프로그램을 포함 하는, `< access origin="*" >` 기본적으로. |
||||
|
|
||||
|
특질: 안 드 로이드 또한 수 있습니다 요청을 https://ssl.gstatic.com/accessibility/javascript/android/ 기본적으로 필요 제대로 작동 하려면 의견 이므로. |
||||
|
|
||||
|
### 콘텐츠 보안 정책 |
||||
|
|
||||
|
요청을 네트워크 컨트롤 (이미지, XHRs, 등) (webview 직접)를 통해 할 수 있습니다. |
||||
|
|
||||
|
안 드 로이드와 iOS에 네트워크 요청 허용 (위 참조)는 모든 종류의 요청 (예: `< 비디오 >` & WebSockets 차단 되지 않습니다)를 필터링 할 수 없습니다. 그래서, 허용, 뿐만 아니라 귀하의 모든 페이지에 [콘텐츠 보안 정책](http://content-security-policy.com/) `< meta >` 태그를 사용 해야 합니다. |
||||
|
|
||||
|
안 드 로이드, 시스템 webview 내에서 CSP에 대 한 지원을 KitKat 시작 (하지만 횡단 보도 WebView를 사용 하 여 모든 버전에서 사용할 수). |
||||
|
|
||||
|
다음은 `.html` 페이지에 대 한 몇 가지 예제 CSP 선언입니다. |
||||
|
|
||||
|
<!-- Good default declaration: |
||||
|
* gap: is required only on iOS (when using UIWebView) and is needed for JS->native communication |
||||
|
* https://ssl.gstatic.com is required only on Android and is needed for TalkBack to function properly |
||||
|
* Disables use of eval() and inline scripts in order to mitigate risk of XSS vulnerabilities. To change this: |
||||
|
* Enable inline JS: add 'unsafe-inline' to default-src |
||||
|
* Enable eval(): add 'unsafe-eval' to default-src |
||||
|
--> |
||||
|
<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com; style-src 'self' 'unsafe-inline'; media-src *"> |
||||
|
|
||||
|
<!-- Allow requests to foo.com --> |
||||
|
<meta http-equiv="Content-Security-Policy" content="default-src 'self' foo.com"> |
||||
|
|
||||
|
<!-- Enable all requests, inline styles, and eval() --> |
||||
|
<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'"> |
||||
|
|
||||
|
<!-- Allow XHRs via https only --> |
||||
|
<meta http-equiv="Content-Security-Policy" content="default-src 'self' https:"> |
||||
|
|
||||
|
<!-- Allow iframe to https://cordova.apache.org/ --> |
||||
|
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; frame-src 'self' https://cordova.apache.org"> |
@ -0,0 +1,148 @@ |
|||||
|
<!-- |
||||
|
# license: Licensed to the Apache Software Foundation (ASF) under one |
||||
|
# or more contributor license agreements. See the NOTICE file |
||||
|
# distributed with this work for additional information |
||||
|
# regarding copyright ownership. The ASF licenses this file |
||||
|
# to you under the Apache License, Version 2.0 (the |
||||
|
# "License"); you may not use this file except in compliance |
||||
|
# with the License. You may obtain a copy of the License at |
||||
|
# |
||||
|
# http://www.apache.org/licenses/LICENSE-2.0 |
||||
|
# |
||||
|
# Unless required by applicable law or agreed to in writing, |
||||
|
# software distributed under the License is distributed on an |
||||
|
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
||||
|
# KIND, either express or implied. See the License for the |
||||
|
# specific language governing permissions and limitations |
||||
|
# under the License. |
||||
|
--> |
||||
|
|
||||
|
# cordova-plugin-whitelist |
||||
|
|
||||
|
Ten plugin wdraża polityki białej nawigacja widoku sieci Web aplikacji na Cordova 4.0 |
||||
|
|
||||
|
## Cordova obsługiwanych platform |
||||
|
|
||||
|
* Android 4.0.0 lub powyżej |
||||
|
* iOS 4.0.0 lub powyżej |
||||
|
|
||||
|
## Biała lista nawigacji |
||||
|
|
||||
|
Kontroluje, których adresy URL widoku sieci Web, samej można nawigować do. Dotyczy tylko najwyższego poziomu nawigacje. |
||||
|
|
||||
|
Dziwactwa: na Android to dotyczy także IFRAME do nie-http (s) systemów. |
||||
|
|
||||
|
Domyślnie, nawigacje tylko do URLi `file://` , są dozwolone. Aby zezwolić na inne adresy URL, należy dodać Tagi `< allow-navigation >` do pliku `config.xml`: |
||||
|
|
||||
|
<!-- Allow links to example.com --> |
||||
|
<allow-navigation href="http://example.com/*" /> |
||||
|
|
||||
|
<!-- Wildcards are allowed for the protocol, as a prefix |
||||
|
to the host, or as a suffix to the path --> |
||||
|
<allow-navigation href="*://*.example.com/*" /> |
||||
|
|
||||
|
<!-- A wildcard can be used to whitelist the entire network, |
||||
|
over HTTP and HTTPS. |
||||
|
*NOT RECOMMENDED* --> |
||||
|
<allow-navigation href="*" /> |
||||
|
|
||||
|
<!-- The above is equivalent to these three declarations --> |
||||
|
<allow-navigation href="http://*/*" /> |
||||
|
<allow-navigation href="https://*/*" /> |
||||
|
<allow-navigation href="data:*" /> |
||||
|
|
||||
|
|
||||
|
## Zamiarem biała |
||||
|
|
||||
|
Kontroluje, których adresy URL aplikacji jest możliwość zapytać systemem otwierania. Domyślnie nie ma zewnętrznych adresów URL są dozwolone. |
||||
|
|
||||
|
Na Android to przyrównuje do wysyłania zamiarem typu BROWSEABLE. |
||||
|
|
||||
|
Ta biała nie ma zastosowania do pluginów, tylko hiperłącza i wywołania `window.open()`. |
||||
|
|
||||
|
W `pliku config.xml`dodawanie tagów `< allow-intent >` , jak to: |
||||
|
|
||||
|
<!-- Allow links to web pages to open in a browser --> |
||||
|
<allow-intent href="http://*/*" /> |
||||
|
<allow-intent href="https://*/*" /> |
||||
|
|
||||
|
<!-- Allow links to example.com to open in a browser --> |
||||
|
<allow-intent href="http://example.com/*" /> |
||||
|
|
||||
|
<!-- Wildcards are allowed for the protocol, as a prefix |
||||
|
to the host, or as a suffix to the path --> |
||||
|
<allow-intent href="*://*.example.com/*" /> |
||||
|
|
||||
|
<!-- Allow SMS links to open messaging app --> |
||||
|
<allow-intent href="sms:*" /> |
||||
|
|
||||
|
<!-- Allow tel: links to open the dialer --> |
||||
|
<allow-intent href="tel:*" /> |
||||
|
|
||||
|
<!-- Allow geo: links to open maps --> |
||||
|
<allow-intent href="geo:*" /> |
||||
|
|
||||
|
<!-- Allow all unrecognized URLs to open installed apps |
||||
|
*NOT RECOMMENDED* --> |
||||
|
<allow-intent href="*" /> |
||||
|
|
||||
|
|
||||
|
## Sieci wniosek biała |
||||
|
|
||||
|
Formanty, które sieci żądań (obrazy, XHRs, itp.) mogą być wykonane (za pośrednictwem cordova rodzimych haki). |
||||
|
|
||||
|
Uwaga: Zalecamy, że używasz treści polityki bezpieczeństwa (patrz poniżej), który jest bardziej bezpieczne. Ta Biała jest głównie historyczne dla webviews, które nie obsługują CSP. |
||||
|
|
||||
|
W `pliku config.xml`dodawanie tagów `< access >` , jak to: |
||||
|
|
||||
|
<!-- Allow images, xhrs, etc. to google.com --> |
||||
|
<access origin="http://google.com" /> |
||||
|
<access origin="https://google.com" /> |
||||
|
|
||||
|
<!-- Access to the subdomain maps.google.com --> |
||||
|
<access origin="http://maps.google.com" /> |
||||
|
|
||||
|
<!-- Access to all the subdomains on google.com --> |
||||
|
<access origin="http://*.google.com" /> |
||||
|
|
||||
|
<!-- Enable requests to content: URLs --> |
||||
|
<access origin="content:///*" /> |
||||
|
|
||||
|
<!-- Don't block any requests --> |
||||
|
<access origin="*" /> |
||||
|
|
||||
|
|
||||
|
Bez żadnych tagów `< access >` dozwolone są tylko żądania do URLi `file://` . Jednak domyślnie Cordova aplikacja zawiera `< access origin = "*" >` domyślnie. |
||||
|
|
||||
|
Cokół: Android pozwala również żądania do https://ssl.gstatic.com/accessibility/javascript/android/ domyślnie, ponieważ jest to wymagane dla TalkBack wobec funkcja poprawnie. |
||||
|
|
||||
|
### Zasady zabezpieczeń zawartości |
||||
|
|
||||
|
Formanty, które sieci żądań (obrazy, XHRs, itp.) mogą być wykonane (za pomocą widoku sieci Web bezpośrednio). |
||||
|
|
||||
|
Na Androida i iOS biała żądanie sieci (patrz wyżej) nie jest w stanie filtrować wszystkie rodzaje wniosków (np. `< video >` & WebSockets nie są zablokowane). Tak oprócz białej listy, należy użyć tagu `< meta >` [Treści polityki bezpieczeństwa](http://content-security-policy.com/) na wszystkich stronach. |
||||
|
|
||||
|
Na Android wsparcie dla CSP w ramach systemu widoku sieci Web zaczyna KitKat (ale jest dostępne we wszystkich wersjach przy użyciu widoku sieci Web przejście dla pieszych). |
||||
|
|
||||
|
Oto niektóre przykład CSP deklaracje dla strony `HTML` : |
||||
|
|
||||
|
<!-- Good default declaration: |
||||
|
* gap: is required only on iOS (when using UIWebView) and is needed for JS->native communication |
||||
|
* https://ssl.gstatic.com is required only on Android and is needed for TalkBack to function properly |
||||
|
* Disables use of eval() and inline scripts in order to mitigate risk of XSS vulnerabilities. To change this: |
||||
|
* Enable inline JS: add 'unsafe-inline' to default-src |
||||
|
* Enable eval(): add 'unsafe-eval' to default-src |
||||
|
--> |
||||
|
<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com; style-src 'self' 'unsafe-inline'; media-src *"> |
||||
|
|
||||
|
<!-- Allow requests to foo.com --> |
||||
|
<meta http-equiv="Content-Security-Policy" content="default-src 'self' foo.com"> |
||||
|
|
||||
|
<!-- Enable all requests, inline styles, and eval() --> |
||||
|
<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'"> |
||||
|
|
||||
|
<!-- Allow XHRs via https only --> |
||||
|
<meta http-equiv="Content-Security-Policy" content="default-src 'self' https:"> |
||||
|
|
||||
|
<!-- Allow iframe to https://cordova.apache.org/ --> |
||||
|
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; frame-src 'self' https://cordova.apache.org"> |
@ -0,0 +1,148 @@ |
|||||
|
<!-- |
||||
|
# license: Licensed to the Apache Software Foundation (ASF) under one |
||||
|
# or more contributor license agreements. See the NOTICE file |
||||
|
# distributed with this work for additional information |
||||
|
# regarding copyright ownership. The ASF licenses this file |
||||
|
# to you under the Apache License, Version 2.0 (the |
||||
|
# "License"); you may not use this file except in compliance |
||||
|
# with the License. You may obtain a copy of the License at |
||||
|
# |
||||
|
# http://www.apache.org/licenses/LICENSE-2.0 |
||||
|
# |
||||
|
# Unless required by applicable law or agreed to in writing, |
||||
|
# software distributed under the License is distributed on an |
||||
|
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
||||
|
# KIND, either express or implied. See the License for the |
||||
|
# specific language governing permissions and limitations |
||||
|
# under the License. |
||||
|
--> |
||||
|
|
||||
|
# cordova-plugin-whitelist |
||||
|
|
||||
|
這個外掛程式實現一個用於導航在科爾多瓦 4.0 應用程式 web 視圖的白名單策略 |
||||
|
|
||||
|
## 支援的科爾多瓦平臺 |
||||
|
|
||||
|
* Android 4.0.0 或以上 |
||||
|
* iOS 4.0.0 或以上 |
||||
|
|
||||
|
## 導航白名單 |
||||
|
|
||||
|
控制 web 視圖本身可以導航到的 Url。適用于頂級導航只。 |
||||
|
|
||||
|
怪癖: 在 Android 上它也適用于 iframe 的非-結計畫。 |
||||
|
|
||||
|
預設情況下,只有到`file://` Url 導航允許。若要允許其他其他 Url,必須將`<allow-navigation>`標籤添加到您的`config.xml`: |
||||
|
|
||||
|
<!-- Allow links to example.com --> |
||||
|
<allow-navigation href="http://example.com/*" /> |
||||
|
|
||||
|
<!-- Wildcards are allowed for the protocol, as a prefix |
||||
|
to the host, or as a suffix to the path --> |
||||
|
<allow-navigation href="*://*.example.com/*" /> |
||||
|
|
||||
|
<!-- A wildcard can be used to whitelist the entire network, |
||||
|
over HTTP and HTTPS. |
||||
|
*NOT RECOMMENDED* --> |
||||
|
<allow-navigation href="*" /> |
||||
|
|
||||
|
<!-- The above is equivalent to these three declarations --> |
||||
|
<allow-navigation href="http://*/*" /> |
||||
|
<allow-navigation href="https://*/*" /> |
||||
|
<allow-navigation href="data:*" /> |
||||
|
|
||||
|
|
||||
|
## 科爾多瓦-外掛程式-白名單 |
||||
|
|
||||
|
控制應用程式允許讓系統打開的 Url。 預設情況下,沒有外部 Url 允許。 |
||||
|
|
||||
|
在 android 系統,這相當於發送類型 BROWSEABLE 的意圖。 |
||||
|
|
||||
|
此白名單並不適用于只超連結和對`window.open ()`調用的外掛程式. |
||||
|
|
||||
|
在`config.xml`中添加`<allow-intent>`標籤,像這樣: |
||||
|
|
||||
|
<!-- Allow links to web pages to open in a browser --> |
||||
|
<allow-intent href="http://*/*" /> |
||||
|
<allow-intent href="https://*/*" /> |
||||
|
|
||||
|
<!-- Allow links to example.com to open in a browser --> |
||||
|
<allow-intent href="http://example.com/*" /> |
||||
|
|
||||
|
<!-- Wildcards are allowed for the protocol, as a prefix |
||||
|
to the host, or as a suffix to the path --> |
||||
|
<allow-intent href="*://*.example.com/*" /> |
||||
|
|
||||
|
<!-- Allow SMS links to open messaging app --> |
||||
|
<allow-intent href="sms:*" /> |
||||
|
|
||||
|
<!-- Allow tel: links to open the dialer --> |
||||
|
<allow-intent href="tel:*" /> |
||||
|
|
||||
|
<!-- Allow geo: links to open maps --> |
||||
|
<allow-intent href="geo:*" /> |
||||
|
|
||||
|
<!-- Allow all unrecognized URLs to open installed apps |
||||
|
*NOT RECOMMENDED* --> |
||||
|
<allow-intent href="*" /> |
||||
|
|
||||
|
|
||||
|
## 網路請求白名單 |
||||
|
|
||||
|
網路請求的控制項 (圖像,XHRs 等) 允許 (通過科爾多瓦本機掛鉤)。 |
||||
|
|
||||
|
注意: 我們建議你使用內容的安全性原則 (見下文),這是更安全。 此白名單大多是為 webviews 不支援 CSP 的歷史。 |
||||
|
|
||||
|
在`config.xml`中添加`<access>`標記,像這樣: |
||||
|
|
||||
|
<!-- Allow images, xhrs, etc. to google.com --> |
||||
|
<access origin="http://google.com" /> |
||||
|
<access origin="https://google.com" /> |
||||
|
|
||||
|
<!-- Access to the subdomain maps.google.com --> |
||||
|
<access origin="http://maps.google.com" /> |
||||
|
|
||||
|
<!-- Access to all the subdomains on google.com --> |
||||
|
<access origin="http://*.google.com" /> |
||||
|
|
||||
|
<!-- Enable requests to content: URLs --> |
||||
|
<access origin="content:///*" /> |
||||
|
|
||||
|
<!-- Don't block any requests --> |
||||
|
<access origin="*" /> |
||||
|
|
||||
|
|
||||
|
沒有任何`<access>`標籤,只到`file://` Url 允許請求。 但是,預設的科爾多瓦應用程式包括`<access origin="*">` ,預設情況。 |
||||
|
|
||||
|
怪癖: Android 還允許對 HTTPs://ssl.gstatic.com/accessibility/javascript/android/ 請求預設情況下,因為這是對講正常所需。 |
||||
|
|
||||
|
### 內容安全政策 |
||||
|
|
||||
|
網路請求的控制項 (圖像,XHRs 等) 允許 (通過 web 視圖直接)。 |
||||
|
|
||||
|
對 Android 和 iOS,網路請求白名單 (見上文) 是不能夠過濾所有類型的請求 (例如`<video>` & Websocket 未被阻止)。 那麼,除了白名單中,你應使用[內容安全性原則](http://content-security-policy.com/) `< 元 >`標記您的所有頁面。 |
||||
|
|
||||
|
在 android 系統,對 CSP 系統 web 視圖的支援開始奇巧 (但是是上使用 web 視圖人行橫道上的所有版本可用)。 |
||||
|
|
||||
|
下面是一些示例 CSP 聲明為`.html`頁面: |
||||
|
|
||||
|
<!-- Good default declaration: |
||||
|
* gap: is required only on iOS (when using UIWebView) and is needed for JS->native communication |
||||
|
* https://ssl.gstatic.com is required only on Android and is needed for TalkBack to function properly |
||||
|
* Disables use of eval() and inline scripts in order to mitigate risk of XSS vulnerabilities. To change this: |
||||
|
* Enable inline JS: add 'unsafe-inline' to default-src |
||||
|
* Enable eval(): add 'unsafe-eval' to default-src |
||||
|
--> |
||||
|
<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com; style-src 'self' 'unsafe-inline'; media-src *"> |
||||
|
|
||||
|
<!-- Allow requests to foo.com --> |
||||
|
<meta http-equiv="Content-Security-Policy" content="default-src 'self' foo.com"> |
||||
|
|
||||
|
<!-- Enable all requests, inline styles, and eval() --> |
||||
|
<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'"> |
||||
|
|
||||
|
<!-- Allow XHRs via https only --> |
||||
|
<meta http-equiv="Content-Security-Policy" content="default-src 'self' https:"> |
||||
|
|
||||
|
<!-- Allow iframe to https://cordova.apache.org/ --> |
||||
|
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; frame-src 'self' https://cordova.apache.org"> |
@ -0,0 +1,28 @@ |
|||||
|
{ |
||||
|
"name": "cordova-plugin-whitelist", |
||||
|
"version": "1.2.2", |
||||
|
"description": "Cordova Whitelist Plugin", |
||||
|
"cordova": { |
||||
|
"platforms": [ |
||||
|
"android" |
||||
|
] |
||||
|
}, |
||||
|
"repository": { |
||||
|
"type": "git", |
||||
|
"url": "https://github.com/apache/cordova-plugin-whitelist" |
||||
|
}, |
||||
|
"keywords": [ |
||||
|
"cordova", |
||||
|
"whitelist", |
||||
|
"ecosystem:cordova", |
||||
|
"cordova-android" |
||||
|
], |
||||
|
"engines": [ |
||||
|
{ |
||||
|
"name": "cordova-android", |
||||
|
"version": ">=4.0.0" |
||||
|
} |
||||
|
], |
||||
|
"author": "Apache Software Foundation", |
||||
|
"license": "Apache 2.0" |
||||
|
} |
@ -0,0 +1,50 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<!-- |
||||
|
Licensed to the Apache Software Foundation (ASF) under one |
||||
|
or more contributor license agreements. See the NOTICE file |
||||
|
distributed with this work for additional information |
||||
|
regarding copyright ownership. The ASF licenses this file |
||||
|
to you under the Apache License, Version 2.0 (the |
||||
|
"License"); you may not use this file except in compliance |
||||
|
with the License. You may obtain a copy of the License at |
||||
|
|
||||
|
http://www.apache.org/licenses/LICENSE-2.0 |
||||
|
|
||||
|
Unless required by applicable law or agreed to in writing, |
||||
|
software distributed under the License is distributed on an |
||||
|
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
||||
|
KIND, either express or implied. See the License for the |
||||
|
specific language governing permissions and limitations |
||||
|
under the License. |
||||
|
--> |
||||
|
|
||||
|
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" |
||||
|
id="cordova-plugin-whitelist" |
||||
|
version="1.2.2"> |
||||
|
<name>Whitelist</name> |
||||
|
<description>Cordova Network Whitelist Plugin</description> |
||||
|
<license>Apache 2.0</license> |
||||
|
<keywords>cordova,whitelist,policy</keywords> |
||||
|
|
||||
|
<engines> |
||||
|
<engine name="cordova-android" version=">=4.0.0" /> |
||||
|
</engines> |
||||
|
|
||||
|
<platform name="android"> |
||||
|
<config-file target="res/xml/config.xml" parent="/*"> |
||||
|
<feature name="Whitelist" > |
||||
|
<param name="android-package" value="org.apache.cordova.whitelist.WhitelistPlugin"/> |
||||
|
<param name="onload" value="true" /> |
||||
|
</feature> |
||||
|
</config-file> |
||||
|
|
||||
|
<source-file src="src/android/WhitelistPlugin.java" target-dir="src/org/apache/cordova/whitelist" /> |
||||
|
|
||||
|
<info> |
||||
|
This plugin is only applicable for versions of cordova-android greater than 4.0. If you have a previous platform version, you do *not* need this plugin since the whitelist will be built in. |
||||
|
</info> |
||||
|
</platform> |
||||
|
|
||||
|
|
||||
|
|
||||
|
</plugin> |
@ -0,0 +1,161 @@ |
|||||
|
/* |
||||
|
Licensed to the Apache Software Foundation (ASF) under one |
||||
|
or more contributor license agreements. See the NOTICE file |
||||
|
distributed with this work for additional information |
||||
|
regarding copyright ownership. The ASF licenses this file |
||||
|
to you under the Apache License, Version 2.0 (the |
||||
|
"License"); you may not use this file except in compliance |
||||
|
with the License. You may obtain a copy of the License at |
||||
|
|
||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
|
||||
|
Unless required by applicable law or agreed to in writing, |
||||
|
software distributed under the License is distributed on an |
||||
|
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
||||
|
KIND, either express or implied. See the License for the |
||||
|
specific language governing permissions and limitations |
||||
|
under the License. |
||||
|
*/ |
||||
|
|
||||
|
package org.apache.cordova.whitelist; |
||||
|
|
||||
|
import org.apache.cordova.CordovaPlugin; |
||||
|
import org.apache.cordova.ConfigXmlParser; |
||||
|
import org.apache.cordova.Whitelist; |
||||
|
import org.xmlpull.v1.XmlPullParser; |
||||
|
|
||||
|
import android.content.Context; |
||||
|
import android.util.Log; |
||||
|
|
||||
|
public class WhitelistPlugin extends CordovaPlugin { |
||||
|
private static final String LOG_TAG = "WhitelistPlugin"; |
||||
|
private Whitelist allowedNavigations; |
||||
|
private Whitelist allowedIntents; |
||||
|
private Whitelist allowedRequests; |
||||
|
|
||||
|
// Used when instantiated via reflection by PluginManager
|
||||
|
public WhitelistPlugin() { |
||||
|
} |
||||
|
// These can be used by embedders to allow Java-configuration of whitelists.
|
||||
|
public WhitelistPlugin(Context context) { |
||||
|
this(new Whitelist(), new Whitelist(), null); |
||||
|
new CustomConfigXmlParser().parse(context); |
||||
|
} |
||||
|
public WhitelistPlugin(XmlPullParser xmlParser) { |
||||
|
this(new Whitelist(), new Whitelist(), null); |
||||
|
new CustomConfigXmlParser().parse(xmlParser); |
||||
|
} |
||||
|
public WhitelistPlugin(Whitelist allowedNavigations, Whitelist allowedIntents, Whitelist allowedRequests) { |
||||
|
if (allowedRequests == null) { |
||||
|
allowedRequests = new Whitelist(); |
||||
|
allowedRequests.addWhiteListEntry("file:///*", false); |
||||
|
allowedRequests.addWhiteListEntry("data:*", false); |
||||
|
} |
||||
|
this.allowedNavigations = allowedNavigations; |
||||
|
this.allowedIntents = allowedIntents; |
||||
|
this.allowedRequests = allowedRequests; |
||||
|
} |
||||
|
@Override |
||||
|
public void pluginInitialize() { |
||||
|
if (allowedNavigations == null) { |
||||
|
allowedNavigations = new Whitelist(); |
||||
|
allowedIntents = new Whitelist(); |
||||
|
allowedRequests = new Whitelist(); |
||||
|
new CustomConfigXmlParser().parse(webView.getContext()); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
private class CustomConfigXmlParser extends ConfigXmlParser { |
||||
|
@Override |
||||
|
public void handleStartTag(XmlPullParser xml) { |
||||
|
String strNode = xml.getName(); |
||||
|
if (strNode.equals("content")) { |
||||
|
String startPage = xml.getAttributeValue(null, "src"); |
||||
|
allowedNavigations.addWhiteListEntry(startPage, false); |
||||
|
} else if (strNode.equals("allow-navigation")) { |
||||
|
String origin = xml.getAttributeValue(null, "href"); |
||||
|
if ("*".equals(origin)) { |
||||
|
allowedNavigations.addWhiteListEntry("http://*/*", false); |
||||
|
allowedNavigations.addWhiteListEntry("https://*/*", false); |
||||
|
allowedNavigations.addWhiteListEntry("data:*", false); |
||||
|
} else { |
||||
|
allowedNavigations.addWhiteListEntry(origin, false); |
||||
|
} |
||||
|
} else if (strNode.equals("allow-intent")) { |
||||
|
String origin = xml.getAttributeValue(null, "href"); |
||||
|
allowedIntents.addWhiteListEntry(origin, false); |
||||
|
} else if (strNode.equals("access")) { |
||||
|
String origin = xml.getAttributeValue(null, "origin"); |
||||
|
String subdomains = xml.getAttributeValue(null, "subdomains"); |
||||
|
boolean external = (xml.getAttributeValue(null, "launch-external") != null); |
||||
|
if (origin != null) { |
||||
|
if (external) { |
||||
|
Log.w(LOG_TAG, "Found <access launch-external> within config.xml. Please use <allow-intent> instead."); |
||||
|
allowedIntents.addWhiteListEntry(origin, (subdomains != null) && (subdomains.compareToIgnoreCase("true") == 0)); |
||||
|
} else { |
||||
|
if ("*".equals(origin)) { |
||||
|
allowedRequests.addWhiteListEntry("http://*/*", false); |
||||
|
allowedRequests.addWhiteListEntry("https://*/*", false); |
||||
|
} else { |
||||
|
allowedRequests.addWhiteListEntry(origin, (subdomains != null) && (subdomains.compareToIgnoreCase("true") == 0)); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
@Override |
||||
|
public void handleEndTag(XmlPullParser xml) { |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public Boolean shouldAllowNavigation(String url) { |
||||
|
if (allowedNavigations.isUrlWhiteListed(url)) { |
||||
|
return true; |
||||
|
} |
||||
|
return null; // Default policy
|
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public Boolean shouldAllowRequest(String url) { |
||||
|
if (Boolean.TRUE == shouldAllowNavigation(url)) { |
||||
|
return true; |
||||
|
} |
||||
|
if (allowedRequests.isUrlWhiteListed(url)) { |
||||
|
return true; |
||||
|
} |
||||
|
return null; // Default policy
|
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public Boolean shouldOpenExternalUrl(String url) { |
||||
|
if (allowedIntents.isUrlWhiteListed(url)) { |
||||
|
return true; |
||||
|
} |
||||
|
return null; // Default policy
|
||||
|
} |
||||
|
|
||||
|
public Whitelist getAllowedNavigations() { |
||||
|
return allowedNavigations; |
||||
|
} |
||||
|
|
||||
|
public void setAllowedNavigations(Whitelist allowedNavigations) { |
||||
|
this.allowedNavigations = allowedNavigations; |
||||
|
} |
||||
|
|
||||
|
public Whitelist getAllowedIntents() { |
||||
|
return allowedIntents; |
||||
|
} |
||||
|
|
||||
|
public void setAllowedIntents(Whitelist allowedIntents) { |
||||
|
this.allowedIntents = allowedIntents; |
||||
|
} |
||||
|
|
||||
|
public Whitelist getAllowedRequests() { |
||||
|
return allowedRequests; |
||||
|
} |
||||
|
|
||||
|
public void setAllowedRequests(Whitelist allowedRequests) { |
||||
|
this.allowedRequests = allowedRequests; |
||||
|
} |
||||
|
} |
@ -0,0 +1,10 @@ |
|||||
|
{ |
||||
|
"cordova-plugin-whitelist": { |
||||
|
"source": { |
||||
|
"type": "registry", |
||||
|
"id": "cordova-plugin-whitelist@1" |
||||
|
}, |
||||
|
"is_top_level": true, |
||||
|
"variables": {} |
||||
|
} |
||||
|
} |
@ -0,0 +1 @@ |
|||||
|
../../app/ |
@ -0,0 +1,22 @@ |
|||||
|
## Role |
||||
|
|
||||
|
Desktop version of application. |
||||
|
|
||||
|
## Install |
||||
|
|
||||
|
``` |
||||
|
npm install electron-prebuilt -g |
||||
|
``` |
||||
|
|
||||
|
## Run |
||||
|
|
||||
|
``` |
||||
|
# application is already running (foreman start) |
||||
|
|
||||
|
cd tools/electron |
||||
|
electron . |
||||
|
``` |
||||
|
|
||||
|
## Documentation |
||||
|
|
||||
|
[http://electron.atom.io/docs/tutorial/quick-start](http://electron.atom.io/docs/tutorial/quick-start) |
@ -0,0 +1,61 @@ |
|||||
|
const fs = require('fs') |
||||
|
const electron = require('electron') |
||||
|
// Module to control application life.
|
||||
|
const app = electron.app |
||||
|
// Module to create native browser window.
|
||||
|
const BrowserWindow = electron.BrowserWindow |
||||
|
|
||||
|
function fileExists(filePath){ try{ return fs.statSync(filePath).isFile() } catch (err){ return false } } |
||||
|
|
||||
|
// Keep a global reference of the window object, if you don't, the window will
|
||||
|
// be closed automatically when the JavaScript object is garbage collected.
|
||||
|
let mainWindow |
||||
|
|
||||
|
function createWindow () { |
||||
|
// Create the browser window.
|
||||
|
mainWindow = new BrowserWindow({width: 800, height: 600}) |
||||
|
|
||||
|
var path = __dirname + '/../../../../app/index.html' |
||||
|
if( !fileExists(path) ){ path = __dirname + '/../../../app/index.html' } |
||||
|
|
||||
|
// and load the index.html of the app.
|
||||
|
mainWindow.loadURL('file://' + path) |
||||
|
|
||||
|
// Open the DevTools.
|
||||
|
mainWindow.webContents.openDevTools() |
||||
|
|
||||
|
// Emitted when the window is closed.
|
||||
|
mainWindow.on('closed', function () { |
||||
|
// Dereference the window object, usually you would store windows
|
||||
|
// in an array if your app supports multi windows, this is the time
|
||||
|
// when you should delete the corresponding element.
|
||||
|
mainWindow = null |
||||
|
}) |
||||
|
} |
||||
|
|
||||
|
// This method will be called when Electron has finished
|
||||
|
// initialization and is ready to create browser windows.
|
||||
|
// Some APIs can only be used after this event occurs.
|
||||
|
app.on('ready', createWindow) |
||||
|
|
||||
|
// Quit when all windows are closed.
|
||||
|
app.on('window-all-closed', function () { |
||||
|
// On OS X it is common for applications and their menu bar
|
||||
|
// to stay active until the user quits explicitly with Cmd + Q
|
||||
|
if (process.platform !== 'darwin') { |
||||
|
app.quit() |
||||
|
} |
||||
|
}) |
||||
|
|
||||
|
app.on('activate', function () { |
||||
|
// On OS X it's common to re-create a window in the app when the
|
||||
|
// dock icon is clicked and there are no other windows open.
|
||||
|
if (mainWindow === null) { |
||||
|
createWindow() |
||||
|
} |
||||
|
}) |
||||
|
|
||||
|
// In this file you can include the rest of your app's specific main process
|
||||
|
// code. You can also put them in separate files and require them here.
|
||||
|
|
||||
|
|
@ -0,0 +1,4 @@ |
|||||
|
{ |
||||
|
"name" : "electron", |
||||
|
"version" : "0.1.0" |
||||
|
} |
@ -0,0 +1,8 @@ |
|||||
|
FROM node |
||||
|
|
||||
|
RUN mkdir -p /primus |
||||
|
WORKDIR /primus |
||||
|
|
||||
|
RUN npm install -g browserify coffee-script derequire http-server |
||||
|
ADD package.json package.json |
||||
|
RUN npm install && cd node_modules/primus && npm install && npm run build |
@ -0,0 +1,19 @@ |
|||||
|
## Role |
||||
|
|
||||
|
Communication between browser and application. |
||||
|
|
||||
|
## Setup |
||||
|
|
||||
|
[https://github.com/primus/primus](https://github.com/primus/primus) |
||||
|
|
||||
|
``` |
||||
|
cd tools/primus |
||||
|
npm install |
||||
|
``` |
||||
|
|
||||
|
## Procfile |
||||
|
|
||||
|
``` |
||||
|
dialogI: sh -c 'cd ./tools/primus && exec coffee entry.coffee' |
||||
|
dialogO: sh -c 'cd ./tools/primus && exec coffee outgo.coffee' |
||||
|
``` |
@ -0,0 +1,11 @@ |
|||||
|
global.L = require('lodash') |
||||
|
Primus = require('primus') |
||||
|
disque = require('thunk-disque') |
||||
|
global.Disque = disque.createClient(["#{process.env.disque_host}:#{process.env.disque_port}"]) |
||||
|
|
||||
|
module.exports.createPrimus = (port) -> |
||||
|
primus = Primus.createServer |
||||
|
port: port |
||||
|
parser: 'binary' |
||||
|
compression: true |
||||
|
transformer: 'uws' |
@ -0,0 +1,23 @@ |
|||||
|
communication_input: |
||||
|
build: framework/tools/communication/primus |
||||
|
extends: |
||||
|
file: framework/tools/containers/docker/common.yml |
||||
|
service: pro |
||||
|
command: coffee entry.coffee |
||||
|
volumes: |
||||
|
- ./framework/tools/communication/primus:/primus |
||||
|
- /primus/node_modules |
||||
|
ports: |
||||
|
- "8090:8090" |
||||
|
|
||||
|
communication_output: |
||||
|
build: framework/tools/communication/primus |
||||
|
extends: |
||||
|
file: framework/tools/containers/docker/common.yml |
||||
|
service: pro |
||||
|
command: coffee outgo.coffee |
||||
|
volumes: |
||||
|
- ./framework/tools/communication/primus:/primus |
||||
|
- /primus/node_modules |
||||
|
ports: |
||||
|
- "8091:8091" |
@ -0,0 +1,13 @@ |
|||||
|
base = require('./base') |
||||
|
|
||||
|
primus = base.createPrimus(8090) |
||||
|
primus.on 'connection', (spark) -> |
||||
|
|
||||
|
spark.on 'data', (data) -> |
||||
|
return if /primus::ping/.exec(data) |
||||
|
job = "front/#{data.event}" |
||||
|
payload = JSON.stringify L.merge(data, sid: spark.id) |
||||
|
|
||||
|
Disque.addjob(job, payload, 60, 'replicate', 1, 'retry', 0, 'ttl', 1) (err, id) -> |
||||
|
return console.error(err) if err |
||||
|
console.log "(#{id} - #{job}): #{payload}" |
@ -0,0 +1 @@ |
|||||
|
../../../../node_modules |
@ -0,0 +1,39 @@ |
|||||
|
base = require('./base') |
||||
|
|
||||
|
connections = {} |
||||
|
|
||||
|
primus = base.createPrimus(8091) |
||||
|
primus.on 'connection', (spark) -> |
||||
|
|
||||
|
spark.on 'data', (data) -> |
||||
|
unless connections[data] |
||||
|
connections[data] = spark.id |
||||
|
spark.pair = data |
||||
|
|
||||
|
spark.on 'end', -> |
||||
|
delete connections[spark.pair] |
||||
|
|
||||
|
get_jobs = -> |
||||
|
Disque.getjob('timeout', 0, 'count', 16, 'from', 'send') (err, jobs) -> |
||||
|
setTimeout get_jobs, 0 |
||||
|
if err |
||||
|
then console.error(err) |
||||
|
else |
||||
|
L.each jobs, (payload) -> |
||||
|
data = payload[2] |
||||
|
|
||||
|
console.log data |
||||
|
|
||||
|
sid = /"sid":"([^"]*)"/.exec(data)[1] |
||||
|
if sid == 'all' |
||||
|
primus.write data |
||||
|
else |
||||
|
if /"broadcast":true/.exec(data) |
||||
|
L.each connections, (output_id, input_id) -> |
||||
|
if input_id != sid |
||||
|
primus.spark(output_id)?.write data |
||||
|
else |
||||
|
spark_id = connections[sid] |
||||
|
primus.spark(spark_id)?.write data |
||||
|
|
||||
|
get_jobs() |
@ -0,0 +1,19 @@ |
|||||
|
{ |
||||
|
"name": "primus-dialog", |
||||
|
"version": "1.0.0", |
||||
|
"description": "", |
||||
|
"main": "gulpfile.js", |
||||
|
"scripts": { |
||||
|
"test": "echo \"Error: no test specified\" && exit 1" |
||||
|
}, |
||||
|
"author": "", |
||||
|
"license": "ISC", |
||||
|
"dependencies": { |
||||
|
"binary-pack": "^1.0.2", |
||||
|
"lodash": "^4.17.1", |
||||
|
"primus": "primus/primus", |
||||
|
"thunk-disque": "^0.5.9", |
||||
|
"thunk-redis": "^1.7.3", |
||||
|
"uws": "^0.14.1" |
||||
|
} |
||||
|
} |
File diff suppressed because it is too large
@ -0,0 +1 @@ |
|||||
|
2.4.0 |
@ -0,0 +1,10 @@ |
|||||
|
FROM ruby:2.4.0 |
||||
|
|
||||
|
RUN mkdir /pro |
||||
|
WORKDIR /pro |
||||
|
|
||||
|
ADD framework/tools/consumers/ruby/Gemfile /pro/Gemfile |
||||
|
ADD framework/tools/consumers/ruby/Gemfile.lock /pro/Gemfile.lock |
||||
|
RUN bundle install |
||||
|
|
||||
|
RUN apt-get update && apt-get install -y postgresql-client |
@ -0,0 +1,16 @@ |
|||||
|
source 'https://rubygems.org' |
||||
|
|
||||
|
# pro gems: |
||||
|
gem 'concurrent-ruby' |
||||
|
gem 'concurrent-ruby-ext' |
||||
|
gem 'connection_pool' |
||||
|
gem 'disque' |
||||
|
gem 'oj' |
||||
|
gem 'pg' |
||||
|
gem 'semantic_logger' |
||||
|
gem 'sequel' |
||||
|
gem 'sequel_pg' |
||||
|
gem 'sequel-seek-pagination', git: 'git://github.com/madmaniak/sequel-seek-pagination.git' |
||||
|
|
||||
|
# development: |
||||
|
gem 'byebug' |
@ -0,0 +1,47 @@ |
|||||
|
GIT |
||||
|
remote: git://github.com/madmaniak/sequel-seek-pagination.git |
||||
|
revision: 8907400653c551d24a8dae7548de05616883c467 |
||||
|
specs: |
||||
|
sequel-seek-pagination (0.2.1) |
||||
|
sequel (~> 4.0) |
||||
|
|
||||
|
GEM |
||||
|
remote: https://rubygems.org/ |
||||
|
specs: |
||||
|
byebug (9.0.6) |
||||
|
concurrent-ruby (1.0.4) |
||||
|
concurrent-ruby-ext (1.0.4) |
||||
|
concurrent-ruby (= 1.0.4) |
||||
|
connection_pool (2.2.1) |
||||
|
disque (0.0.6) |
||||
|
redic (~> 1.5.0) |
||||
|
hiredis (0.6.1) |
||||
|
oj (2.18.1) |
||||
|
pg (0.19.0) |
||||
|
redic (1.5.0) |
||||
|
hiredis |
||||
|
semantic_logger (3.4.1) |
||||
|
concurrent-ruby (~> 1.0) |
||||
|
sequel (4.42.1) |
||||
|
sequel_pg (1.6.17) |
||||
|
pg (>= 0.8.0) |
||||
|
sequel (>= 4.0.0) |
||||
|
|
||||
|
PLATFORMS |
||||
|
ruby |
||||
|
|
||||
|
DEPENDENCIES |
||||
|
byebug |
||||
|
concurrent-ruby |
||||
|
concurrent-ruby-ext |
||||
|
connection_pool |
||||
|
disque |
||||
|
oj |
||||
|
pg |
||||
|
semantic_logger |
||||
|
sequel |
||||
|
sequel-seek-pagination! |
||||
|
sequel_pg |
||||
|
|
||||
|
BUNDLED WITH |
||||
|
1.13.7 |
@ -0,0 +1,20 @@ |
|||||
|
## Role |
||||
|
|
||||
|
Backend. |
||||
|
|
||||
|
## Setup |
||||
|
[http://bundler.io/#getting-started](http://bundler.io/#getting-started) |
||||
|
|
||||
|
``` |
||||
|
cd tools/ruby |
||||
|
bundle |
||||
|
``` |
||||
|
|
||||
|
## Procfile |
||||
|
|
||||
|
``` |
||||
|
ruby-1: sh -c 'cd ./tools/ruby && exec ruby entry.rb' |
||||
|
ruby-2: sh -c 'cd ./tools/ruby && exec ruby entry.rb' |
||||
|
ruby-3: sh -c 'cd ./tools/ruby && exec ruby entry.rb' |
||||
|
ruby-4: sh -c 'cd ./tools/ruby && exec ruby entry.rb' |
||||
|
``` |
@ -0,0 +1,9 @@ |
|||||
|
require "irb" |
||||
|
require "irb/completion" |
||||
|
|
||||
|
ARGV = [] |
||||
|
puts "This is Ruby console. You have access to database through $db and following $models: |
||||
|
#{$models.values.join("\n")}" |
||||
|
puts "You can investigate also $services." |
||||
|
|
||||
|
IRB.start |
@ -0,0 +1,8 @@ |
|||||
|
set -e |
||||
|
|
||||
|
until PGPASSWORD=$POSTGRES_PASSWORD psql -h $POSTGRES_HOST -U $POSTGRES_USER -c '\l'; do |
||||
|
>&2 echo "Waiting for Postgres" |
||||
|
sleep 1 |
||||
|
done |
||||
|
|
||||
|
bundle exec ruby framework/tools/starter/start.rb |
@ -0,0 +1,22 @@ |
|||||
|
consumer: |
||||
|
build: |
||||
|
context: . |
||||
|
dockerfile: ./Dockerfile.consumer |
||||
|
extends: |
||||
|
file: framework/tools/containers/docker/common.yml |
||||
|
service: pro |
||||
|
environment: |
||||
|
pg_host: db |
||||
|
pg_port: 5432 |
||||
|
pg_user: pro |
||||
|
pg_pass: pro |
||||
|
app: pro |
||||
|
command: bash framework/tools/consumers/ruby/docker-up.sh |
||||
|
volumes: |
||||
|
- .:/pro |
||||
|
depends_on: |
||||
|
- communication_input |
||||
|
- communication_output |
||||
|
- bus |
||||
|
- db |
||||
|
- static |
@ -0,0 +1,26 @@ |
|||||
|
require 'connection_pool' |
||||
|
require 'disque' |
||||
|
|
||||
|
require_relative '../../db/postgres/db' |
||||
|
require_relative 'helpers/monkey_patches' |
||||
|
require_relative 'helpers/load_models' |
||||
|
require_relative 'helpers/load_services' |
||||
|
|
||||
|
PathsResolver.free # PathsResolver will be not used anymore |
||||
|
|
||||
|
connect_disque = ->{ Disque.new(["#{ENV['disque_host']}:#{ENV['disque_port']}"]) } |
||||
|
$dis = ConnectionPool.new(size: 8, timeout: 2) { connect_disque.call } |
||||
|
dis = connect_disque.call |
||||
|
|
||||
|
services = $services.reduce({}){ |h, (name, service)| |
||||
|
h[name] = service.new; h |
||||
|
} |
||||
|
|
||||
|
NAME = 0 |
||||
|
ID = 1 |
||||
|
PAYLOAD = 2 |
||||
|
|
||||
|
loop do |
||||
|
jobs = dis.que(:getjob, :from, *$services.keys) |
||||
|
jobs.each do |job| services[job[NAME]].run(job[PAYLOAD]) end |
||||
|
end |
@ -0,0 +1,118 @@ |
|||||
|
module CollectionIds |
||||
|
|
||||
|
refine Array do |
||||
|
def ids |
||||
|
@ids ||= map{ |c| c[:id] } |
||||
|
end |
||||
|
end |
||||
|
|
||||
|
end |
||||
|
|
||||
|
class Getter < Service |
||||
|
|
||||
|
using CollectionIds |
||||
|
|
||||
|
class << self |
||||
|
attr_reader :s |
||||
|
|
||||
|
def setup(opts) |
||||
|
@s = { |
||||
|
base: nil, # collection name |
||||
|
scope: ->(ds, params) { ds }, # set scope using Sequel |
||||
|
order: [ [:id, true] ], # order [Sequel:key, boolean:descending] |
||||
|
limit: 20, # limit per page |
||||
|
relations: {}, # relations name => Getter |
||||
|
fields: [] # fields to select from data |
||||
|
}.merge(opts) |
||||
|
end |
||||
|
|
||||
|
def iterate(sql, request, results) |
||||
|
result = $db.fetch(sql).all |
||||
|
return result if result.empty? |
||||
|
|
||||
|
# merge relevant data |
||||
|
results[@s[:base]] += |
||||
|
result |
||||
|
.map{ |row| |
||||
|
row |
||||
|
.select{ |k| [:id, :data, :v].include? k } |
||||
|
.merge(row[:data].select{ |k| @s[:fields].include? k.to_sym }) |
||||
|
.reject{ |k| k == :data } |
||||
|
} |
||||
|
|
||||
|
@s[:relations].each do |rel_name, getter| |
||||
|
relation = model.association_reflections[getter.s[:base]] |
||||
|
|
||||
|
relation_sql = \ |
||||
|
case relation[:type] |
||||
|
when :one_to_many |
||||
|
query = getter |
||||
|
.base_scope(request) |
||||
|
.where("#{relation[:key]} = relation_id") |
||||
|
.sql |
||||
|
|
||||
|
"select results.* from unnest(ARRAY#{result.ids}) as relation_id join lateral (#{query}) results on true" |
||||
|
end |
||||
|
|
||||
|
# add relation pointers |
||||
|
results[@s[:base]] += |
||||
|
getter.iterate(relation_sql, request, results) |
||||
|
.group_by{ |row| row[relation[:key]] } |
||||
|
.map{ |id, rows| { id: id, rel_name => rows.ids } } |
||||
|
end |
||||
|
|
||||
|
result |
||||
|
end |
||||
|
|
||||
|
def base_scope(request) |
||||
|
scope = @s[:scope] |
||||
|
.call(model, request) |
||||
|
.limit(@s[:limit]) |
||||
|
scope.opts[:order] ||= order |
||||
|
scope |
||||
|
end |
||||
|
|
||||
|
def model |
||||
|
@model ||= $models[@s[:base]] |
||||
|
end |
||||
|
|
||||
|
def order |
||||
|
@order ||= @s[:order].map{ |field, descending| |
||||
|
descending ? Sequel::SQL::OrderedExpression.new(field) : field |
||||
|
} |
||||
|
end |
||||
|
|
||||
|
private |
||||
|
|
||||
|
def j |
||||
|
@j ||= Sequel.expr(:data).pg_jsonb |
||||
|
end |
||||
|
|
||||
|
def field(name) |
||||
|
j.get_text(name) |
||||
|
end |
||||
|
|
||||
|
end |
||||
|
|
||||
|
def perform(data) |
||||
|
base_scope = self.class.base_scope(data) |
||||
|
base_sql = \ |
||||
|
if cursor = data[:before] |
||||
|
base_scope.seek cursor, by_pk: !cursor.is_a?(Array), back: true |
||||
|
elsif cursor = data[:after] |
||||
|
base_scope.seek cursor, by_pk: !cursor.is_a?(Array) |
||||
|
elsif cursor = data[:dynamic] |
||||
|
base_scope.exclude(id: cursor) |
||||
|
elsif cursor = data[:ids] |
||||
|
base_scope.limit(false).where id: cursor |
||||
|
elsif cursor = data[:page] |
||||
|
$db["select results.* from (#{base_scope.offset(base_scope.opts[:limit] * cursor).select(:id).sql}) ids join lateral (#{base_scope.limit(false).where('id = ids.id').sql}) results on true"] |
||||
|
else |
||||
|
base_scope |
||||
|
end.sql |
||||
|
|
||||
|
result = self.class.iterate(base_sql, data, results = Hash.new([])) |
||||
|
reply data, data: results, scope: result.ids |
||||
|
end |
||||
|
|
||||
|
end |
@ -0,0 +1,24 @@ |
|||||
|
require_relative 'paths_resolver' |
||||
|
|
||||
|
module Sequel::Plugins::CustomModel |
||||
|
module ClassMethods |
||||
|
def immutable(*value) |
||||
|
return @immutable if value.empty? |
||||
|
@immutable = !!value.first |
||||
|
end |
||||
|
end |
||||
|
end |
||||
|
|
||||
|
Sequel::Model.plugin :custom_model |
||||
|
|
||||
|
constants = Object.constants |
||||
|
|
||||
|
PathsResolver.resolve('model.rb').each do |model| |
||||
|
require "#{Dir.pwd}/#{model}" |
||||
|
end |
||||
|
|
||||
|
$models = (Object.constants - constants).inject({}) { |h, model| |
||||
|
model = Kernel.const_get(model) |
||||
|
h[model.table_name] = model |
||||
|
h |
||||
|
} |
@ -0,0 +1,13 @@ |
|||||
|
require_relative 'paths_resolver' |
||||
|
require_relative 'namespacer' |
||||
|
require './framework/tools/consumers/ruby/service' |
||||
|
require './framework/tools/consumers/ruby/getter' |
||||
|
|
||||
|
def Getter namespace, █ Namespacer.make(namespace, Getter, block); end |
||||
|
def Service namespace, █ Namespacer.make(namespace, Service, block); end |
||||
|
|
||||
|
require './framework/services/store/index' |
||||
|
|
||||
|
PathsResolver.resolve(:rb, blacklist: [:model], sort: :leafs_first).each{ |service| |
||||
|
require "./#{service}" |
||||
|
} |
@ -0,0 +1,23 @@ |
|||||
|
class Disque |
||||
|
|
||||
|
DEFAULTS = { |
||||
|
getjob: { count: 16, timeout: 0 } |
||||
|
} |
||||
|
|
||||
|
def que(method, *attributes) |
||||
|
@count += 1 |
||||
|
pick_client! |
||||
|
call method, *attributes |
||||
|
end |
||||
|
|
||||
|
end |
||||
|
|
||||
|
class String |
||||
|
def camelize |
||||
|
split('/').map{ |word| word.split('_').map(&:capitalize).join }.join('::') |
||||
|
end |
||||
|
|
||||
|
def constantize |
||||
|
Object.const_get self |
||||
|
end |
||||
|
end |
@ -0,0 +1,29 @@ |
|||||
|
$services = {} |
||||
|
|
||||
|
module Namespacer |
||||
|
|
||||
|
def self.make(path, sclass, block, prefix = 'front') |
||||
|
ns = prepare(path, prefix) |
||||
|
modules = ns.split('/').map(&:camelize) |
||||
|
klass = modules.pop |
||||
|
|
||||
|
$services[ns] = \ |
||||
|
modules.inject(Kernel) { |mod, mod_name| |
||||
|
if mod.const_defined?("#{mod.to_s}::#{mod_name}") |
||||
|
then mod.const_get(mod_name) |
||||
|
else mod.const_set(mod_name, Module.new) |
||||
|
end |
||||
|
}.const_set klass, Class.new(sclass, &block) |
||||
|
end |
||||
|
|
||||
|
def self.take(path, prefix = 'front') |
||||
|
prepare(path, prefix).gsub(/\/\w+$/, "" ).camelize.constantize |
||||
|
end |
||||
|
|
||||
|
def self.prepare(path, prefix) |
||||
|
"#{prefix}/#{path.gsub!(/^#{ENV['root']}\//, '')}"[0...-3] # [0...-3] rm .rb |
||||
|
end |
||||
|
|
||||
|
end |
||||
|
|
||||
|
NS = Namespacer |
@ -0,0 +1,28 @@ |
|||||
|
module PathsResolver |
||||
|
def self.resolve(kind, blacklist: [], sort: false) |
||||
|
@paths.map{ |paths_group| |
||||
|
paths = paths_group.select{ |path| path =~ /#{kind}$/ } |
||||
|
|
||||
|
if blacklist.any? |
||||
|
paths.reject!{ |path| path =~ /(#{blacklist.join('|')})/ } |
||||
|
end |
||||
|
|
||||
|
if sort |
||||
|
paths.sort_by!{ |path| |
||||
|
parts = path.split("/") |
||||
|
[ ( sort == :leafs_first ? -parts.size : parts.size ) , parts.last ] |
||||
|
} |
||||
|
else paths end |
||||
|
}.flatten |
||||
|
end |
||||
|
|
||||
|
def self.load |
||||
|
@paths = [ Dir["services/**/*"], Dir["components/**/*"], Dir["app/**/*"] ] |
||||
|
end |
||||
|
|
||||
|
def self.free |
||||
|
@paths = nil |
||||
|
end |
||||
|
end |
||||
|
|
||||
|
PathsResolver.load |
@ -0,0 +1,55 @@ |
|||||
|
require 'concurrent' |
||||
|
|
||||
|
require 'oj' |
||||
|
Oj.default_options = { symbol_keys: true, mode: :compat } |
||||
|
|
||||
|
require 'semantic_logger' |
||||
|
SemanticLogger.add_appender('development.log') |
||||
|
SemanticLogger.default_level = :trace |
||||
|
|
||||
|
class Service |
||||
|
|
||||
|
SERVICE_POOL = Concurrent::CachedThreadPool.new |
||||
|
include SemanticLogger::Loggable |
||||
|
|
||||
|
def run(job) |
||||
|
SERVICE_POOL.post do |
||||
|
begin |
||||
|
perform(prepare(job)) |
||||
|
logger.trace "#{job}: OK" |
||||
|
rescue => reason |
||||
|
logger.error "#{job}: #{reason}" |
||||
|
end |
||||
|
end |
||||
|
end |
||||
|
|
||||
|
private |
||||
|
|
||||
|
def prepare(message) |
||||
|
Oj.load message |
||||
|
end |
||||
|
|
||||
|
def prepare_send(message) |
||||
|
Oj.dump message |
||||
|
end |
||||
|
|
||||
|
def perform(data) |
||||
|
end |
||||
|
|
||||
|
def send(data) |
||||
|
$dis.with do |dis| |
||||
|
dis.que :addjob, |
||||
|
:send, prepare_send(data), 60, |
||||
|
:replicate, 1, :retry, 0, :ttl, 2 |
||||
|
end |
||||
|
end |
||||
|
|
||||
|
def reply(data, payload) |
||||
|
send payload.merge(sid: data[:sid], r: data[:r]) |
||||
|
end |
||||
|
|
||||
|
def broadcast(data, payload = nil) |
||||
|
send (payload || data).merge(sid: data[:sid], broadcast: true).reject{ |k| k == :r } |
||||
|
end |
||||
|
|
||||
|
end |
@ -0,0 +1,4 @@ |
|||||
|
FROM ruby:2.4.0 |
||||
|
|
||||
|
WORKDIR /pro |
||||
|
ENTRYPOINT ruby /pro/framework/tools/containers/docker/init.rb |
@ -0,0 +1,13 @@ |
|||||
|
version: '2' |
||||
|
services: |
||||
|
pro: |
||||
|
environment: |
||||
|
APP: pro |
||||
|
|
||||
|
disque_host: bus |
||||
|
disque_port: 7711 |
||||
|
|
||||
|
POSTGRES_HOST: db |
||||
|
POSTGRES_PORT: 5432 |
||||
|
POSTGRES_USER: pro |
||||
|
POSTGRES_PASSWORD: pro |
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue