
# THIS IS PULLED FROM SCRIPTS AND AUTOGENERATED!
# Please use openapi/combine.py to regenerate!
openapi: 3.0.0
info:
  version: 1.0.0
  description: This is the API specifications for interacting with the Blocky/2 UI.
  title: Blocky/2
  license:
    name: Apache 2.0
    url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
components:
  schemas:
    ActionCompleted:
      properties:
        message:
          description: Acknowledgement message
          example: Action completed
          type: string
      required:
      - message
    Empty:
      properties:
        id:
          description: optional object ID
          type: string
        page:
          description: optional page id
          type: string
      required: []
    Error:
      properties:
        code:
          description: HTTP Error Code
          example: 403
          format: int16
          type: integer
        reason:
          description: Human readable error message
          example: You need to be logged in to view this endpoint!
          type: string
      required:
      - code
      - reason
    IPAddress:
      properties:
        force:
          description: Force addition, even if it means removing conflicting rules
            already in the DB
          type: boolean
        reason:
          description: The reason for banning
          type: string
        rule:
          description: the ID of an existing rule
          type: string
        source:
          description: the source IP Address or Network
          type: string
        target:
          description: Target machine to ban on (or * for all machines)
          type: string
        timeout:
          description: If present and greater than 0, denotes the UNIX timestamp when
            this rule stops working
          type: integer
    IPTables:
      properties:
        hostname:
          type: string
        iptables:
          items:
            $ref: '#/components/schemas/IPTablesObject'
          type: array
    IPTablesObject:
      properties:
        action:
          description: What to do
          example: DROP
          type: string
        chain:
          description: iptables chain for this rule
          example: INPUT
          type: string
        destination:
          description: The destination IP address
          example: 1.2.3.4
          type: string
        extensions:
          description: Any extensions used for this rule
          example: /* comment here */
          type: string
        linenumber:
          description: Line-number for the rule
          example: 26
          type: string
        option:
          description: rule options (mods etc)
          example: comment
          type: string
        protocol:
          description: the protocol (tcp/udp/etc)
          example: tcp
          type: string
        source:
          description: The source IP address
          example: 1.2.3.4
          type: string
      required:
      - chain
      - linenumber
      - protocol
      - source
      - action
      - destination
    Ruleset:
      properties:
        limit:
          description: The limit that causes a ban
          type: integer
        name:
          description: The name of the rule
          type: string
        query:
          description: The individual query args to look for
          type: array
        rid:
          description: rule ID, if overriding a previous rule
          type: string
        span:
          description: The span (in hours) within which to look for offenses
          type: integer
        type:
          description: The type of rule
          type: string
    SearchObject:
      properties:
        source:
          description: IP Address or Network to search for
          type: string
    SearchResult:
      properties:
        banlist:
          description: Banned IP blocks found matching
          type: array
        iptables:
          description: Banned IP blocks found matching in local iptables
          type: array
        whitelist:
          description: Whitelisted IP blocks found matching
          type: array
  securitySchemes:
    cookieAuth:
      in: cookie
      name: kibble_session
      type: apiKey
paths:
  /api/activity:
    get:
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Empty'
          description: 200 response
        default:
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
          description: unexpected error
      security:
      - cookieAuth: []
      summary: Displays the current activity entries
  /api/bans:
    delete:
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/IPAddress'
        description: Removes a banlist entry
        required: true
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ActionCompleted'
          description: Removal successful
        default:
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
          description: unexpected error
      security:
      - cookieAuth: []
      summary: Remove a whitelist entry
    get:
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Empty'
          description: 200 response
        default:
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
          description: unexpected error
      security:
      - cookieAuth: []
      summary: Displays the current banlistr entries
    put:
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/IPAddress'
        description: IP address or block to ban
        required: true
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ActionCompleted'
          description: Ban entry added
        default:
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
          description: unexpected error
      summary: Add a banmlist entry
  /api/fail2ban:
    post:
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SearchObject'
        description: Search query
        required: true
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SearchResult'
          description: Search result
        default:
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
          description: unexpected error
      summary: Search for whether a user was blocked via fail2ban
  /api/myrules:
    put:
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/IPTables'
        description: iptables ruleset blob
        required: true
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ActionCompleted'
          description: iptables entries updatd
        default:
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
          description: unexpected error
      summary: Set a host's iptables list
  /api/rules:
    delete:
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Ruleset'
        description: Removes a rule entry
        required: true
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ActionCompleted'
          description: Removal successful
        default:
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
          description: unexpected error
      security:
      - cookieAuth: []
      summary: Remove a rule entry
    get:
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Empty'
          description: 200 response
        default:
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
          description: unexpected error
      security:
      - cookieAuth: []
      summary: Displays the current ruleset entries
    put:
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Ruleset'
        description: Ruleset to add/modify
        required: true
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ActionCompleted'
          description: Ruleset added
        default:
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
          description: unexpected error
      summary: Adds or overrides a ruleset
  /api/search:
    post:
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SearchObject'
        description: Search query
        required: true
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SearchResult'
          description: Search result
        default:
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
          description: unexpected error
      summary: Search for whether an IP or block is banned or whitelisted
  /api/whitelist:
    delete:
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/IPAddress'
        description: Removes a whitelist entry
        required: true
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ActionCompleted'
          description: Removal successful
        default:
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
          description: unexpected error
      security:
      - cookieAuth: []
      summary: Remove a whitelist entry
    get:
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Empty'
          description: 200 response
        default:
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
          description: unexpected error
      security:
      - cookieAuth: []
      summary: Displays the current whitelist entries
    put:
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/IPAddress'
        description: IP address or block to whitelist
        required: true
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ActionCompleted'
          description: Whitelist entry added
        default:
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
          description: unexpected error
      summary: Add a whitelist entry
