+  HandyCache форум
|-+  Главная категория» English forum» Filtering out subdomains from a host with Lua re.find
Имя пользователя:
Пароль:
Страниц: [1]   Вниз
  Отправить эту тему    Печать  
Автор Тема: Filtering out subdomains from a host with Lua re.find  (Прочитано 5486 раз)
0 Пользователей и 1 Гость смотрят эту тему.
www
Новичок
*

Репутация: +5/-0
Offline Offline

Сообщений: 39


« : 30 мая 2011, 09:18:58 »

I've made this code for transforming sub.example.org into example.org:

Код:
referer_host = re.find(referer_host,[[(.*\.)?(\w+\.\w+)]],2)

However, I haven't managed to find a way for it to transform sub.example.org.br => example.org.br without breaking it for regular org/com/net domains. Can you help me with this?

Edit: changed "URL" to "host" in the title. My variable already has only the host (example.com, sub.example.com, example.com.br etc.).
« Последнее редактирование: 30 мая 2011, 09:45:39 от www » Сообщить модератору   Записан
mirny
Пользователь
**

Репутация: +11/-1
Offline Offline

Сообщений: 84


« Ответ #1 : 30 мая 2011, 09:28:51 »

www,

Why do you want to use Lua doing this? Maybe just to add some simple rules to the "URL transforming" list would be enough?
Сообщить модератору   Записан
www
Новичок
*

Репутация: +5/-0
Offline Offline

Сообщений: 39


« Ответ #2 : 30 мая 2011, 09:37:00 »

I've created an extension that forges (modifies) referers to make external servers think that requests are coming from their own pages. This is the last thing that I need to fix to post it.
Сообщить модератору   Записан
mirny
Пользователь
**

Репутация: +11/-1
Offline Offline

Сообщений: 84


« Ответ #3 : 30 мая 2011, 10:22:34 »

Now I understand. This somesite.co.uk type of hosts complicates all the matter.
I've been in similar situation before when customizing the structure of the cache to my needs. Solved it by breaking the task into two stages. Here is what I did. Don't know if it helps.
Сообщить модератору   Записан
mai62
Автор HC
*****

Репутация: +226/-4
Offline Offline

Сообщений: 6383


« Ответ #4 : 30 мая 2011, 12:05:18 »

www
Код:
--[[ <HCExtension>
@name          Replace referer
@version       0.1
@description   Replace referer example
@event         RequestHeaderReceived/request
</HCExtension> ]]

function request()
  local x = re.replace(hc.request_header, "(?-s)(Referer:.*\r\n)", "Referer: ".."My referer".."\r\n")
  if x then
    hc.request_header= x
  end
  hc.put_to_log(hc.request_header)
end
Сообщить модератору   Записан
www
Новичок
*

Репутация: +5/-0
Offline Offline

Сообщений: 39


« Ответ #5 : 30 мая 2011, 23:35:00 »

mai62, my extension is a little different from that. It only changes the referer when the request comes from another host. I had your code already from last year's thread. I actually based my extension on it, so thank you again for pointing me in the right direction.

mirny, I've finally  found a way to do that. I didn't use your code, but it was helpful to exercise my brain a little. Показывает язык I used a negative look-ahead; here's the working code:

Код:
referer_host = re.find(referer_host,[[(.*\.(?!biz|co|com|info|name|net|org|pro|edu|gov|int|mil|mobi))?(\w+\.\w+)]],2)

I'll post the full extension on another thread later on.
Сообщить модератору   Записан
www
Новичок
*

Репутация: +5/-0
Offline Offline

Сообщений: 39


« Ответ #6 : 31 мая 2011, 06:33:27 »

Here's the extension.
Сообщить модератору   Записан
Страниц: [1]   Вверх
  Отправить эту тему    Печать  

 
Перейти в: