syntax = "proto2";

import "grr_response_proto/jobs.proto";
import "grr_response_proto/knowledge_base.proto";
import "grr_response_proto/semantic.proto";
import "grr_response_proto/sysinfo.proto";
import "grr_response_proto/user.proto";


message ClientLabel {
  optional string name = 1;
  optional string owner = 2 [(sem_type) = {
      description: "Username of the user who added the label.",
    }];
}

message StringMapEntry {
  optional string key = 1;
  optional string value = 2;
}

// Next field: 17
message ClientSnapshot {
  optional string client_id = 1 [(sem_type) = {
      description: "The client id of this client.",
    }];
  repeated Filesystem filesystems = 2 [(sem_type) = {
      description: "Mounted Filesystems",
    }];
  optional string os_release = 3 [(sem_type) = {
      description: "OS Distribution or release.",
    }];
  optional string os_version = 4 [(sem_type) = {
      description: "The OS version ID e.g. 6.1.7601SP1, 10.9.2, 14.04.",
    }];
  optional string arch = 5 [(sem_type) = {
      description: "Architecture",
    }];
  optional uint64 install_time = 6 [(sem_type) = {
      type: "RDFDatetime",
      description: "When system was installed.",
    }]; // Called install_date in some legacy code.
  optional KnowledgeBase knowledge_base = 7 [(sem_type) = {
      description: "Knowledge Base",
    }];
  repeated StringMapEntry grr_configuration = 8 [(sem_type) = {
      description: "Running configuration for the GRR client.",
    }];
  repeated StringMapEntry library_versions = 9 [(sem_type) = {
      description: "Running library versions for the client.",
    }];
  optional string kernel = 10 [(sem_type) = {
      description: "Kernel version string.",
    }];
  repeated Volume volumes = 11 [(sem_type) = {
      description: "Client disk volumes.",
    }];
  repeated Interface interfaces = 12 [(sem_type) = {
      description: "Network interfaces.",
    }];
  optional HardwareInfo hardware_info = 13 [(sem_type) = {
      description: "Various hardware information.",
    }];
  optional uint64 memory_size = 14 [(sem_type) = {
      type: "ByteSize",
      description: "Amount of memory this client's machine has.",
    }];
  optional CloudInstance cloud_instance = 15 [(sem_type) = {
      description: "Information about cloud machines.",
    }];
  optional StartupInfo startup_info = 16 [(sem_type) = {
      description: "Information about the GRR client.",
    }];
}


message ClientMetadata {
  optional bytes certificate = 1 [(sem_type) = {
      type: "RDFX509Cert",
    }];
  optional bool fleetspeak_enabled = 2;
  optional uint64 ping = 3 [(sem_type) = {
      type: "RDFDatetime",
      description: "The last time the server heard from this client.",
    }];
  optional uint64 clock = 4 [(sem_type) = {
      type: "RDFDatetime",
      description: "The last clock read on the client. "
                   "(Can be used to estimate client clock skew).",
    }];
  optional NetworkAddress ip = 5;
  optional uint64 last_foreman_time = 6 [(sem_type) = {
      type: "RDFDatetime",
      description: "The last time the foreman checked us.",
    }];
  optional uint64 first_seen = 7 [(sem_type) = {
      type: "RDFDatetime",
      description: "First time the client registered with us",
    }];
  optional uint64 last_crash_timestamp = 8 [(sem_type) = {
      type: "RDFDatetime",
      description: "Last time this client reported a crash.",
    }];
  optional uint64 startup_info_timestamp = 9 [(sem_type) = {
      type: "RDFDatetime",
      description: "Timestamp for the latest change of startup information for "
                   "this client.",
    }];
}

message ClientFullInfo {
  optional ClientMetadata metadata = 1;
  optional ClientSnapshot last_snapshot = 2;
  optional StartupInfo last_startup_info = 3;
  repeated ClientLabel labels = 4;
}

// Next field id: 6
message GRRUser {
  optional string username = 4;
  optional Password password = 1;
  optional GUISettings.UIMode ui_mode = 2;
  optional bool canary_mode = 3;

  enum UserType {
    USER_TYPE_NONE = 0;
    USER_TYPE_STANDARD = 1;
    USER_TYPE_ADMIN = 2;
  }
  optional UserType user_type = 5;
}

// Next message id: 12
message ApprovalRequest {
  enum ApprovalType {
    APPROVAL_TYPE_NONE = 0;
    APPROVAL_TYPE_CLIENT = 1;
    APPROVAL_TYPE_HUNT = 2;
    APPROVAL_TYPE_CRON_JOB = 3;
  }
  optional ApprovalType approval_type = 1;
  optional string approval_id = 2;
  optional string subject_id = 3;
  optional string requestor_username = 4;
  optional string reason = 5;
  optional uint64 timestamp = 6 [(sem_type) = {
      type: "RDFDatetime"
    }];
  optional uint64 expiration_time = 7 [(sem_type) = {
      type: "RDFDatetime"
    }];

  optional string email_message_id = 11;

  repeated string notified_users = 8;
  repeated string email_cc_addresses = 9;

  repeated ApprovalGrant grants = 10;
}

