Advertisement
sekedus

Create new paste & get paste list - pastes.io

Feb 28th, 2023 (edited)
3,857
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.48 KB | None | 0 0
  1. <?php
  2. /*
  3. Example:
  4.   - Paste list: http://localhost/backup.php?list
  5.   - Create file: http://localhost/backup.php?content=tezt&title=test1&pass=123456
  6.   - Create file with callback (JS): http://localhost/backup.php?content=tezt&title=test1&pass=123456&callback=run
  7. */
  8.  
  9. // 🟥 Source: https://pastes.io/pages/pastebin-api-docs
  10.  
  11. // Get 'api_token' : https://pastebin.com/9F2QY3k6
  12.  
  13. $api_token = 'YOUR_API_TOKEN';
  14.  
  15. function response($data)
  16. {
  17.   // https://stackoverflow.com/a/1678243/7598333
  18.   if (param_check('callback', $_GET)) {
  19.     header('Content-Type: text/javascript; charset=utf8');
  20.     if (param_check('HTTP_REFERER', $_SERVER)) header('Access-Control-Allow-Origin: ' . $_SERVER['HTTP_REFERER']);
  21.     echo $_GET['callback'] . '(' . $data . ');';
  22.   } else {
  23.     echo $data;
  24.   }
  25. }
  26.  
  27. function param_check($name, $array = [])
  28. {
  29.   return isset($array[$name]) && (!empty($array[$name]) || $array[$name] != '');
  30. }
  31.  
  32. if (param_check('content', $_GET) && param_check('title', $_GET) && param_check('pass', $_GET)) {
  33.   $curl = curl_init();
  34.  
  35.   curl_setopt_array($curl, array(
  36.     CURLOPT_URL => 'https://pastes.io/api/paste/create',
  37.     CURLOPT_RETURNTRANSFER => true,
  38.     CURLOPT_ENCODING => '',
  39.     CURLOPT_MAXREDIRS => 10,
  40.     CURLOPT_TIMEOUT => 0,
  41.     CURLOPT_FOLLOWLOCATION => true,
  42.     CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  43.     CURLOPT_CUSTOMREQUEST => 'POST',
  44.     CURLOPT_POSTFIELDS => array(
  45.       'content' => $_GET['content'],
  46.       'status' => '1', // 0=public 1=unlisted 2=private
  47.       'expire' => '10M', // 10 Minutes
  48.       'title' => $_GET['title'],
  49.       'syntax' => 'markdown', // https://pastes.io/archive
  50.       'password' => $_GET['pass']
  51.     ),
  52.     CURLOPT_HTTPHEADER => array(
  53.       'Accept: application/json',
  54.       'Authorization: Bearer '. $api_token
  55.     ),
  56.   ));
  57.  
  58.   $response = curl_exec($curl);
  59.   curl_close($curl);
  60.   response($response);
  61. }
  62.  
  63. if (isset($_GET['list'])) {
  64.   $curl = curl_init();
  65.  
  66.   curl_setopt_array($curl, array(
  67.     CURLOPT_URL => 'https://pastes.io/api/my-pastes',
  68.     CURLOPT_RETURNTRANSFER => true,
  69.     CURLOPT_ENCODING => '',
  70.     CURLOPT_MAXREDIRS => 10,
  71.     CURLOPT_TIMEOUT => 0,
  72.     CURLOPT_FOLLOWLOCATION => true,
  73.     CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  74.     CURLOPT_CUSTOMREQUEST => 'GET',
  75.     CURLOPT_HTTPHEADER => array(
  76.       'Accept: application/json',
  77.       'Authorization: Bearer '. $api_token
  78.     ),
  79.   ));
  80.  
  81.   $response = curl_exec($curl);
  82.   curl_close($curl);
  83.   response($response);
  84. }
  85.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement