Skip to content

Instantly share code, notes, and snippets.

@blueo
Last active December 19, 2015 10:49
Show Gist options
  • Save blueo/5942863 to your computer and use it in GitHub Desktop.
Save blueo/5942863 to your computer and use it in GitHub Desktop.
A simple phing task to help with deploying to shared hosting. My shared host requires I register my IP to use ssh, but my IP changes as I'm on a cheapy dynamic connection.... oh yeah, and they blacklist me if I use an old one... So this task simply checks that the IP passed in the phing task (eg <ICanHazSSH CurrentIP="1.1.1.1"/>) matches my curr…
<?xml version="1.0" ?>
<project name="Example build file" default="externalIP" basedir=".">
<!-- Define the custom task, defined and located in/at classname -->
<taskdef name="ICanHazSSH" classname="conf.tasks.ICanHazSSH"/>
<target name="externalIP">
<echo msg="checking external IP OK for ssh..."/>
<ICanHazSSH CurrentIP="203.118.172.95" />
</target>
</project>
<?php
class ICanHazSSH extends Task {
private $CurrentIP = null;
private $ichip = "icanhazip.com";
private $IP = null;
private function setIP(){
$data = $this->get_data($this->ichip);
$this->IP = trim($data);
}
public function setCurrentIP($str) {
$this->CurrentIP = $str;
}
private function get_data($url) {
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
public function main () {
$this->setIP();
if ($this->IP == $this->CurrentIP ) {
echo "IP OK";
} else {
throw new BuildException($this->cIP." does not match that the IP registered with hosting provider, please update at: https://support.247hosting.co.nz/submitticket.php?step=2&deptid=16");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment