Class: ActiveStix::IdentitiesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/active_stix/identities_controller.rb

Instance Method Summary collapse

Instance Method Details

#attributionObject



99
100
101
102
103
104
105
106
107
108
109
# File 'app/controllers/active_stix/identities_controller.rb', line 99

def attribution

  organization = ActiveStix::Identity.find(params[:identity_id])
  threat_actor = ActiveStix::ThreatActor.find(params[:threat_actor_id])
  ActiveStix::Relationship.relate(threat_actor, organization, "attributed-to")

  respond_to do |format|
    format.html {redirect_to organization, notice: 'Identity was successfully updated.'}
    format.json {render :show, status: :ok, location: organization}
  end
end

#corpusObject



111
112
113
114
# File 'app/controllers/active_stix/identities_controller.rb', line 111

def corpus
  #download all the email attachments in an evaluation
  send_data(File.read(@identity.corpus(params[:mailbox])), :type => 'application/zip', :disposition => "attachment")
end

#createObject

POST /stix/identities POST /stix/identities.json



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/controllers/active_stix/identities_controller.rb', line 43

def create
  @identity = ActiveStix::Identity.new(stix_identity_params)
  @identity.identity_class = "organization"

  respond_to do |format|
    if @identity.save
      Ldap.stix_ingest(@identity, params[:identity][:uploaded_file].path)
      format.html {redirect_to @identity, notice: 'Identity was successfully created.'}
      format.json {render :show, status: :created, location: @identity}
    else
      format.html {render :new}
      format.json {render json: @identity.errors, status: :unprocessable_entity}
    end
  end
end

#destroyObject

DELETE /stix/identities/1 DELETE /stix/identities/1.json



75
76
77
78
79
80
81
# File 'app/controllers/active_stix/identities_controller.rb', line 75

def destroy
  @identity.destroy
  respond_to do |format|
    format.html {redirect_to stix_identities_url, notice: 'Identity was successfully destroyed.'}
    format.json {head :no_content}
  end
end

#editObject

GET /stix/identities/1/edit



38
39
# File 'app/controllers/active_stix/identities_controller.rb', line 38

def edit
end

#employmentObject



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'app/controllers/active_stix/identities_controller.rb', line 83

def employment
  organization = ActiveStix::Identity.find(params[:organization_id])
  @identity = ActiveStix::Identity.find(params[:identity_id])

  respond_to do |format|
    if ActiveStix::Identity.employ(@identity, organization)
      format.html {redirect_to @identity, notice: 'Identity was successfully updated.'}
      format.json {render :show, status: :ok, location: @identity}
    else
      format.html {render @identity, notice: 'Could not create employment.'}
      format.json {render json: @identity.errors, status: :unprocessable_entity}
    end
  end

end

#indexObject

GET /stix/identities GET /stix/identities.json



6
7
8
# File 'app/controllers/active_stix/identities_controller.rb', line 6

def index
  @identities = ActiveStix::Identity.where("name like ?", "%#{params[:search]}%").order("name").page params[:page]
end

#newObject

GET /stix/identities/new



33
34
35
# File 'app/controllers/active_stix/identities_controller.rb', line 33

def new
  @identity = ActiveStix::Identity.new
end

#showObject

GET /stix/identities/1 GET /stix/identities/1.json



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/active_stix/identities_controller.rb', line 12

def show
  if @identity.identity_class == 'organization'
    @employment_records = @identity.source_relationships.where(relationship_type: "employs").page(params[:page])
    @threat_groups = @identity.threat_groups
    @attack_patterns = @identity.attack_patterns
  else
    case params[:mailbox]
    when 'sent'
      @mailbox = "Sent"
      @sent_email_messages = @identity.email_messages.includes(:eml).order("created_at DESC").page(params[:page])
    when 'received'
      @mailbox = "Received"
      @received_email_messages = @identity.to_refs.order("created_at DESC").page(params[:page])
    else
      @mailbox = "Sent"
      @sent_email_messages = @identity.email_messages.includes(:eml).order("created_at DESC").page(params[:page])
    end
  end
end

#updateObject

PATCH/PUT /stix/identities/1 PATCH/PUT /stix/identities/1.json



61
62
63
64
65
66
67
68
69
70
71
# File 'app/controllers/active_stix/identities_controller.rb', line 61

def update
  respond_to do |format|
    if @identity.update(stix_identity_params)
      format.html {redirect_to @identity, notice: 'Identity was successfully updated.'}
      format.json {render :show, status: :ok, location: @identity}
    else
      format.html {render :edit}
      format.json {render json: @identity.errors, status: :unprocessable_entity}
    end
  end
end