Commit ae819c48 authored by Pierre DAVID's avatar Pierre DAVID

Add /domains and /hinfos API

parent 2566904b
##############################################################################
api-handler get {/domains} yes {
} {
set idgrp [::u idgrp]
set sql "SELECT json_agg (t.*) AS j FROM (
SELECT d.*
FROM dns.domain d
INNER JOIN dns.p_dom p USING (iddom)
WHERE p.idgrp = $idgrp
ORDER BY p.sort ASC
) AS t
"
set j {[]}
::dbdns exec $sql tab {
set j $tab(j)
}
::scgi::set-header Content-Type application/json
::scgi::set-body $j
}
##############################################################################
api-handler get {/domains/([0-9]+:iddom)} yes {
} {
set idgrp [::u idgrp]
set sql "SELECT json_agg (t.*) AS j FROM (
SELECT d.*
FROM dns.domain d
INNER JOIN dns.p_dom p USING (iddom)
WHERE p.idgrp = $idgrp
AND d.iddom = $iddom
) AS t
"
set found 0
::dbdns exec $sql tab {
set found 1
set j $tab(j)
}
if {! $found} then {
::scgi::serror 404 [mc "Domain %s not found"]
}
::scgi::set-header Content-Type application/json
::scgi::set-body $j
}
##############################################################################
api-handler get {/hinfos} yes {
} {
set sql "SELECT json_agg (t.*) AS j FROM (
SELECT idhinfo, name
FROM dns.hinfo
WHERE present != 0
ORDER BY sort ASC
) AS t
"
set j {[]}
::dbdns exec $sql tab {
set j $tab(j)
}
::scgi::set-header Content-Type application/json
::scgi::set-body $j
}
##############################################################################
api-handler get {/hinfos/([0-9]+:idhinfo)} yes {
} {
set idgrp [::u idgrp]
set sql "SELECT json_agg (t.*) AS j FROM (
SELECT idhinfo
FROM dns.hinfo
WHERE present != 0
AND idhinfo = $idhinfo
) AS t
"
set found 0
::dbdns exec $sql tab {
set found 1
set j $tab(j)
}
if {! $found} then {
::scgi::serror 404 [mc "Hinfo %s not found"]
}
::scgi::set-header Content-Type application/json
::scgi::set-body $j
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment