public
Last active — forked from dhrrgn/pow_port.rb

  • Download Gist
pow_port.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
#!/usr/bin/env ruby
 
# Pow Port
#
# Quickly and easily change the port that Pow is running on. This allows
# you too run Apache and Pow side-by-side (on different ports of course).
#
# WARNING: This will OVERWRITE your ~/.powconfig file. If you have custom
# configurations in there, please back it up first.
#
# This file must be executable (chmod +x pow_port.rb)
# This must be ran with administrative privelages (sudo).
#
# Usage:
# sudo ./pow_port.rb <new_port>
#
# Author: Dan Horrigan <http://dhorrigan.com>
# Copyright: 2011 Dan Horrigan
# License: MIT License
 
if ARGV[0].nil?
puts 'Usage: sudo ./pow_port.rb <new_port>'
exit
end
 
new_port = ARGV[0]
rule_num = nil
fw_rules = `sudo ipfw list`
 
fw_rules.split("\n").each do |rule|
unless rule.index(",20559 ").nil?
rule_num = rule.split(" ")[0]
break
end
end
 
if rule_num.nil?
puts "Could not find the firewall rule. Are you sure you have Pow installed?"
exit
end
 
system("sudo ipfw delete #{rule_num}")
system("sudo ipfw add fwd 127.0.0.1,20559 tcp from any to me dst-port #{new_port} in 1> /dev/null")
 
File.open(File.expand_path("~/.powconfig"), 'w+') {|f| f.write("export POW_DST_PORT=#{new_port}") }
 
puts "Pow is now running on port #{new_port}! You may need to restart your browser to see the results."

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.