V
V
Vanya Mironov2022-04-19 13:53:40
PHP
Vanya Mironov, 2022-04-19 13:53:40

How to check the domain for presence in the database from a remote server?

Hello, how can I check for the presence of a domain in the database
; there is a gamecms engine; it sends all the necessary data
, here is the code:

<?PHP
  require($_SERVER['DOCUMENT_ROOT'] . '/inc/start.php');
  if(empty($_POST['phpaction'])) {
    exit(json_encode(['status' => '2']));
  }
  if($_SESSION['token'] != $_POST['token']) {
    exit(json_encode(['status' => '2']));
  }
  if(!is_admin()) {
    echo 'Ошибка: [Доступно только администратору]';
    exit(json_encode(['status' => '2']));
  }
  if(isset($_POST['setup_key_market'])) {
    $key = checkJs($_POST['key'], null);
    if(empty($key)) {
      exit(json_encode(['status' => '2', 'message' => 'Введите ключ.']));
    }
    ignore_user_abort(1);
    set_time_limit(0);
    $wa = new market($pdo);
    if($_POST['is_template'] == '1') {
      $result = json_decode(gzdecode($wa->teps("&product=gamecms&resource={$_SERVER['SERVER_NAME']}&code={$_POST['key']}")),true);
      if($result['status'] == 2) { exit(json_encode(['status' => '2', 'message' => $result['message']])); }
      $link          = $result['file'];
      $arr           = explode("/", $link);
      $zip_file      = $arr[count($arr) - 1];
      $template_name = $result['name'];
      $path = $_SERVER['DOCUMENT_ROOT'] . '/templates/';
      mkdir($path, 0777);
      $update_file = $path.$zip_file;
      $cInit = curl_init($link);
      $fOpen = fopen($update_file, "wb");
      curl_setopt($cInit, CURLOPT_FILE, $fOpen);
      curl_setopt($cInit, CURLOPT_HEADER, 0);
      curl_exec($cInit);
      curl_close($cInit);
      fclose($fOpen);
      $archive = new PclZip($update_file);
      $result  = $archive->extract(PCLZIP_OPT_PATH, $path);
      unlink($update_file);
      exit(json_encode([
        'status' => '1',
        'message' => 'Шаблон "'.$template_name.'" успешно установлен!'
      ]));
    }
    $result = $wa->curl_get_process([
      'website' => "https://tpl-market.ru/api?type=downloads",
      'data' => "&product=gamecms&resource={$_SERVER['SERVER_NAME']}&code={$_POST['key']}"
    ]);
    $result = json_decode(gzdecode($result), true);
    if($result['status'] == 2) {
      exit(json_encode(['status' => '2', 'message' => $result['message']]));
    }
    $link        = $result['file'];
    $arr         = explode("/", $link);
    $zip_file    = $arr[count($arr) - 1];
    $module_name = $result['name'];
    $STH = $pdo->prepare("SELECT id FROM modules WHERE name=:name LIMIT 1");
    $STH->setFetchMode(PDO::FETCH_OBJ);
    $STH->execute([':name' => $module_name]);
    $row = $STH->fetch();
    if(isset($row->id)) {
      exit(json_encode(['status' => '2', 'message' => 'Данный модуль уже установлен']));
    }
    $path = $_SERVER['DOCUMENT_ROOT'] . '/modules_extra/';
    if(!file_exists($path)) {
      mkdir($path, 0777);
    }
    $update_file = $path.$zip_file;
    $cInit = curl_init($link);
    $fOpen = fopen($update_file, "wb");
    curl_setopt($cInit, CURLOPT_FILE, $fOpen);
    curl_setopt($cInit, CURLOPT_HEADER, 0);
    curl_exec($cInit);
    curl_close($cInit);
    fclose($fOpen);
    $archive = new PclZip($update_file);
    $result  = $archive->extract(PCLZIP_OPT_PATH, $path);
    unlink($update_file);
    $tpls_path  = $path . $module_name . "/settings/tpls.txt";
    $pages_path = $path . $module_name . "/settings/pages.txt";
    $base_path  = $path . $module_name . "/settings/base.sql";
    $info_path  = $path . $module_name . "/settings/info.txt";
    $files_path = $path . $module_name . "/settings/files.txt";
    if(file_exists($tpls_path)) {
      $tpls = file_get_contents(trim($tpls_path));
      unlink($tpls_path);
    } else {
      $tpls = 'none';
    }
    if(file_exists($pages_path)) {
      $pages = file_get_contents(trim($pages_path));
      eval('$pages = ' . $pages);
      unlink($pages_path);
    } else {
      $pages = 'none';
    }
    if(file_exists($base_path)) {
      $pdo->exec(trim(file_get_contents($base_path)));
      unlink($base_path);
    }
    if(file_exists($info_path)) {
      $info = file_get_contents(trim($info_path));
      unlink($info_path);
    }
    else {
      $info = "";
    }
    if(file_exists($files_path)) {
      $files = file_get_contents(trim($files_path));
      unlink($files_path);
    } else {
      $files = '';
    }
    $STH = $pdo->prepare(
      "INSERT INTO modules (name,tpls,info,files,client_key) values (:name, :tpls, :info, :files, :client_key)"
    );
    $STH->execute(
      [':name' => $module_name, ':tpls' => $tpls, ':info' => $info, ':files' => $files, ':client_key' => $key]
    );
    if(is_array($pages)) {
      $module_id = get_ai($pdo, "modules");
      $module_id--;
      for($i = 0; $i < count($pages); $i++) {
        $STH = $pdo->prepare(
          "INSERT INTO pages (file,url,name,title,description,keywords,kind,image,robots,privacy,type,active,module,page,class) values (:file, :url, :name, :title, :description, :keywords, :kind, :image, :robots, :privacy, :type, :active, :module, :page, :class)"
        );
        $STH->execute(
          [
            ':file'        => $pages[$i]['file'],
            ':url'         => $pages[$i]['url'],
            ':name'        => $pages[$i]['name'],
            ':title'       => $pages[$i]['title'],
            ':description' => $pages[$i]['description'],
            ':keywords'    => $pages[$i]['keywords'],
            ':kind'        => $pages[$i]['kind'],
            ':image'       => $pages[$i]['image'],
            ':robots'      => $pages[$i]['robots'],
            ':privacy'     => $pages[$i]['privacy'],
            ':type'        => $pages[$i]['type'],
            ':active'      => $pages[$i]['active'],
            ':module'      => $module_id,
            ':page'        => '0',
            ':class'       => '0'
          ]
        );
      }
    }
    exit(json_encode(['status' => '1', 'message' => 'Модуль "'.$module_name.'" - успешно установлен (обновите стр.)']));
}

