<?php
####################################################################################
##                                      WARNING!                                  ##
##                                                                                ##
##             This script is copyrighted to Free Monthly Websites.               ##
##               Duplication, selling, or transferring of this script             ##
##              is a violation of the copyright and purchase agreement.           ##
##                   Please read the Terms and Conditions here:                   ##
##   https://freemonthlywebsites2.com/legal/Copyright_Terms_and_Conditions.pdf    ##
##      Any violation of these terms will be dealt with serious legal action!     ##
##                                                                                ##
####################################################################################
session_start();



//Admin Login
if($_REQUEST['do_type']=="admin_settings_read")
{
	$filename="settings/admin_settings.txt";

	if(!$handle = fopen($filename, 'r'))
	{
		echo "Cannot open file ($filename)";
		exit;
	}
	$contents = fread($handle, filesize($filename));
	fclose($handle);
	$argument_arr=explode("#_1_#",$contents);

	if($argument_arr['0']==$_REQUEST['username'] && $argument_arr['1']==$_REQUEST['pass'])
	{
		$_SESSION['logged_in']=true;
		$_SESSION['sec']=1;
		header("location:welcome.php");
		exit;
	}
	else
	{
		$_SESSION['sec']=0;
		header("location:index.php?flag=1");
		exit;
	}
}

//Admin Forgot Password
if($_REQUEST['do_type']=="admin_settings_forgot")
{
	$filename="settings/admin_settings.txt";

	if(!$handle = fopen($filename, 'r'))
	{
		echo "Cannot open file ($filename)";
		exit;
	}
	$contents = fread($handle, filesize($filename));
	fclose($handle);
	$admin_arr=explode("#_1_#",$contents);
	
	$filename="settings/personal_settings.txt";

	if(!$handle = fopen($filename, 'r'))
	{
		echo "Cannot open file ($filename)";
		exit;
	}
	$contents = fread($handle, filesize($filename));
	fclose($handle);
	$personal_arr=explode("#_1_#",$contents);
	
	

	if($personal_arr['1']==$_REQUEST['email'])
	{
		//send email
		$to = "$personal_arr[0] <$personal_arr[1]>";
		$subject = "Your Username and Password";
		$from = "Free Monthly Websites 2.0 <nobody@localhost>";
		$message = "Hi $personal_arr[0],\n\nHere are your requested details:\n\nYour username: $admin_arr[0]\n\nYour password: $admin_arr[1]\n\n";
		$message .= "You can login here: ". str_replace("file_io.php","", $_SERVER['SCRIPT_URI']) . "\n\nRegards,\n\nThe Free Monthly Websites 2.0 Team.";
		mail($to,$subject, $message, "From: $from");
		header("location:forgot.php?flag=1");
		exit;
	}
	else
	{
		header("location:forgot.php?flag=2");
		exit;
	}
}

//Admin Login Settings
if($_REQUEST['do_type']=="admin_settings_write" && $_SESSION['sec']=="1")
{
	$filename="settings/admin_settings.txt";

	$content  =$_REQUEST['user_name'];
	$content .="#_1_#";
	$content .=$_REQUEST['password'] ;

	if(file_exists($filename))
	{
		//Do nothing;
	}
	else
	{
		copy("blank.txt",$filename);
		chmod($filename, 0750);
	}


	if(is_writable($filename))
	{
		if(!$handle = fopen($filename, 'w'))
		{
			echo "Cannot open file ($filename)";
			exit;
		}
		if(fwrite($handle, $content) === FALSE)
		{
			echo "Cannot write to file ($filename)";
			exit;
		}
		fclose($handle);
		header("location:admin_settings.php?flag=1");
		exit;
	} else
	{
		echo "The file $filename is not writable";
	}
}else if($_REQUEST['do_type']=="admin_settings_write" && $_SESSION['sec'] == "0"){
	
	
	echo "WARNING! Hacking Attempt - All abuse is reported.";
	
	}

//Advert Settings

