Changeset 18995


Ignore:
Timestamp:
04/10/18 09:38:20 (7 years ago)
Author:
tbretz
Message:
Allow to run without authentication.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/src/rainsensor.cc

    r18993 r18995  
    185185    void PostRequest()
    186186    {
     187        const string auth = fAuthentication.empty() ? "" :
     188            "Authorization: Basic "+fAuthentication+"\r\n";
     189
    187190        const string cmd =
    188191            "GET "+fSite+" HTTP/1.1\r\n"
    189192            "Accept: */*\r\n"
    190193            "Content-Type: application/octet-stream\r\n"
    191             "Authorization: Basic "+fAuthentication+"\r\n"
     194            +auth+
    192195            "User-Agent: FACT\r\n"
    193196            "Host: www.fact-project.org\r\n"
     
    287290    void SetAuthentication(const string &user, const string &password)
    288291    {
     292        if (user.empty() && password.empty())
     293        {
     294            fAuthentication = "";
     295            return;
     296        }
     297
    289298        const string auth = user+":"+password;
    290299
     
    437446    int EvalOptions(Configuration &conf)
    438447    {
     448        const string user = conf.Has("user") ? conf.Get<string>("user") : "";
     449        const string pass = conf.Has("password") ? conf.Get<string>("password") : "";
     450
    439451        fRain.SetInterval(conf.Get<uint16_t>("interval"));
    440452        fRain.SetDebugTx(conf.Get<bool>("debug-tx"));
     
    442454        fRain.SetSite(conf.Get<string>("url"));
    443455        fRain.SetEndpoint(conf.Get<string>("addr"));
    444         fRain.SetAuthentication(conf.Get<string>("user"), conf.Get<string>("password"));
     456        fRain.SetAuthentication(user, pass);
    445457        fRain.StartConnect();
    446458
     
    468480        ("no-dim,d",  po_switch(), "Disable dim services")
    469481        ("addr,a",  var<string>("www.magic.iac.es:80"),  "Network address of Cosy")
    470         ("url,u",  var<string>("/site/weather/protected/current.json"),  "File name and path to load")
     482        ("url,u",  var<string>("/site/weather/rain_current.json"),  "File name and path to load")
    471483        ("quiet,q", po_bool(true),  "Disable printing contents of all received messages (except dynamic data) in clear text.")
    472484        ("interval,i", var<uint16_t>(60), "Interval between two updates on the server in seconds")
    473485        ("debug-tx", po_bool(), "Enable debugging of ethernet transmission.")
    474486        ("debug-rx", po_bool(), "Enable debugging of ethernet receptions.")
    475         ("user", var<string>("FACT")->required(), "User name for authentication.")
    476         ("password", var<string>()->required(), "Password for authentication.")
     487        ("user", var<string>(), "User name for authentication.")
     488        ("password", var<string>(), "Password for authentication.")
    477489        ;
    478490
Note: See TracChangeset for help on using the changeset viewer.