Wednesday, 26 November 2014

picky plesk problems

I recently needed to move some domains from an older reseller account which my hosts manage to my VPS which I'm responsible for (hosted by the same firm).

As I do not have root access to the reseller account I was not able to use the plesk migration manager myself so the lovely people at my hosting company (34sp) moved the domains for me.

All seemed to go well and all the domains were up and running as they should (databases, email, web etc). It was only a couple of weeks later when I needed to change one of the domains that I realise there was a little problem.

It seems that the plesk migration manager had created a new reseller on my VPS (which makes sense) but it failed to add a "plan" for the reseller. This meant that when it tried to add the domains under that reseller it was unable to do so as there was no plan for them to be added to. So, not wanting to be defeated the migration manager added the domains with a reseller ID for a none existent reseller (id 0).

I also found that when I tried to add a plan to the reseller that I got an error in plesk (I forget what it was now but it was red and angry looking)

So, good news, they all transferred, bad news I can't do anything with them.

The solution....
(normal; it worked for me, your mileage may vary, backup first, if it goes wrong it isn't my fault rules apply).

Logon to your vps and run mysql as a user that has access to everything (root or admin probably). I'm not giving details of how to do this, if you don't know go away and work that out before even thinking about this)

Rather than using select * statements I have included the fields that I found handy to help work things out. Some or all of the fields may not be required.

Select the psa database
use psa

Check the clients table for resellers
select count(*) from clients where type='reseller';
select id, parent_id, vendor_id, type, cname, pname, account_id, status from clients where type='reseller';

Check the subscriptions table for clients
select count(*) from Subscriptions where object_type='client';
select * from Subscriptions where object_type='client';

There should be the same number of record returned by both. In my instance the new reseller was not in the subscriptions table.

Generate a new uuid for the record
select uuid();

Insert a new subscription record for the new reseller. Use the ID from the clients table and the uuid you generated
INSERT INTO Subscriptions (object_id,object_type,locked,synchronized,custom,uuid) VALUES (<CLIENT ID>,'client','false','true','false','<THE UUID')

By this point you should be able to give the reseller a plan but will still have missing domains. For me clicking on the reseller showed no plans, customers or domains in the general section but 7 domains used in the resources section.

Find one of your missing domains
select id, name, displayName, status, vendor_id, cl_id from domains where name="wffsystems.co.uk";

Take the cl_id from the above query and use it in the next one. In my instance the "missing" domains were owned by a cl_id of zero so this gave me a shorter list. Fingers crossed this will list all the ones that are missing.
select id, name, displayName, status, vendor_id, cl_id from domains where cl_id=<YOUR CL_ID>;

Last but not least, update each domain to have the cl_id of the reseller you want them to belong to. I did this one by one but with a bit of thought I'm sure I could have done it as a one liner.
update domains set cl_id=<YOUR RESELLER ID> where id=<THE DOMAIN ID>;

I'm not totally convinced that this has totally fixed things as my new reseller still has 7 domains listed as used even though there are none actualy in that reseller account but at least I can get to all my domains now!

Hope this helps someone.

***UPDATE***

In the domains table there is a cl_id and a vendor_id. No idea what the difference is but changing vendor_id to be the same as everything else seems to have resolved the issue.

Tuesday, 25 November 2014

Installing the Ubiquity UniFi software on ubuntu

This is shamelessly stolen from the following site and I have not tested it but wanted somewhere I could go that I knew I would be able to find the info.

https://community.ubnt.com/t5/UniFi-Updates-Blog/UniFi-3-2-7-is-released/ba-p/1085473

UniFi Controller APT howto
  1. edit /etc/apt/sources.list
    ## Ubuntu
    deb http://www.ubnt.com/downloads/unifi/distros/deb/ubuntu ubuntu ubiquiti
    
  2. add GPG Key
    # for Ubiquiti
    sudo apt-key adv --keyserver keyserver.ubuntu.com --recv C0A52C50
    
  3. update, install, and upgrade
    # retrieve the latest package information
    apt-get update
    apt-get install unifi
    
UniFi API
A shell library, unifi_sh_api is provided with the release. here's a sample script to authorize a guest for 30 minutes
#!/bin/sh
## define required variables
username=admin
password=admin
baseurl=https://localhost:8443
site=default
## include the API library
. unifi_sh_api
unifi_login
# authorize a client for 30 minutes, limit down/up speed to 2048/1024kbps, quota is 500MB
unifi_authorize_guest "e8:17:22:10:5d:4d" 30 down=2048 up=1024 bytes=500 
# generate 10 voucher(s) valid for 60 minutes, limit down/up speed to 2048/1024kbps, quota is 500MB
unifi_create_voucher 60 10 down=2048 up=1024 bytes=500
# this returns you a token that you can call by using unifi_get_vouchers()
unifi_logout
Notes
  1. AP->Performance view is experimental. Currently it shows what the radio is doing by red (packets not sent because of likely interference) / yellow (packets retried) / green (packets sent)
  2. voucher.css and voucher.html, at data/sites/SITE_NAME/portal/bundle/, is where you can fully customize your voucher.
  3. If you have existing customized guest portal, make sure to change form="/guest/login" to form="login" - let the relative path take care of per-site URL
  4. For API access, you pretty much need to insert /s/SITENAME into the URL. (after login with an admin in for site)

