solutions/CCTF_Solutions_main/frontend/sendflag.html

116 lines
5.1 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<title>Flag Submission Page</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/web3/1.6.1/web3.min.js" integrity="sha512-5erpERW8MxcHDF7Xea9eBQPiRtxbse70pFcaHJuOhdEBQeAxGQjUwgJbuBDWve+xP/u5IoJbKjyJk50qCnMD7A==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<!--<script src="dist/bundle.js"></script>-->
</head>
<body style="height:1500px">
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="#">Flag Submission Page</a>
</div>
<ul class="nav navbar-nav">
<li>
<a href="leaderboard.html">Leaderboard</a>
</li>
<li class="active">
<a href="sendflag.html">Send Flag</a>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>
<button class="btn btn-default navbar-btn" id="metamask-login" type="button" style="margin-right:20px">
<span class="glyphicon glyphicon-log-in"></span>
Connect Wallet</button>
</li>
<!--<button class="btn btn-danger navbar-btn">Button</button>-->
</ul>
</div>
</nav>
<div class="container" style="margin-top:50px">
<h1>Send the flag</h1>
<form class="form-inline" id="flag-form" style="display:none">
<div class="form-group">
<label for="flagbox">Flag id:</label>
<input type="number" class="form-control" id="flagID">
</div>
<div class="form-group">
<label for="flagbox">Proof:</label>
<input type="text" class="form-control" id="flagbox">
</div>
<button id="submitFlagBtn" type="button" class="btn btn-default btn-warning">Submit Flag</button>
</form>
</div>
<script type='module'>
var web3js;
var accounts;
const contractAddress = "0x970e1d481CEDbeaeFE776275F0d1b4E1B301bB3b";
window.addEventListener("load", function () {
let loginbutton = document.getElementById('metamask-login');
ethereum.request({method: 'eth_requestAccounts'}).then(acc => {
console.log(acc);
accounts = acc;
if (acc.length > 0) {
document.getElementById('flag-form').style.display = "block";
loginbutton.textContent = accounts[0];
loginbutton.disabled = true;
}
});
});
let loginbutton = document.getElementById('metamask-login');
loginbutton.addEventListener('click', event => {
let account;
ethereum.request({method: 'eth_requestAccounts'}).then(accounts => {
account = accounts[0];
document.getElementById('flag-form').style.display = "block";
loginbutton.textContent = account;
loginbutton.disabled = true;
})
})
let flagID = document.getElementById('flagID');
let flagbox = document.getElementById('flagbox');
let submitFlagBtn = document.getElementById('submitFlagBtn');
submitFlagBtn.addEventListener('click', event => {
contract.methods.SubmitFlag(JSON.parse(flagbox.value),flagID.value).send( { from: accounts[0] });
})
var contactABI;
var contract;
async function getAbi() {
fetch("/abi.json").then(a => a.json().then(abi => {
contactABI = abi
contract = new web3js.eth.Contract(contactABI, contractAddress);
}));
}
window.addEventListener("load", function () {
if (typeof web3 !== "undefined") {
web3js = new Web3(web3.currentProvider);
// console.log(web3);
getAbi();
} else {
console.log("No web3? You should consider trying MetaMask!");
}
});
</script>
</body>
</html>