if($_REQUEST['do_type']=="advert_settings_write"  && $_SESSION['sec']=="1")
{
	$filename="settings/advert_settings.txt";

	$content .=$_REQUEST['advert'];
	$content .="#_1_#";
	$content .=$_REQUEST['keyword'];
	$content .="#_1_#";
	$content .=$_REQUEST['cbid'];
	$content .="#_1_#";
	$content .=$_REQUEST['adsense_pub'];
	$content .="#_1_#";
	$content .=$_REQUEST['adsense_ch'];
	$content .="#_1_#";
	$content .=stripslashes($_REQUEST['other']);
	$content .="#_1_#";
	$content .=$_REQUEST['display_top_nav'];
	$content .="#_1_#";
	$content .=$_REQUEST['display_bot_nav'];
	$content .="#_1_#";
	$content .=$_REQUEST['display_inline'];
	$content .="#_1_#";
	$content .=stripslashes($_REQUEST['other_inline']);

	if(file_exists($filename))
	{
		//Do nothing;
	}
	else
	{
		copy("blank.txt",$filename);
		chmod($filename, 0750);
	}


	if(is_writable($filename))
	{
		if(!$handle = fopen($filename, 'w'))
		{
			echo "Cannot open file ($filename)";
			exit;
		}
		if(fwrite($handle, $content) === FALSE)
		{
			echo "Cannot write to file ($filename)";
			exit;
		}
		fclose($handle);
		header("location:advert_settings.php?flag=1");
		exit;
	} else
	{
		echo "The file $filename is not writable";
	}
}

//Clickbank Settings
if($_REQUEST['do_type']=="clickbank_settings_write" && $_SESSION['sec']=="1")
{
	$filename="settings/clickbank_settings.txt";

	$content .=$_REQUEST['clickbank'];
	$content .="#_1_#";
	$content .=$_REQUEST['keyword'];


	if(file_exists($filename))
	{
		//Do nothing;
	}
	else
	{
		copy("blank.txt",$filename);
		chmod($filename, 0750);
	}


	if(is_writable($filename))
	{
		if(!$handle = fopen($filename, 'w'))
		{
			echo "Cannot open file ($filename)";
			exit;
		}
		if(fwrite($handle, $content) === FALSE)
		{
			echo "Cannot write to file ($filename)";
			exit;
		}
		fclose($handle);
		header("location:clickbank_settings.php?flag=1");
		exit;
	} else
	{
		echo "The file $filename is not writable";
	}
}

//Optin Settings
if($_REQUEST['do_type']=="optin_settings_write" && $_SESSION['sec']=="1")
{
	$filename="settings/optin_settings.txt";

	$content  =stripslashes($_REQUEST['text']);
	$content .="#_1_#";
	$content .=$_REQUEST['meta_web'];
	$content .="#_1_#";
	$content .=$_REQUEST['unit'];
	$content .="#_1_#";
	$content .=stripslashes($_REQUEST['redirect']);
	$content .="#_1_#";
	$content .=$_REQUEST['to_display_form'];
	$content .="#_1_#";
	$content .=stripslashes($_REQUEST['form']);
	$content .="#_1_#";
	$content .=$_REQUEST['to_display_alternate'];
	$content .="#_1_#";
	$content .=$_REQUEST['grlist'];
	$content .="#_1_#";
	$content .=$_REQUEST['grref'];
	$content .="#_1_#";
	$content .=$_REQUEST['autoresponder'];
	$content .="#_1_#";
	$content .=$_REQUEST['prlist'];
	$content .="#_1_#";
	$content .=$_REQUEST['prmeta'];
	$content .="#_1_#";
	$content .=$_REQUEST['wzref'];

	if(file_exists($filename))
	{
		//Do nothing;
	}
	else
	{
		copy("blank.txt",$filename);
		chmod($filename, 0750);
	}


	if(is_writable($filename))
	{
		if(!$handle = fopen($filename, 'w'))
		{
			echo "Cannot open file ($filename)";
			exit;
		}
		if(fwrite($handle, $content) === FALSE)
		{
			echo "Cannot write to file ($filename)";
			exit;
		}
		fclose($handle);
		header("location:optin_settings.php?flag=1");
		exit;
	} else
	{
		echo "The file $filename is not writable";
	}
}