Monday, 27 January 2014

Adding Extensions to a free PBX / Asterisk server

Logon to your server
http://172.17.0.11/freepbx/admin



From the applications menu select extensions




Select generic sip device as the type and continue




Enter the user extension eg 110

enter the display name eg Gareth Westwood

from the "This device uses sip technology" section either note down or create a new secret (password) to use when you configure the phone handset
click submit from the bottom of the page
The extension should now appear with any others you have created in the top right of the screen

Configuring a Linksys SPA941 on Freepbx (Asterisk)

For this post I am going to assume you have the phone plugged into your network and that something is giving out dhcp address. I'm also assuming you have already configured your extensions on the server and have the extension password to hand.

I have seen some talk of this phone being either a 2 line or 4 line version depending on the firmware. I don't know how to do that bit and for my install I only need 1 line so am not really fussed.

First job (just to be safe) is to reset the phone to factory defaults.
Press the menu button
Use the up/down arrows to select option 14 "Facroy Reset"  and press select (or key in 14)
Confirm by pressing ok
The phone will then restart and get a dhcp address from the dhcp server.

Check the current IP
Press the menu button
use the up/down arrows to select option 9 "Network" and press select (or key in 9)
The phones current IP should be listed in item 2 on the screen. For my example it is  172.17.0.152

Enter the settings for your asterisk/Freepbx server
goto the phones ip address in your browser (I used chrome)
click on the admin login link from the top of the page
select regional tab
clear all "Vertical Service Activation Codes"
change timezone to GMT
select the Phone Tab
under line key 2, 3 and 4 change extension from 1 to disabled
select the Ext 1 tab
Enter the ip address of the asterisk server in the proxy box (172.17.0.20)
Under Subscriber information put;
the users name in display name
the extension number in user ID
The secret key from the asterisk extension config in the password box
(as long as this is the same on both ends it doesn't really matter what it is)
Click the Submit all changes button and wait for the phone to restart (which sometimes takes a while)

Monday, 13 January 2014

Installing the Unifi wireless AP controller as a service

I have recently started using the Ubiquity wireless access points. They have come very highly recommended by the engineers I work with at Quietly Confident Technology Ltd. The only issue I have is that by default installation of the controller goes to the users profile directory and therefore needs that user to be logged on for it to work.

I needed a way to get it running as a service so it could be auto started on reboot and not require a user to be logged in. I did all of this on a new windows 7 64 bit machine accepting all defaults unless otherwise mentioned. This is all provided as is, I am not saying this will work seamlessly on all machines, use at your own risk...

Most of the info here is stolen from the unifi FAQ HERE but there are a couple of extra bits.

Install Java
The first thing to do is download and install the latest version of Java. The unifi software will do this automatically for you but I had issues starting the service if I used the version of Java that was auto installed.
download from: http://www.java.com/en/download/windows_offline.jsp
Follow the prompts onscreen. Be aware that some java installers try to sneak crap ware onto your PC so make sure to keep your eyes open for "Yes, please install xx, yy and zz" for me.

Install Unifi AP
Once Java is on install the unifi AP controller software
download from: http://www.ubnt.com/download#UniFi:AP
Again, follow the onscreen instructions, it's another next, next, ok, next thing. Do not bother to run the controller when the install finishes. We want to move it around first.

Move it all around
The default install for the unifi software is into the user profile. This helps when doing updates but seems a little none standard to me so to prevent issues at a later date move the folder "c:\users\admin\Ubiquiti UniFi" to "c:\program files".

Install the service
Make sure that the java bin directory to the PATH (Computer > Properties > Advanced > Environment Variables > in the System Variables bit) as by default is isn't in there. On my install "C:\Program Files\Java\jre7\bin" needed adding (is't a ";" separated list).
run cmd as an Administrator, (right click 'Run as administrator')
cd to the location you moved Ubiquiti UniF to earlier ("c:\program files\Ubiquiti UniF")
run the following command "java -jar lib\ace.jar installsvc"
Start the service either by running 'net start "Unifi Controller"' or by going to the services control panel (run > services.msc)

Checkout your skills
Browse to https://<your ip here>:8443 and go through the setup.
This should auto run when the computer is restarted.

I hope someone somewhere finds that handy.