0

FreshBooks and Mikrotik Automatic Non-Payment Script

by Jim Bouse 9. October 2012 11:12

I have a WISP that has more customers that I would like to keep up with.  Most of the time is spent chasing down late payments.

I wrote the following combination of files to handle automating handling of Non-Payment customers.

Requirements:

  • Web server on a public IP address.
  • Domain Name.
  • FreshBooks account.
  • Simple Queue with a name EXACTLY matching the Last Name, First Name of the customer from FreshBooks.
  • Mikrotik Router with API access enabled.

Instructions:

  • In the Readme.txt

Problems?

 

Zip File (v1.0)

From the Readme.txt:

Mikrotik Freshbooks Intergration Script v1.0

Jim Bouse
jim@mobileitpro.com
http://jimbouse.com/post/2012/10/09/FreshBooks-and-Mikrotik-Automatic-Non-Payment-Script.aspx
October 9, 2012

License: None... Feel free to use, modify, butcher, whatever, this code. I ask that if you add features, you send me a copy.

Plug: I own and operate an WISP that uses Ubiquiti and Mikrotik equipment. I also do consulting work and onsite assistance.

======================================================================================

Description:
I needed to automatically block customers with overdue invoices. This is what I came up with.

======================================================================================

Files:
config.php <-- all PHP variables set here
create_callback.php <-- creates callbacks on FreshBooks.com
email.php <-- queries FreshBooks for customers matching names in Simple Queues
index.php <-- responds to callback requests from FreshBooks.com
AND is the page the customer is redirected to on non-payment.
Readme.txt <-- This file.
routeros_api.class.php <-- API class downloaded from http://wiki.mikrotik.com/wiki/API_PHP_class

======================================================================================

