<.link navigate={ if @live_action == :edit, do: ~p"/sites/#{@site.id}", else: ~p"/sites" } class="inline-flex items-center gap-1 text-sm text-gray-600 hover:text-gray-900 dark:text-gray-400 dark:hover:text-white" > <.icon name="hero-arrow-left" class="h-4 w-4" /> {if @live_action == :edit, do: "Back to Site", else: "Back to Sites"}
<.header> {@page_title} <:subtitle> {if @live_action == :new, do: "Add a new site to your organization", else: "Update site details"}
<.form for={@form} id="site-form" phx-change="validate" phx-submit="save"> <.input field={@form[:name]} type="text" label="Site Name" required />
<%= if @available_agents != [] do %>

Agent Configuration (optional)

Set a default agent for SNMP polling at this site. This will override the organization default for all devices at this site. Leave blank to inherit from organization.

<.input field={@form[:agent_token_id]} type="select" label="Default Agent for Site" prompt="Inherit from organization" options={Enum.map(@available_agents, &{&1.name, &1.id})} /> <%= if @live_action == :edit and @site.agent_token_id do %>

<.icon name="hero-exclamation-triangle" class="h-4 w-4" /> Overriding organization default - all devices at this site will use this agent

Force Apply to Site Device

This will assign this agent to ALL devices at this site.

<.button type="button" phx-click="apply_agent_to_all" data-confirm="This will replace agent assignments for ALL devices at this site. Are you sure?" variant="danger" > <.icon name="hero-arrow-path" class="h-4 w-4" /> Apply Agent to All Device
<% else %> <%= if Map.get(assigns, :org_agent) do %>

<.icon name="hero-building-office-2" class="h-4 w-4" /> Currently inheriting organization default: {@org_agent.name}

<% else %>

Set a default agent for all devices at this site. Device can override this setting individually.

<% end %> <% end %>
<% end %>

SNMP Configuration (optional)

Override organization SNMP defaults for all devices at this site. Leave blank to inherit from organization.

<.input field={@form[:snmp_version]} type="select" label="SNMP Version" prompt="Inherit from organization" options={[{"SNMP v1", "1"}, {"SNMP v2c", "2c"}, {"SNMP v3", "3"}]} /> <.input field={@form[:snmp_community]} type="text" label="SNMP Community String" placeholder="Leave blank to inherit from organization" /> <%= if @live_action == :edit and @site.snmp_community do %>

Force Apply to Site Device

This will override SNMP settings for ALL devices at this site.

<.button type="button" phx-click="apply_snmp_to_all" data-confirm="This will replace SNMP settings for ALL devices at this site. Are you sure?" variant="danger" > <.icon name="hero-arrow-path" class="h-4 w-4" /> Apply SNMP Config to All Device
<% end %>
<%= if @current_scope.user.is_superuser do %>

MikroTik API Configuration (optional)

Override organization MikroTik API defaults for all devices at this site. Leave blank to inherit from organization. Only applies to MikroTik devices.

<.input field={@form[:mikrotik_enabled]} type="checkbox" label="Enable MikroTik API" /> <%= if @form[:mikrotik_enabled].value do %> <.input field={@form[:mikrotik_username]} type="text" label="Username" placeholder="Leave blank to inherit from organization" /> <.input field={@form[:mikrotik_password]} type="password" label="Password" placeholder="Leave blank to inherit from organization" /> <.input field={@form[:mikrotik_port]} type="number" label="API Port" placeholder="8729 (SSL) or 8728 (plain)" /> <.input field={@form[:mikrotik_use_ssl]} type="checkbox" label="Use SSL (API-SSL)" /> <%= if @form[:mikrotik_use_ssl].value == false do %>

🚨 Critical Security Warning: Plain API (port 8728) sends credentials unencrypted over the network. This setting is blocked for devices using cloud pollers and should only be used with local agents on trusted networks.

<% else %>

⚠️ Security Warning: Plain API (port 8728) sends credentials unencrypted. Use SSL (port 8729) whenever possible.

<% end %> <% end %>
<% end %>
<.button phx-disable-with="Saving..." variant="primary">Save Site <.button navigate={~p"/sites"}>Cancel
<%= if @live_action == :edit do %>

Danger Zone

Once you delete a site, there is no going back. This will also delete all devices at this site.

<.button phx-click="delete" data-confirm="Are you sure you want to delete this site? This will also delete all devices at this site." variant="danger" > <.icon name="hero-trash" class="h-4 w-4" /> Delete Site
<% end %>