Changeset 765 for trunk/dns-rpc.cgi
- Timestamp:
- 06/23/17 13:01:18 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/dns-rpc.cgi
r749 r765 134 134 exit; 135 135 136 137 =head1 dns-rpc.cgi 138 139 The RPC API for DeepNet DNS Administrator. 140 141 =head2 Common required arguments 142 143 A few arguments for primitive authorization are required on all calls. 144 145 =over 4 146 147 =item rpcuser 148 149 A string identifying the remote user in some way. Used to generate a hidden local user for logging. 150 151 =item rpcsystem 152 153 A string identifying the remote system doing the RPC call. This is checked against a list of IPs allowed to 154 claim this system identifier. 155 156 =back 157 158 =cut 159 136 160 ## 137 161 ## Subs below here … … 214 238 ## Shims for DNSDB core subs 215 239 ## 240 241 242 =head2 Exposed RPC subs 243 244 =cut 245 #over 4 246 216 247 217 248 #sub connectDB { … … 225 256 #sub _log { 226 257 258 259 =head3 addDomain 260 261 Add a domain. Note that while this should accept a formal .arpa reverse zone name, doing so will disrupt 262 several features that ease management of bulk reverse records. Use C<addRDNS> to add reverse zones. 263 264 =over 4 265 266 =item domain 267 268 The domain to add. 269 270 =item group 271 272 The group ID to add the domain to. Group ID 1 is expected to exist; otherwise a list of groups should be 273 retrieved with C<getGroupList> for selection. The group defines which template records will be used to create 274 the initial record set in the domain. 275 276 =item state 277 278 Active/inactive flag. Send C<active>, C<on>, or C<1> for domains that should be published; C<inactive>, 279 C<off>, or C<0> for domains that should be added but not currently published. 280 281 =item defloc 282 283 Optional argument for the default location/view the domain's records should be published in. Leave blank, or a 284 list of locations can be retrieved with C<getLocList> or C<getLocDropdown> for selection. 285 286 =back 287 288 Returns the ID of the domain. 289 290 =cut 227 291 sub addDomain { 228 292 my %args = @_; … … 235 299 } 236 300 301 302 =head3 delZone 303 304 Delete a domain or reverse zone 305 306 =over 4 307 308 =item zone 309 310 The domain name, domain ID, .arpa zone name, or logical CIDR range to remove 311 312 =item revrec 313 314 Flag to indicate whether to go looking for a domain or a reverse zone to delete. Accepts "y" or "n". 315 316 =back 317 318 Returns an informational confirmation message on success. 319 320 =cut 237 321 sub delZone { 238 322 my %args = @_; … … 258 342 } # delZone() 259 343 344 260 345 #sub domainName {} 261 346 #sub revName {} 262 347 348 349 =head3 domainID 350 351 Retrieve the ID for a domain 352 353 =over 4 354 355 =item domain 356 357 The domain name to find the ID for 358 359 =back 360 361 Returns the integer ID of the domain if found. 362 363 =cut 263 364 sub domainID { 264 365 my %args = @_; … … 273 374 #sub revID {} 274 375 376 377 =head3 addRDNS 378 379 Add a reverse zone 380 381 =over 4 382 383 =item revzone 384 385 The logical reverse zone to be added. Can be specified as either formal .arpa notation or a valid CIDR 386 netblock. Using a CIDR netblock allows logical aggregation of related records even if the CIDR range covers 387 multiple formal .arpa zone boundaries. For example, the logical zone 192.168.4.0/22 covers 388 4.168.192.in-addr.arpa, 5.168.192.in-addr.arpa, 6.168.192.in-addr.arpa, and 7.168.192.in-addr.arpa, and will be 389 correctly published as such. 390 391 =item revpatt 392 393 A string representing the pattern to use for an initial template record. 394 395 =item group 396 397 The group ID to add the zone to. 398 399 =item state 400 401 Active/inactive flag. Send C<active>, C<on>, or 1 for zones that should be published; C<inactive>, 402 C<off>, or C<0> for zones that should be added but not currently published. 403 404 =item defloc 405 406 Optional argument for the default location/view the zone's records should be published in. Leave blank, or a 407 list of locations can be retrieved with C<getLocList> or C<getLocDropdown> for selection. 408 409 =back 410 411 Returns the zone ID on success. 412 413 =cut 275 414 sub addRDNS { 276 415 my %args = @_; … … 287 426 #sub getZoneLocation {} 288 427 428 429 =head3 addGroup 430 431 Add a group 432 433 =over 4 434 435 =item groupname 436 437 The name for the new group 438 439 =item parent_id 440 441 The ID of the group to put the new group in 442 443 =back 444 445 Note that the RPC API does not currently expose the full DNSDB::addGroup interface; the permissions hashref is 446 substituted with a reasonable standard default user permissions allowing users to add/edit/delete zones and 447 records. 448 449 Returns literal 'OK' on success. 450 451 =cut 289 452 sub addGroup { 290 453 my %args = @_; … … 305 468 } 306 469 470 471 =head3 delGroup 472 473 Delete a group. The group must be empty of users, zones, or subgroups. 474 475 =over 4 476 477 =item group 478 479 The group name or group ID to delete 480 481 =back 482 483 Returns an informational message on success. 484 485 =cut 307 486 sub delGroup { 308 487 my %args = @_; … … 330 509 #sub groupID {} 331 510 511 512 =head3 addUser 513 514 Add a user. 515 516 =over 4 517 518 =item username 519 520 The username to add 521 522 =item group 523 524 The group ID to add the user in. Users in subgroups only have access to data in that group and its subgroups. 525 526 =item pass 527 528 The password for the account 529 530 =item state 531 532 Flag to indicate if the account should be active on creation or set to inactive. Accepts the same values as 533 domains and reverse zones - C<active>, C<on>, or C<1> for an active user, C<inactive>, C<off>, or C<0> for an 534 inactive one. 535 536 =back 537 538 B<Optional arguments> 539 540 =over 4 541 542 =item type 543 544 Type of user account to add. Current types are C<u> (normal user) and C<s> (superuser). Defaults to C<u>. 545 546 =item permstring 547 548 A string encoding the permissions a normal user receives. By default this is set to C<i> indicating 549 permissions are inherited from the group. 550 551 C<c:[digits]> clones permissions from user with id [digits] 552 553 C<C:,[string]> sets the exact permissions indicated by [string]. It is currently up to the caller to ensure 554 that related/cascading permissions are set correctly; see C<%DNSDB::permchains> for the current set. Current 555 valid permission identifiers match 556 C<(group|user|domain|record|location|self)_(edit|create|delete|locchg|view)>, however see C<@DNSDB::permtypes> 557 for the exact list. 558 559 The comma after the colon is not a typo. 560 561 =item fname 562 563 First name 564 565 =item lname 566 567 Last name 568 569 =item phone 570 571 Phone number 572 573 =back 574 575 Note that some user properties originate in DNS Administrator's inspiration, VegaDNS. 576 577 =cut 332 578 sub addUser { 333 579 my %args = @_; … … 355 601 #sub checkUser {} 356 602 603 604 =head3 updateUser 605 606 Update a user's username, password, state, type, first/last names, and/or phone number 607 608 Most arguments are the same as for addUser. 609 610 =over 4 611 612 =item uid 613 614 The ID of the user record 615 616 =item username 617 618 The username 619 620 =item group 621 622 The group ID the user is in (for logging). Users cannot currently be moved to a different group. 623 624 =item pass 625 626 An updated password, if provided. Leave blank to keep the existing password. 627 628 =item state 629 630 The account state (active/inactive). Takes the same values as addUser. 631 632 =item type 633 634 The account type (user [C<u>] or superuser [C<S>]) 635 636 =item fname 637 638 First name (optional) 639 640 =item lname 641 642 Last name (optional) 643 644 =item phone 645 646 Phone contact (optional) 647 648 =back 649 650 =cut 357 651 sub updateUser { 358 652 my %args = @_; … … 376 670 } 377 671 672 673 =head3 delUser 674 675 Delete a user 676 677 =over 4 678 679 =item uid 680 681 The ID of the user record to delete 682 683 =back 684 685 =cut 378 686 sub delUser { 379 687 my %args = @_; … … 398 706 #sub getLocList {} 399 707 708 709 =head3 getLocDropdown 710 711 Retrieve a list of locations for display in a dropdown. 712 713 =over 4 714 715 =item group 716 717 The group ID to select locations from 718 719 =item defloc 720 721 Optional argument to flag the "default" location in the list 722 723 =back 724 725 Returns an arrayref to a list of hashrefs with elements C<locname>, C<loc> and C<selected>. C<selected> will 726 be 0 for all entries unless the C<loc> value matches C<defloc>, where it will be set to 1. 727 728 =cut 400 729 sub getLocDropdown { 401 730 my %args = @_; … … 408 737 } 409 738 739 740 =head3 getSOA 741 742 Retrieve the SOA record for a zone 743 744 =over 4 745 746 =item defrec 747 748 Default/live records flag. Accepts C<y> and C<n>. 749 750 =item revrec 751 752 Forward/reverse flag. Accepts C<y> and C<n>. 753 754 =item id 755 756 The zone ID (if C<defrec> is C<y>) or the group ID (if C<defrec> is C<n>) to retrieve the SOA from 757 758 =back 759 760 =cut 410 761 sub getSOA { 411 762 my %args = @_; … … 428 779 #sub updateSOA {} 429 780 781 782 =head3 getRecLine 783 784 Retrieve all fields for a specific record 785 786 =over 4 787 788 =item defrec 789 790 Default/live records flag. Accepts C<y> and C<n>. 791 792 =item revrec 793 794 Forward/reverse flag. Accepts C<y> and C<n>. Mildly abused to determine whether to include C<distance>, 795 C<weight>, and C<port> fields, since MX and SRV records don't make much sense in reverse zones. 796 797 =item id 798 799 The record ID (if C<defrec> is C<y>) or default record ID (if C<defrec> is C<n>) to retrieve 800 801 =back 802 803 =cut 430 804 sub getRecLine { 431 805 my %args = @_; … … 442 816 } 443 817 818 819 =head3 getRecList 820 821 Retrieve a list of records for a zone. 822 823 =over 4 824 825 =item id 826 827 The zone ID (if C<defrec> is C<n>) or group ID (if C<defrec> is C<y>) to retrieve records from 828 829 =item defrec 830 831 Default/live records flag. Accepts C<y> and C<n>. 832 833 =item revrec 834 835 Forward/reverse flag. Accepts C<y> and C<n>. 836 837 =back 838 839 Optional arguments 840 841 =over 4 842 843 =item offset 844 845 Offset from the start of the raw record list. Mainly for pagination. Defaults 0. 846 847 =item nrecs 848 849 Number of records to return. Defaults to C<$DNSDB::perpage> 850 851 =item sortby 852 853 Sort field. Defaults to host for domain zones, val for reverse zones. Supports multifield sorts; pass the 854 fields in order separated by commas. 855 856 =item sortorder 857 858 SQL sort order. Defaults to C<ASC>. 859 860 =item filter 861 862 Return only records whose host or val fields match this string. 863 864 =item type, distance, weight, port, ttl, description 865 866 If these arguments are present, use the value to filter on that field. 867 868 =back 869 870 =cut 444 871 sub getRecList { 445 872 my %args = @_; … … 486 913 } 487 914 915 916 =head3 getRecCount 917 918 Return count of non-SOA records in zone (or default records in a group). 919 920 Uses the same arguments as getRecList, except for C<offset>, C<nrecs>, C<sortby>, and C<sortorder>. 921 922 =cut 488 923 sub getRecCount { 489 924 my %args = @_; … … 525 960 } # getRecCount() 526 961 962 963 =head3 addRec 964 965 Add a record to a zone or add a default record to a group. 966 967 Note that the name, type, and address arguments may be modified for normalization or to match available zones 968 for A+PTR and related metatypes. 969 970 =over 4 971 972 =item defrec 973 974 Default/live records flag. Accepts C<y> and C<n>. 975 976 =item revrec 977 978 Forward/reverse flag. Accepts C<y> and C<n>. 979 980 =item parent_id 981 982 The ID of the parent zone or group. 983 984 =item name 985 986 The fully-qualified hostname for the record. Trailing periods will automatically be stripped for storage, and 987 added on export as needed. Note that for reverse zone records, this is the nominal record target. 988 989 =item type 990 991 The record type. Both the nominal text identifiers and the bare integer types are accepted. 992 993 =item address 994 995 The record data or target. Note that for reverse zones this is the nominal .arpa name for the record. 996 997 =item ttl 998 999 The record TTL. 1000 1001 =item location 1002 1003 The location identifier for the record. 1004 1005 =item expires 1006 1007 Flag to indicate the record will either expire at a certain time or become active at a certain time. 1008 1009 =item stamp 1010 1011 The timestamp a record will expire or become active at. Note that depending on the DNS system in use this may 1012 not result in an exact expiry or activation time. 1013 1014 =back 1015 1016 B<Optional arguments> 1017 1018 =over 4 1019 1020 =item distance 1021 1022 MX and SRV distance or priority 1023 1024 =item weight 1025 1026 SRV weight 1027 1028 =item port 1029 1030 SRV port number 1031 1032 =back 1033 1034 =cut 527 1035 # The core sub uses references for some arguments to allow limited modification for 528 1036 # normalization or type+zone matching/mapping/availability. … … 556 1064 } # rpc_addRec 557 1065 1066 1067 =head3 updateRec 1068 1069 Update a record. 1070 1071 Takes the same arguments as C<addRec> except that C<id> is the record to update, not the primary parent zone ID. 1072 1073 If C<stamp> is blank or undefined, any timestamp will be removed. 1074 1075 =cut 558 1076 sub rpc_updateRec { 559 1077 my %args = @_; … … 590 1108 591 1109 1110 1111 =head3 addOrUpdateRevRec 1112 1113 Add or update a reverse DNS record (usually A+PTR template) as appropriate based on a passed CIDR address and 1114 hostname pattern. The record will automatically be downconverted to a PTR template if the forward zone 1115 referenced by the hostname pattern is not managed in this DNSAdmin instance. 1116 1117 =over 4 1118 1119 =item cidr 1120 1121 The CIDR address or IP for the record 1122 1123 =item name 1124 1125 The hostname pattern for template records, or the hostname for single IP records 1126 1127 =back 1128 1129 =cut 592 1130 # Takes a passed CIDR block and DNS pattern; adds a new record or updates the record(s) affected 593 1131 sub addOrUpdateRevRec { … … 685 1223 } # done addOrUpdateRevRec() 686 1224 1225 1226 =head3 updateRevSet 1227 1228 Update reverse DNS entries for a set of IP addresses all at once. Calls addOrUpdateRevRec internally. 1229 1230 =over 4 1231 1232 =item host_[ip.add.re.ss] (Multiple entries) 1233 1234 One or more identifiers for one or more IP addresses to update reverse DNS on. The value of the argument is the 1235 hostname to set on that IP. 1236 1237 =back 1238 1239 =cut 687 1240 # Update rDNS on a whole batch of IP addresses. Presented as a separate sub via RPC 688 1241 # since RPC calls can be s...l...o...w.... … … 715 1268 } # done updateRevSet() 716 1269 1270 1271 =head3 splitTemplate 1272 1273 Split a PTR template record into multiple records. 1274 1275 =over 4 1276 1277 =item cidr 1278 1279 The CIDR address for the record to split 1280 1281 =item newmask 1282 1283 The new masklength for the new records. 1284 1285 =back 1286 1287 =cut 717 1288 # Split a template record as per a passed CIDR. 718 1289 # Requires the CIDR and the new mask length … … 782 1353 } # done splitTemplate() 783 1354 1355 1356 =head3 resizeTemplate 1357 1358 Resize a template record based on a pair of passed CIDR addresses. 1359 1360 =over 4 1361 1362 =item oldcidr 1363 1364 The old CIDR to look for in the existing records 1365 1366 =item newcidr 1367 1368 The new CIDR 1369 1370 =back 1371 1372 =cut 784 1373 # Resize a template according to an old/new CIDR pair 785 1374 # Takes the old cidr in $args{oldcidr} and the new in $args{newcidr} … … 850 1439 } # done resizeTemplate() 851 1440 1441 1442 =head3 templatesToRecords 1443 1444 Convert one or more template records to individual IP records, expanding the template as would be done on 1445 export. 1446 1447 =over 4 1448 1449 =item templates 1450 1451 A list/array of CIDR addresses to search for for conversion. 1452 1453 =back 1454 1455 =cut 852 1456 # Convert one or more template records to a set of individual IP records. Expands the template. 853 1457 # Handle the case of nested templates, although the primary caller (IPDB) should not be … … 928 1532 } # done templatesToRecords() 929 1533 1534 1535 =head3 delRec 1536 1537 Delete a record. 1538 1539 =over 4 1540 1541 =item defrec 1542 1543 Default/live records flag. Accepts C<y> and C<n>. 1544 1545 =item revrec 1546 1547 Forward/reverse flag. Accepts C<y> and C<n>. Used for logging to pick the "primary" zone of the record. 1548 1549 =item id 1550 1551 The record to delete. 1552 1553 =back 1554 1555 =cut 930 1556 sub delRec { 931 1557 my %args = @_; … … 941 1567 } 942 1568 1569 1570 =head3 delByCIDR 1571 1572 Delete a record by CIDR address. 1573 1574 =over 4 1575 1576 =item cidr 1577 1578 The CIDR address for the record or record group to delete. 1579 1580 =back 1581 1582 B<Optional arguments> 1583 1584 =over 4 1585 1586 =item delforward (default 0/off) 1587 1588 Delete the matching A record on A+PTR and similar metarecords. 1589 1590 =item delsubs (default 0/off) 1591 1592 Delete all records within C<cidr>. Send C<y> if desired, otherwise it reverts to default even for other 1593 otherwise "true" values. 1594 1595 =item parpatt 1596 1597 Template pattern to add a replacement record if the delete removes all records from a reverse zone. 1598 1599 =back 1600 1601 =cut 943 1602 sub delByCIDR { 944 1603 my %args = @_; … … 1059 1718 } # end delByCIDR() 1060 1719 1720 1721 =head3 delRevSet 1722 1723 Delete a set of single-IP records similar to updateRevSet 1724 1725 =over 4 1726 1727 =item cidrlist 1728 1729 Simple comma-separated string containing the IP addresses that should be removed. 1730 1731 =back 1732 1733 =cut 1061 1734 # Batch-delete a set of reverse entries similar to updateRevSet 1062 1735 sub delRevSet { … … 1077 1750 #sub getLogEntries {} 1078 1751 1752 1753 =head3 getRevPattern 1754 1755 Get the pattern that would be applied to IPs in a CIDR range that do not have narrower patterns or separate 1756 individual reverse entries. 1757 1758 =over 4 1759 1760 =item cidr 1761 1762 The CIDR address range to find a pattern for. 1763 1764 =item group 1765 1766 The group to restrict reverse zone matches to. 1767 1768 =item location 1769 1770 The DNS view/location to restrict record matches to. 1771 1772 =back 1773 1774 =cut 1079 1775 sub getRevPattern { 1080 1776 my %args = @_; … … 1085 1781 } 1086 1782 1783 1784 =head3 getRevSet 1785 1786 Retrieve the set of per-IP reverse records within a CIDR range, if any. 1787 1788 Returns a list of hashes. 1789 1790 =over 4 1791 1792 =item cidr 1793 1794 The CIDR address range to find a pattern for. 1795 1796 =item group 1797 1798 The group to restrict reverse zone matches to. 1799 1800 =item location 1801 1802 The DNS view/location to restrict record matches to. 1803 1804 =back 1805 1806 =cut 1087 1807 sub getRevSet { 1088 1808 my %args = @_; … … 1093 1813 } 1094 1814 1815 1816 =head3 getTypelist 1817 1818 Retrieve a list of record types suitable for a dropdown form field. Returns only record types currently 1819 supported by DNSAdmin. 1820 1821 Returns a list of hashes. 1822 1823 =over 4 1824 1825 =item recgroup 1826 1827 Flag argument to determine which record types will be returned. Values not listed fall back to C<f>. 1828 1829 =over 4 1830 1831 =item r 1832 1833 Logical records commonly found in reverse zones (includes A+PTR and related metatypes) 1834 1835 =item l 1836 1837 Records that can actually be looked up in the DNS. 1838 1839 =item f 1840 1841 Logical records commonly found in forward zones (includes A+PTR and similar metatypes that include a forward 1842 record component). Append C<o> to exclude the metatypes. 1843 1844 =back 1845 1846 =item selected 1847 1848 Optional flag argument if a particular type should be "selected". Sets the C<tselect> key on that entry. Note 1849 that the passed type will always be present in the returned list, even if it wouldn't be otherwise - eg, PTR 1850 template if C<recgroup> is set to C<fo>, or SRV if C<recgroup> is set to C<r>. 1851 1852 =back 1853 1854 =cut 1095 1855 sub getTypelist { 1096 1856 my %args = @_; … … 1102 1862 } 1103 1863 1864 1865 =head3 getTypemap 1866 1867 Return DNS record type hash mapping DNS integer type values to text names 1868 1869 =cut 1104 1870 sub getTypemap { 1105 1871 my %args = @_; … … 1108 1874 } 1109 1875 1876 1877 =head3 getReverse_typemap 1878 1879 Return DNS record type hash mapping text names to integer type values 1880 1881 =cut 1110 1882 sub getReverse_typemap { 1111 1883 my %args = @_; … … 1117 1889 #sub isParent {} 1118 1890 1891 1892 =head3 zoneStatus 1893 1894 Get or set the status of a zone. Returns the status of the zone. 1895 1896 =over 4 1897 1898 =item zoneid 1899 1900 The ID of the zone to get or set status on 1901 1902 =back 1903 1904 B<Optional arguments> 1905 1906 =over 4 1907 1908 =item reverse 1909 1910 Set to C<y> if you want to get/set the status for a reverse zone 1911 1912 =item status 1913 1914 Pass C<0> or C<domoff> to set the zone to inactive; C<1> or C<domon> to set it to active 1915 1916 =back 1917 1918 =cut 1119 1919 sub zoneStatus { 1120 1920 my %args = @_; … … 1128 1928 my $status = $dnsdb->zoneStatus(@arglist); 1129 1929 } 1930 1931 1932 =head3 getZonesByCIDR 1933 1934 Get a list of reverse zones within a passed CIDR block. Returns a list of hashes. 1935 1936 =over 4 1937 1938 =item cidr 1939 1940 The CIDR range to look for reverse zones in 1941 1942 =back 1943 1944 =cut 1130 1945 1131 1946 # Get a list of hashes referencing the reverse zone(s) for a passed CIDR block … … 1150 1965 return \@methods; 1151 1966 } 1967 1968 1969 # and we're done. close the POD 1970 1971 #back
Note:
See TracChangeset
for help on using the changeset viewer.