Linux Unifi Controller Change Admin password

Password reset procedure for Linux:

1. Find out your username.
If you don’t know it any more and it’s not ‘admin’, run this command to get all Admin users on the controller:


mongo --port 27117 ace --eval "db.admin.find().forEach(printjson);"
 

You should get a result like this:

MongoDB shell version: 2.4.10
connecting to: 127.0.0.1:27117/ace
{
"_id" : ObjectId("56e178af97f2d0511ce3abea"),
"email" : "admin@admin",
"last_site_name" : "default",
"name" : "admin",
"time_created" : NumberLong(1457617071),
"x_shadow" : "$6$O6Uuq5Vww6zNxd$06bwBj5v4e0omEZ97qRbiaZbOi75o.r 5M4ympQYmY5FP8C.0QGenCIkymiK/YkWoDDfw1YcS42LYSFvPH gP7U0"
}
 

Note the “name” field above. It contains the username (“admin” in this example).

2. Generate a new password.
Run this command to get a new salted hash:

  

mkpasswd -m sha-512
Password: <enter your new password>
$6$9Ter1EZ9$lSt6/tkoPguHqsDK0mXmUsZ1WE2qCM4m9AQ.x9 /eVNJxws.hAxt2Pe8oA9TFB7LPBgzaHBcAfKFoLpRQlpBiX1
 

The long $6$9Ter… string is your new salted password hash. (The example above uses ‘password’, so if you just want to reset your account to ‘password’, you can copy/paste it directly from the example.)

3. Update the salted hash in the database.
Run this command to update the salted hash that’s stored in the database (replace the respective values with the ones you determined above):

 
mongo --port 27117 ace --eval 'db.admin.update( { "name" : "admin" }, { $set : { "x_shadow" : "$6$9Ter1EZ9$lSt6/tkoPguHqsDK0mXmUsZ1WE2qCM4m9AQ.x 9/eVNJxws.hAxt2Pe8oA9TFB7LPBgzaHBcAfKFoLpRQlpBiX1" } } )'
 

(Note: If your username is ‘admin’ and you just want to set the password to ‘password’, you can simply copy/paste the above command and run it to do so.)

You’re done! You can now log in with the new password that you set.

Grab MAC From ARP Table With PHP

Cool function you can use on your local network to lookup a devices MAC address, (assuming the device is on your network), using PHP.
For a big company, either look in the remote locations router, or your core router.
// =============================================
// getmac(Device IP, Router, SNMP Read Community)
// Michael Requeny -- http://michael.requeny.com
// - Looks up remote devices MAC
// - SNMP to routers ARP table
// - Converts MAC from HEX to ASCII
// - Inserts : seperators
// =============================================
function getmac($ip, $router, $snmpread) {
	$oid = ".1.3.6.1.2.1.3.1.1.2";
	$mac = snmprealwalk($router, $snmpread, $oid, 1000000 ,10);
	// load up array keys for lookups
	$keys = array_keys($mac);
	foreach ($keys as $key) {
		// if needle contains IP &amp;&amp; needle = IP
		// this prevents srch for 10.254.254.1 returning
		// multiple values (like .1, .11, .111, etc.
		if (strstr($key,$ip) == $ip) {
			$mackey = $key;
		}
	}
	$mac = trim(str_replace('Hex-STRING: ', '', $mac));
	$mac = str_replace(' ', ':', $mac);
	return $mac;
}

Disable IPv6 On Ubuntu/Debian

The more formal way of doing this, which fits in with the don’t-change-a-core-system-file-otherwise-it-could-be-replaced-when-you-upgrade-packages-and-your-changes-could-be-lost methodology, and such that it continues across a reboot, is as follows:

# create the long-life config file

echo "net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1" | sudo tee /etc/sysctl.d/99-my-disable-ipv6.conf

# ask the system to use it

sudo service procps reload

# check the result

cat /proc/sys/net/ipv6/conf/all/disable_ipv6

 

Bad Behavior has blocked 109 access attempts in the last 7 days.