-
Notifications
You must be signed in to change notification settings - Fork 0
/
adres.js
158 lines (132 loc) · 6.01 KB
/
adres.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
const express = require('express');
const mysql = require('mysql2/promise');
const axios = require('axios');
const { Builder, By, until } = require('selenium-webdriver');
const chrome = require('selenium-webdriver/chrome');
const app = express();
const PORT = 1943;
// CapMonster API ve site bilgileri
const CAPMONSTER_API_KEY = 'CAPMONSTER_API_KEY';
const SITE_KEY = 'CAPMONSTER_SITE_KEY';
const PAGE_URL = 'https://adusem.adu.edu.tr/?p=egitim-portal';
// Rastgele telefon numarası üretme fonksiyonu
const generateRandomPhoneNumber = () => {
const operatorCodes = ['50', '51', '52', '53', '54', '55', '56', '57', '58'];
const randomOperatorCode = operatorCodes[Math.floor(Math.random() * operatorCodes.length)];
const randomNumber = Math.floor(1000000 + Math.random() * 9000000);
return `5${randomOperatorCode} ${String(randomNumber).slice(0, 3)} ${String(randomNumber).slice(3, 5)} ${String(randomNumber).slice(5)}`;
};
// Doğum tarihi formatlama fonksiyonu
const formatDateForAPI = (dogumtarihi) => {
const [day, month, year] = dogumtarihi.split('.');
return `${day.padStart(2, '0')}/${month.padStart(2, '0')}/${year}`;
};
// Veritabanından kullanıcı doğum tarihini alma fonksiyonu
const getUserInfoFromDB = async (tc) => {
const connection = await mysql.createConnection({
host: 'localhost',
user: 'root',
password: '',
database: '101m'
});
const [rows] = await connection.execute('SELECT DOGUMTARIHI FROM 101m WHERE TC = ?', [tc]);
await connection.end();
return rows[0] ? rows[0].DOGUMTARIHI : null;
};
// CAPTCHA çözümü için CapMonster API kullanma fonksiyonu
const solveCaptcha = async () => {
const response = await axios.post('https://api.capmonster.cloud/createTask', {
clientKey: CAPMONSTER_API_KEY,
task: {
type: 'RecaptchaV2Task',
websiteURL: PAGE_URL,
websiteKey: SITE_KEY
}
});
const taskId = response.data.taskId;
if (!taskId) {
throw new Error('CAPTCHA çözüm talebi başarısız: ' + response.data.error || 'Bilinmeyen hata');
}
// CAPTCHA çözümünün tamamlanmasını bekleme döngüsü
while (true) {
await new Promise(resolve => setTimeout(resolve, 1500)); // 1.5 saniye bekleme süresi
const resultResponse = await axios.post('https://api.capmonster.cloud/getTaskResult', {
clientKey: CAPMONSTER_API_KEY,
taskId: taskId
});
const result = resultResponse.data;
if (result.status === 'ready') {
return result.solution.gRecaptchaResponse;
}
if (result.errorId) {
throw new Error('CAPTCHA çözüm alma hatası: ' + result.errorId);
}
}
};
// Kullanıcı bilgilerini formdan alma fonksiyonu
const getUserInfo = async (driver) => {
const userInfo = {};
userInfo.TCKN = await driver.findElement(By.xpath("//label[contains(text(), 'T.C. Kimlik No')]/following-sibling::div")).getText();
userInfo.ADSOYAD = await driver.findElement(By.xpath("//label[contains(text(), 'Ad Soyad')]/following-sibling::div")).getText();
userInfo.DOGUMTARİHİ = await driver.findElement(By.xpath("//label[contains(text(), 'Doğum Tarihi')]/following-sibling::div")).getText();
userInfo.CİNSİYET = await driver.findElement(By.xpath("//label[contains(text(), 'Cinsiyet')]/following-sibling::div")).getText();
userInfo.ADRES = await driver.findElement(By.xpath("//label[contains(text(), 'Adresi')]/following-sibling::div")).getText();
return userInfo;
};
// TC işlemi süreci
const processTC = async (tc) => {
const startTime = Date.now();
const dogumtarihi = await getUserInfoFromDB(tc);
if (!dogumtarihi) {
return { status: 'error', message: 'Kullanıcı bulunamadı.' };
}
const formattedDate = formatDateForAPI(dogumtarihi);
if (!formattedDate) {
return { status: 'error', message: 'Doğum tarihi formatı geçersiz.' };
}
const cepTel = generateRandomPhoneNumber();
const chromeOptions = new chrome.Options();
chromeOptions.addArguments("--headless", "--disable-gpu", "--no-sandbox");
chromeOptions.addArguments("--disable-dev-shm-usage");
const driver = await new Builder().forBrowser('chrome').setChromeOptions(chromeOptions).build();
try {
await driver.get(PAGE_URL);
await driver.findElement(By.name('tckimlikno')).sendKeys(tc);
await driver.findElement(By.name('dogumtarihi')).sendKeys(formattedDate);
await driver.findElement(By.name('ceptel')).sendKeys(cepTel.replace(' ', ''));
const kvkkCheckbox = await driver.findElement(By.name('kvkk'));
if (!(await kvkkCheckbox.isSelected())) {
await kvkkCheckbox.click();
}
const captchaSolution = await solveCaptcha();
await driver.executeScript("document.getElementsByName('g-recaptcha-response')[0].value = arguments[0];", captchaSolution);
await driver.findElement(By.css('button[type="submit"]')).click();
// Bekleme fonksiyonu
await driver.wait(until.elementLocated(By.xpath("//label[contains(text(), 'T.C. Kimlik No')]")), 10000);
const userInfo = await getUserInfo(driver);
const elapsedTime = Date.now() - startTime;
return {
status: 'success',
response_time_ms: elapsedTime,
data: userInfo
};
} catch (error) {
return { status: 'error', message: error.message };
} finally {
await driver.quit();
}
};
// API için adres route'u
app.get('/adres', async (req, res) => {
const tc = req.query.tc;
if (tc) {
const response = await processTC(tc);
res.json(response);
} else {
res.json({ status: 'error', message: 'TC kimlik numarası verilmedi.' });
}
});
// Sunucuyu başlat
app.listen(PORT, () => {
console.log(`Server running on http://localhost:${PORT}`);
});