Advertisement
khalequzzaman17

foodoma store_config.php

Jun 2nd, 2022 (edited)
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.68 KB | None | 0 0
  1. <?php
  2.  
  3. error_reporting(0);
  4. if (!isset($_POST["main_domain"])) {
  5.     header("Location: setup.html");
  6.     exit;
  7. }
  8. $domain = parse_url_all($_POST["main_domain"]);
  9. $domain = $domain["host"];
  10. $mainDomain = preg_replace("#^www\\.(.+\\.)#i", "\$1", $domain);
  11. if ($mainDomain == NULL) {
  12.     print_r("<b>ERROR:</b> Domain Error. Check domain and try again.");
  13.     print_r("<br><br>");
  14.     print_r("Following are the correct domain formats:");
  15.     print_r("<ul><li>mydomain.com</li><li>myapp.mydomain.com</li></ul>");
  16.     exit;
  17. }
  18. print_r("Your main domain is set: <b>" . $mainDomain . "</b>");
  19. $mainDomain = "https://" . $mainDomain;
  20. $toReplace = "http://foodomaamain.com";
  21. $jsFiles = glob("static/js/*");
  22. foreach ($jsFiles as $file) {
  23.     if (preg_match("/\\bmain\\b/", $file)) {
  24.         $fileContents = file_get_contents($file);
  25.         if (strpos($fileContents, $toReplace) !== false) {
  26.             $replaced = str_replace("http://foodomaamain.com", $mainDomain, $fileContents);
  27.             file_put_contents($file, $replaced);
  28.         }
  29.     }
  30. }
  31. unlink("setup.html");
  32. unlink("store_config.php");
  33. print_r("<br> <b>Done. </b>");
  34. function parse_url_all($url)
  35. {
  36.     $url = substr($url, 0, 4) == "http" ? $url : "http://" . $url;
  37.     $d = parse_url($url);
  38.     $tmp = explode(".", $d["host"]);
  39.     $n = count($tmp);
  40.     if (2 <= $n) {
  41.         if ($n == 4 || $n == 3 && strlen($tmp[$n - 2]) <= 3) {
  42.             $d["domain"] = $tmp[$n - 3] . "." . $tmp[$n - 2] . "." . $tmp[$n - 1];
  43.             $d["domainX"] = $tmp[$n - 3];
  44.         } else {
  45.             $d["domain"] = $tmp[$n - 2] . "." . $tmp[$n - 1];
  46.             $d["domainX"] = $tmp[$n - 2];
  47.         }
  48.     }
  49.     return $d;
  50. }
  51.  
  52. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement