Siteβ―Builder
Editing:
more2.php
writable 0666
<?php // more.php // ββ CONFIGURATION ββ define('COOKIE_NAME','openai_key'); define('COOKIE_TTL', 30 * 24 * 3600); // 30 days define('SECRET', __FILE__); // change to your own secret salt // β SIMPLE ENCRYPT/DECRYPT β function encrypt_val($v) { $method = 'aes-128-ctr'; $key = substr(hash('sha256', SECRET, true), 0, 16); $iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length($method)); $ct = openssl_encrypt($v, $method, $key, 0, $iv); return base64_encode("$ct::$iv"); } function decrypt_val($c) { @list($ct,$iv) = explode('::', base64_decode($c), 2); $method = 'aes-128-ctr'; $key = substr(hash('sha256', SECRET, true), 0, 16); return openssl_decrypt($ct, $method, $key, 0, $iv); } // β HANDLE KEY SAVE β $msg = ''; if ($_SERVER['REQUEST_METHOD']==='POST' && isset($_POST['save_key'])) { $raw = trim($_POST['api_key']); // quick βlist modelsβ check $opts = [ 'http'=>[ 'method'=>'GET', 'header'=>"Authorization: Bearer $raw\r\n", 'timeout'=>10 ] ]; if (@file_get_contents('https://api.openai.com/v1/models', false, stream_context_create($opts))) { setcookie(COOKIE_NAME, encrypt_val($raw), time()+COOKIE_TTL, '/', '', isset($_SERVER['HTTPS']), true); $msg = "β Key saved!"; } else { $msg = "β Invalid key."; } } // β HANDLE KEY DELETE β if (isset($_GET['delete_key'])) { setcookie(COOKIE_NAME,'', time()-3600, '/', '', isset($_SERVER['HTTPS']), true); header("Location: {$_SERVER['PHP_SELF']}"); exit; } // β FETCH SYNONYMS via Chat Completions β $key = $_COOKIE[COOKIE_NAME] ?? ''; $key = $key ? decrypt_val($key) : ''; $scope = $_GET['scope'] ?? 'synonyms'; $word = trim($_GET['word'] ?? ''); $items = []; if ($key && $word) { // build chat payload $payload = [ 'model' => 'gpt-3.5-turbo', 'messages' => [ ['role'=>'system', 'content'=>"You are a helpful assistant that replies ONLY with a comma-separated list of {$scope}, no extra text."], ['role'=>'user', 'content'=>"List only the {$scope} for β{$word}β."] ], 'max_tokens' => 60, 'temperature' => 0.3, 'stop' => ["\n"] ]; $ch = curl_init('https://api.openai.com/v1/chat/completions'); curl_setopt_array($ch, [ CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => [ 'Authorization: Bearer '.$key, 'Content-Type: application/json', ], CURLOPT_POST => true, CURLOPT_POSTFIELDS => json_encode($payload), CURLOPT_TIMEOUT => 15, ]); $response = curl_exec($ch); $err = curl_error($ch); $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if (!$err && $code === 200) { $data = json_decode($response, true); $text = $data['choices'][0]['message']['content'] ?? ''; $items = array_filter(array_map('trim', explode(',', $text))); } } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Promptinator Simple</title> <style> body { font-family:sans-serif; max-width:600px; margin:2rem auto; } .token { display:inline-block; background:#eee; padding:4px 8px; margin:3px; border-radius:4px; } pre { background:#f6f6f6; padding:8px; } label { display:inline-block; width:80px; vertical-align: top; } input[type=text], input[type=password] { width:200px; padding:4px; } </style> </head> <body> <h2>1) OpenAI API Key</h2> <?php if($msg): ?><p><strong><?=htmlspecialchars($msg)?></strong></p><?php endif; ?> <?php if(!$key): ?> <form method="post"> <input type="password" name="api_key" placeholder="sk-..." required> <button name="save_key">Save & Validate</button> </form> <?php else: ?> <p>Key is saved. <a href="?delete_key=1">Delete key</a></p> <?php endif; ?> <?php if($key): ?> <h2>2) Generate Synonyms</h2> <form method="get"> <label for="scope">Scope</label> <input id="scope" name="scope" value="<?=htmlspecialchars($scope)?>"> <br><label for="word">Seed</label> <input id="word" name="word" value="<?=htmlspecialchars($word)?>"> <button>Go</button> </form> <?php if(count($items)): ?> <h3>3) Select Token</h3> <select id="token_select" style="width:100%;padding:8px;"> <?php foreach($items as $i => $it): ?> <option value="<?=htmlspecialchars($it)?>" <?= $i===0?'selected':'' ?>> <?=htmlspecialchars($it)?> </option> <?php endforeach; ?> </select> <h3>4) Shortcode Preview</h3> <pre id="shortcode"> [B-synonyms-|<?=implode('|', array_map('htmlspecialchars',$items))?>|~<?=htmlspecialchars($items[0])?>~] </pre> <script> document.getElementById('token_select') .addEventListener('change', function(){ const def = this.value; const opts = Array.from(this.options).map(o=>o.value).join('|'); document.getElementById('shortcode').textContent = `[B-synonyms-|${opts}|~${def}~]`; }); </script> <?php endif; ?> <?php endif; ?> </body> </html>
Save changes
Create folder
writable 0777
Create
Cancel