message ApprovalGrant {
  optional string grantor_username = 1;
  optional uint64 timestamp = 6 [(sem_type) = {
      type: "RDFDatetime",
    }];
}

// Next field id: 9.
message PathInfo {
  enum PathType {
    UNSET = 0;
    OS = 1;
    TSK = 2;
    REGISTRY = 3;
    TEMP = 4;
  }
  optional PathType path_type = 1;
  repeated string components = 2;
  optional uint64 timestamp = 8 [(sem_type) = { type: "RDFDatetime" }];
  optional uint64 last_stat_entry_timestamp = 3
      [(sem_type) = { type: "RDFDatetime" }];
  optional uint64 last_hash_entry_timestamp = 7 [(sem_type) = {
    type: "RDFDatetime",
  }];
  optional bool directory = 4;
  optional StatEntry stat_entry = 5;
  optional Hash hash_entry = 6;
}

message ObjectReference {
  option (semantic) = {
    union_field: "reference_type"
  };

  enum Type {
    UNSET = 0;
    CLIENT = 1;
    HUNT = 2;
    FLOW = 3;
    CRON_JOB = 4;
    VFS_FILE = 5;
    APPROVAL_REQUEST = 6;
  }
  optional Type reference_type = 1;

  optional ClientReference client = 2;
  optional HuntReference hunt = 3;
  optional FlowReference flow = 4;
  optional CronJobReference cron_job = 5;
  optional VfsFileReference vfs_file = 6;
  optional ApprovalRequestReference approval_request = 7;
}

message ClientReference {
  optional string client_id = 1;
}

message HuntReference {
  optional string hunt_id = 1;
}

message CronJobReference {
  optional string cron_job_id = 1;
}

message FlowReference {
  optional string flow_id = 1 [(sem_type) = {
      description: "The session id of the referenced flow."
    }];
  optional string client_id = 2 [(sem_type) = {
      description: "The client id the referenced flow ran on."
    }];
}

// Next field id: 4
message VfsFileReference {
  optional string client_id = 1;
  optional PathInfo.PathType path_type = 3;
  repeated string path_components = 2;
}

message ApprovalRequestReference {
  optional ApprovalRequest.ApprovalType approval_type = 1;
  optional string approval_id = 2;
  optional string subject_id = 3;
  optional string requestor_username = 4;
}

message UserNotification {
  enum Type {
    TYPE_UNSET = 0;
    TYPE_CLIENT_INTERROGATED = 1;
    TYPE_CLIENT_APPROVAL_REQUESTED = 2;
    TYPE_HUNT_APPROVAL_REQUESTED = 3;
    TYPE_CRON_JOB_APPROVAL_REQUESTED = 4;
    TYPE_CLIENT_APPROVAL_GRANTED = 5;
    TYPE_HUNT_APPROVAL_GRANTED = 6;
    TYPE_CRON_JOB_APPROVAL_GRANTED = 7;
    TYPE_VFS_FILE_COLLECTED = 8;
    TYPE_VFS_FILE_COLLECTION_FAILED = 9;
    TYPE_HUNT_STOPPED = 10;
    TYPE_FILE_ARCHIVE_GENERATED = 11;
    TYPE_FILE_ARCHIVE_GENERATION_FAILED = 12;
    TYPE_FLOW_RUN_COMPLETED = 13;
    TYPE_FLOW_RUN_FAILED = 14;
    TYPE_VFS_LIST_DIRECTORY_COMPLETED = 15;
    TYPE_VFS_RECURSIVE_LIST_DIRECTORY_COMPLETED = 16;
  }

  enum State {
    STATE_UNSET = 0;
    STATE_PENDING = 1;
    STATE_NOT_PENDING = 2;
  }

  optional string username = 1;
  optional Type notification_type = 2;
  optional State state = 3;
  optional uint64 timestamp = 4 [(sem_type) = {
      type: "RDFDatetime"
    }];

  optional string message = 5;
  optional ObjectReference reference = 6;
}

message MessageHandlerRequest {
  optional string client_id = 1;
  optional string handler_name = 2;
  optional uint64 timestamp = 3 [(sem_type) = {
      type: "RDFDatetime"
    }];
  optional uint64 request_id = 4;
  optional uint64 leased_until = 5 [(sem_type) = {
      type: "RDFDatetime"
    }];
  optional string leased_by = 6;
  optional EmbeddedRDFValue request = 7;
}
