Initial commit
This commit is contained in:
commit
4df121acbe
28
LICENSE
Normal file
28
LICENSE
Normal file
@ -0,0 +1,28 @@
|
||||
domainwatcher.php
|
||||
=================
|
||||
Created by Jack-Benny Persson and licensed under GNU GPL,
|
||||
see below.
|
||||
|
||||
Copyright (C) 2014 Jack-Benny Persson <jack-benny@cyberinfo.se>
|
||||
|
||||
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/
|
13
README.md
Normal file
13
README.md
Normal file
@ -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'.
|
71
colors.php
Normal file
71
colors.php
Normal file
@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
Thanks for this to goes to the site 'If not true then false'.
|
||||
I found this 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/
|
||||
*/
|
||||
class Colors {
|
||||
private $foreground_colors = array();
|
||||
private $background_colors = array();
|
||||
|
||||
public function __construct() {
|
||||
// Set up shell colors
|
||||
$this->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);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
61
domainwatcher.php
Executable file
61
domainwatcher.php
Executable file
@ -0,0 +1,61 @@
|
||||
#!/usr/bin/php
|
||||
<?php
|
||||
/* CLI script to check domain expiry dates.
|
||||
Domain names with more days until expiry than threshold is marked green,
|
||||
otherwise it's marked in red.
|
||||
|
||||
Copyright 2014 - Jack-Benny Persson <jack-benny@cyberinfo.se>
|
||||
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");
|
||||
}
|
||||
|
||||
?>
|
Loading…
x
Reference in New Issue
Block a user