connect_error) { $success=0; die("Connection failed: " . $conn->connect_error); } ?> Add Machine

Add a machine

machineid,cert,apikey * setup_script => server location, to download settings, databases etc * add installer.exe to download list => downloads the app and all the files */ //create machineid: $random_bytes = random_bytes(6); // Convert the random bytes to hexadecimal $machineid = bin2hex($random_bytes); if($_POST["ip"]=="") $ip="nan"; $location=htmlspecialchars($_POST["location"]); $stmt = $conn->prepare("INSERT INTO machines (machine_name, machine_location,machine_ip) VALUES (?, ?, ?)"); $stmt->bind_param("sss", $machineid, $location, $ip); $stmt->execute(); $stmt->close(); //create secrets $random_bytes = random_bytes(248); // Convert the random bytes to hexadecimal $cert = bin2hex($random_bytes); //create secrets $random_bytes = random_bytes(248); // Convert the random bytes to hexadecimal $apikey = bin2hex($random_bytes); $stmt = $conn->prepare("INSERT INTO secrets (machine_id, cert) VALUES (?, ?)"); $stmt->bind_param("ss", $machineid, $cert); $stmt->execute(); $stmt->close(); $stmt = $conn->prepare("INSERT INTO api (machine_id, apikey) VALUES (?, ?)"); $stmt->bind_param("ss", $machineid, $apikey); $stmt->execute(); $stmt->close(); //get the address of this server $sql = "SELECT * FROM settings WHERE name = 'setting_server_server_url'"; $stmt = $conn->prepare($sql); // Execute the statement $stmt->execute(); // Get the result $result = $stmt->get_result(); $row = $result->fetch_assoc(); if($row!==null){ $this_server=$row["value"]; } $stmt -> close(); //create the files and download them $fp=fopen("/var/www/html/setup.txt","w"); fwrite($fp,"$this_server"); fclose($fp); $fp=fopen("/var/www/html/secrets.txt","w"); fwrite($fp,"machineid $machineid\n"); fwrite($fp,"cert $cert\n"); fwrite($fp,"apikey $apikey\n"); fclose($fp); echo("Download config file1"); echo("Download config file2"); echo("Download installer"); } ?>