Example #1
0
        public function OnStartForking()
        {            
            global $TLDs, $modules_config;
            
        	Log::Log("Starting 'Renew' cronjob...", E_USER_NOTICE);
            
            $db = Core::GetDBInstance();
            $RegFactory = RegistryModuleFactory::GetInstance();
            $DbDomain = DBDomain::GetInstance();
            
            $this->ThreadArgs = array();
            
            // For each client send notice about expiring domains
            $sql = "SELECT id FROM users";
            foreach ($db->GetAll($sql) as $client_data)
            {
            	try
            	{
	            	$Client = Client::Load($client_data["id"]);
	            	
	            	$sql = "
						SELECT 
							d.id, d.name, d.TLD, d.end_date, 
							IF(dd.`key` IS NOT NULL, FROM_UNIXTIME(dd.`value`), DATE_SUB(end_date, INTERVAL 1 DAY)) AS last_renew_date 
						FROM domains d 
						LEFT JOIN domains_data dd ON (dd.domainid = d.id AND dd.`key` = 'RenewalDate') 
						WHERE d.status = '".DOMAIN_STATUS::DELEGATED."' AND d.userid = ? AND (TO_DAYS(end_date) - TO_DAYS(NOW()) BETWEEN 0 AND ?) AND renew_disabled != 1
						ORDER BY d.end_date ASC";
					$start_days = $Client->GetSettingValue(ClientSettings::EXPIRE_NOTIFY_START_DAYS);
	            	$domains_data = $db->GetAll($sql, array($Client->ID, $start_days ? $start_days : 60));
	            	
	            	// Send email to client
	            	if ($domains_data) 
	            	{
	            		$eml_args = array(
	            			"client_name" => $Client->Name,
	            			"domains" => array()
	            		);
	            		foreach ($domains_data as $domain_data)
	            		{
	            			$eml_args["domains"][] = array(
	            				"name" => "{$domain_data["name"]}.{$domain_data["TLD"]}",
	            				"expire_date" => date("Y-m-d", strtotime($domain_data["end_date"])),
	            				"last_renew_date" => date("Y-m-d", strtotime($domain_data["last_renew_date"]))
	            			);
	            		}
	            		mailer_send("bulk_renew_notice.eml", $eml_args, $Client->Email, $Client->Name);
	            	}
	            	
	            	foreach ($domains_data as $domain_data)
	            	{
	            		$Domain = $DbDomain->Load($domain_data['id']);
	            		
	            		 // Find more then 60 days invoice
	            		 // Legacy from old notification system.
	            		 // FIXME: Need to create a better solution to finding unpaid invoices for upgoing renew 
						$dtNearest = date("Y-m-d", $Domain->ExpireDate - 60*24*60*60);
						$invoiceid = $db->GetOne("SELECT id FROM invoices 
							WHERE userid=? AND itemid=? AND purpose=? AND dtcreated >= ?", 
							array($Domain->UserID, $Domain->ID, INVOICE_PURPOSE::DOMAIN_RENEW, $dtNearest)
						);

							
						// Generate invoice
						if (!$invoiceid && !$Domain->RenewDisabled)
						{				
							$Registry = $RegFactory->GetRegistryByExtension($Domain->Extension);
							$config = $Registry->GetManifest()->GetSectionConfig();
							$period = (int)$config->domain->renewal->min_period;
							$Domain->Period = $period;
							$DbDomain->Save($Domain);

							try
							{
								$Invoice = new Invoice(INVOICE_PURPOSE::DOMAIN_RENEW, $Domain->ID, $Domain->UserID);
								$Invoice->Description = sprintf(_("%s domain name renewal for %s years"), $Domain->GetHostName(), $period);
								$Invoice->Cancellable = 1;
								$Invoice->Save();
								
								if ($Invoice->Status == INVOICE_STATUS::PENDING)
								{
									$diff_days = ceil(($Domain->ExpireDate - time())/(60*60*24));
									Application::FireEvent('DomainAboutToExpire', $Domain, $diff_days);
								}
							}
							catch(Exception $e)
							{
								Log::Log("Cannot create renew invoice. Caught: {$e->getMessage()}", E_USER_ERROR);
							}
						}
	            	}
            	}
            	catch (Exception $e)
            	{
            		Log::Log("Caught: {$e->getMessage()}", E_USER_ERROR);
            	}
            	
            }
            
            /*
			$supported_extensions = $RegFactory->GetExtensionList();
			// For all supported TLDs
            foreach ($supported_extensions as $ext)
            {
            	$Registry = $RegFactory->GetRegistryByExtension($ext);
            	
            	
            	$config = $Registry->GetManifest()->GetSectionConfig();
				$days = $config->domain->renewal->notifications->period;
				$biggest_period = (int)$days[0];
				
				
				
				
				// For each notification 
				foreach($days as $expireDays)
				{
					$expireDays = (int)$expireDays;
					
					$domains = $db->GetAll("
						SELECT dom.* FROM domains AS dom 
						LEFT JOIN domains_data AS ext 
						ON dom.id = ext.domainid AND ext.`key` = 'RenewalDate'
						WHERE dom.TLD = ? 
						AND dom.status = ? 
						AND TO_DAYS(IF 
						(
							ext.`key` IS NOT NULL AND TO_DAYS(FROM_UNIXTIME(ext.`value`)) < TO_DAYS(dom.end_date),
							FROM_UNIXTIME(ext.`value`),
							dom.end_date 
						)) - TO_DAYS(NOW()) = ?
					", array(
						$ext, DOMAIN_STATUS::DELEGATED, $expireDays
					));

					// For each domain
					foreach($domains as $domain_info)
					{
						try
						{
							$Domain = DBDomain::GetInstance()->Load($domain_info['id']);
							
							$dtNearest = date("Y-m-d", strtotime($domain_info["end_date"]) - $biggest_period*24*60*60);
							$invoiceid = $db->GetOne("SELECT id FROM invoices 
								WHERE userid=? AND itemid=? AND purpose=? AND status=? AND dtcreated >= ?", 
								array($Domain->UserID, $Domain->ID, INVOICE_PURPOSE::DOMAIN_RENEW, INVOICE_STATUS::PENDING, $dtNearest)
							);
							
							// Generate invoice
							if (!$invoiceid && !$Domain->RenewDisabled)
							{				
								
								$period = (int)$config->domain->renewal->min_period;
								$Domain->Period = $period;
								DBDomain::GetInstance()->Save($Domain);
								 
								try
								{
									$Invoice = new Invoice(INVOICE_PURPOSE::DOMAIN_RENEW, $Domain->ID, $Domain->UserID);
									$Invoice->Description = sprintf(_("%s domain name renewal for %s years"), $Domain->GetHostName(), $period);
									$Invoice->Cancellable = 1;
									$Invoice->Save();
									
									if ($Invoice->Status == INVOICE_STATUS::PENDING)
									{
										$userinfo = $db->GetRow("SELECT * FROM users WHERE id=?", array($Domain->UserID));
										
										//print "send notification and invoice about {$Domain->GetHostName()} to {$userinfo['email']}\n";									
										
										$args = array(
											"domain_name"	=> $Domain->Name, 
											"extension"		=> $Domain->Extension,
											"invoice"		=> $Invoice,
											"expDays"		=> $expireDays,
											"client"		=> $userinfo,
											"renewal_date"  => $Domain->RenewalDate
										);
										mailer_send("renew_notice.eml", $args, $userinfo["email"], $userinfo["name"]);
	
										Application::FireEvent('DomainAboutToExpire', $Domain, $expireDays);
									}
								}
								catch(Exception $e)
								{
									$errmsg = $e->getMessage();
								}
							}
							else
							{
								$userinfo = $db->GetRow("SELECT * FROM users WHERE id=?", array($Domain->UserID));
								//print "send notification about {$Domain->GetHostName()} to {$userinfo['email']}\n";
								$args = array(
									"domain_name"	=> $Domain->Name, 
									"extension"		=> $Domain->Extension,
									"expDays"		=> $expireDays,
									'client' 		=> $userinfo,
									"renewal_date"  => $Domain->RenewalDate
								);
								mailer_send("renew_notice.eml", $args, $userinfo["email"], $userinfo["name"]);
							}
						} 
						catch (Exception $e)
						{
							Log::Log("First domains loop. Caught: ".$e->getMessage(), E_USER_ERROR);
						}
					}
				}
            }
            */

            
			// For auto-renew registries the day before expiration date 
			// send to unpaid domains delete command and mark them as expired
			Log::Log("Going to process expiring tomorrow domains in 'auto-renew' registries", E_USER_NOTICE);			
			$days_before = 1;
			$del_date = strtotime("+$days_before day");
			$delete_report = array();
			$domains = $db->GetAll("SELECT dom.id, dom.name, dom.TLD FROM domains AS dom 
				LEFT JOIN domains_data AS ext ON dom.id = ext.domainid AND ext.`key` = 'RenewalDate'
				LEFT JOIN invoices AS i ON (dom.id = i.itemid AND i.purpose = 'Domain_Renew')
				WHERE dom.status = ? 
				AND TO_DAYS(IF
				(
					ext.`key` IS NOT NULL AND TO_DAYS(FROM_UNIXTIME(ext.`value`)) < TO_DAYS(dom.end_date),
					FROM_UNIXTIME(ext.`value`),
					dom.end_date 
				)) - TO_DAYS(NOW()) = ?	AND ((i.status = ? AND TO_DAYS(NOW()) - TO_DAYS(i.dtcreated) <= 60) OR i.status IS NULL)",
				array(DOMAIN_STATUS::DELEGATED, $days_before, INVOICE_STATUS::PENDING));
				
			foreach ($domains as $domain_info)
			{
				try
				{
					$Domain = $DbDomain->Load($domain_info["id"]);
					$Registry = $RegFactory->GetRegistryByExtension($domain_info["TLD"]);
					$RegistryOptions = $Registry->GetManifest()->GetRegistryOptions();
					$auto_renewal = (int)$RegistryOptions->ability->auto_renewal;
					$scheduled_delete = (int)$RegistryOptions->ability->scheduled_delete;
					
					if ($auto_renewal)
					{
						if (CONFIG::$AUTO_DELETE)
						{
							try
							{
								// For 'auto-renew + scheduled delete' send scheduled delete
								if ($scheduled_delete)
								{
									Log::Log(sprintf("Send scheduled delete to domain '%s' at '%s'", 
											$Domain->GetHostName(), date("Y-m-d", $del_date)), E_USER_NOTICE);
									
									$Registry->DeleteDomain($Domain, $del_date);
								}
								// For 'auto-renew' only send direct delete
								else
								{
									Log::Log(sprintf("Send direct delete to domain '%s'", 
											$Domain->GetHostName()), E_USER_NOTICE);
									$Registry->DeleteDomain($Domain);
								}
								
								$this->MarkAsExpired($Domain);
							}
							catch (Exception $e)
							{
								Log::Log(sprintf("Cannot delete expiring domain '%s'. %s", 
										$Domain->GetHostName(), $e->getMessage()), E_USER_ERROR);
							}								
						}
						else
						{
							Log::Log(sprintf("Domain %s need to be deleted. Send it to admin court", 
									$Domain->GetHostName()), E_USER_NOTICE);
							
							// Send to the administrator court
							$db->Execute("UPDATE domains SET delete_status = ? WHERE id = ?",
									array(DOMAIN_DELETE_STATUS::AWAIT, $Domain->ID));
							$userinfo = $db->GetRow("SELECT * FROM users WHERE id = ?", array($Domain->UserID));
							$delete_report[] = array
							(
								"domain" => $Domain->GetHostName(),
								"user" => "{$userinfo["name"]}({$userinfo["email"]})"
							);
						}
					}
				}
				catch (Exception $e)
				{
					Log::Log(sprintf("Cannot load expiring domain '%s'. %s", 
							"{$domain_info["name"]}.{$domain_info["TLD"]}", $e->getMessage()), E_USER_ERROR);
				}
			}
			// Notify admin about expiring domains need to be deleted
			if ($delete_report)
			{
				$args = array(
					"date" => date("Y-m-d", $del_date), 
					"report" => $delete_report, 
					"confirm_url" => CONFIG::$SITE_URL . "/admin/domains_await_delete_confirmation.php"
				);
				
				mailer_send("root_domains_await_delete.eml", $args, CONFIG::$EMAIL_ADMIN, CONFIG::$EMAIL_ADMINNAME);
			}
			
			
			// For all registries mark domain as expired at expiration date
			Log::Log("Going to process expiring today domains", E_USER_NOTICE);
			$domains = $db->GetAll("SELECT id, name, TLD FROM domains 
					WHERE TO_DAYS(end_date) = TO_DAYS(NOW()) AND status = ? AND delete_status != ?",
					array(DOMAIN_STATUS::DELEGATED, DOMAIN_DELETE_STATUS::AWAIT));
			
			foreach ($domains as $domain_info)
			{
				try
				{
					$Domain = $DbDomain->Load($domain_info["id"]);
					
					$this->MarkAsExpired($Domain);
				}
				catch (Exception $e)
				{
					Log::Log(sprintf("Cannot load expired domain '%s'. %s", 
							"{$domain_info["name"]}.{$domain_info["TLD"]}", $e->getMessage()), E_USER_ERROR);
				}
			}

			
			// Cleanup database from expired and transferred domains (more then 60 days)
			Log::Log("Going to cleanup database from transferred and expired domains (more then 60 days)", E_USER_NOTICE);
			$domains = $db->GetAll("
					SELECT * FROM domains 
					WHERE (status=? OR status=?) AND 
					((TO_DAYS(NOW()-TO_DAYS(end_date)) >= 60) OR (TO_DAYS(NOW()-TO_DAYS(dtTransfer)) >= 60))", 
					array(DOMAIN_STATUS::TRANSFERRED, DOMAIN_STATUS::EXPIRED));
					
			foreach ($domains as $domain_info)
			{
				try
				{
					Log::Log("Delete {$domain_info["name"]}.{$domain_info["TLD"]} from database. "
						. "(start_date={$domain_info["start_date"]}, end_date={$domain_info["end_date"]}, status={$domain_info["status"]})", 
						E_USER_NOTICE);
					$Domain = $DbDomain->Load($domain_info['id']);
					$DbDomain->Delete($Domain);
				}
				catch (Exception $ignore) 
				{
					Log::Log("Catch ignored exception. {$ignore->getMessage()}", E_USER_NOTICE);
				}
			}
			
			
			// Notify customers about low balance
			Log::Log("Going to notify customers about their low balance", E_USER_NOTICE);
			$user_ids = $db->GetAll("SELECT userid FROM user_settings 
					WHERE `key` = '".ClientSettings::LOW_BALANCE_NOTIFY."' AND `value` = '1'");
			foreach ($user_ids as $id) 
			{
				try 
				{
					$id = $id["userid"];
					$Client = Client::Load($id);
					$amount = (float)$db->GetOne("SELECT `total` FROM balance WHERE clientid = ?", array($id));
					$min_amount = (float)$Client->GetSettingValue(ClientSettings::LOW_BALANCE_VALUE);
					if ($amount < $min_amount)
					{
						mailer_send("low_balance_notice.eml", array(
							"client" => array("name" => $Client->Name),
							"amount" => number_format($min_amount, 2),
							"currency" => CONFIG::$CURRENCYISO
						), $Client->Email, $Client->Name);
					}
				}
				catch (Exception $e)
				{
					Log::Log("Cannot notify customer about his low balance. Error: {$e->getMessage()}", E_USER_ERROR);
					
				}
			}
        }
Example #2
0
 public function HandleImpendingExpiration(Domain $domain)
 {
     // http://bugzilla.webta.net/show_bug.cgi?id=210
     // Prevent domain expiration
     $Config = $this->GetManifest()->GetSectionConfig();
     $days = $Config->domain->xpath("//renewal/notifications/period");
     $last_notification_period = (int) end($days);
     $last_renewal_date = $domain->RenewalDate ? $domain->RenewalDate : $domain->ExpireDate;
     $days_before_expire = (int) ceil(($last_renewal_date - time()) / 86400);
     if ($days_before_expire <= $last_notification_period) {
         if ($days_before_expire < 0) {
             // Today will expire... OMG!
             $days_before_expire = 0;
         }
         // Set renew period
         $period = (int) $Config->domain->renewal->min_period;
         $domain->Period = $period;
         // Copypasta from class.RenewProcess.php
         // Issue invoice for renew and send notification to client.
         $Invoice = new Invoice(INVOICE_PURPOSE::DOMAIN_RENEW, $domain, $domain->UserID);
         $Invoice->Description = sprintf(_("%s domain name renewal for %s years"), $domain->GetHostName(), $period);
         $Invoice->Save();
         if ($Invoice->Status == INVOICE_STATUS::PENDING) {
             $userinfo = $this->DB->GetRow("SELECT * FROM users WHERE id=?", array($domain->UserID));
             $args = array("domain_name" => $domain->Name, "extension" => $domain->Extension, "invoice" => $Invoice, "expDays" => $days_before_expire, "client" => $userinfo, "renewal_date" => $domain->RenewalDate);
             mailer_send("renew_notice.eml", $args, $userinfo["email"], $userinfo["name"]);
             Application::FireEvent('DomainAboutToExpire', $domain, $days_before_expire);
         }
     }
 }
Example #3
0
					{
						foreach ((array)$_SESSION['wizard']['newclient']["add"] as $k=>$v)
							$Client->{$k} = $v;
					}
					catch(Exception $e){}
					
					try
					{
						$_SESSION["userid"] = $Client->Save()->ID;
					}
					catch(Exception $e)
					{
						throw new ApplicationException($e->getMessage(), $e->getCode());
					}
							
					Application::FireEvent('ClientCreated', $Client);
					
					if (CONFIG::$CLIENT_MANUAL_APPROVAL == 1)
					{
						$Client->SetSettingValue("pwd", $password);
						mailer_send("signup_pending.eml", $args, $_SESSION['wizard']['newclient']["email"], $_SESSION['wizard']['newclient']["name"]);
					}
					else
					{
						mailer_send("signup.eml", $args, $_SESSION['wizard']['newclient']["email"], $_SESSION['wizard']['newclient']["name"]);
						$Client->SetSettingValue("welcome_send", 1);
					}
					

				    if ($_SESSION['userid'] && $_SESSION['c_login'] && $_SESSION['c_password'])
				    {
Example #4
0
			
			foreach ((array)$_POST["add"] as $k=>$v)
				$Client->{$k} = $v;
			
			try
			{
				$Client->Save();
			}
			catch(Exception $e)
			{
				$errmsg = $e->getMessage();
			}

			if (!$errmsg)
			{
				Application::FireEvent('ClientUpdated', $oldClient, $Client);
				
				// CoreUtils::Redirect to users view page
				$okmsg = _("Profile successfully updated");
				CoreUtils::Redirect("index.php");
			}
		}
	}

	if (!$_POST)
		$display["attr"] = $db->GetRow("SELECT * FROM users WHERE id = ?", array($_SESSION['userid']));
	else
		$display["attr"] = $_POST;
		
	$display["countries"] = $db->GetAll("SELECT * FROM countries");
	
