diff --git a/index.js b/index.js index 0ac00ca..45bd541 100644 --- a/index.js +++ b/index.js @@ -590,6 +590,32 @@ app.put('/api/v1/user/route', (req, res) => { // Update route }); }); +app.patch('/api/v1/user/update', async (req, res) => { // Update users server, port, auth, or secret via API key instead of session. Used for automated scripts + const apiKey = req.headers['authorization']; + if (!apiKey) { + res.status(401).json({ error: 'Unauthorized' }); + return; + } + const oldData = await pool.query("SELECT * FROM routes WHERE apiKey = ?", [apiKey]); + if (!oldData || oldData.length === 0) { + res.status(401).json({ error: 'Unauthorized' }); + return; + } + const row = oldData[0]; + const server = req.body.server || row.server; + const port = req.body.port || row.port; + const auth = req.body.auth || row.auth; + const secret = req.body.secret || row.secret; + + const updateData = await pool.query('UPDATE routes SET server = ?, port = ?, auth = ?, secret = ? WHERE apiKey = ?', + [server, port, auth, secret, apiKey]); + if (updateData.affectedRows === 1) { + res.json({ message: 'Updated' }); + } else { + res.status(500).json({ error: 'Internal server error' }); + } +}); + app.get('/api/v1/user/directory', (req, res) => { // Get directory entries created by user if (!req.session.userAuthenticated) { res.status(401).json({ error: 'Unauthorized' }); diff --git a/tools/astrocom_dynamic_ip.sh b/tools/astrocom_dynamic_ip.sh new file mode 100644 index 0000000..1133948 --- /dev/null +++ b/tools/astrocom_dynamic_ip.sh @@ -0,0 +1,22 @@ +#!/bin/bash +# AstroCom Dynamic IP Update Script +# Gets current public IP from https://myip.wtf/text and posts it to the AstroCom API +# Requires: curl + +# Configuration +API_KEY="your_api_key_here" # Replace with your AstroCom API Key! + + + +# Get current IP +CURRENT_IP=$(curl -s https://myip.wtf/text) +if [[ -z "$CURRENT_IP" ]]; then + echo "Failed to retrieve current IP address." + exit 1 +fi +echo "Current IP: $CURRENT_IP" +# Update IP via AstroCom API PATCH https://astrocom.tel/api/v1/user/update; JSON body: {"server": "current_ip"} +RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" -X PATCH https://astrocom.tel/api/v1/user/update \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $API_KEY" \ + -d "{\"server\": \"$CURRENT_IP\"}" \ No newline at end of file