# HG changeset patch # User Sebastien Jodogne # Date 1528546532 -7200 # Node ID eaf10085ffa183fb17b6a71cd80adb75c3e8ebfd # Parent d26dd081df97f9d6136ad58fb5f0bd0542021c0c no passwords in public content of jobs diff -r d26dd081df97 -r eaf10085ffa1 Core/JobsEngine/JobsRegistry.cpp --- a/Core/JobsEngine/JobsRegistry.cpp Fri Jun 08 18:08:48 2018 +0200 +++ b/Core/JobsEngine/JobsRegistry.cpp Sat Jun 09 14:15:32 2018 +0200 @@ -50,6 +50,7 @@ static const char* JOBS_REGISTRY = "JobsRegistry"; static const char* MAX_COMPLETED_JOBS = "MaxCompletedJobs"; static const char* CREATION_TIME = "CreationTime"; + static const char* LAST_CHANGE_TIME = "LastChangeTime"; static const char* RUNTIME = "Runtime"; @@ -226,6 +227,11 @@ return lastStateChangeTime_; } + void SetLastStateChangeTime(const boost::posix_time::ptime& time) + { + lastStateChangeTime_ = time; + } + const boost::posix_time::time_duration& GetRuntime() const { return runtime_; @@ -282,6 +288,7 @@ target[STATE] = EnumerationToString(state_); target[PRIORITY] = priority_; target[CREATION_TIME] = boost::posix_time::to_iso_string(creationTime_); + target[LAST_CHANGE_TIME] = boost::posix_time::to_iso_string(lastStateChangeTime_); target[RUNTIME] = static_cast(runtime_.total_milliseconds()); return true; } @@ -294,7 +301,6 @@ JobHandler(IJobUnserializer& unserializer, const Json::Value& serialized) : - lastStateChangeTime_(boost::posix_time::microsec_clock::universal_time()), pauseScheduled_(false), cancelScheduled_(false) { @@ -303,17 +309,13 @@ priority_ = SerializationToolbox::ReadInteger(serialized, PRIORITY); creationTime_ = boost::posix_time::from_iso_string (SerializationToolbox::ReadString(serialized, CREATION_TIME)); + lastStateChangeTime_ = boost::posix_time::from_iso_string + (SerializationToolbox::ReadString(serialized, LAST_CHANGE_TIME)); runtime_ = boost::posix_time::milliseconds (SerializationToolbox::ReadInteger(serialized, RUNTIME)); retryTime_ = creationTime_; - if (state_ == JobState_Retry || - state_ == JobState_Running) - { - state_ = JobState_Pending; - } - job_.reset(unserializer.UnserializeJob(serialized[JOB])); job_->GetJobType(jobType_); job_->Start(); @@ -591,7 +593,8 @@ void JobsRegistry::SubmitInternal(std::string& id, - JobHandler* handlerRaw) + JobHandler* handlerRaw, + bool keepLastChangeTime) { if (handlerRaw == NULL) { @@ -600,6 +603,8 @@ std::auto_ptr handler(handlerRaw); + boost::posix_time::ptime lastChangeTime = handler->GetLastStateChangeTime(); + boost::mutex::scoped_lock lock(mutex_); CheckInvariants(); @@ -633,6 +638,11 @@ throw OrthancException(ErrorCode_InternalError); } + if (keepLastChangeTime) + { + handler->SetLastStateChangeTime(lastChangeTime); + } + jobsIndex_.insert(std::make_pair(id, handler.release())); LOG(INFO) << "New job submitted with priority " << priority << ": " << id; @@ -645,7 +655,7 @@ IJob* job, // Takes ownership int priority) { - SubmitInternal(id, new JobHandler(job, priority)); + SubmitInternal(id, new JobHandler(job, priority), false); } @@ -653,7 +663,7 @@ int priority) { std::string id; - SubmitInternal(id, new JobHandler(job, priority)); + SubmitInternal(id, new JobHandler(job, priority), false); } @@ -1250,9 +1260,9 @@ for (Json::Value::ArrayIndex i = 0; i < s[JOBS].size(); i++) { std::auto_ptr job(new JobHandler(unserializer, s[JOBS][i])); - + std::string id; - SubmitInternal(id, job.release()); + SubmitInternal(id, job.release(), true); } } } diff -r d26dd081df97 -r eaf10085ffa1 Core/JobsEngine/JobsRegistry.h --- a/Core/JobsEngine/JobsRegistry.h Fri Jun 08 18:08:48 2018 +0200 +++ b/Core/JobsEngine/JobsRegistry.h Sat Jun 09 14:15:32 2018 +0200 @@ -113,7 +113,8 @@ void RemoveRetryJob(JobHandler* handler); void SubmitInternal(std::string& id, - JobHandler* handler); + JobHandler* handler, + bool keepLastChangeTime); public: JobsRegistry() : diff -r d26dd081df97 -r eaf10085ffa1 Core/WebServiceParameters.cpp --- a/Core/WebServiceParameters.cpp Fri Jun 08 18:08:48 2018 +0200 +++ b/Core/WebServiceParameters.cpp Sat Jun 09 14:15:32 2018 +0200 @@ -130,6 +130,11 @@ SetUsername(""); SetPassword(""); } + else if (peer.size() == 2) + { + LOG(ERROR) << "The HTTP password is not provided"; + throw OrthancException(ErrorCode_BadFileFormat); + } else if (peer.size() == 3) { SetUsername(peer.get(1u, "").asString()); @@ -178,12 +183,25 @@ SetUsername(GetStringMember(peer, "Username", "")); SetPassword(GetStringMember(peer, "Password", "")); + if (!username_.empty() && + !peer.isMember("Password")) + { + LOG(ERROR) << "The HTTP password is not provided"; + throw OrthancException(ErrorCode_BadFileFormat); + } + #if ORTHANC_SANDBOXED == 0 if (peer.isMember("CertificateFile")) { SetClientCertificate(GetStringMember(peer, "CertificateFile", ""), GetStringMember(peer, "CertificateKeyFile", ""), GetStringMember(peer, "CertificateKeyPassword", "")); + + if (!peer.isMember("CertificateKeyPassword")) + { + LOG(ERROR) << "The password for the HTTPS certificate is not provided"; + throw OrthancException(ErrorCode_BadFileFormat); + } } #endif @@ -229,7 +247,8 @@ } - void WebServiceParameters::ToJson(Json::Value& value) const + void WebServiceParameters::ToJson(Json::Value& value, + bool includePasswords) const { if (advancedFormat_) { @@ -240,7 +259,11 @@ !password_.empty()) { value["Username"] = username_; - value["Password"] = password_; + + if (includePasswords) + { + value["Password"] = password_; + } } if (!certificateFile_.empty()) @@ -253,7 +276,8 @@ value["CertificateKeyFile"] = certificateKeyFile_; } - if (!certificateKeyPassword_.empty()) + if (!certificateKeyPassword_.empty() && + includePasswords) { value["CertificateKeyPassword"] = certificateKeyPassword_; } @@ -267,7 +291,11 @@ !password_.empty()) { value.append(username_); - value.append(password_); + + if (includePasswords) + { + value.append(password_); + } } } } @@ -283,6 +311,7 @@ target["CertificateKeyFile"] = certificateKeyFile_; target["CertificateKeyPassword"] = certificateKeyPassword_; target["PKCS11"] = pkcs11Enabled_; + target["AdvancedFormat"] = advancedFormat_; } @@ -304,5 +333,6 @@ } pkcs11Enabled_ = SerializationToolbox::ReadBoolean(serialized, "PKCS11"); + advancedFormat_ = SerializationToolbox::ReadBoolean(serialized, "AdvancedFormat"); } } diff -r d26dd081df97 -r eaf10085ffa1 Core/WebServiceParameters.h --- a/Core/WebServiceParameters.h Fri Jun 08 18:08:48 2018 +0200 +++ b/Core/WebServiceParameters.h Sat Jun 09 14:15:32 2018 +0200 @@ -128,7 +128,8 @@ void FromJson(const Json::Value& peer); - void ToJson(Json::Value& value) const; + void ToJson(Json::Value& value, + bool includePasswords) const; void Serialize(Json::Value& target) const; }; diff -r d26dd081df97 -r eaf10085ffa1 OrthancServer/OrthancInitialization.cpp --- a/OrthancServer/OrthancInitialization.cpp Fri Jun 08 18:08:48 2018 +0200 +++ b/OrthancServer/OrthancInitialization.cpp Sat Jun 09 14:15:32 2018 +0200 @@ -960,7 +960,7 @@ peers.removeMember(symbolicName); Json::Value v; - peer.ToJson(v); + peer.ToJson(v, true); peers[symbolicName] = v; } diff -r d26dd081df97 -r eaf10085ffa1 OrthancServer/ServerJobs/OrthancPeerStoreJob.cpp --- a/OrthancServer/ServerJobs/OrthancPeerStoreJob.cpp Fri Jun 08 18:08:48 2018 +0200 +++ b/OrthancServer/ServerJobs/OrthancPeerStoreJob.cpp Sat Jun 09 14:15:32 2018 +0200 @@ -98,7 +98,7 @@ SetOfInstancesJob::GetPublicContent(value); Json::Value v; - peer_.ToJson(v); + peer_.ToJson(v, false /* don't include passwords */); value["Peer"] = v; }