<?php

/**
 * This is a FILTER POINT in Virtualizor.
 * NOTE : You must rename this file to filter.php
 */
 
//////////////////////////////////////////////////////////////
//===========================================================
// filter.php
//===========================================================
// SOFTACULOUS VIRTUALIZOR
// Version : 1.1
// Inspired by the DESIRE to be the BEST OF ALL
// ----------------------------------------------------------
// Started by: Alons
// Date:       26th Apr 2020
// Time:       14:00 hrs
// Site:       http://www.softaculous.com/ (SOFTACULOUS VIRTUALIZOR)
// ----------------------------------------------------------
// Please Read the Terms of use at http://www.softaculous.com
// ----------------------------------------------------------
//===========================================================
// (c)Softaculous Inc.
//===========================================================
//////////////////////////////////////////////////////////////

if(!defined('VIRTUALIZOR')){

	die('Hacking Attempt');

}

////////////// perform_operations filter starts //////////////
/* 
// Use this filter to trigger your function when a new VM is created
insert_filter('perform_operations', 'my_perform_operations', 1, 1);

// @param	array $newvs NEW VPS values
function my_perform_operations($mount){
	// Add your custom code here
	
} */

////////////// before_addvs filter starts //////////////
/* 
// Use this filter to trigger your function when a new VM is created
insert_filter('before_addvs', 'my_before_addvs', 1, 1);

// @param	array $newvs NEW VPS values
function my_before_addvs($newvs){
	// Add your custom code here
	//DO NOT ECHO/PRINT ANYTHING INSIDE THIS FUNCTION IT WILL BREAK THE FRONTEND
	
	// $newvs must have all the keys as it was provided, you can change the values
	return $newvs;
} */


////////////// before_send_email filter starts //////////////
/* 
// Use this filter to trigger your function when a new VM is created
insert_filter('before_send_email', 'my_before_send_email', 1, 1);

// @param	array $newvs NEW VPS values
function my_before_send_email($array){
	// Add your custom code here
	//DO NOT ECHO/PRINT ANYTHING INSIDE THIS FUNCTION IT WILL BREAK THE FRONTEND
	
	// $array must have all the keys as it was provided, you can change the values
	// Return the modified array if you want virtualizor to send your modified email
	// return $array;
} */

////////////// before_send_email filter ends //////////////

////////////// addvs filter starts //////////////
/* 
// Use this filter to trigger your function when a new VM is created
insert_filter('addvs', 'my_addvs', 1, 1);

// @param	array $newvs NEW VPS values
function my_addvs($newvs){
	// Add your custom code here
} */

////////////// addvs filter ends //////////////

////////////// editvs filter starts //////////////
/* 
// Use this filter to trigger your function when you edit the VM
insert_filter('editvs', 'my_editvs', 1, 2);

// @param	array $vps OLD VPS values
// @param	array $editvs NEW Posted VPS values
function my_editvs($vps, $editvs){
	// Add your custom code here
} */

////////////// editvs filter ends //////////////

////////////// before_config_write filter starts //////////////
/* 
// Use this filter to trigger your function before virtualizor writes the configuration file of VM
insert_filter('before_config_write', 'my_before_config_write', 1, 1);

// @param	array $vps vps configuration details
function my_before_config_write($vps){
	// Add your custom code here
	return $vps;
}
 */
////////////// before_config_write filter ends //////////////

////////////// after_config_write filter starts //////////////
/* 
// Use this filter to trigger your function after virtualizor writes the configuration file of VM
insert_filter('after_config_write', 'my_after_config_write', 1, 1);

// @param	array $vps vps configuration details
function my_after_config_write($vps){
	// Add your custom code here
}
 */
////////////// after_config_write filter ends //////////////

////////////// after_createvps filter starts //////////////
/* 
// Use this filter to trigger your function after the vm is created
insert_filter('after_createvps', 'my_after_createvps', 1, 1);

// @param	array $vps vps configuration details
function my_after_createvps($vps){
	// Add your custom code here
} */

////////////// after_createvps filter ends //////////////

////////////// before_deletevps filter starts //////////////
/* 
// Use this filter to trigger your function after before deletion of a VM
insert_filter('before_deletevps', 'my_before_deletevps', 1, 1);

// @param	array $vps vps configuration details
function my_before_deletevps($vps){
	// Add your custom code here
}
 */
////////////// before_deletevps filter ends //////////////

////////////// deletevs filter starts //////////////
/* 
// Use this filter to trigger your function when virtualizor deletes the VM
insert_filter('deletevs', 'my_deletevs', 1, 1);

// @param	array $vps vps configuration details
function my_deletevs($vps){
	// Add your custom code here
}
 */

////////////// deletevs filter ends //////////////

////////////// after_deletevps filter starts //////////////
/* 
// Use this filter to trigger your function after the vm is deleted
insert_filter('after_deletevps', 'my_after_deletevps', 1, 1);

// @param	array $vps vps configuration details
function my_after_deletevps($vps){
	// Add your custom code here
}
 */

////////////// after_deletevps filter ends //////////////

