Viewing File: /usr/local/cpanel/whostmgr/docroot/cgi/ardcluster/index.cgi

#!/usr/local/cpanel/3rdparty/bin/perl
#
# Copyright: NameCheap Inc. 
# Written by Andrew A. Razdolsky
#

use Carp ();
use XML::Simple;
use lib "/usr/local/cpanel";
use strict;
use CGI qw(:standard);
use LWP::UserAgent();
require "/root/ard/readconfig.pl";

our $VERSION = "6.1";

# To get local module's VERSION
require "/root/ard/ardcluster.pl";

# URL from where I get the SVN repository project version 
# It's the project's file ardcluster.pl evidently. And I need no create additional file telling us
# what the latest package version is.

# get configured options
my $conf_file           = '/root/ard/etc/global.conf';
my $Conf                = &readconfig::ReadConfig ( $conf_file );
my $Release_File_URL    = $Conf->{'release_file'};
my $Change_File_URL     = $Conf->{'changelog_file'};

#  
# Call:  
#      &Get_Remote_Release_Number($url);
#
# Returns:
#      - on success: remote release number given in the URL file;
#      - on fail:    undef;
#
sub Get_Remote_Release_Number ($) {
   my $url = shift;
   my $rel_number;
   my $ua;
   my $response;
  
  
   $ua = LWP::UserAgent->new();
   $ua->timeout(5);
   $response = $ua->get($url);

   #$rel_number = ' 2.2 ';
   
   if ( $response->is_success ) {
         if ($response->decoded_content =~ m/VERSION\s*=\s*['"]\s*((?:\d+)(?:\.\d+)?)\s*['"]\s*;/ ) {
                       $rel_number = $1;
         }
   } else {
      return undef;
   }

   return $rel_number;
}

#
#
#
#
sub Get_ChangeLog_Portion ($$) {

   my $url                   = shift;
   my $local_release_number  = shift;
   my $changelog_text;
   my $ua;
   my $response;


   $ua = LWP::UserAgent->new();
   $ua->timeout(5);
   $response = $ua->get($url);

   if ( $response->is_success ) {
         if ($response->decoded_content =~ m/(Release.*?)Release\s*$local_release_number/ims ) {
                       $changelog_text = $1;
         }
   } else {
      return undef;
   }

   return $changelog_text;
}

#  
# Call:  
#      &Get_Local_Release_Number($file_path);
#
# Returns:
#      - on success: local release number(VERSION line) found in the ardcluster.pl file;
#      - on fail:    undef;
#
sub Get_Local_Release_Number ($) {
   my $file_path = shift;
   my $rel_number = $ardcluster::VERSION;

   #open (FH , '<', $file_path) or return undef;
   #while ( <FH>) {
   #      if (/^.+VERSION.*((?:\d+)(?:\.\d+))?.*$/) {
   #             $rel_number= $1;
   #             last;
   #      }
   #}
   #close (FH);

   return $rel_number;
}




print "Content-type: text/html\n\n";
print <<EOF;
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Web Host Manager 11.25.0 - Synchronizing Dns Zones</title>

<link href="/cPanel_magic_revision_1257778541/combined_optimized.css" rel="stylesheet" type="text/css" />
<link rel="shortcut icon" href="/cPanel_magic_revision_1257778541/favicon.ico" type="image/x-icon" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!--[if gt IE 6]>
<link rel="stylesheet" href="/cPanel_magic_revision_1182229590/themes/x/ie7.css" />
<![endif]-->
<!--[if lt IE 7]>
<link rel="stylesheet" href="/cPanel_magic_revision_1233735414/themes/x/ie6.css" />
<![endif]-->
<link href="/cPanel_magic_revision_1257778536/themes/x/style_optimized.css" type="text/css" rel="stylesheet" />

<!--[if IE]>
<style type="text/css">
h3{font-size:11px;}
</style>
<![endif]-->
<script type="text/javascript" src="/cPanel_magic_revision_1257778308/yui/utilities_container/utilities_container.js"></script>
<script type="text/javascript" src="/cPanel_magic_revision_1257778299/cjt/cpanel-all-min.js"></script>

<script type="text/javascript">
//<![CDATA[
// Security token for xml-api calls
CPANEL.security_token = "";
//]]>
</script>
<style>
.green {
     color: green;
     font-weight: bold;
     font-family: arial, times new roman;
}

</style>
</head>
<body class="yui-skin-sam">
<!-- <table style="margin 0pt; padding:0pt" cellpadding="0" cellspacing="0" link="#0000ee" vlink="#0000ee" text="#000000" border="0" align="center" width="100%">
<tr class="scellheader">
<td background="/cPanel_magic_revision_1182229590/themes/x/bg.png">
&nbsp;<a href="/scripts/command?PFILE=main">Main</a>&nbsp;&gt;&gt;&nbsp;<a href="/scripts/command?PFILE=DNS_Functions">DNS Functions</a>&nbsp;&gt;&gt;&nbsp;<a class="active" href="/scripts/makesec">Synchronize DNS Records</a>
<div class="doctitle">Synchronizing Dns Zones</div>
</td>
</tr>
</table>
-->	

<div id="pageheader">
<div id="doctitle">							
EOF

print "<h1>Ardcluster NameCheap V.$VERSION</h1>\n";
print <<EOF;
</div>
</div>
								
<div class="topboxmargin"></div>
<!-- END DEFHEADER -->
EOF

my $Remote_Rel_Number = &Get_Remote_Release_Number ( $Release_File_URL );
my $Local_Rel_Number =  &Get_Local_Release_Number (undef);

if ( defined $Remote_Rel_Number and defined $Local_Rel_Number and 
     ( $Remote_Rel_Number > $Local_Rel_Number) 
   ) {
     my $ChangeLog_Portion = &Get_ChangeLog_Portion( $Change_File_URL,$Local_Rel_Number);
print <<EOF;
<table width="900">
<tr>
<td align="left" height="150" width="50%" style="padding-left: 40px;">
Download latest version. <br>
<form action="update.cgi" method="GET">
<input type="submit" class="input-button" name="action"  value="Update Plugin! Installed Version: $Local_Rel_Number. New Version $Remote_Rel_Number Available!">
</form>
</td>
<td height="150" style="padding-left: 50px;">
<div style="overflow:auto;height:150px;">
EOF
print "<pre>$ChangeLog_Portion</pre>";
print <<EOF;
</div>
</td></tr>
</table>
<br><hr><br>
EOF
} else {
  print "<p style=\"padding-left: 20px;\">";
  print "Repository Version: <span class='green'>$Remote_Rel_Number</span><br>";
  print "Local File Version: <span class='green'>$Local_Rel_Number</span><br>";
  print "<b>No updates needed!</b> <br><br><br></p>"; 
}

print <<EOF;

<form action="switchmaster.cgi" method="GET">
<div class="body-content">
<h3>Synchronizing DNS Zones ensures zone in the cluster  use this server as master.<br> This prevents invalid or old data being used from the old server.</h3>
<hr>
<h4>Choose synchronization method</h2>
<div class="sync_dns_container">
<div class="sdc_container">
<input type="radio" name="sync_zones" checked="checked" id="one_local" value="one_local" />
<label for="onezonelocal">Synchronize one zone to the cluster</label>
<div class="sdc_module">
<input type="text" name="onezonelocal" id="onezonelocal" /> 
<small>(ex. userdomain.tld)</small>
</div>
<p class="description">One zone will be compared with the same zone on all servers in the cluster and the masterIP on the cluster will be set to these server.</p>
</div>
<div class="sdc_container">
<input type="checkbox" name="all_domains" value="1" onClick="verifythis(this);">
<label>Synchronize all zones owned by the user, who is owner of the domain you've put</label>

<p class="description">All DNS zones located at the current user will be syncronized to the cluster. No matter they are or aren's present on the other servers.</p>
</div>
<hr>
<div class="sdc_container">

<input type="radio" name="sync_zones" id="all_zones" value="all_zones" />
<label>Synchronize all zones to all servers</label><br />
<input type="checkbox" name="all_domains" value="1" onClick="verifythis(this);">
<label>Synchronize zones that are not configured on this server</label>
<p class="description">Please be CAREFUL with the following option.</p>
</div>
</div>
<hr>
<input type="submit" class="input-button" name="action" value="Synchronize" />
</form>
</div>
<script>

function verifythis(El) {
    if (!El.checked) { return; }
        
    var forsure = confirm("Are you sure you wish to pull in all dns zones from the user in the cluster?");
    if (!forsure) {
    El.checked=false;
    }
}
</script>
			


EOF
Back to Directory File Manager