{"action":"created","issue":{"url":"https://api.github.com/repos/BOINC/boinc/issues/665","labels_url":"https://api.github.com/repos/BOINC/boinc/issues/665/labels{/name}","comments_url":"https://api.github.com/repos/BOINC/boinc/issues/665/comments","events_url":"https://api.github.com/repos/BOINC/boinc/issues/665/events","html_url":"https://github.com/BOINC/boinc/issues/665","id":56195035,"number":665,"title":"Prevent Scraping of userw.php","user":{"login":"romw","id":985772,"avatar_url":"https://avatars.githubusercontent.com/u/985772?v=3","gravatar_id":"","url":"https://api.github.com/users/romw","html_url":"https://github.com/romw","followers_url":"https://api.github.com/users/romw/followers","following_url":"https://api.github.com/users/romw/following{/other_user}","gists_url":"https://api.github.com/users/romw/gists{/gist_id}","starred_url":"https://api.github.com/users/romw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/romw/subscriptions","organizations_url":"https://api.github.com/users/romw/orgs","repos_url":"https://api.github.com/users/romw/repos","events_url":"https://api.github.com/users/romw/events{/privacy}","received_events_url":"https://api.github.com/users/romw/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":{"login":"romw","id":985772,"avatar_url":"https://avatars.githubusercontent.com/u/985772?v=3","gravatar_id":"","url":"https://api.github.com/users/romw","html_url":"https://github.com/romw","followers_url":"https://api.github.com/users/romw/followers","following_url":"https://api.github.com/users/romw/following{/other_user}","gists_url":"https://api.github.com/users/romw/gists{/gist_id}","starred_url":"https://api.github.com/users/romw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/romw/subscriptions","organizations_url":"https://api.github.com/users/romw/orgs","repos_url":"https://api.github.com/users/romw/repos","events_url":"https://api.github.com/users/romw/events{/privacy}","received_events_url":"https://api.github.com/users/romw/received_events","type":"User","site_admin":false},"milestone":null,"comments":1,"created_at":"2015-02-02T04:31:41Z","updated_at":"2015-02-02T16:55:14Z","closed_at":"2015-02-02T04:31:51Z","body":"**Reported by bryanRS on 28 Feb 37450671 19:06 UTC**\nUpdate userw.php and includes to cache the userw.php file (WAP stats), to prevent \"scraping\" (remote data pull) to stats/team sites.  Recommend this patch to prevent excessive database queries running these signature graphics, as sometimes there are 5-10 requests per second for the same userid.\r\n\r\nNew userw.php:\r\n\r\n```\r\n<?php\r\n    require_once(\"../inc/cache.inc\"); \r\n    require_once(\"../inc/util.inc\");\r\n    require_once(\"../inc/userw.inc\");\r\n    require_once(\"../inc/db.inc\");\r\n    require_once(\"../inc/wap.inc\");\r\n\r\n$userid = get_int('id');\r\n \r\n\r\n$cacheddata=get_cached_data(WAP_STAT_TTL,$userid);\r\n    if ($cacheddata){ //If we have got the data in cache\r\n        $wapstr = $cacheddata; // use the cached data\r\n    }\r\nelse { //if not do queries etc to generate new data\r\n    db_init();\r\n    $user = lookup_user_id($userid);\r\n    if (!$user) {\r\n        sleep(5);\r\n        error_page(\"No such user\");\r\n    }\r\n        $wapstr = show_user_wap($user);\r\n        set_cache_data($wapstr,$userid); //save data in cache\r\n}\r\n\r\nwap_begin();\r\necho $wapstr;\r\nwap_end(); \r\n\r\n?>\r\n```\r\n\r\nNew userw.inc\r\n\r\n```\r\n<?php\r\n\r\nfunction show_credit($user) {\r\n    $retstr = \"<br/>User TotCred: \" . format_credit($user->total_credit) . \"<br/>\";\r\n    $retstr .= \"User AvgCred: \" . format_credit($user->expavg_credit) . \"<br/>\";\r\n    /*\r\n    if ($user->seti_nresults) {\r\n        row2(\"SETI@home classic workunits\", number_format($user->seti_nresults));\r\n    }\r\n    if ($user->seti_total_cpu) {\r\n        $x = number_format($user->seti_total_cpu/3600).\" hours\";\r\n        row2(\"SETI@home classic CPU time\", $x);\r\n    }\r\n    */\r\n    return $retstr;\r\n}\r\n\r\nfunction show_user_wap($user)\r\n{\r\n\r\n//   wap_begin();\r\n \r\n   if (!$user) {\r\n      echo \"<br/>User not found!<br/>\";\r\n  //    wap_end();\r\n      return;\r\n   }\r\n\r\n    // keep a 'running tab' in wapstr in case exceeds 1K WAP limit\r\n\r\n    $wapstr = PROJECT . \"<br/>Account Data<br/>for $user->name<br/>Time: \" . wap_timestamp();\r\n \r\n    $wapstr .= show_credit($user);\r\n\r\n    if ($user->teamid) {\r\n        $result = mysql_query(\"select name, total_credit, expavg_credit from team where id = $user->teamid\");\r\n        $team = mysql_fetch_object($result);\r\n\r\n        $wapstr .= \"<br/>Team: $team->name<br/>\";\r\n        $wapstr .= \"Team TotCred: \" . format_credit($team->total_credit) . \"<br/>\";\r\n        $wapstr .= \"Team AvgCred: \" . format_credit($team->expavg_credit) . \"<br/>\";\r\n\r\n        mysql_free_result($result);\r\n\r\n    } else {\r\n        $wapstr .= \"<br/>Team: None<br/>\";\r\n    }\r\n\r\n   // finally get last 5 trickles for user\r\n   //$wapstr .= show_trickles(\"u\", $user->id, 5, 1);\r\n\r\n   // don't want to send more than 1KB probably?\r\n   if (strlen($wapstr)>1024)\r\n       return substr($wapstr,0,1024);\r\n   else\r\n       return $wapstr;\r\n\r\n//   wap_end();\r\n}\r\n\r\n?>\r\n\r\n```\r\n\r\nAdd the following line to project/cache_parameters.inc\r\n\r\n```\r\ndefine('WAP_STAT_TTL',1800);\r\n```\r\n\r\nSomething we had to do after a number of teams started creating stats sigs & other pages w/the data.  Cuts down the database queries to 2x/hour rather than 3/request.  Thought I'd share."},"comment":{"url":"https://api.github.com/repos/BOINC/boinc/issues/comments/72492343","html_url":"https://github.com/BOINC/boinc/issues/665#issuecomment-72492343","issue_url":"https://api.github.com/repos/BOINC/boinc/issues/665","id":72492343,"user":{"login":"romw","id":985772,"avatar_url":"https://avatars.githubusercontent.com/u/985772?v=3","gravatar_id":"","url":"https://api.github.com/users/romw","html_url":"https://github.com/romw","followers_url":"https://api.github.com/users/romw/followers","following_url":"https://api.github.com/users/romw/following{/other_user}","gists_url":"https://api.github.com/users/romw/gists{/gist_id}","starred_url":"https://api.github.com/users/romw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/romw/subscriptions","organizations_url":"https://api.github.com/users/romw/orgs","repos_url":"https://api.github.com/users/romw/repos","events_url":"https://api.github.com/users/romw/events{/privacy}","received_events_url":"https://api.github.com/users/romw/received_events","type":"User","site_admin":false},"created_at":"2015-02-02T16:55:14Z","updated_at":"2015-02-02T16:55:14Z","body":"**Commented by Rytis on 12 Sep 37513285 12:53 UTC**\n(In [13111]) Fix #268: use fullpage cache for WAP stats, cache interval USER_PAGE_TTL (default 60 minutes)"}}