Deploying NextJS to Heroku

This took me quite sometime to figure out, so I hope this helps:

  1. Follow Heroku’s instructions on Getting Started on Node.js up until “Deploy the app”
  2. At this point, visiting your site via heroku open will only show an error
  3. Modify your package.json to include the following scripts:
  4. "scripts": {
      // ...
      "heroku-postbuild": "next build",
      "start": "next start -p $PORT"
    }
  5. Push to Heroku again, and voila, it should now work.

Mac OS X: How to change your network settings based on Wifi SSID

Ever since I’ve seen Mac OS’s Location profiles (I think it was 2007), I’ve been wondering why the hell GNU/Linux didn’t have something like that. It was really convenient.

About a year after (maybe), Ubuntu switched to using NetworkManager which had something better: network profiles tied to the wifi network. Now I’m on Mac, I’ve been wondering why doesn’t Mac do that?

Good thing that the Internet fixes this.

I found this script through this SuperUser question.

Install it via Terminal by:

cd ~
git clone https://github.com/rimar/wifi-location-changer.git
cd wifi-location-changer
cp locationchanger /usr/local/bin
cp LocationChanger.plist ~/Library/LaunchAgents/
launchctl load ~/Library/LaunchAgents/LocationChanger.plist

If you don’t have git, you can copy the scripts below and save them in the paths provided with respective filenames:
Continue reading “Mac OS X: How to change your network settings based on Wifi SSID”

Squid Splash Page Notes

I’m playing with Squid and setting it up as a captive portal.
This is my notes on their documentation.

  • Top-down processing of rules gave me 90% of the troubles I encountered.
  • The deny_info path doesn’t really work. It should be a filename relative to the error_directory directory.
  • You have to manually create the session db/session folder the first time. mkdir /var/lib/squid/session && chmod 777 /var/lib/squid/session
  • To clear sessions from the server (for testing), you can delete and re-create the sessions folder: rm /var/lib/squid/session -r && mkdir /var/lib/squid/session -r && chmod 777 /var/lib/squid/session
  • Always check permissions.

Next things to do:

  • Making it a transparent proxy
  • Dealing with SSL (port 443)
  • Changing upstream providers from LAN to USB Dongle

http://www.andybev.com/index.php/Setting_up_a_captive_portal_from_scratch_using_Debian
http://system-admin.xtronix.in/2012/07/captive-portal-with-transparent-proxy.html
https://wiki.archlinux.org/index.php/squid#Installation

Here’s a copy of my squid.conf:

#
# Recommended minimum configuration:
#

# Example rule allowing access from your local networks.
# Adapt to list your (internal) IP networks from where browsing
# should be allowed
acl localnet src 10.0.0.0/8 # RFC1918 possible internal network
acl localnet src 172.16.0.0/12 # RFC1918 possible internal network
acl localnet src 192.168.0.0/16 # RFC1918 possible internal network
acl localnet src fc00::/7 # RFC 4193 local private network range
acl localnet src fe80::/10 # RFC 4291 link-local (directly plugged) machines

acl SSL_ports port 443
acl Safe_ports port 80 # http
acl Safe_ports port 21 # ftp
acl Safe_ports port 443 # https
acl Safe_ports port 70 # gopher
acl Safe_ports port 210 # wais
acl Safe_ports port 1025-65535 # unregistered ports
acl Safe_ports port 280 # http-mgmt
acl Safe_ports port 488 # gss-http
acl Safe_ports port 591 # filemaker
acl Safe_ports port 777 # multiling http
acl CONNECT method CONNECT

#
# Recommended minimum Access Permission configuration:
#
# Deny requests to certain unsafe ports
http_access deny !Safe_ports

# Deny CONNECT to other than secure SSL ports
http_access deny CONNECT !SSL_ports

# Only allow cachemgr access from localhost
http_access allow localhost manager
http_access deny manager

# We strongly recommend the following be uncommented to protect innocent
# web applications running on the proxy server who think the only
# one who can access services on “localhost” is a local user
#http_access deny to_localhost

#
# INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS
#

# Squid normally listens to port 3128
# http_port 3128 transparent
# http_port 80 vhost
# http_port 3128 intercept
http_port 3128 intercept

error_directory /makubex

# http://wiki.squid-cache.org/ConfigExamples/Portal/Splash
#### Passive ####

# external_acl_type splash_page ttl=60 concurrency=100 %SRC /usr/lib/squid/ext_session_acl -t 7200 -b /var/lib/squid/session.db
# acl existing_users external splash_page
# http_access deny !existing_users
# deny_info 511:splash.html existing_users

#### Active ####

# external_acl_type session ttl=300 negative_ttl=0 children-startup=1 concurrency=200 %LOGIN /usr/lib/squid/ext_session_acl
# acl session_login external session LOGIN
# http_access deny !session
# deny_info http://rystraum.com?url=%s session

external_acl_type session concurrency=100 ttl=3 %SRC /usr/lib/squid/ext_session_acl -a -T 10800 -b /var/lib/squid/session/
acl session_login external session LOGIN
external_acl_type session_active_def concurrency=100 ttl=3 %SRC /usr/lib/squid/ext_session_acl -a -T 10800 -b /var/lib/squid/session/
acl session_is_active external session_active_def
# acl clicked_login_url url_regex -i http://rystraum.com$
acl clicked_login_url url_regex -i http://rystraum.com/search$
http_access allow clicked_login_url session_login
http_access deny !session_is_active
deny_info 511:index.html session_is_active
# deny_info http://10.1.0.1?url=%s session_is_active
# acl clicked_login_url url_regex -i http://google.com$

##### Catch All #####

# Example rule allowing access from your local networks.
# Adapt localnet in the ACL section to list your (internal) IP networks
# from where browsing should be allowed
http_access allow localnet
http_access allow localhost

# And finally deny all other access to this proxy
http_access deny all

# Uncomment and adjust the following to add a disk cache directory.
#cache_dir ufs /var/cache/squid 256 16 256

# Leave coredumps in the first cache dir
coredump_dir /var/cache/squid

#
# Add any of your own refresh_pattern entries above these.
#
refresh_pattern ^ftp: 1440 20% 10080
refresh_pattern ^gopher: 1440 0% 1440
refresh_pattern -i (/cgi-bin/|\?) 0 0% 0
refresh_pattern . 0 20% 4320

visible_hostname makubex