Yosemite support

This commit is contained in:
unstop
2014-10-18 06:33:57 +08:00
parent 11935e6807
commit 668da59f93
6 changed files with 52 additions and 33 deletions

View File

@@ -1,5 +1,5 @@
Copyright (c) 2014 Sam Stephenson, Basecamp
Copyright (c) 2014 Sun Liang, HackPlan
Copyright (c) 2014 Sam Stephenson, Basecamp
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the

View File

@@ -111,7 +111,7 @@
# Check to see if the server is running at all.
function check_status() {
sleep 1
curl -sH host:power "localhost:$POWER_HTTP_PORT/status.json" | grep -c "$VERSION" >/dev/null
curl -sH host:power "127.0.0.1:$POWER_HTTP_PORT/status.json" | grep -c "$VERSION" >/dev/null
}
# Attempt to connect to Power via each configured domain. If a

View File

@@ -37,15 +37,19 @@ module.exports = function(__obj) {
}
(function() {
(function() {
__out.push('<?xml version="1.0" encoding="UTF-8"?>\n<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">\n<plist version="1.0">\n<dict>\n\t<key>Label</key>\n\t<string>com.hackplan.power.firewall</string>\n\t<key>ProgramArguments</key>\n\t<array>\n\t\t<string>sh</string>\n\t\t<string>-c</string>\n\t\t<string>ipfw add fwd 127.0.0.1,');
__out.push(__sanitize(this.httpPort));
__out.push(' tcp from any to me dst-port ');
__out.push('<?xml version="1.0" encoding="UTF-8"?>\n<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">\n<plist version="1.0">\n<dict>\n <key>Label</key>\n <string>com.hackplan.power.firewall</string>\n <key>ProgramArguments</key>\n <array>\n <string>/bin/sh</string>\n <string>-c</string>\n <string>\n sysctl -w net.inet.ip.forwarding=1;\n echo "rdr pass proto tcp from any to any port {');
__out.push(__sanitize(this.dstPort));
__out.push(' in &amp;&amp; sysctl -w net.inet.ip.forwarding=1 &amp;&amp; sysctl -w net.inet.ip.fw.enable=1</string>\n\t</array>\n\t<key>RunAtLoad</key>\n\t<true/>\n\t<key>UserName</key>\n\t<string>root</string>\n</dict>\n</plist>\n');
__out.push(',');
__out.push(__sanitize(this.httpPort));
__out.push('} -> 127.0.0.1 port ');
__out.push(__sanitize(this.httpPort));
__out.push('" | pfctl -a "com.apple/250.PowerFirewall" -Ef -\n </string>\n </array>\n <key>RunAtLoad</key>\n <true/>\n <key>UserName</key>\n <string>root</string>\n</dict>\n</plist>\n');
}).call(this);

View File

@@ -1,7 +1,7 @@
{
"name": "power",
"description": "Zero-configuration static web server for Mac OS X",
"version": "0.0.1",
"version": "0.1.0",
"author": "Sun Liang",
"repository": {
"type": "git",

View File

@@ -2,17 +2,20 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.hackplan.power.firewall</string>
<key>ProgramArguments</key>
<array>
<string>sh</string>
<string>-c</string>
<string>ipfw add fwd 127.0.0.1,<%= @httpPort %> tcp from any to me dst-port <%= @dstPort %> in &amp;&amp; sysctl -w net.inet.ip.forwarding=1 &amp;&amp; sysctl -w net.inet.ip.fw.enable=1</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>UserName</key>
<string>root</string>
<key>Label</key>
<string>com.hackplan.power.firewall</string>
<key>ProgramArguments</key>
<array>
<string>/bin/sh</string>
<string>-c</string>
<string>
sysctl -w net.inet.ip.forwarding=1;
echo "rdr pass proto tcp from any to any port {<%= @dstPort %>,<%= @httpPort %>} -> 127.0.0.1 port <%= @httpPort %>" | pfctl -a "com.apple/250.PowFirewall" -Ef -
</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>UserName</key>
<string>root</string>
</dict>
</plist>
</plist>

View File

@@ -52,26 +52,38 @@
rm -f "$POWERD_PLIST_PATH"
# Read the firewall plist, if possible, to figure out what ports are in use.
# Determine if the firewall uses ipfw or pf.
if [[ -a "$FIREWALL_PLIST_PATH" ]]; then
ports=($(ruby -e'puts $<.read.scan(/fwd .*?,([\d]+).*?dst-port ([\d]+)/)' "$FIREWALL_PLIST_PATH"))
HTTP_PORT=${ports[0]}
DST_PORT=${ports[1]}
if grep ipfw "$FIREWALL_PLIST_PATH" >/dev/null; then
FIREWALL_TYPE=ipfw
elif grep pfctl "$FIREWALL_PLIST_PATH" >/dev/null; then
FIREWALL_TYPE=pf
fi
# Assume reasonable defaults otherwise.
# If ipfw, extract the port numbers from the plist.
[[ -z "$HTTP_PORT" ]] && HTTP_PORT=20559
[[ -z "$DST_PORT" ]] && DST_PORT=80
if [ "$FIREWALL_TYPE" = "ipfw" ]; then
ports=( $(ruby -e'puts $<.read.scan(/fwd .*?,([\d]+).*?dst-port ([\d]+)/)' "$FIREWALL_PLIST_PATH") )
HTTP_PORT="${ports[0]:-80}"
DST_PORT="${ports[1]:-20559}"
fi
# Try to find the ipfw rule and delete it.
RULE=$(sudo ipfw show | (grep ",$HTTP_PORT .* dst-port $DST_PORT in" || true) | cut -f 1 -d " ")
[[ -n "$RULE" ]] && sudo ipfw del "$RULE"
if [ "$FIREWALL_TYPE" = "ipfw" ] && [ -x /sbin/ipfw ]; then
RULE=$(sudo ipfw show | (grep ",$HTTP_PORT .* dst-port $DST_PORT in" || true) | cut -f 1 -d " ")
[ -z "$RULE" ] || sudo ipfw del "$RULE"
fi
# If pf, just flush all rules from the Pow anchor.
if [ "$FIREWALL_TYPE" = "pf" ]; then
sudo pfctl -a "com.apple/250.PowerFirewall" -F all 2>/dev/null || true
fi
# Unload the firewall plist and remove it.