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 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
|
//////////////////////////////////////////////////////////////////
// //
// PLINK (c) 2005-2008 Shaun Purcell //
// //
// This file is distributed under the GNU General Public //
// License, Version 2. Please see the file COPYING for more //
// details //
// //
//////////////////////////////////////////////////////////////////
#include <iostream>
#include <sstream>
#include <ctime>
#include "plink.h"
#include "helper.h"
#include "options.h"
#include "sockets.h"
using namespace std;
extern string PVERSION;
extern string PREL;
#define PORT_NUM 80
#define IP_ADDR "155.52.206.11"
#define GET_STRING "GET /~purcell/plink/version2.txt HTTP/1.1\nHost: pngu.mgh.harvard.edu\nConnection: close\n\n"
void Plink::webcheck(CArgs & a)
{
#ifdef SKIP
printLOG("Web-check not implemented on this system...\n");
return;
#else
//////////////////////////////////////////
// First look for a local .pversion file in
// the local directory
// Get today's date
time_t curr=time(0);
string tdstamp = (string)ctime(&curr);
string buf;
stringstream ss(tdstamp);
vector<string> date_tokens;
while (ss >> buf)
date_tokens.push_back(buf);
string thisDate = date_tokens[0] + date_tokens[1] + date_tokens[2];
bool hasRecord = doesFileExist(".pversion");
////////////////////////////////////////////////////////
// Web-based message (but may be cached in local file)
vector<string> tokens;
bool connect2web = true;
printLOG("Web-based version check ( --noweb to skip )\n");
////////////////////////////////////////////
// If we have a record, are we up-to-date?
if ( hasRecord )
{
ifstream VER;
VER.open(".pversion",ios::in);
string oldDay, oldMonth, oldDate, webVersion;
VER >> oldDay >> oldMonth >> oldDate;
if ( thisDate == oldDay+oldMonth+oldDate )
{
printLOG("Recent cached web-check found...");
connect2web = false;
// Read rest of cached web message
while ( ! VER.eof() )
{
string t;
VER >> t;
if (t=="")
break;
tokens.push_back(t);
}
}
VER.close();
}
if ( connect2web )
{
//printLOG("Connecting to web to get version...\n");
tokens = socketConnection( this ,
IP_ADDR,
PORT_NUM,
GET_STRING);
}
bool print = false;
bool print2 = false;
bool version_okay = true;
for (int i=0; i<tokens.size(); i++)
{
if (tokens[i]=="END") break;
if (tokens[i]=="END-MESSAGE")
{
print2=false;
continue;
}
if (tokens[i]=="WARN")
{
if ( i < tokens.size()-1 )
{
i++;
if ( a.find(tokens[i]) )
{
printLOG("\n*** ALERT ***\n*** A warning flag has been set for: "+tokens[i]+
"\n*** See http://pngu.mgh.harvard.edu/purcell/plink/warnings.shtml\n");
warnings = true;
}
}
continue;
}
if (tokens[i]=="FATAL")
{
if ( i < tokens.size()-1 )
{
i++;
if ( a.find( tokens[i]) )
error("A serious warning flag has been set for: "+tokens[i]+
"\nPLINK has been instructed to stop"+
"\nPlease see http://pngu.mgh.harvard.edu/purcell/plink/warnings.shtml\n");
}
continue;
}
if (tokens[i]=="MESSAGE-ALL")
{
print2=true;
continue;
}
// Display any other messages
// Either conditional on old version (print)
// or a broadcast to all users (print2)
if ( ( print && !version_okay) || print2 )
{
if (tokens[i]=="\\n")
printLOG("\n");
else
printLOG(tokens[i]+" ");
}
// Check version code
if (tokens[i]=="PLINK-VERSION")
{
print=true;
if ( i < tokens.size() - 1)
{
if (tokens[i+1] == PVERSION)
printLOG(" OK, v"+PVERSION+" is current\n");
else
{
printLOG("\n\n *** UPDATE REQUIRED ***\n\n");
printLOG("\tThis version : "+PVERSION+PREL+"\n");
printLOG("\tMost recent version : "+tokens[i+1]+"\n\n");
printLOG("Please upgrade your version of PLINK as soon as possible!\n");
printLOG(" (visit the above website for free download)\n\n");
version_okay=false;
}
// Skip the version number
i++;
}
}
}
// did we get the information we needed?
if (!print) printLOG("Problem connecting to web\n");
printLOG("\n");
////////////////////////////////////////////////////
// Create a record that we've checked
// First line is date-stamp; then simply copy the
// whole message
ofstream VER;
VER.open(".pversion",ios::out);
VER << date_tokens[0] << " "
<< date_tokens[1] << " "
<< date_tokens[2] << "\n";
for (int i=0; i<tokens.size(); i++)
VER << tokens[i] << "\n";
VER.close();
#endif
}
|