this code checks if the domain exists in the database on the site where i get the key
here is the code from the site where i get the code
case "downloads": {
      switch($_POST['product']) {
        /* GameCMS */
        case "gamecms": {
          $q = $sql->query("SELECT * FROM `product__links` WHERE `code`='{$_POST['code']}'");
          $r = $sql->arr($q);
          
          if($r['timeleft'] + 600 < time()) {
            exit(gzencode(json_encode([
              'status' => '2',
              'message' => 'Срок действия ключа закончился!'
            ])));
          }
          
          $q2 = $sql->query("SELECT * FROM `store__product` WHERE `id`='{$r['product_id']}'");
          $r2 = $sql->arr($q2);
          
          if($r2['binding']) {
            $fqr = $sql->fqr("SELECT * FROM `product__binding` WHERE `id`='{$r['binding_id']}'");
            
            /* Привязка товара */
            
            if(empty($fqr['first_ip']) || $fqr['first_ip'] == 'none') {
              $sql->query("UPDATE `product__binding` SET `first_ip`='{$_SERVER['REMOTE_ADDR']}' WHERE `id`='{$r['binding_id']}'");
            }
            else if($_SERVER['REMOTE_ADDR'] != $fqr['first_ip']) {
              $bT = time() + 2678400;
              
              $sql->query("UPDATE `product__binding` SET `block_ip`='{$_SERVER['REMOTE_ADDR']}', `block_date`='{$bT}',`reason`='Передача ключа.' WHERE `id`='{$r['binding_id']}'");
              
              exit(gzencode(json_encode([
                'status' => '2',
                'message' => "Ваш ключ заблокирован!"
              ])));
            }
            
            if(time() < $fqr['block_date']) {
              exit(gzencode(json_encode([
                'status' => '2',
                'message' => ("Ваш ключ заблокирован! Ждите " . floor(($fqr['block_date'] - time()) / 60) . " мин.")
              ])));
            }
          }
          
          exit(gzencode(json_encode([
            'status' => '1',
            'name' => $r2['code_name'],
            'file' => "https://{$_SERVER['SERVER_NAME']}/{$r2['file']}"
          ])));
          
          break;
        }
        /* GameCMS */
      }
      
      exit("ok");
      
      break;
    }

here is the link to the api

$result = $wa->curl_get_process([
'website' => " https://tpl-market.ru/api?type=downloads ",
'data' => "&product=gamecms&resource={$_SERVER['SERVER_NAME' ]}&code={$_POST['key']}"
]);

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question