thảo luận Hướng dẫn dùng Cloudflare Zero Trust

báo lỗi rồi fen ơi huhu, có phải sửa tên cái file workflow này thành update... gì ko fen? hay cứ để main?

Code:
Run npm run cloudflare-delete

> cloudflare-delete
> npm run cloudflare-delete:rule && npm run cloudflare-delete:list


> cloudflare-delete:rule
> node cf_gateway_rule_delete.js

No rule(s) with matching name found - this is not an issue if you haven't run the create script yet. Exiting.

> cloudflare-delete:list
> node cf_list_delete.js

Got 214 lists, 214 of which are CGPS lists that will be deleted.
Deleting 214 lists...
Error occurred while deleting lists - SyntaxError: Unexpected token '<', "<!DOCTYPE "... is not valid JSON
undefined:1
<!DOCTYPE html>
^

SyntaxError: Unexpected token '<', "<!DOCTYPE "... is not valid JSON
    at JSON.parse (<anonymous>)
    at parseJSONFromBytes (node:internal/deps/undici/undici:4306:19)
    at successSteps (node:internal/deps/undici/undici:4288:27)
    at fullyReadBody (node:internal/deps/undici/undici:2724:9)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async consumeBody (node:internal/deps/undici/undici:4297:7)
    at async request (file:///home/runner/work/cloudflare-gateway-pihole-scripts/cloudflare-gateway-pihole-scripts/lib/helpers.js:107:16)
    at async Promise.all (index 26)
    at async deleteZeroTrustListsAtOnce (file:///home/runner/work/cloudflare-gateway-pihole-scripts/cloudflare-gateway-pihole-scripts/lib/api.js:136:5)
    at async file:///home/runner/work/cloudflare-gateway-pihole-scripts/cloudflare-gateway-pihole-scripts/cf_list_delete.js:35:5

Node.js v20.14.0
Error: Process completed with exit code 1.
Cloudflare đang bị lỗi giới hạn tốc độ. Bạn xem vài post trước, sếp có hướng dẫn cách cho nghỉ vài giây khi xóa/tạo list.
Đây là cách tạm thời, thời gian chạy tăng đáng kể khi list của bạn lớn
 
Cloudflare đang bị lỗi giới hạn tốc độ. Bạn xem vài post trước, sếp có hướng dẫn cách cho nghỉ vài giây khi xóa/tạo list.
Đây là cách tạm thời, thời gian chạy tăng đáng kể khi list của bạn lớn
Chạy 1 commit mà nó cứ hiện 2 action cái được cái ko là sao v fen? Mình làm theo hd 2s bạn nói.
 
Update thêm một cách khác để chữa cháy, đó là liên tục request nhét vào mồm thằng cf nếu nó lỗi, chừng nào chạy đc thì thôi. Ưu điểm là mốt cf nó sửa lại hết giới hạn thì lại tự chạy nhanh lại, và tiết kiệm thời gian chạy xuống một chút hagezi normal khoảng tầm 8p.
:shame:
Ai đã làm như quote trên rồi hoặc đã sync fork bản mới nhất của repo gốc thì vào đây
Copy paste vào file lib/api.js

Sau đó copy paste đè toàn bộ nội dung file lib/helpers.js rồi bấm commit
Code:
import {
  ACCOUNT_EMAIL,
  ACCOUNT_ID,
  API_HOST,
  API_KEY,
  API_TOKEN,
} from "./constants.js";

if (!globalThis.fetch) {
  console.warn(
    "\nIMPORTANT: Your Node.js version doesn't have native fetch support and may not be supported in the future. Please update to v18 or later.\n"
  );
  // Advise what to do if running in GitHub Actions
  if (process.env.GITHUB_WORKSPACE)
    console.warn(
      "Since you're running in GitHub Actions, you should update your Actions workflow configuration to use Node v18 or higher."
    );
  // Import node-fetch since there's no native fetch in this environment
  globalThis.fetch = (await import("node-fetch")).default;
}

/**
 * Sends a message to a Discord-compatible webhook.
 * @param {url|string} url The webhook URL.
 * @param {string} message The message to be sent.
 * @returns {Promise}
 */
async function sendMessageToWebhook(url, message) {
  // Create the payload object with the message
  // The message is provided as 2 different properties to improve compatibility with webhook servers outside Discord
  const payload = { content: message, body: message };

  // Send a POST request to the webhook url with the payload as JSON
  try {
    const response = await fetch(url, {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify(payload),
    });

    // Check if the request was successful
    if (!response.ok) {
      throw new Error(`HTTP error! Status: ${response.status}`);
    } else {
      return true;
    }
  } catch (error) {
    console.error('Error sending message to webhook:', error);
    return false;
  }
}

/**
 * Sends a CGPS notification to a Discord-compatible webhook.
 * Automatically checks if the webhook URL exists.
 * @param {string} msg The message to be sent.
 * @returns {Promise}
 */
export async function notifyWebhook(msg) {
  // Check if the webhook URL exists
  const webhook_url = process.env.DISCORD_WEBHOOK_URL;

  if (webhook_url && webhook_url.startsWith('http')) {
    // Send the message to the webhook
    try {
      await sendMessageToWebhook(webhook_url, `CGPS: ${msg}`);
    } catch (e) {
      console.error('Error sending message to Discord webhook:', e);
    }
  }
  // Not logging the lack of a webhook URL since it's not a feature everyone would use
}

/**
 * Fires request to the specified URL.
 * @param {string} url The URL to which the request will be fired.
 * @param {RequestInit} options The options to be passed to `fetch`.
 * @returns {Promise}
 */
const request = async (url, options) => {
  if (!(API_TOKEN || API_KEY) || !ACCOUNT_ID) {
    throw new Error(
      "The following secrets are required: CLOUDFLARE_API_TOKEN, CLOUDFLARE_ACCOUNT_ID"
    );
  }

  const headers = API_TOKEN
    ? {
        Authorization: `Bearer ${API_TOKEN}`,
        "Content-Type": "application/json",
      }
    : {
        Authorization: `Bearer ${API_KEY}`,
        "Content-Type": "application/json",
        "X-Auth-Email": ACCOUNT_EMAIL,
        "X-Auth-Key": API_KEY,
      };

  const wait = (ms) => new Promise(resolve => setTimeout(resolve, ms));

  let response;
  let data;
  let attempts = 0;

  while(attempts < 50) {
    try {
      response = await fetch(url, {
        ...options,
        headers: {
          ...options.headers,
          ...headers,
        },
      });

      data = await response.json();

      if (!response.ok) {
        throw new Error('Response not OK');
      }
      return data;
    } catch (error) {
      attempts++;
      if(attempts >= 50) {
        // Send a message to the Discord webhook if it exists
        await notifyWebhook(`An HTTP error has occurred (${response.status}) while making a web request. Please check the logs for further details.`);
        throw new Error(`HTTP error! Status: ${response.status} - ${ 'errors' in data ? data.errors[0].message : JSON.stringify(data) }`);
      }
      await wait(5000);
    }
  }
};

/**
 * Fires request to the Zero Trust gateway.
 * @param {string} path The path which will be appended to the request URL.
 * @param {RequestInit} options The options to be passed to `fetch`.
 * @returns {Promise}
 */
export const requestGateway = (path, options) =>
  request(`${API_HOST}/accounts/${ACCOUNT_ID}/gateway${path}`, options);

/**
 * Normalizes a domain.
 * @param {string} value The value to be normalized.
 * @param {boolean} isAllowlisting Whether the value is to be allowlisted.
 * @returns {string}
 */
export const normalizeDomain = (value, isAllowlisting) => {
  const normalized = value
    .replace(/(0\.0\.0\.0|127\.0\.0\.1|::1|::)\s+/, "")
    .replace("||", "")
    .replace("^$important", "")
    .replace("*.", "")
    .replace("^", "");

  if (isAllowlisting) return normalized.replace("@@||", "");

  return normalized;
};
Sau đó nhớ sửa file .yml workflow mục checkout giống y như vậy
View attachment 2534110
mình update helper là bị lỗi luôn chủ tịch ơi
Code:
Number of processed domains: 686408
Number of duplicate domains: 346842
Number of unnecessary domains: 113317
Number of allowed domains: 768
Number of blocked domains: 225481
Number of lists to be created: 226



Creating 226 lists for 225481 domains...
Error occurred while creating lists - TypeError: Cannot use 'in' operator to search for 'errors' in undefined
file:///home/runner/work/cloudflare-gateway-pihole-scripts/cloudflare-gateway-pihole-scripts/lib/helpers.js:126
        throw new Error(`HTTP error! Status: ${response.status} - ${ 'errors' in data ? data.errors[0].message : JSON.stringify(data) }`);
                                                                              ^

TypeError: Cannot use 'in' operator to search for 'errors' in undefined
    at request (file:///home/runner/work/cloudflare-gateway-pihole-scripts/cloudflare-gateway-pihole-scripts/lib/helpers.js:126:79)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Promise.all (index 108)
    at async createZeroTrustListsAtOnce (file:///home/runner/work/cloudflare-gateway-pihole-scripts/cloudflare-gateway-pihole-scripts/lib/api.js:77:5)
    at async file:///home/runner/work/cloudflare-gateway-pihole-scripts/cloudflare-gateway-pihole-scripts/cf_list_create.js:139:5

Node.js v20.14.0
Error: Process completed with exit code 1.
 
Là cái domain để tạo DoT ấy chủ tịch, domain trỏ qua cf thì ko chạy còn ddns thì ngon :v.View attachment 2537153
bên cf chọn kiểu dns only chưa
PzuvODo.png

mình update helper là bị lỗi luôn chủ tịch ơi
Code:
Number of processed domains: 686408
Number of duplicate domains: 346842
Number of unnecessary domains: 113317
Number of allowed domains: 768
Number of blocked domains: 225481
Number of lists to be created: 226



Creating 226 lists for 225481 domains...
Error occurred while creating lists - TypeError: Cannot use 'in' operator to search for 'errors' in undefined
file:///home/runner/work/cloudflare-gateway-pihole-scripts/cloudflare-gateway-pihole-scripts/lib/helpers.js:126
        throw new Error(`HTTP error! Status: ${response.status} - ${ 'errors' in data ? data.errors[0].message : JSON.stringify(data) }`);
                                                                              ^

TypeError: Cannot use 'in' operator to search for 'errors' in undefined
    at request (file:///home/runner/work/cloudflare-gateway-pihole-scripts/cloudflare-gateway-pihole-scripts/lib/helpers.js:126:79)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Promise.all (index 108)
    at async createZeroTrustListsAtOnce (file:///home/runner/work/cloudflare-gateway-pihole-scripts/cloudflare-gateway-pihole-scripts/lib/api.js:77:5)
    at async file:///home/runner/work/cloudflare-gateway-pihole-scripts/cloudflare-gateway-pihole-scripts/cf_list_create.js:139:5

Node.js v20.14.0
Error: Process completed with exit code 1.
link repo t xem thử xem
 
bên cf chọn kiểu dns only chưa
PzuvODo.png


link repo t xem thử xem
check hộ mình nhé :* iu chủ tịt
 
check hộ mình nhé :* iu chủ tịt
2 lần chạy fail nó đều chạy cái xóa list, lần đầu xóa rồi, mà lần sau lại xóa tiếp, chứng tỏ mấy cái list của fen có vấn đề... fen dùng repo của người khác giờ nó gây lỗi script này nên t cũng bó tay, vào trang quản lí của cf, xem coi có list gì không, tự xóa bằng tay hết đống này đi, rồi chạy lại.
hPzVIXE.png

và vào đây xóa luôn mấy cái rule cho sạch 100%
I9ZIJFv.png
 
2 lần chạy fail nó đều chạy cái xóa list, lần đầu xóa rồi, mà lần sau lại xóa tiếp, chứng tỏ mấy cái list của fen có vấn đề... fen dùng repo của người khác giờ nó gây lỗi script này nên t cũng bó tay, vào trang quản lí của cf, xem coi có list gì không, tự xóa bằng tay hết đống này đi, rồi chạy lại.
hPzVIXE.png
hả @@ mình xài repo folk từ #1 như fen chỉ mà, có xài repo nào khác đâu :ah:
Edit1: mình check list của mình trắng bóc, ko có list nào luôn.
 
Last edited:
hả @@ mình xài repo folk từ #1 như fen chỉ mà, có xài repo nào khác đâu :ah:
thế chịu, t có làm sẵn cái t đang dùng đây, fen fork lại
rồi thêm variable, là chạy thôi
 
thế chịu, t có làm sẵn cái t đang dùng đây, fen fork lại
rồi thêm variable, là chạy thôi
mình xóa hết đi folk lại repo của fen chạy vẫn lỗi huhu
Code:
Run npm run cloudflare-create

> cloudflare-create
> npm run cloudflare-create:list && npm run cloudflare-create:rule


> cloudflare-create:list
> node cf_list_create.js

Processing allowlist.txt
Processing blocklist.txt



Number of processed domains: 687960
Number of duplicate domains: 347126
Number of unnecessary domains: 113312
Number of allowed domains: 768
Number of blocked domains: 226754
Number of lists to be created: 227



Creating 227 lists for 226754 domains...
Error occurred while creating lists - TypeError: Cannot use 'in' operator to search for 'errors' in undefined
file:///home/runner/work/cloudflare-gateway-pihole-scripts/cloudflare-gateway-pihole-scripts/lib/helpers.js:129
        throw new Error(`HTTP error! Status: ${response.status} - ${ 'errors' in data ? data.errors[0].message : JSON.stringify(data) }`);
                                                                              ^

TypeError: Cannot use 'in' operator to search for 'errors' in undefined
    at request (file:///home/runner/work/cloudflare-gateway-pihole-scripts/cloudflare-gateway-pihole-scripts/lib/helpers.js:129:79)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Promise.all (index 106)
    at async createZeroTrustListsAtOnce (file:///home/runner/work/cloudflare-gateway-pihole-scripts/cloudflare-gateway-pihole-scripts/lib/api.js:77:5)
    at async file:///home/runner/work/cloudflare-gateway-pihole-scripts/cloudflare-gateway-pihole-scripts/cf_list_create.js:139:5

Node.js v20.14.0
Error: Process completed with exit code 1.
 
Nextdns mua chung được ko ta thấy nhiều người mua rồi share có giới hạn sẽ ko bị BAN account
Mua dùng chung là cách xài rẻ nextdns giờ rồi. Mà nên kiểm soát số lượng thành viên acc. Dựa theo acc bussiness thì 450k/tháng cho block 50 nhân viên, vậy chia sẻ nhau gói Pro khoảng 35-40 người, mỗi người từ 2-3 thiết bị (2 điện thoại + 1 laptop) thì sẽ k bị ban.
 
Nextdns mua chung được ko ta thấy nhiều người mua rồi share có giới hạn sẽ ko bị BAN account
Cái này ko rõ. Năm ngoài mình mua có gần 100k thì phải share cho 5 người dùng rất ổn. Nhưng năm nay lên hơn 400 rồi. Tìm giải pháp miễn phí thôi
 
Chạy 1 commit mà nó cứ hiện 2 action cái được cái ko là sao v fen? Mình làm theo hd 2s bạn nói.
2 action là cái gì với cái gì fen? Mình dùng list nhỏ, vẫn code trước đó không cần cho nghỉ, bị lỗi thì chạy lại 2-3 lần là được. Có vẻ dưới 1 phút thì không sao
các fen cho mình hỏi như cái CF này đang lỗi thì những cái khác như rethink với vercel ko ảnh hưởng gì đúng hem 😁
Rethink không ảnh hưởng vì dùng Workers
Vercel ảnh hưởng do sử dụng nguồn là DoH của Zero Trust
 
2 action là cái gì với cái gì fen? Mình dùng list nhỏ, vẫn code trước đó không cần cho nghỉ, bị lỗi thì chạy lại 2-3 lần là được. Có vẻ dưới 1 phút thì không sao

Rethink không ảnh hưởng vì dùng Workers
Vercel ảnh hưởng do sử dụng nguồn là DoH của Zero Trust
Tình hình là ngồi làm cả buổi hôm nay vẫn chưa chạy đc, xoá đi folk lại repo của chủ tịch vẫn lỗi 🥲
 
mình xóa hết đi folk lại repo của fen chạy vẫn lỗi huhu
Code:
Run npm run cloudflare-create

> cloudflare-create
> npm run cloudflare-create:list && npm run cloudflare-create:rule


> cloudflare-create:list
> node cf_list_create.js

Processing allowlist.txt
Processing blocklist.txt



Number of processed domains: 687960
Number of duplicate domains: 347126
Number of unnecessary domains: 113312
Number of allowed domains: 768
Number of blocked domains: 226754
Number of lists to be created: 227



Creating 227 lists for 226754 domains...
Error occurred while creating lists - TypeError: Cannot use 'in' operator to search for 'errors' in undefined
file:///home/runner/work/cloudflare-gateway-pihole-scripts/cloudflare-gateway-pihole-scripts/lib/helpers.js:129
        throw new Error(`HTTP error! Status: ${response.status} - ${ 'errors' in data ? data.errors[0].message : JSON.stringify(data) }`);
                                                                              ^

TypeError: Cannot use 'in' operator to search for 'errors' in undefined
    at request (file:///home/runner/work/cloudflare-gateway-pihole-scripts/cloudflare-gateway-pihole-scripts/lib/helpers.js:129:79)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Promise.all (index 106)
    at async createZeroTrustListsAtOnce (file:///home/runner/work/cloudflare-gateway-pihole-scripts/cloudflare-gateway-pihole-scripts/lib/api.js:77:5)
    at async file:///home/runner/work/cloudflare-gateway-pihole-scripts/cloudflare-gateway-pihole-scripts/cf_list_create.js:139:5

Node.js v20.14.0
Error: Process completed with exit code 1.
xem cái cái token tạo cấp đủ quyền chưa, như hình
KusAmcR.png
 
Back
Top