Hello everybody!

Updating to an Umbraco site, which is now primarly going to be a blog about useful and interesting software development related things.

Historic articles and software has been kept and more will be added in due course.

View the Archive...

Archive for tag: PHP

APC PDU Power control via SNMP

Below are a couple of simple examples on how you can use PHP/SNMP to control the power outlets on APC PDU devices , AP7951 or the lower priced model here

Note : in the example below you need to replace "readcommunity" and "writecommunity" with your SNMP community strings that you set on the APC

function apcGetStatus($APCip, $APCport) {  
  $APCresponse = snmpget($APCip, "readcommunity", ".1.3.6.1.4.1.318.1.1.4.4.2.1.3.$APCport");
  $APCresponse = str_replace('INTEGER: ', '', $APCresponse);
  switch ($APCresponse) {
    case '1':
      $returnVal = 'On';
      break;
    case '2':
      $returnVal = 'Off';
      break;
    case '3':
      $returnVal = 'Reboot';
      break;
    case '4':
      $returnVal = 'Unknown';
      break;
    case '5':
      $returnVal = 'On with delay';
      break;
    case '6':
      $returnVal = 'Off with delay';
      break;
    case '7':
      $returnVal = 'Reboot with delay';
      break;
    default:
      $returnVal = $APCresponse;
  }
  return $returnVal;
}
function apcSetStatus($APCip, $APCport, $rebootOption) {

  switch ($rebootOption) {
    case '1':
      $actionTo = 'On';
      break;
    case '2':
      $actionTo = 'Off';
      break;
    case '3':
      $actionTo = 'Reboot';
      break;
    case '5':
      $actionTo = 'On with delay';
      break;
    case '6':
      $actionTo = 'Off with delay';
      break;
    case '7':
      $actionTo = 'Reboot with delay';
      break;
    default:
      return 'Invalid reboot option passed';
  }
  
  $actionFrom = apcGetStatus($APCip, $APCport);

  if ( snmpset ( $APCip, "writecommunity", ".1.3.6.1.4.1.318.1.1.4.4.2.1.3.$APCport", 'i', $rebootOption) )
  {
    $returnVal = "Actioned:$actionFrom to $actionTo";
  }
  else
  {
    $returnVal = "Failed to Action:$actionFrom to $actionTo";
  }
  return $returnVal;
}

Kayako Login Share for H-Sphere

Here is how you can setup Kayako Login Share to work with your H-Sphere user accounts.

First log in to your H-Sphere database and run the following SQL - this is just to be more secure as you really don't want the loginshare php script accessing your hsphere DB with a high privilege user account. So we create a view that only feeds back username and md5hash of password - and setup a new user to access this view.

CREATE VIEW public.kayakologinshare (username, pass, email, name, lastname )
AS
select distinct users.username,
md5(users.password) as pass,
email,
name,
last_name as lastname
from contact_info,
accounts,
user_account,
users
where contact_info.id = accounts.ci_id
and accounts.id = user_account.account_id
and user_account.user_id = users.id
and users.reseller_id = 1;

CREATE USER "kayakologinshare" PASSWORD 'STRONGPASSWORDHERE';

GRANT SELECT ON "public"."kayakologinshare" TO "kayakologinshare";

If you have the full version with source code

I personaly know this way works as I have implemented it - Next you need to edit your /includes/LoginShare/loginshare.config.php and add the following lines...

define("LOGINAPI_HS",108);
$_LOGINAPI[LOGINAPI_HS] = array("title" => "H-Sphere login", "include" =>"hs.login.php");

NOTE : where 108 is in the first line above, this needs to be an usused number in the loginshare.config.php file, so make sure 108 is not already used otherwise change it.

Now download the zip file below and place the unzipped hs.login.php file in the /includes/LoginShare/ folder.

If you have the leased version without access to source code

This way will work as well, but I have not personally tried it, although I know others have with success. Unzip the file below and rename the file to hsphere.login.php and upload it to your /includes/LoginShare/ folder overwriting the existing file that is already there.

Finally...

When you have done this you can login to your Kayako admin screen and enter the DB details for kayakologinshare as above and then assign that login share to your template group.

You do also need to make sure that your the CP Postgre Server will accept connections from the server running Kayako
NOTE:Replace 10.11.12.13 with your server IP that is running Kayako

echo 'host all all 10.11.12.13 255.255.255.255 password' >> /var/lib/pgsql/data/pg_hba.conf

You also need to make sure that your firewall will allow access, eg if you are running iptables this should work.
NOTE:Replace 10.11.12.13 with your server IP that is running Kayako

iptables -I INPUT -s 10.11.12.13 -p tcp --dport 5432 -j ACCEPT