commit 4df121acbe7de2ac53c670cb5d04beb1853a575c Author: Jack-Benny Persson Date: Fri Jul 25 20:16:31 2014 +0200 Initial commit diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..1090400 --- /dev/null +++ b/LICENSE @@ -0,0 +1,28 @@ +domainwatcher.php +================= + Created by Jack-Benny Persson and licensed under GNU GPL, + see below. + + Copyright (C) 2014 Jack-Benny Persson + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + +colors.php +========== + Created by JR at www.if-not-true-then-false.com and + has a unknown (but seemingly free) license. + The original post can be found at the below URL: + http://www.if-not-true-then-false.com/2010/php-class-for-coloring-php-command-line-cli-scripts-output-php-output-colorizing-using-bash-shell-colors/ diff --git a/README.md b/README.md new file mode 100644 index 0000000..60e6ba9 --- /dev/null +++ b/README.md @@ -0,0 +1,13 @@ +# Domainwatcher # +Domainwatcher is meant to be a simple way to keep track of your domains +expiraion dates (so you don't miss to renew them). + +## Usage ## +Just fill the array ($domains) with all yours domain names and the run the +script from a Bash-prompt (colors only work in Bash). +If the domain has less days than the treshold ($warnLevel) the domain name will +be marked in red, otherwise it will be marked in green. The script also prints +out how many days each domain has left until expiration. + +## Thanks ## +The Color-class was found online at http://www.if-not-true-then-false.com/2010/php-class-for-coloring-php-command-line-cli-scripts-output-php-output-colorizing-using-bash-shell-colors/ so a thanks goes to 'If not true than false'. diff --git a/colors.php b/colors.php new file mode 100644 index 0000000..41ee545 --- /dev/null +++ b/colors.php @@ -0,0 +1,71 @@ +foreground_colors['black'] = '0;30'; + $this->foreground_colors['dark_gray'] = '1;30'; + $this->foreground_colors['blue'] = '0;34'; + $this->foreground_colors['light_blue'] = '1;34'; + $this->foreground_colors['green'] = '0;32'; + $this->foreground_colors['light_green'] = '1;32'; + $this->foreground_colors['cyan'] = '0;36'; + $this->foreground_colors['light_cyan'] = '1;36'; + $this->foreground_colors['red'] = '0;31'; + $this->foreground_colors['light_red'] = '1;31'; + $this->foreground_colors['purple'] = '0;35'; + $this->foreground_colors['light_purple'] = '1;35'; + $this->foreground_colors['brown'] = '0;33'; + $this->foreground_colors['yellow'] = '1;33'; + $this->foreground_colors['light_gray'] = '0;37'; + $this->foreground_colors['white'] = '1;37'; + + $this->background_colors['black'] = '40'; + $this->background_colors['red'] = '41'; + $this->background_colors['green'] = '42'; + $this->background_colors['yellow'] = '43'; + $this->background_colors['blue'] = '44'; + $this->background_colors['magenta'] = '45'; + $this->background_colors['cyan'] = '46'; + $this->background_colors['light_gray'] = '47'; + } + + // Returns colored string + public function getColoredString($string, $foreground_color = null, $background_color = null) { + $colored_string = ""; + + // Check if given foreground color found + if (isset($this->foreground_colors[$foreground_color])) { + $colored_string .= "\033[" . $this->foreground_colors[$foreground_color] . "m"; + } + // Check if given background color found + if (isset($this->background_colors[$background_color])) { + $colored_string .= "\033[" . $this->background_colors[$background_color] . "m"; + } + + // Add string and end coloring + $colored_string .= $string . "\033[0m"; + + return $colored_string; + } + + // Returns all foreground color names + public function getForegroundColors() { + return array_keys($this->foreground_colors); + } + + // Returns all background color names + public function getBackgroundColors() { + return array_keys($this->background_colors); + } + } + +?> diff --git a/domainwatcher.php b/domainwatcher.php new file mode 100755 index 0000000..1561e57 --- /dev/null +++ b/domainwatcher.php @@ -0,0 +1,61 @@ +#!/usr/bin/php + + Release under the GNU General Public Licence version 2, se LICENSE for + more information. + + Version: 0.1 +*/ + +require("colors.php"); //A color-class +date_default_timezone_set('Europe/Stockholm'); //Change this to match your TZ +$warnLevel = 30; //Numbers of days until warning + +//List all the domains you want to check below +$domains = array("svt.se", "github.com", "sourceforge.net", + "wikipedia.org" ,"g.me"); + +//Let's iterate through all the domains +foreach($domains as $domain) +{ + $data = shell_exec("whois $domain"); + + // For TLDs .org, .info + if (preg_match("/(?:[-_a-z0-9])+(\.(org|info))+/i", $domain)) + { + preg_match("/(Expiry Date:\s)([-0-9]+)/", $data, + $matches); //Second group is the date + } + // For TLDs .se, .net, .nu, .com, .me etc (trying to match all the rest) + else + { + preg_match("/(expir(?:es|y|ation)(?:[-:a-z\s])*)([-0-9a-z]+)/i", $data, + $matches); //Second group is the date + } + + //Preparations needed for the calcultations + $expiryDate = $matches[2]; //Second group is the date, see above + $expiryUnixTime = strtotime($expiryDate) . "\n"; + $nowUnixTime = strtotime("now"); + + //Calculate days to expire + $diff = $expiryUnixTime - $nowUnixTime; + $days = $diff / 60 / 60 / 24; + + $colors = new Colors; //Using the color class found on the net + if ($days <= $warnLevel) + { + print $colors->getColoredString("$domain", "red"); + } + else + { + print $colors->getColoredString("$domain", "green"); + } + print (" will expire in ". floor($days) . " days.\n"); +} + +?>