////////////// before_startvps filter starts //////////////
/* 
// Use this filter to trigger your function before start of the VM
insert_filter('before_startvps', 'my_before_startvps', 1, 1);

// @param	array $vps vps configuration details
function my_before_startvps($vps){
	// Add your custom code here
}
 */

//////////////////////// 
// after_startvps
////////////////////////
/*
// Use this filter to trigger your function after start of the VM
insert_filter('after_startvps', 'my_after_startvps', 1, 1);

// @param	array $vps vps configuration details
function my_after_startvps($vps){
	// Add your custom code here
}
*/

//////////////////////// 
// after_startvps
////////////////////////
/*
// Use this filter to trigger your function before vm is created by CLOUD user 
insert_filter('create_vm_pre_addvs', 'my_create_vm_pre_addvs', 1, 1);

// @param	array $vps vps configuration details
function my_create_vm_pre_addvs($vps){
	// Add your custom code here
	
	// $vps must have all the keys as it was provided, you can change the values
	return $vps;
}
*/

//////////////////////// 
// pre_process_payment
////////////////////////
/*
// Use this filter to trigger your function for preprocessing when the response from payment gateway is sent to Virtualizor  (It is used fro ccavenue payment gateway)
insert_filter('pre_process_payment', 'my_pre_process_payment', 1, 0);

// @param	array $vps vps configuration details
function my_pre_process_payment(){
	// Add your custom code here
}
*/

//////////////////////// 
// error_handle
////////////////////////
/*
// Use this filter to trigger your custom function when any error occurs in virtualizor 
insert_filter('error_handle', 'my_error_handle', 1, 1);

// @param	array $error Array containing error details
function my_error_handle($error){
	// Add your custom code here
}
*/

//////////////////////// 
// Server Selection
////////////////////////
/*
// Use this filter to trigger your custom function when you want to apply your own server selection criteria after getting eligible server list from Virtualizor 
insert_filter('server_selection', 'my_server_selection', 1, 1);

// @param	array $tmp_servers Array containing eligible server list
function my_server_selection($tmp_servers){
	// Add your custom code here
	return $tmp_servers;
}
*/

//////////////////
//Randomize IPs
//////////////////
/*
// Use this filter to Randomize IPs 
insert_filter('randomize_ips', 'my_randomize_ips', 1, 4);

// @param	array $ips Array containting available ipv4 addresses
// @param	array $ips_int Array containting available internal ipv4 addresses
// @param	array $ips6 Array containting available ipv6 addresses
// @param	array $ips6_subnet Array containting available ipv6 subnets
function my_randomize_ips($ips, $ips_int, $ips6, $ips6_subnet){

	if(!empty($ips)){
		shuffle($ips);
	}
	
	if(!empty($ips_int)){
		shuffle($ips_int);
	}

	if(!empty($ips6)){
		shuffle($ips6);
	}

	if(!empty($ips6_subnet)){
		shuffle($ips6_subnet);
	}

	return array('ips' => $ips, 'ips_int' => $ips_int, 'ips6' => $ips6, 'ips6_subnet' => $ips6_subnet);
}
*/

///////////////////////////////////////////// 
// VM Bandwidth check before inserting in DB
/////////////////////////////////////////////
/*
// Use this filter to check bandwidth usage
insert_filter('check_insert_vps_bw', 'my_check_insert_vps_bw', 1, 3);

// @param	$default it will always be false. 
// @param	array $vps Array containing vm information
// @param	array $value contains IN and OUT info of bandwidth
function my_check_insert_vps_bw($default, $vps, $value){
	
	// Add your custom code here
	$changed = 0;
	// $value['in'] and $value['out'] is the value which will be coming from CT/VM for bandwidth (Total download till NOW)
	// $vps['last_in'] and $vps['last_out'] are the values which are calculated for the CT/VM till last cron
	
	// Following is just an example to handle the value you can write your own logic to modify $in and $out
 	if($vps['last_in'] > $value['in'] && (($vps['last_in'] - $value['in']) > SOME_VALUE)){
		$in = $vps['last_in'];
		$value['in'] = 0;
		$changed = 1;
	}

	if($vps['last_out'] > $value['out'] && (($vps['last_out'] - $value['out']) > SOME_VALUE)){
		$out = $vps['last_out'];
		$value['out'] = 0;
		$changed = 1;
	}

	if(!empty($changed)){
		return array(
				'in' => $in, 'out' => $out,
				'c_in' => $value['in'], 'c_out' => $value['out']
				);
	}

	return $default;
}
*/

//////////////////
//Before Add user
//////////////////
/*
// Use this filter to post data while adding user
insert_filter('before_adduser', 'my_before_adduser', 1, 1);

// @param	array $user_posted_data Array containing all the posted data
function my_before_adduser($user_posted_data){
	// Add your custom code here
	return $user_posted_data;
}
*/

//////////////////
//After Add user
//////////////////
/*
// Use this filter to perform some operations after adding the user
insert_filter('after_adduser', 'my_after_adduser', 1, 1);

// @param	int $uid Integer containing user id of the user that is added
function my_after_adduser($uid){
	// Add your custom code here
}
*/
