<?php

//////////////////////////////////////////////////////////////
//===========================================================
// editbackuploc_theme.php
//===========================================================
// SOFTACULOUS 
// Version : 1.1
// Inspired by the DESIRE to be the BEST OF ALL
// ----------------------------------------------------------
// Started by: Alons
// Date:       10th Jan 2009
// Time:       21:00 hrs
// Site:       http://www.softaculous.com/ (SOFTACULOUS)
// ----------------------------------------------------------
// Please Read the Terms of use at http://www.softaculous.com
// ----------------------------------------------------------
//===========================================================
// (c)Softaculous Inc.
//===========================================================
//////////////////////////////////////////////////////////////

if(!defined('SOFTACULOUS')){

	die('Hacking Attempt');

}


function editbackuploc_theme(){

global $user, $globals, $l, $theme, $error, $dropbox;
global $saved, $edit_location;

softheader(__('$0 - Edit Backup Location', array($globals['sn'])));

echo '
<div class="bg"><br />
	<form accept-charset="'.$globals['charset'].'" name="editbackup" method="post" action="" class="form-horizontal">
	
		<div class="row">
			<div class="col-12 text-center sai_main_head">
				<i class="fas fa-file-archive fa-2x mr-2" style="color:#00A0D2;"></i>
				<span class="form-title">'.__('Edit Backup Location').'</span>
			</div>
		</div>';
		
		error_handle($error, '100%');
		
		if(!empty($saved)){
			echo '<div class="alert alert-success mt-4" style="padding:10px;font-size:15px;"><center><img src="'.$theme['images'].'message_success.gif">&nbsp;&nbsp;'.__('Backup location details saved successfully').'</div></center>';
		}
		
		echo'
		<div class="card m-2 p-3">
		<div class="row">
			<div class="col-12 col-md-6 col-xl-6 mb-2">
				<label for="location_name" class="sai_head">'.__('Location Name').'</label><br/>
				<span class="sai_exp2">'.__('Choose a name for backup location for your reference').'</span>
				<input type="text" name="location_name" id="location_name" class="form-control" value="'.POSTval('location_name', $edit_location['name']).'" />
			</div>
			<div class="col-12 col-md-6 col-xl-6 mb-2">
				<label for="protocol" class="sai_head">'.__('Protocol').'</label><br />
				<span class="sai_exp2">'.__('Select the protocol by which $0 will communicate', array(APP)).'</span>
				<select name="protocol" class="form-control" id="protocol">'
					.(empty($globals['disable_backup_ftp']) ? '<option value="ftp" '.(isset($_REQUEST['protocol']) && $_REQUEST['protocol'] == 'ftp' ? 'selected="selected"' : ($edit_location['protocol'] == 'ftp' ? 'selected="selected"' : '')).'>'.__('FTP').'</option>' : '').
					(empty($globals['disable_backup_softftpes']) ? '<option value="softftpes" '.(isset($_REQUEST['protocol']) && $_REQUEST['protocol'] == 'softftpes' ? 'selected="selected"' : ($edit_location['protocol'] == 'softftpes' ? 'selected="selected"' : '')).'>'.__('FTPS').'</option>' : '').
					(empty($globals['disable_backup_softsftp']) ? '<option value="softsftp" '.(isset($_REQUEST['protocol']) && $_REQUEST['protocol'] == 'softsftp' ? 'selected="selected"' : ($edit_location['protocol'] == 'softsftp' ? 'selected="selected"' : '')).'>'.__('SFTP').'</option>' : '').
					(empty($globals['disable_backup_dropbox']) ? '<option value="dropbox" '.(isset($_REQUEST['protocol']) && $_REQUEST['protocol'] == 'dropbox' ? 'selected="selected"' : ($edit_location['protocol'] == 'dropbox' ? 'selected="selected"' : '')).'>'.__('Dropbox').'</option>' : '').	
					(empty($globals['disable_backup_gdrive']) ? '<option value="gdrive" '.(isset($_REQUEST['protocol']) && $_REQUEST['protocol'] == 'gdrive' ? 'selected="selected"' : ($edit_location['protocol'] == 'gdrive' ? 'selected="selected"' : '')).'>'.__('Google Drive').'</option>' : '').
					(empty($globals['disable_backup_webdav']) ? '<option value="webdav" '.(isset($_REQUEST['protocol']) && $_REQUEST['protocol'] == 'webdav' ? 'selected="selected"' : ($edit_location['protocol'] == 'webdav' ? 'selected="selected"' : '')).'>'.__('WebDAV').'</option>' : '').
					(empty($globals['disable_backup_onedrive']) ? '<option value="onedrive" '.(isset($_REQUEST['protocol']) && $_REQUEST['protocol'] == 'onedrive' ? 'selected="selected"' : ($edit_location['protocol'] == 'onedrive' ? 'selected="selected"' : '')).'>'.__('Microsoft OneDrive').'</option>' : '').
					(empty($globals['disable_backup_aws']) ? '<option value="softaws" '.(isset($_REQUEST['protocol']) && $_REQUEST['protocol'] == 'softaws' ? 'selected="selected"' : ($edit_location['protocol'] == 'softaws' ? 'selected="selected"' : '')).'>'.__('Amazon S3').'</option>' : '').'
				</select>
			</div>
		</div>
		
		<div class="row" id="dropbox_authorize"><br/>
			<div class="col-12 col-md-6 col-xl-6 mb-2">
				<label for="dropbox_auth" class="sai_head" id="dropbox_auth_head">'.__('Authorization').'</label><br />
				<span class="sai_exp2">'.__('Click to re-authorize $0 APP access to create backups in your Dropbox account. Click on the <b>Re-Authorize</b> button and follow the steps. Make a note of the code generated and enter the same in the <b>Auth Code</b> text box below', array(APP)).maybe_show_docs('https://softaculous.com/docs/Edit_Backup_Location_Dropbox', '&nbsp;&nbsp;'.__('View Guide')).'</span>
				<br /><a href="https://www.dropbox.com/oauth2/authorize?response_type=code&token_access_type=offline&client_id='.$dropbox->app_key.'" target="_blank"><input class="flat-butt someclass" type="button" name="dropbox_auth" id="dropbox_auth" value="'.__('Re-Authorize').'" title="'.__('Hit this button to authorize Dropbox Access').'" style="font-size:15px; width:150px;" /></a>
			</div>
			<div class="col-12 col-md-6 col-xl-6 mb-2" id="dropbox_code">
				<label for="access_code" class="sai_head" id="dropbox_code_head">'.__('Auth Code').'</label><br />
				<span class="sai_exp2">'.__('Enter the code generated after allowing access via <b>Re-Authorize</b> button above').'</span>
				<input type="text" name="access_code" id="access_code" class="form-control" value="'.POSTval('access_code', '').'" />
			</div>
		</div>
		
		<div id="aws_s3bucket">

			<div class="row">
				<div class="col-12 col-md-6 col-xl-6 mb-2">
					<label for="aws_endpoint" class="sai_head" id="aws_endpoint_head">'.__('AWS S3 Endpoint').'</label><br />
					<span class="sai_exp2">'.__('Enter your AWS S3 Endpoint e.g. "s3.amazonaws.com"<br /> For more Information <a href="https://docs.aws.amazon.com/general/latest/gr/s3.html" target="_blank">Click here</a>').'</span>
					<input type="text" name="aws_endpoint" id="aws_endpoint" class="form-control" value="'.POSTval('aws_endpoint', $edit_location['aws_endpoint']).'" />
				</div>
				<div class="col-12 col-md-6 col-xl-6 mb-2">
					<label for="aws_region" class="sai_head" id="aws_region_head">'.__('AWS S3 Region').'</label><br />
					<span class="sai_exp2">'.__('Enter your AWS S3 Region e.g. "us-east-1"<br />  For more Information   <a href="https://docs.aws.amazon.com/general/latest/gr/s3.html" target="_blank">Click here</a>').'</span>
					<input type="text" name="aws_region" id="aws_region" class="form-control" value="'.POSTval('aws_region', $edit_location['aws_region']).'" />
				</div>
			</div>

			<div class="row">
				<div class="col-12 col-md-6 col-xl-6 mb-2">
					<label for="aws_accessKey" class="sai_head" id="aws_accessKey_head">'.__('AWS S3 Access Key').'</label><br />
					<input type="text" name="aws_accessKey" id="aws_accessKey" class="form-control" value="'.POSTval('aws_accessKey', $edit_location['aws_accessKey']).'" />
				</div>
				<div class="col-12 col-md-6 col-xl-6 mb-2">
					<label for="aws_secretKey" class="sai_head" id="aws_secretKey_head">'.__('AWS S3 Secret Key').'</label><br />
					<div class="row">
						<div class="col-sm-11">
						<input type="password" name="aws_secretKey" id="aws_secretKey" class="form-control" value="'.POSTval('aws_secretKey', $edit_location['aws_secretKey']).'" autocomplete="off" />
						</div>
						<div class="col-sm-1" style="margin-left:-20px;">
						<input id="aws_toggle_passwd" type="checkbox" style="display:none;" onclick="toggle_pass(\'aws_show_hide\', \'aws_secretKey\');" /><label for="aws_toggle_passwd" style="margin-top:6px;"><span id="aws_show_hide">'.__('Show').'</span></label>
						</div>
					</div>
				</div>
			</div>

			<div class="row">
				<div class="col-12 col-md-6 col-xl-6 mb-2">
					<label for="aws_bucketname" class="sai_head" id="aws_bucketname_head">'.__('AWS S3 Bucket Name').'</label><br />
					<span class="sai_exp2">'.__('Enter the AWS S3 bucket name where you wish to create softaculous backups. If the bucket is not present, it will be created automatically<br /> For Bucket Naming Rules <a href="https://docs.aws.amazon.com/AmazonS3/latest/userguide/bucketnamingrules.html" target="_blank">Click here</a>').'</span>
					<input type="text" name="aws_bucketname" id="aws_bucketname" class="form-control" value="'.POSTval('aws_bucketname', $edit_location['aws_bucketname']).'" />
				</div>
			</div>

		</div>
		
		<div class="row" id="ftp_details">
		
			<div class="col-12 col-md-6 col-xl-6 mb-2">
				<label for="server_host" class="sai_head">'.__('Server Host (Required)').'</label><br/>
				<span class="sai_exp2" id="server_host_exp">'.__('Enter the server host e.g. ftp.mydomain.com').'</span>
				<input type="text" name="server_host" id="server_host" class="form-control" value="'.POSTval('server_host', $edit_location['server_host']).'" />
			</div>
			
			<div class="col-12 col-md-6 col-xl-6 mb-2">
				<label for="port" class="sai_head">'.__('Port').'</label><br/>
				<span class="sai_exp2" id="port_exp">'.__('Enter the port to connect (default FTP port is <b>21</b>)').'</span>
				<input type="text" name="port" id="port" class="form-control" value="'.POSTval('port', $edit_location['port']).'" />
			</div>
		</div>

		<div class="row">
			<div class="col-12 col-md-6 col-xl-6 mb-2" id="trauthpass">
				<label for="auth_password" class="sai_head">'.__('Authentication method').'</label><br/>
				<span class="sai_exp2">'.__('Select the authentication method').'</span>
				&nbsp;&nbsp; <input type="radio" name="auth_password" id="auth_password" value="1" onchange="check_auth_password();" '.POSTradio('auth_password', 1, (empty($edit_location['private_key']) ? 1 : 0)).' />&nbsp;'.__('Password').' &nbsp;&nbsp;
				<input type="radio" name="auth_password" id="auth_password" value="" onchange="check_auth_password();" '.POSTradio('auth_password', '', (empty($edit_location['private_key']) ? null : '')).' />&nbsp;'.__('SSH Key').'<br /><br />
			</div>
		</div>
			
		<div class="row" id="ftp_credentials">
			<div class="col-12 col-md-6 col-xl-6 mb-2">
				<label for="ftp_user" class="sai_head" id="ftp_user_head">'.__('Username').'</label><br />
				<span class="sai_exp2" id="ftp_user_exp">'.__('The username of your FTP Account').'</span>
				<input type="text" name="ftp_user" id="ftp_user" class="form-control" value="'.POSTval('ftp_user', $edit_location['ftp_user']).'" />
			</div>
			
			<div class="col-12 col-md-6 col-xl-6 mb-2" id="ftp_pass">
				<label for="ftp_passwd" class="sai_head" id="ftp_pass_head">'.__('Password').'</label><br />
				<span class="sai_exp2" id="ftp_pass_exp">'.__('The Password of your FTP account').'</span>
				<div class="row">
					<div class="col-sm-11">
					<input type="password" name="ftp_pass" id="ftp_passwd" class="form-control" value="'.POSTval('ftp_pass', $edit_location['ftp_pass']).'" autocomplete="off" />
					</div>
					<div class="col-sm-1" style="margin-left:-20px;">
					<input id="toggle_passwd" type="checkbox" style="display:none;" onclick="toggle_pass(\'show_hide\', \'ftp_passwd\');" /><label for="toggle_passwd" style="margin-top:6px;"><span id="show_hide">'.__('Show').'</span></label>
					</div>
				</div>
			</div>
		</div>
			
		<div class="row">
			<div class="col-12 col-md-6 col-xl-6 mb-2" id="pri">
				<label for="private_key" class="sai_head">'.__('Private Key').'</label><br/>
				<span class="sai_exp2">'.__('Paste the private key here').'</span>
				<textarea name="private_key" id="private_key" rows="15" cols="70" class="form-control">'.aPOSTval('private_key', $edit_location['private_key']).'</textarea>
			</div>
			
			<div class="col-12 col-md-6 col-xl-6 mb-2" id="passphrase_div">
				<label for="passphrase" class="sai_head">'.__('Passphrase').'</label><br/>
				<span class="sai_exp2">'.__('Passphrase for the private key (Optional)').'</span>
				<input type="text" name="passphrase" id="passphrase" class="form-control" value="'.POSTval('passphrase', $edit_location['passphrase']).'" />
			</div>
		</div>
		
		<div class="row" id="backup_location"><br />
			<div class="col-12 col-md-6 col-xl-6 mb-2">
				<label for="backup_loc" class="sai_head" id="backup_loc_title">'.__('Backup Location').'</label><br />
				<span class="sai_exp2" id="backup_loc_exp"></span>
				<input type="text" name="backup_loc" id="backup_loc" class="form-control" value="'.POSTval('backup_loc', $edit_location['backup_loc']).'" />
			</div>
		</div>
		
		<p align="center">
			<br /><br />
			'.csrf_display().'
			<input class="btn sai-button" type="submit" name="editbackuploc" value="'.__('Save Changes').'" />
			<br /><br />
			<img id="waiting" src="'.$theme['images'].'progress.gif" style="display:none">
			
			<b><a class="sai_head" href="'.$globals['ind'].'act=settings">'.__('Return to Settings').'</a></b>
		</p>
	
	</div><!--end of card m-3-->
	</form>
	</div>
</div><br /><!--end of bg class-->	

<script src="'.$theme['url'].'/js/spectrum.js" type="text/javascript"></script>
<script type="text/javascript">

	//Added the show_text & hide_text variable for when the header is not loaded (Iframe)
	var show_text = "'.__js('Show').'";
	var hide_text = "'.__js('Hide').'";
	
	$(document).ready(function(){
		check_auth_password();
		checkprotocol();
		$("#protocol").change(function(){
			checkprotocol();
		});
		
		$("#dropbox_auth").click(function(){
			$("#dropbox_code").show();
		});
	});

	function checkprotocol(){
		
		$("#ftp_user_head").html($("#protocol option:selected").text().toUpperCase()+" "+"'.__js('Username').'");
		$("#ftp_pass_head").html($("#protocol option:selected").text().toUpperCase()+" "+"'.__js('Password').'");

		if($("#protocol").val() == "ftp"){
			if($("#port").val() == "" || $("#port").val() == "22" || $("#port").val() == "443"){
				$("#port").val("21");
			}
			
			show_ftp();
			hide_dropbox();
			hide_aws_s3bucket();

			$("#trauthpass").hide();
			hide_sshkey();
			$("#server_host_exp").html("'.__js('Enter the server host e.g. ftp.mydomain.com').'");
			$("#port_exp").html("'.__js('Enter the port to connect (default FTP port is <b>21</b>)').'");
			$("#ftp_user_exp").html("'.__js('The username of your FTP Account').'");
			$("#ftp_pass_exp").html("'.__js('The Password of your FTP account').'");
			$("#backup_loc_exp").html("'.__js("Relative path from FTP user's directory e.g. /backups").'");
			$("#backup_loc_title").html("'.__js('Backup Location').'");
		}
		
		if($("#protocol").val() == "softftpes"){
			if($("#port").val() == "" || $("#port").val() == "22" || $("#port").val() == "443"){
				$("#port").val("21");
			}
			
			show_ftp();
			hide_dropbox();
			hide_aws_s3bucket();

			$("#trauthpass").hide();
			hide_sshkey();
			$("#server_host_exp").html("'.__js('Enter the server host e.g. ftp.mydomain.com').'");
			$("#port_exp").html("'.__js('Enter the port to connect (default FTP port is <b>21</b>)').'");
			$("#ftp_user_exp").html("'.__js('The username of your FTP Account').'");
			$("#ftp_pass_exp").html("'.__js('The Password of your FTP account').'");
			$("#backup_loc_exp").html("'.__js("Relative path from FTP user's directory e.g. /backups").'");
			$("#backup_loc_title").html("'.__js('Backup Location').'");
		}		
		
		if($("#protocol").val() == "softsftp"){
			if($("#port").val() == "" || $("#port").val() == "21" || $("#port").val() == "443"){
				$("#port").val("22");
			}
			
			show_ftp();
			hide_dropbox();
			hide_aws_s3bucket();

			$("#trauthpass").show();
			check_auth_password();
			$("#server_host_exp").html("'.__js('Enter the server host e.g. ftp.mydomain.com').'");
			$("#port_exp").html("'.__js('Enter the port to connect (default FTP port is <b>21</b>)').'");
			$("#ftp_user_exp").html("'.__js('The username of your FTP Account').'");
			$("#ftp_pass_exp").html("'.__js('The Password of your FTP account').'");
			$("#backup_loc_exp").html("'.__js('Absolute path to backup directory e.g. /home/USERNAME/backups').'");
			$("#backup_loc_title").html("'.__js('Backup Location').'");
		}		
		
		if($("#protocol").val() == "dropbox"){		
			$("#dropbox_code").hide();
			show_dropbox();
			hide_ftp();
			hide_aws_s3bucket();

			$("#trauthpass").hide();
			hide_sshkey();
			$("#backup_loc_exp").html("'.__js('Backup Directory e.g. /backups or you can leave empty to allow $0 to manage the backup directory', array(APP)).'");
			$("#backup_loc_title").html("'.__js('Backup Location (Optional)').'");
		}
		
		if($("#protocol").val() == "gdrive"){
			hide_ftp();
			hide_dropbox();
			hide_aws_s3bucket();

			$("#trauthpass").hide();
			hide_sshkey();
			$("#backup_loc_exp").html("'.__js('Backup Directory e.g. /backups or you can leave empty to allow $0 to manage the backup directory', array(APP)).'");
			$("#backup_loc_title").html("'.__js('Backup Location (Optional)').'");
		}

		if($("#protocol").val() == "onedrive"){
			hide_ftp();
			hide_dropbox();
			hide_aws_s3bucket();
			
			$("#trauthpass").hide();
			hide_sshkey();
			$("#backup_loc_exp").html("'.__js('Backup Directory e.g. /backups or you can leave empty to allow $0 to manage the backup directory', array(APP)).'");
			$("#backup_loc_title").html("'.__js('Backup Location (Optional)').'");
		}

		if($("#protocol").val() == "webdav"){
			if($("#port").val() == "" || $("#port").val() == "21"){
				$("#port").val("443");
			}
			
			show_ftp();
			hide_dropbox();
			hide_aws_s3bucket();

			$("#trauthpass").hide();
			hide_sshkey();
			$("#server_host_exp").html("'.__js('Enter the server host e.g. webdav.mydomain.com').'");
			$("#port_exp").html("'.__js('Enter the port to connect (default WebDAV port is <b>80</b> for insecure and <b>443</b> for secure)').'");
			$("#ftp_user_exp").html("'.__js('The username of your WebDAV Account').'");
			$("#ftp_pass_exp").html("'.__js('The Password of your WebDAV account').'");
			$("#backup_path_exp").html("'.__js("Relative path from WebDAV user's directory e.g. /backups").'");
			$("#backup_loc_title").html("'.__js('Backup Location').'");
		}

		if($("#protocol").val() == "softaws"){
			hide_ftp();
			hide_dropbox();
			show_aws_s3bucket();

			$("#trauthpass").hide();
			hide_sshkey();
			$("#backup_path_exp").html("'.__js('Backup Directory e.g. /backups  or you can leave empty to allow $0 to manage the backup directory', array(APP)).'");
			$("#backup_loc_title").html("'.__js('AWS S3 Backup Location (Optional)').'");
		}
	}
	
	function check_auth_password(){
		if($("#auth_password").is(":checked")){
			hide_sshkey();
		}else{
			show_sshkey();
		}
	}
	
	function show_ftp(){
		$("#ftp_details").show();
		$("#ftp_credentials").show();
		$("#host").show();
		$("#server_host").prop("disabled", false);
		$("#port").prop("disabled", false);
		$("#ftp_user").prop("disabled", false);
		$("#ftp_pass").prop("disabled", false);
	}
	
	function hide_ftp(){
		$("#ftp_details").hide();
		$("#ftp_credentials").hide();
		$("#host").hide();
		$("#server_host").prop("disabled", true);
		$("#port").prop("disabled", true);
		$("#ftp_user").prop("disabled", true);
		$("#ftp_pass").prop("disabled", true);
	}
	
	function show_dropbox(){
		$("#dropbox_authorize").show();
		$("#access_code").prop("disabled", false);
	}
	
	function hide_dropbox(){
		$("#dropbox_authorize").hide();
		$("#access_code").prop("disabled", true);
	}

	function show_aws_s3bucket(){
		$("#aws_s3bucket").show();
	}
	
	function hide_aws_s3bucket(){
		$("#aws_s3bucket").hide();
	}
	
	function hide_sshkey(){
		$("#private_key").prop("disabled", true);
		$("#pri").hide();
		$("#passphrase_div").hide();
		$("#ftp_pass").show();
	}

	function show_sshkey(){
		$("#private_key").prop("disabled", false);
		$("#pri").show();
		$("#passphrase_div").show();
		$("#ftp_pass").hide();
	}
	
	function theme_init(){
		$(".someclass").tipTip();
	}

</script>';
	
	softfooter();
}

?>