<?php

//////////////////////////////////////////////////////////////
//===========================================================
// server_sshkeys_theme.php
//===========================================================
// SOFTACULOUS VIRTUALIZOR
// Version : 1.0
// Inspired by the DESIRE to be the BEST OF ALL
// ----------------------------------------------------------
// Started by: Alons
// Date:       8th Mar 2010
// Time:       23:00 hrs
// Site:       https://www.virtualizor.com/ (SOFTACULOUS VIRTUALIZOR)
// ----------------------------------------------------------
// Please Read the Terms of use at https://www.virtualizor.com
// ----------------------------------------------------------
//===========================================================
// (c)Softaculous Ltd.
//===========================================================
//////////////////////////////////////////////////////////////

if(!defined('VIRTUALIZOR')){

	die('Hacking Attempt');

}

function server_sshkeys_theme(){

global $theme, $globals, $kernel, $user, $l, $error, $current_status, $server_sshkeys;

softheader($l['<title>']);
					
echo '
<script language="javascript" type="text/javascript">
	function delete_key(sshkey_id){
		showalert("'.__J('Are you sure you want to delete the SSH Key?').'", "3", function(confirm){
			if(confirm == true){
				var data = {"del_sshkey_id":sshkey_id};
				$.ajax({type: "POST",
					url: "'.$globals['index'].'act=server_sshkeys&jsnohf=1&api=json&random="+Math.random(),
					data: data,
					success:function(response){
						if(!isNaN(response)){
							
						}else{
							//$("#softcontent").html(response);
							
						}
						
						response = JSON.parse(response);
						if(response.error != undefined){
							showalert(response.error, "1");
							$("#progress-cont").hide();
						}
					},
				});
			}
		});
		return false;
	}
</script>';

$GLOBALS['breadcrumbs'] = ['dashboard', 'lms_server_sshkeys'];

echo page_header(__('Server SSH Keys'), 'fas fa-key', '', 1, 0, '');

echo '<div class="card p-2 mx-3">

	<div id="showsearch" style="display:'.(optREQ('search') || (!empty($server_sshkeys) && !empty($globals['showsearch'])) ? "" : "none").';">
<form accept-charset="'.$globals['charset'].'" name="server_sshkeys" method="get" action="" class="form-horizontal">
<input type="hidden" name="act" value="server_sshkeys">
		
<div class="form-group_head">
  <div class="row mx-auto w-100">
    <div class="col-sm-3"></div>
	<div class="col-sm-3">
		<label>'.__('IP').'</label>
		<input type="text" class="form-control" name="ip" id="ip" size="30" value="'.REQval('ip','').'"/>
	</div>
	<div class="col-sm-3">
		<label>'.__('VPSID').'</label>
		<input type="text" class="form-control" name="vpsid" id="vpsid" size="30" value="'.REQval('vpsid','').'"/>
	</div>
  </div>
  <div class="row mt-2 mx-auto w-100">
  	<div class="col-sm-12 text-center"><button type="submit" name="search" class="go_btn mt-2" value="Search"/>'.__('Search').'</button></div> 
  </div>
</div>
</form>
</div>';

if(empty($server_sshkeys)){
	optREQ('search') ? show_alert(__('No results were found for your search query !'), "2") : "";
	echo '<div class="notice"><b>NOTE : </b>&nbsp; '.(optREQ('search') ? __('No results were found for your search query !') : __('There are no SSH keys present')).'</div>';
	
}else{
	echo'
	<div class="row mx-auto w-100 mb-3">
		<div class="col-sm-8 col-lg-8 col-md-6 d-flex align-items-center justify-content-end p-0 mt-2 mt-md-0 mt-lg-0">';
			page_links($globals['num_res'], $globals['cur_page'], $globals['reslen']);
		echo''.get_num_records($globals['num_res']).'
		</div>
	</div>
	<div class="sticky">
	<table class="table table-hover tablesorter" style="table-layout: fixed;">
	<tr class="table_heading">
		<th width="5%">'.__('ID').'</th>
		<th width="5%">'.__('Type').'</th>
		<th width="20%">'.__('Server Name').'</th>
		<th width="10%">'.__('Time').'</th>
		<th width="10%" style="text-align:right !important;">'.__('Action').'</th>
	</tr>';
	$i = 0;
	foreach($server_sshkeys as $k => $v){
		
	echo '<tr>
			<td align="left">'.$v['serid'].'</td>
			<td>'.$v['server_name'].'</td>
			<td align="left">'.$v['type'].'</td>';
			// <!-- 
			// <td style="word-wrap: break-word;">
			// 	<div id="pubkey_'.$k.'" class="d-none">'.$v['public_key'].'</div>
			// 	<a id="pop_pubkey_'.$k.'" href="javascript:copy($(\'#pop_pubkey_'.$k.'\'),\'pubkey_'.$k.'\')" class="copyflare">'.__('Public Key').'</a>
			// </td>
			// <td style="word-wrap: break-word;">
			// 	<div id="private_'.$k.'" class="d-none">'.$v['private_key'].'</div>
			// 	<a id="pop_privatekey_'.$k.'" href="javascript:copy($(\'#pop_privatekey_'.$k.'\'),\'private_'.$k.'\')" class="copyflare">'.__('Private Key').'</a>
			// </td>-->
			echo '
			<td>'.datify($v['time'], 0, 1, "d M Y h:i:s A").'</td>
			<td align="right">
				<a class="badge badge-settings" onclick="delete_key('.$k.')" title="'.__('Delete key').'"><i class="fas fa-trash text-danger"></i></a>
			</td>
		<tr>';
		$i++;
	}
	
	echo '</table></div>
	<div class="row mx-auto w-100 mt-5">
		<div class="col-sm-8 col-lg-8 col-md-6 mb-3 p-0">';
			page_links($globals['num_res'], $globals['cur_page'], $globals['reslen']);
		echo'
		</div>
	</div>';
}
echo '</div>';
softfooter();

}

?>