//Personal Settings
if($_REQUEST['do_type']=="personal_settings_write" && $_SESSION['sec']=="1")
{
	$filename="settings/personal_settings.txt";

	$content  =stripslashes($_REQUEST['f_name']);
	$content .="#_1_#";
	$content .=$_REQUEST['email'] ;
	$content .="#_1_#";
	$content .=$_REQUEST['display_form'];
	$content .="#_1_#";
	$content .=stripslashes($_REQUEST['content']);
	$content .="#_1_#";
	$content .=stripslashes($_REQUEST['title']);
	$content .="#_1_#";
	$content .=$_REQUEST['display_captcha'];
	$content .="#_1_#";
	$content .=$_REQUEST['captcha_key'];
	$content .="#_1_#";
	$content .=$_REQUEST['captcha_sec'];


	if(file_exists($filename))
	{
		//Do nothing;
	}
	else
	{
		copy("blank.txt",$filename);
		chmod($filename, 0750);
	}


	if(is_writable($filename))
	{
		if(!$handle = fopen($filename, 'w'))
		{
			echo "Cannot open file ($filename)";
			exit;
		}
		if(fwrite($handle, $content) === FALSE)
		{
			echo "Cannot write to file ($filename)";
			exit;
		}
		fclose($handle);
		header("location:personal_settings.php?flag=1");
		exit;
	} else
	{
		echo "The file $filename is not writable";
	}
}

// RRFW Settings
if($_REQUEST['do_type']=="rrfw_settings_write" && $_SESSION['sec']=="1")
{
	$filename="settings/rrfw_settings.txt";

	$content  = $_REQUEST['rrfw_display'] ;
	$content .= "#_1_#";
	$content .= $_REQUEST['rrfw_option'];
	$content .= "#_1_#";
	$content .= trim($_REQUEST['rrfw_link']);
	$content .= "#_1_#";
	$content .= trim($_REQUEST['rrfw_affid']);
	$content .= "#_1_#";
	$content .= trim($_REQUEST['rrfw_keyword']);
	$content .= "#_1_#";
	$content .= $_REQUEST['rrfw_items'];
	$content .= "#_1_#";
	$content .= $_REQUEST['rrfw_images'];
	$content .= "#_1_#";
	$content .= $_REQUEST['rrfw_description'];
	$content .= "#_1_#";
	$content .= $_REQUEST['rrfw_width'];
	$content .="#_1_#";
	$content .=stripslashes($_REQUEST['fmw_aff']);
	$content .="#_1_#";
	$content .=$_REQUEST['display_fmw'];//10
	$content .="#_1_#";
	$content .=stripslashes($_REQUEST['cb_aff']);
	$content .="#_1_#";
	$content .=$_REQUEST['display_cb'];
	$content .="#_1_#";
	$content .=$_REQUEST['select_cbcat'];
	$content .="#_1_#";
	$content .=$_REQUEST['rrfw_items2'];

	if(file_exists($filename))
	{
		//Do nothing;
	}
	else
	{
		copy("blank.txt",$filename);
		chmod($filename, 0750);
	}


	if(is_writable($filename))
	{
		if(!$handle = fopen($filename, 'w'))
		{
			echo "Cannot open file ($filename)";
			exit;
		}
		if(fwrite($handle, $content) === FALSE)
		{
			echo "Cannot write to file ($filename)";
			exit;
		}
		fclose($handle);
		header("location:affiliate_settings.php?flag=1");
		exit;
	} else
	{
		echo "The file $filename is not writable";
	}
}

