Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
slapos
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nirina Malard
slapos
Commits
1d7d6db4
Commit
1d7d6db4
authored
Dec 07, 2011
by
Cédric de Saint Martin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
kvm frontend : set script and wrapper
parent
fab605c1
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
131 additions
and
3 deletions
+131
-3
slapos/recipe/kvm_frontend/__init__.py
slapos/recipe/kvm_frontend/__init__.py
+17
-3
slapos/recipe/kvm_frontend/template/kvm-proxy.js
slapos/recipe/kvm_frontend/template/kvm-proxy.js
+114
-0
No files found.
slapos/recipe/kvm_frontend/__init__.py
View file @
1d7d6db4
...
@@ -254,15 +254,29 @@ class Recipe(BaseSlapRecipe):
...
@@ -254,15 +254,29 @@ class Recipe(BaseSlapRecipe):
def
installFrontendNode
(
self
,
ip
,
port
,
key
,
certificate
,
plain_http
,
def
installFrontendNode
(
self
,
ip
,
port
,
key
,
certificate
,
plain_http
,
name
,
rewrite_rule_list
):
name
,
rewrite_rule_list
):
# Create Map
map_name
=
"proxy_table.json"
map_name
=
"proxy_table.json"
map_content
=
self
.
_getProxyTableContent
(
rewrite_rule_list
)
map_content
=
self
.
_getProxyTableContent
(
rewrite_rule_list
)
map_file
=
self
.
createConfigurationFile
(
map_name
,
map_content
)
map_file
=
self
.
createConfigurationFile
(
map_name
,
map_content
)
self
.
path_list
.
append
(
map_file
)
self
.
path_list
.
append
(
map_file
)
# Install script
kvm_proxy_script_in
=
pkg_resources
.
resource_filename
(
__name__
,
os
.
path
.
join
(
'template'
,
'kvm-proxy.js'
))
kvm_proxy_script
=
self
.
createRunningWrapper
(
"kvm-proxy.js"
,
kvm_proxy_script_in
)
self
.
path_list
.
append
(
kvm_proxy_script
)
# Get environment
self
.
options
[
'node-path'
]
# Create wrapper
wrapper
=
zc
.
buildout
.
easy_install
.
scripts
([(
wrapper
=
zc
.
buildout
.
easy_install
.
scripts
([(
name
,
'slapos.recipe.librecipe.execute'
,
'execute'
)],
self
.
ws
,
name
,
'slapos.recipe.librecipe.execute'
,
'execute
e_wait
'
)],
self
.
ws
,
sys
.
executable
,
self
.
wrapper_directory
,
arguments
=
[
sys
.
executable
,
self
.
wrapper_directory
,
arguments
=
[
ip
,
port
,
key
,
certificate
,
plain_http
]
self
.
options
[
'dcrond_binary'
].
strip
(),
kvm_proxy_script
,
ip
,
port
,
key
,
certificate
,
plain_http
],
{
'NODE_PATH'
:
self
.
options
[
'node-path'
]}
)[
0
]
)[
0
]
self
.
path_list
.
extend
(
wrapper
)
self
.
path_list
.
extend
(
wrapper
)
...
...
slapos/recipe/kvm_frontend/template/kvm-proxy.js
0 → 100644
View file @
1d7d6db4
var
fs
=
require
(
'
fs
'
),
util
=
require
(
'
util
'
),
colors
=
require
(
'
colors
'
),
http
=
require
(
'
http
'
),
httpProxy
=
require
(
'
http-proxy
'
),
process
=
require
(
'
process
'
)
proxyByUrl
=
require
(
'
proxy-by-url
'
);
var
proxyTable
=
'
proxy-table.json
'
,
//listenInterface = '2a01:e34:ec03:8610:60c:ceff:fed1:b9fc',
listenInterface
=
process
.
argv
[
1
],
port
=
process
.
argv
[
2
],
sslKeyFile
=
process
.
argv
[
3
],
sslCertFile
=
process
.
argv
[
4
],
redirect
=
process
.
argv
[
5
]
||
false
,
isRawIPv6
;
isRawIPv6
=
function
checkipv6
(
str
)
{
// Inspired by http://forums.intermapper.com/viewtopic.php?t=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){1,6})
|
((
:
[
0-9A-Fa-f
]{1,4}){0,4}
:
((
25
[
0-5
]
|2
[
0-4
]\d
|1
\d\d
|
[
1-9
]?\d)(\.(
25
[
0-5
]
|2
[
0-4
]\d
|1
\d\d
|
[
1-9
]?\d)){3}))
|:
))
|
(
:
(((
:
[
0-9A-Fa-f
]{1,4}){1,7})
|
((
:
[
0-9A-Fa-f
]{1,4}){0,5}
:
((
25
[
0-5
]
|2
[
0-4
]\d
|1
\d\d
|
[
1-9
]?\d)(\.(
25
[
0-5
]
|2
[
0-4
]\d
|1
\d\d
|
[
1-9
]?\d)){3}))
|:
)))(
%.+
)?\s
*$/
.
test
(
str
));
}(
listenInterface
);
// Dummy middleware that throws 404 not found.
var
middlewareNotFound
=
function
(
req
,
res
,
proxy
)
{
res
.
statusCode
=
404
;
res
.
setHeader
(
'
Content-Type
'
,
'
text/plain
'
);
res
.
end
(
'
This URL is not known. Please check your URL or contact your
'
+
'
SlapOS administrator.
'
);
};
middlewareNotFound
.
proxyWebSocketRequest
=
function
(
req
,
socket
,
head
,
next
)
{
console
.
log
(
'
stop
'
);
socket
.
end
();
};
/**
* Rewrite URL to match Zope's virtual host monster if we use vifib
*/
var
middlewareVifib
=
function
(
req
,
res
,
next
)
{
// Completely hardcoded rewrite
var
vifibPrefix
=
'
/hosting
'
;
if
(
req
.
url
.
indexOf
(
vifibPrefix
)
==
0
)
{
var
hostname
=
'
localhost
'
,
port
=
'
8000
'
;
// Rewrite URL to match virtual host
req
.
url
=
vifibPrefix
+
'
/VirtualHostBase/https/
'
+
hostname
+
'
:
'
+
port
+
'
/erp5/web_site_module/VirtualHostRoot
'
+
req
.
url
;
console
.
log
(
'
Vifib rewrite. New URL is :
'
+
req
.
url
);
}
next
();
};
/**
* Create server
*/
var
proxyServer
=
httpProxy
.
createServer
(
middlewareVifib
,
// We declare our proxyByUrl middleware
proxyByUrl
(
proxyTable
),
// Then we add your dummy middleware, called when proxyByUrl doesn't find url.
middlewareNotFound
,
// And we set HTTPS options for server. HTTP will be forbidden.
{
https
:
{
key
:
fs
.
readFileSync
(
//'/Users/cedricdesaintmartin/Desktop/SlapOS/slapconsole-keys/cedric-owf-0/ssl.key',
sslKeyFile
,
'
utf8
'
),
cert
:
fs
.
readFileSync
(
//'/Users/cedricdesaintmartin/Desktop/SlapOS/slapconsole-keys/cedric-owf-0/ssl.cert',
sslCertFile
,
'
utf8
'
)
},
source
:
{
host
:
listenInterface
,
port
:
port
}}
);
// We gonna rock this civilization.
proxyServer
.
listen
(
port
,
listenInterface
);
console
.
log
(
'
HTTPS server started and listening at
'
+
listenInterface
+
'
:
'
+
port
);
// Dummy HTTP server redirecting to HTTPS. Only has sense if we can use port 80
if
(
redirect
===
true
)
{
try
{
var
httpPort
=
80
;
http
.
createServer
(
function
(
req
,
res
)
{
var
url
;
if
(
isRawIPv6
===
true
)
{
url
=
'
https://[
'
+
listenInterface
+
'
]
'
;
}
else
{
url
=
'
https://
'
+
listenInterface
;
}
// If non standard port : need to specify it
if
(
port
!==
443
)
{
url
=
url
+
'
:
'
+
port
;
}
// Add last part of URL
url
=
url
+
req
.
url
;
console
.
log
(
url
);
// Anwser "permanently redirected"
res
.
statusCode
=
301
;
res
.
setHeader
(
'
Location
'
,
url
);
res
.
end
();
}).
listen
(
httpPort
,
listenInterface
);
console
.
log
(
'
HTTP redirect server started and listening at
'
+
listenInterface
+
'
:
'
+
httpPort
);
}
catch
(
EACCES
)
{
console
.
log
(
'
Couldn
\'
t start plain HTTP redirection server :
'
+
EACCESS
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment