rejetto forum

USER AGENT (or the connected browser)

Mars · 16 · 3961

0 Members and 1 Guest are viewing this topic.

Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2039
    • View Profile
Here is thus a small proposition in my long existing list.

one new  variable and one new macro
%user-agent% amounts in macro {.header|user-agent}, but in shorter,
 
{ .get|know agents|separator.} if separator is not specified or empty, then a semicolon is used by default.

one usage is:
 hfs.events
[request]
{if not|{is substring|%user-agent%| list of browsers.} | {:{.disconnect.}:} .}


That allows among others to let no download manager connect in the server.

Every new type of connection is registered(recorded) in hfs.ini in the variable 'users-agents' and so available for a later usage with the macro {.get|know agents.}
users-agents=MSIE 6.0|Mozilla/5.0|GetRightPro/6.0

main.pas
Quote
....
type
  TmacroData = record
    cd: TconnData;
    tpl: Ttpl;
    folder, f: Tfile;
    afterTheList, archiveAvailable, hideExt: boolean;
    aliases: THashedStringList;
    end;

function getAgentID(conn:ThttpConn):string; overload; forward;     // add by mars

function cbMacros(fullMacro:string; pars:Tstrings; cbData:pointer):string;

........
   else if name = '%user%' then
      result:=macroQuote(usr)
    else if name = '%password%' then
      result:=macroQuote(md.cd.conn.request.pwd)
    else if name = '%user-agent%' then        // add by mars
      result:=macroQuote(getAgentID(md.cd.conn))       // add by mars

    else if name = '%loggedin%' then
      result:=if_(usr>'', tpl['loggedin'])
........
    if name = 'get' then
      if p = 'can recur' then trueIf(mainFrm.recursiveListingChk.Checked)
      else if p = 'known agents' then result:=join(or_(pars[1],';'),usersagents) // add by mars
      else if p = 'can upload' then trueIf(assigned(md.cd) and accountAllowed(FA_UPLOAD, md.cd.conn, md.folder))
      else if p = 'can delete' then trueIf(assigned(md.cd) and accountAllowed(FA_DELETE, md.cd.conn, md.folder))
      else if p = 'can archive' then canArchive(md.folder)
.......
  // all URIs must begin with /
  if (url = '') or (url[1] <> '/') then
    begin
    conn.reply.mode:=HRM_BAD_REQUEST;
    exit;
    end;
  addUniqueString(getAgentID(conn),usersAgents); // add by mars
  runEventScript('request');
.......
+'enable-no-default='+yesno[enableNoDefaultChk.checked]+CRLF
+'browse-localhost='+yesno[browseUsingLocalhostChk.checked]+CRLF
+'users-agents='+join('|',usersAgents)+CRLF          // add by mars
+'add-folder-default='+addFolderDefault+CRLF
+'default-sorting='+defSorting+CRLF
.......
    if h = 'enable-no-default' then enableNoDefaultChk.checked:=yes;
    if h = 'browse-localhost' then browseUsingLocalhostChk.checked:=yes;
    if h = 'users-agents' then usersAgents:=split('|',l);     // add by mars
    if h = 'tpl-file' then tplFilename:=l;
    if h = 'tpl-editor' then tplEditor:=l;
......


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13308
    • View Profile
1. this script, in a clean configuration, would have an empty "usersagents", right?
then, it would disconnect everybody.

2. every download manager has an option to fake the user-agent, so this is not a very effective method.
« Last Edit: April 12, 2009, 11:47:30 PM by rejetto »


Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2039
    • View Profile
Quote
2. every download manager has an option to fake the user-agent, so this is not a very effective method.

it was only one example of use, i assume that it is not a good example ;)


but if a download manager mask his type %user-agent% can be empty and then we can use this posibility

[request]
{if not|%user-agent%|{:{.disconnect.}:} .}


 ;D
« Last Edit: April 13, 2009, 12:40:56 AM by mars »


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13308
    • View Profile

Offline bacter

  • Operator
  • Tireless poster
  • *****
    • Posts: 681
    • View Profile
When writing my macro to identify the used browsers, I saved the user agents in a file (append) and loaded it to compare with new conections. In only a short test period I got more than 40 different user agents. So, as some people even 'personalisize' their user agents, the list can become very big. (take a look sometimes at http://whatsmyuseragent.com/.)

Also if memory is not a problem in today's computers, I think that there are only few users (or templates) that require such extensive use of the user-agent that a variable %user-agent% should be needed, having already the macro.



your computer has no brain - use your own !


Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2039
    • View Profile
I completely agree that certain macro or combinations of macros allow to make most of the wished features

1) {.header|user-agent.} take a lot of time
2) extract the desired information 'user-agent-id' take another lot of time {.substring| source |mask.} or something as it
3) load the file {.load|user-agen.txt.}   
4) find the 'user-agent-id'  {.is substing|....... .}
5) if false then add  'user-agent-id' to  'user-agent.txt'
6) another action

1+2+3+4+5+6, It really sets a lot of time in term of resources for hfs by comparison with the following action

1+2)
if name = '%user-agent%' then        //
      result:=macroQuote(getAgentID(md.cd.conn))   // define the var %user-agent%

3+4+5)
addUniqueString(getAgentID(conn),usersAgents);   // add the current agent to the list

6) use %user-agent% and {get|know agents|separator.} or {.from table|ini|usersagents.} to do the rest

When they are small actions, I am to use the macro existing, but when to acquire a simple information requires an army of resources system and of time(weather), then I try to propose something more economic for a m├žeme result. What prevents not at all, to whom wishes it, to use only macro for the same job.

by example it is possible with macros to emulate the var %item-url%, when you have only some files, it is not too binding,  but with some tens it becomes long to wait for the final result.

 ;)



Offline bacter

  • Operator
  • Tireless poster
  • *****
    • Posts: 681
    • View Profile
You are right mars  :) !

The steps you mentionned are needed to get the user-agent. But as for my needs I need the user-agent only when a new connection (new IP) connects, the overhead of needed resources is very,very small.

I need the user-agent only to get browser and version (and sometimes language if there is no accept-language string in the header). I need this information only once when a new IP connects, then i set the needed flags in a cookie.

From then on, I use the other time consuming {.header|cookie.} macro.  :D
your computer has no brain - use your own !


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13308
    • View Profile
it's ok for me to eventually expose that agent thing, although i would use {.get|agent.} (symbols should avoided where not strictly appropriated).

anyway, i didn't understand what you and bacter are trying to achieve :-\


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13308
    • View Profile

Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2039
    • View Profile
(take a look sometimes at http://whatsmyuseragent.com/.)

Of course

Quote
Most Recent User Agents Visiting this Page:
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .N
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .N
BACTER IS COMMING HERE
Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.0.8) Gecko/2009032608
Mozilla/4.0 (compatible; MSIE 6.0; Windows 98; .NET CLR 1.1.4322)
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .N
TRALALA POUET POUET
HTC-P3700-orange/PPC; 480x640; OpVer 30.137.2.732 Opera/9.50 (Windows NT 5.1; U; fr)
Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.0.8) Gecko/2009032609 Firefox/3.0.8

 ;D


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13308
    • View Profile

Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2039
    • View Profile
i take getright to fake the referer and download the linkth e result is the messages  green and red


Offline bacter

  • Operator
  • Tireless poster
  • *****
    • Posts: 681
    • View Profile
rejetto, i use the header and cookie in the following form :

Code: [Select]
[special:begin]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
...... some macro definitions (newline, debugstrings..).....

{.load|mod_getaccmode.tpl.}  {.comment| accmode: 0-internet,1-wlan,2-lan,3-localhost.}
{.load|mod_newlogin.tpl.}    {.comment| sets newconect and newlogin when this event happens.}
{.load|mod_definelang.tpl.}  {.comment| gets lang from cookie or form header.}
{.if |{.is substring|browser:|{.^cookie.}.}|
{:{.set|browsername|{.cut|9||{.substring|browser:|,|{.^cookie.}.}.}.}
{.set|brvers|{.cut|2||{.substring|,||{.substring|browser:{.^browsername.},|;|{.^cookie.}.}.}.}.}:}
|{:{.load|mod_browserdetect.tpl.}:}
.}
{.load|btslang_{.^userlang.}.tpl|special:strings.}
{.load|mod_assignsite.tpl.}   {.comment| sets site depending of url -> multisite.}
{.load|bac_head_{.^site.}.tpl.}

the modules definelang and browserdetect can set a flag 'cookierewrite'=1 when detection from header is done.

In the header of the site (bac_head),just before the <meta>, i write or rewrite the cookie if the rewriteflag is set.

Code: [Select]
{.if|{.^rewritecookie.}|
{:<meta http-equiv="Set-Cookie" content="bacter=lang:{.^userlang.},color:blue,browser:{.^browsername.},{.^brvers.};expires=viernes, 18 de febrero de 2011 21:29:33" />:}.}
<META name=description content="hfs - http fileserver" />
your computer has no brain - use your own !


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13308
    • View Profile
i have good news for you.
next build will introduce {.cookie.}


Offline bacter

  • Operator
  • Tireless poster
  • *****
    • Posts: 681
    • View Profile
thank you rejetto for the {.cookie.} , and more thanks even for the global variable thing!

With global variables I will need less {.load| file.} and less cookie.

question: cookie will be a macro-var:
  {.cookie.} == {.set|cookie|{.header|Cookie.}.}
or can it be %cookie% ?
your computer has no brain - use your own !