//SEO Website Settings
if($_REQUEST['do_type']=="seo_settings_write" && $_SESSION['sec']=="1")
{
	$filename="settings/seo_settings.txt";

	$content .=stripslashes($_REQUEST['website_page_title']) ;
	$content .="#_1_#";
	$content .=stripslashes($_REQUEST['website_description']) ;
	$content .="#_1_#";
	$content .=stripslashes($_REQUEST['website_keywords']) ;
	$content .="#_1_#";
	$content .=stripslashes($_REQUEST['track']) ;

	if(file_exists($filename))
	{
		//Do nothing;
	}
	else
	{
		copy("blank.txt",$filename);
		chmod($filename, 0750);
	}


	if(is_writable($filename))
	{
		if(!$handle = fopen($filename, 'w'))
		{
			echo "Cannot open file ($filename)";
			exit;
		}
		if(fwrite($handle, $content) === FALSE)
		{
			echo "Cannot write to file ($filename)";
			exit;
		}
		fclose($handle);
		header("location:seo_settings.php?flag=1");
		exit;
	} else
	{
		echo "The file $filename is not writable";
	}
}

//Theme Website Settings

if($_REQUEST['do_type']=="theme_settings_write")
{
	$filename="settings/theme_settings.txt";

	$content .=$_REQUEST['style'] ;


	if(file_exists($filename))
	{
		//Do nothing;
	}
	else
	{
		copy("blank.txt",$filename);
		chmod($filename, 0750);
	}


	if(is_writable($filename))
	{
		if(!$handle = fopen($filename, 'w'))
		{
			echo "Cannot open file ($filename)";
			exit;
		}
		if(fwrite($handle, $content) === FALSE)
		{
			echo "Cannot write to file ($filename)";
			exit;
		}
		fclose($handle);
		header("location:theme_settings.php?flag=1");
		exit;
	} else
	{
		echo "The file $filename is not writable";
	}
}

//Website Basic Settings
if($_REQUEST['do_type']=="website_settings_write" && $_SESSION['sec']=="1")
{
	$filename="settings/website_settings.txt";

	$content  =stripslashes($_REQUEST['website_title']);
	$content .="#_1_#";
	$content .=stripslashes($_REQUEST['website_sub']);
	$content .="#_1_#";
	$content .=stripslashes($_REQUEST['website_footer']);
	$content .="#_1_#";
	$content .=stripslashes($_REQUEST['copyright_text']);
	$content .="#_1_#";
	$content .=$_REQUEST['copyright_url'];
	$content .="#_1_#";
	$content .=$_REQUEST['to_display'];
	$content .="#_1_#";
	$content .=$_REQUEST['empty1'];
	$content .="#_1_#";
	$content .=$_REQUEST['empty2'];
	$content .="#_1_#";
	$content .=stripslashes($_REQUEST['title_welcome']);
	$content .="#_1_#";
	$content .=stripslashes($_REQUEST['welcome']);
	$content .="#_1_#";
	$content .=stripslashes($_REQUEST['privacy_title']);
	$content .="#_1_#";
	$content .=stripslashes($_REQUEST['privacy_content']);
	$content .="#_1_#";
	$content .=$_REQUEST['display_privacy'];
	$content .="#_1_#";
	$content .=stripslashes($_REQUEST['terms_title']);
	$content .="#_1_#";
	$content .=stripslashes($_REQUEST['terms_content']);
	$content .="#_1_#";
	$content .=$_REQUEST['display_terms'];
	$content .="#_1_#";
	$content .=$_REQUEST['add_social'];

	if(file_exists($filename))
	{
		//Do nothing;
	}
	else
	{
		copy("blank.txt",$filename);
		chmod($filename, 0750);
	}


	if(is_writable($filename))
	{
		if(!$handle = fopen($filename, 'w'))
		{
			echo "Cannot open file ($filename)";
			exit;
		}
		if(fwrite($handle, $content) === FALSE)
		{
			echo "Cannot write to file ($filename)";
			exit;
		}
		fclose($handle);
		header("location:website_settings.php?flag=1");
		exit;
	} else
	{
		echo "The file $filename is not writable";
	}
}

?>