#!/usr/bin/perl

##################################################################
#     _\______                                   		 #
#       \____ \___  _____  _________  ______  ___		 #
#        /  / / _ \| __  \/ _ \___  \/ . \_ \/ _/		 #
#      _/ ___/  .  \  /  /  .  \  \  \ |  \\/ /			 #
#      \  /  \__|__/__\  \__|__/_____/____// /\_   		 #
#       \/=============\_/============-CaR!\/\_/==               #
#								 #
#             Confixx 3.0 License Generator                      #
#                                                                #
##################################################################

$VERSION_LIGHT1 = 'Light';
$VERSION_LIGHT2 = 'Limited';
$ENV{"LANG"}='C'; # ifconfig
$ENV{"LANGUAGE"}='C'; # ifconfig
&loadConfFile;

sub loadConfFile{
  my ($file, $base);
  if(-T "/root/confixx/confixx_main.conf"){
    $file = "/root/confixx/confixx_main.conf";
  }
  else{

   $0 = $^X unless ($^X =~ m%(^|[/\\])(perl)|(perl.exe)$%i);
   ($base) = $0 =~ m%^(.*)[/\\]%;
   $base ||= ".";
   $file = "$base/confixx_main.conf";
   unless(-T $file){
     die("Couldn't find confixx_main.conf");
   }
 }
 do $file;
}

sub get_SystemValues{
  my ($hwaddr, $ip, $ifconfig);
  if ($OSTYPE eq 'Linux'){
     if($virtuozzo eq '1'){
       $ifconfig = `/sbin/ifconfig venet0`;
     }
     else{
       $ifconfig = `/sbin/ifconfig eth0`;
     }
     $ifconfig =~ /HWaddr (\S+)/;
     $hwaddr = $1;
  }
  elsif ($OSTYPE eq 'FreeBSD'){
     $ifconfig = `/sbin/ifconfig xl0`;
     $ifconfig =~ /ether (\S+)/;
     $hwaddr = $1;
  }
  if ($OSTYPE eq 'Linux'){
     $ifconfig =~ /addr:(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}) /;
     $ip = $1;
  }
  elsif ($OSTYPE eq 'FreeBSD'){
     $ifconfig =~ /inet (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}) /;
     $ip = $1;
  }
  if(length($ip) > 15){
    $ip = substr($ip, 0, 15);
  }
  if($virtuozzo eq '1'){
    if(-e "/proc/vz/hwid"){
      open(HWID, "/proc/vz/hwid");
      $hwaddr = <HWID>;
      chop($hwaddr);
      close(HWID);
    }
  }
  $hwaddr =~ tr/a-z/A-Z/;
  return($hwaddr, $ip);
}

sub encryptString{
  my ($string, $salt) = @_;
  my ($temp, $return, $hex);
  $return = "";
  while(length $string > 0){
    while(length $string > 8){
      $temp = substr($string,0,8);
      $return .= unpack("H*", crypt($temp, $salt));
      $return .= "\n";
      $string = substr($string,8);
    }
    if(length $string > 0){
      while(length $string < 8){
        $string .= "\t";
      }
      $return .= unpack("H*", crypt($string, $salt));
      $return .= "\n";
      $string = "";
    }
  }
  $hex = $return;
  return($hex);
}

  $crypt_pw = "0DellAppleSonyIBM0";
  ($hwaddr, $ip) = &get_SystemValues;
  $LicenseKey = "v3-".substr("0000".int( rand(9999)),-4)."-".substr("0000".int( rand(9999)),-4)."-".substr("0000".int( rand(9999)),-4)."-".substr("0000".int( rand(9999)),-4);
  $LicenseTyp = "3pro";
  $time = time() + 315360000 ; # 10 Years from today
  $key = &encryptString("$hwaddr\::::$time\::::$crypt_pw\::::$LicenseKey\::::$LicenseTyp\:::::$ip", "tx");
  print "##################################################################\n";
  print " 			P A R A D O X				   \n";
  print "##################################################################\n";

  print "Keygen for Confixx 3.0 pro\n";
  print "Enter Licensedata through directinput\n";
  print "-------------------------------------\n";
  print "Your Serial: ".$LicenseKey."\n";
  print "Valid until: ".$time."\n";
  print "License Key:\n". $key."\n";