Example #5
0
				$mess = _("Client with specified login not found in database");
				CoreUtils::Redirect("login.php");
			}
			
			if ($Crypto->Hash($post_pass) == $Client->Password)
			{
				if ($Client->Status == 1)
				{
					$sault = $Crypto->Sault();
					$_SESSION["sault"] = $sault;
					$_SESSION["userid"] = $Client->ID;
					$_SESSION["login"] = $Client->Login;
					
					$_SESSION["hash"] = $Crypto->Hash("{$Client->Login}:{$Client->Password}:{$sault}");
					
					Application::FireEvent('LoginSuccess', $post_login, $post_pass);
					
					if (!$_SESSION["REQUEST_URI"])
						CoreUtils::Redirect ("/client/domains_view.php");
					else 
						CoreUtils::Redirect($_SESSION["REQUEST_URI"]);
				}
				else
				{
					$mess = _("Client account is inactive");
					CoreUtils::Redirect("login.php");
				}
				
			}
			else
			{
Example #6
0
                             // Today will expire... OMG!
                             $days_before_expire = 0;
                         }
                         // Set renew period
                         $period = (int) $Config->domain->renewal->min_period;
                         $Domain->Period = $period;
                         // Copypasta from class.RenewProcess.php
                         // Issue invoice for renew and send notification to client.
                         $Invoice = new Invoice(INVOICE_PURPOSE::DOMAIN_RENEW, $Domain, $Domain->UserID);
                         $Invoice->Description = sprintf(_("%s domain name renewal for %s years"), $Domain->GetHostName(), $period);
                         $Invoice->Save();
                         if ($Invoice->Status == INVOICE_STATUS::PENDING) {
                             $userinfo = $db->GetRow("SELECT * FROM users WHERE id=?", array($Domain->UserID));
                             $args = array("domain_name" => $Domain->Name, "extension" => $Domain->Extension, "invoice" => $Invoice, "expDays" => $days_before_expire, "client" => $userinfo, "renewal_date" => $Domain->RenewalDate);
                             mailer_send("renew_notice.eml", $args, $userinfo["email"], $userinfo["name"]);
                             Application::FireEvent('DomainAboutToExpire', $Domain, $days_before_expire);
                         }
                     }
                 } catch (Exception $e) {
                     $err[] = sprintf("%s: %s", $Domain->GetHostName(), $e->getMessage());
                 }
             }
         } else {
             $err[] = sprintf(_("'%s' cannot be imported because it does not belong to the current registar."), $Domain->GetHostName());
         }
     } else {
         $err[] = sprintf(_("'%s' has no RemoteCLID, we cannot check that domain belongs to current registrar."), $Domain->GetHostName());
     }
 } else {
     $err[] = sprintf(_("Domain '%s' already exists in our database."), $Domain->GetHostName());
 }
Example #7
0
			// Delete users
			$i = 0;			
			foreach ((array)$post_id as $k=>$v)
			{
				$i++;
				try
				{
					$Client = Client::Load($v);
					$Client->Delete();
				}
				catch(Exception $e)
				{
					$err[] = $e;
				}
				
				Application::FireEvent('ClientDeleted', $Client);
			}
			
			if (!$err)
			{
				$okmsg = "{$i} users deleted";
				CoreUtils::Redirect("users_view.php");
			}
		}
		elseif($post_action == "mail")
		{
			// Resend registration email
			$i = 0;
			foreach ((array)$post_id as $k=>$v)
			{
				$info = $db->GetRow("SELECT * FROM users WHERE id='{$v}'");