sync.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. // Gasteizko Margolariak API v3 //
  3. // Error messages
  4. define('ERR_USER', '-USER:');
  5. define('ERR_TABLE', '-TABLE:');
  6. define('ERR_WHERE', '-WHERE:');
  7. include('functions.php');
  8. $con = startdb();
  9. // Error control
  10. $error = "";
  11. // Validate user/pass
  12. if (!fastLogin($con)){
  13. error_log(":SECURITY: Reporting location with wrong credentials (IP $_SERVER[REMOTE_ADDR])");
  14. $error = $error . ERR_USER . mysqli_real_escape_string($con, $_POST[GET_USER]);
  15. error_log($error);
  16. http_response_code(403); // Forbidden
  17. exit(-1);
  18. }
  19. // TODO: Ask server to create a SQLdump
  20. $date = date_create();
  21. $fname = date_timestamp_get($date);
  22. include('../../.htpasswd');
  23. exec("mysqldump gm -u $username_ro -p$pass_ro > /var/www-dump/$fname.sql");
  24. // TODO: Ask server to encrypt the dump.
  25. $pass = mysqli_real_escape_string($con, $_POST[GET_USER]);
  26. exec("gpg --batch --yes --passphrase $pass -o /var/www-admin/dump/$fname.gpg -c /var/www-dump/$fname.sql.txt")
  27. // TODO: Make a redirect for a redirect.
  28. header("Location: /dump/$fname.gpg");
  29. ?>