#!/bin/sh /etc/rc.common
# Copyright (c) 2011-2015 OpenWrt.org

START=90

start(){
  enable=$(uci get mproxy.config.enabled 2>/dev/null)
  port=$(uci get mproxy.config.port)
  redir=$(uci get mproxy.config.redir)
	if [ $enable -eq 1 ]; then
      [ ! -f /etc/rc.d/S90mproxy ] && /etc/init.d/mproxy enable
      /usr/bin/mproxy -l $port -r 127.0.0.1:$redir -d
    else
      /etc/init.d/mproxy disable
  fi
}

stop(){
	  pid=$(ps | grep 'mproxy -l' | grep -v grep | cut -c 0-6) 
	  kill -9 $pid
}

restart(){
	  stop
	  start
}