Instructions:
1. Setup a sub-domain for your files to reside on. (http://payments.example.com)
Place all files from zip there.

2. (OPTIONAL) Enable port 800 on web server.
This is needed if you don't have a dedicated IP for your payment server.
Also edit the PaymentServerPort to match in the Mikrotik Script at the bottom.

3. Setup the web server to redirect all 404 errors to index.php

4. Verify that the webserver can write to the directory of these files.
This is used for logging.

5. Modify config.php to match your environment.

6. Add the "Late Payment Fees" add-on in FreshBooks

7. Modify the default behavior of the late payment email to send a notice on day 20
and another notice on day 30. (FreshBooks ->Settings -> Emails)

8. Use create_callback.php to create the following Invoice "Past Due 2" and "Payment Create"

9. Run The script at the bottom on each of your Mikrotiks


======================================================================================
Currently, the index.php script only responds to:

callback.verify
invoice.pastdue.2
payment.create

You can use the existing code as an example to create more.
Reminder: If you add new features, please send me the code so I can update the files for others.


======================================================================================

Mikrotik Script:

:global PaymentServerIP "XXX.XXX.XXX.XXX"
:global PaymentServerPort "80"

/ip firewall nat add action=dst-nat chain=dstnat comment="Redirect Non-Payment HTTP"\
port=80 protocol=tcp src-address-list=NonPayment to-addresses=$PaymentServerIP\
to-ports=$PaymentServerPort
/ip firewall filter add chain=forward comment="Allow Non-Payment HTTPS to FreshBooks"\
dst-port=443 protocol=tcp src-address-list=NonPayment
/ip firewall filter add chain=forward comment="Allow Non-Payment HTTP to Payment Server"\
dst-address=$PaymentServerIP port=800 protocol=tcp src-address-list=NonPayment
/ip firewall filter add chain=forward comment="Allow DNS" port=53 protocol=udp
/ip firewall filter add chain=forward comment="Allow DNS" port=53 protocol=tcp
/ip firewall filter add action=drop chain=forward comment="Drop Non-Payment tcp traffic"\
protocol=tcp src-address-list=NonPayment
/ip firewall filter add action=drop chain=forward comment="Drop Non-Payment udp traffic"\
protocol=udp src-address-list=NonPayment
:put "Done"

FreshBooks-And-Mikrotik-Automatic-Non-Payment-Scripts-v1.0.zip (26.49 kb)

Tags: , , ,

FreshBooks | Mikrotik | WISP

0

Set Simple Queue Burst Rates

by Jim Bouse 30. September 2012 19:56

I have a Mikrotik router as my bandwidth limiter for my ISP.  I use Simple Queues for each IP to assign them to a speed.  I recently decided to be nice and add bursting to the plans.  I decided that the customers would get 2X their purchased speed for 16 seconds (a standard time window).  Since I had about 100 IPs and Simple Queues, I defanately did not want to manually add bursting to my Simple Queues.  I wrote the following script.  It will loop through all your simple queues and add the 2X burst amount.

You can download the .txt here in case the formatting gets screwed up. - setSimpleQueueBurst.txt (1.46 kb)

:local rate
:local inboundrate
:local outboundrate
:local inboundburstrate
:local outboundburstrate
:local inboundburstthreshold
:local outboundburstthreshold
:local ip
 
/queue simple
:foreach i in=[find] do={
  :set ip [get $i target-addresses]
  :set rate [get $i max-limit]
  :set inboundrate [:pick $rate ([:find $rate "/"]+1) 999 ]
  :if ([:find [:tostr $inboundrate] "k" ] > 0) do={
    :set inboundrate ([:pick $inboundrate 0 [:find [:tostr $inboundrate] "k" ]]*1000)
  }
  :if ([:find [:tostr $inboundrate] "M" ] > 0) do={
    :set inboundrate ([:pick $inboundrate 0 [:find [:tostr $inboundrate] "M" ]]*1000000)
  }
  :set outboundrate [:pick $rate 0 ([:find $rate "/"]+1)]
  :if ([:find [:tostr $outboundrate] "k" ] > 0) do={
    :set outboundrate ([:pick $outboundrate 0 [:find [:tostr $outboundrate] "k" ]]*1000)
  }
  :if ([:find [:tostr $outboundrate] "M" ] > 0) do={
    :set outboundrate ([:pick $outboundrate 0 [:find [:tostr $outboundrate] "M" ]]*1000000)
  }
  :set inboundburstrate ($inboundrate*2)
  :set outboundburstrate ($outboundrate*2)
  :set outboundburstthreshold ($outboundrate*2)
  :set inboundburstthreshold ($inboundrate*2)
  :set inboundrate ($inboundrate/5)
  :set outboundrate ($outboundrate/5)
  
  set $i limit-at="$outboundrate/$inboundrate" burst-time="16s/16s" burst-threshold="$outboundburstthreshold/$inboundburstthreshold" burst-limit="$outboundburstrate/$inboundburstrate"
  :put "Set $ip simple queue burst."
 
}

Tags: , ,

Mikrotik | WISP

0

Even Easier UBNT AirCam Snapshot

by Jim Bouse 28. August 2012 21:09

SSH into the unit.

Run:

mkdir /etc/persistent/www ; ln -s /tmp/snap.jpeg /etc/persistent/www/logo.gif ; save

View Image: http://device.address/images/logo.gif

Note: the image is only 640x480

Tags:

0

Low Cost Outdoor UPS

by Jim Bouse 30. July 2012 16:24

I own a small WISP and need an UPS in a small enclosure at the bottom of my towers to provide temporary power for when the grid drops for a few minutes/hours.

This is often coupled with a multi-port POE injector from Wifi-Soft and a router for a WISP tower location.

This comes to $387 for an outdoor UPS with a run time of about 8 hours without power for 2 - 8 watt radios and a RouterBoard.

Here is a similar version of what I have described.



Tags: , , , , ,

Mikrotik | Ubiquiti | WISP

0

Capture full resolution snapshot from UBNT AirCam with PHP and FFMPEG

by Jim Bouse 16. May 2012 08:42
<?php
system("ffmpeg -i rtsp://username:password@10.0.0.1/live/ch00_0 -y -f image2 -sameq -t 0.001 /path/to/warehouse.jpg");

header( "Content-type: image/jpeg" );
@readfile("/path/to/warehouse.jpg");
?>

Originally posted: http://forum.ubnt.com/showpost.php?p=299673&postcount=1

Tags:

Ubiquiti

0

Revert PicoM2 from UniFi to AirOS

by Jim Bouse 15. May 2012 13:46

A person posted this tool on the UBNT.com forums.

The original host is/was http://www.voyagerwireless.com/ubnt/UniFi2AirOS.bin.  I have uploaded it here to make sure it is available when I need it.

UniFi2AirOS.bin (6.78 mb)

Tags:

0

Find Who Has Locked ArcSDE Database

by Jim Bouse 4. May 2012 14:54
select start_time, owner, nodename from SDE_process_information where sde_id in (
select sde_id from SDE_table_locks where registration_id = (
select registration_id from SDE_table_registry where table_name = 'Streets'
)
);

Tags:

0

Multiple SSID with UBNT AP's

by Jim Bouse 28. March 2012 14:00

Tags:

0

Reset UBNT Device to Default via SSH

by Jim Bouse 28. March 2012 11:28

NOTICE! This resets it to default (factory).  If you want to just reboot, use "reboot".

cp /usr/etc/system.cfg /tmp/system.cfg; save; reboot

Tags:

Ubiquiti

0

Mikrotik Simple Queue Script

by Jim Bouse 24. February 2012 11:48

I needed to be able to create simple queues for the /27 I got from my upstream provider.  I wanted to do this with a script instead of typing by hand and perhaps creating a typo.

  • /queue simple add name="Purchased Bandwith" max-limit=10M/10M
  • :for x from=130 to=158 do={/queue simple add name="216.xxx.70.$x" target-addresses="216.xxx.70.$x" parent="Purchased Bandwith" max-limit=384k/1M }

Tags:

Mikrotik

Powered by BlogEngine.NET 2.5.0.6
Original Design by Laptop Geek, Adapted by onesoft