Freebox thin client
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

268 lines
19KB

  1. """
  2. Module dedicated to API spec
  3. """
  4. from collections import namedtuple
  5. from . import utils
  6. _DISC_HTTP_URL = "http://mafreebox.freebox.fr"
  7. _DISC_MDNS_NAME = "_fbx-api._tcp.local."
  8. class _M(namedtuple("Method", ('url', 'doc', 'args'))):
  9. """
  10. Accessor class for API methods
  11. """
  12. __slots__ = ()
  13. @property
  14. def http_method(self):
  15. return self.url.split()[0]
  16. @property
  17. def endpoint(self):
  18. return self.url.split()[1]
  19. def __str__(self):
  20. return "%s\n\nUrl parameters: %s\nPost data:%s" % (
  21. self.doc, ",".join(utils.get_params(self.endpoint)), ",".join(self.args))
  22. SYSTEMS = {
  23. "Download": {
  24. "Retrieve_a_Download_task": _M("GET downloads/", "Retrieve a Download task", []),
  25. "Delete_a_Download_task": _M("DELETE downloads/{id}", "Delete a Download task", []),
  26. "Update_a_Download_task": _M("PUT downloads/{id}", "Update a Download task", ["PostData"]),
  27. "Get_download_log": _M("GET downloads/{id}/log", "Get download log", []),
  28. "Adding_a_new_Download_task": _M("POST downloads/add", "Adding a new Download task", ["PostData"]),
  29. },
  30. "Download_Feeds": {
  31. "Get_the_list_of_all_download_Feeds": _M("GET downloads/feeds/", "Get the list of all download Feeds", []),
  32. "Get_a_download_Feed": _M("GET downloads/feeds/{id}", "Get a download Feed", []),
  33. "Add_a_Download_Feed": _M("POST downloads/feeds/", "Add a Download Feed", ["PostData"]),
  34. "Delete_Download_Feed": _M("DELETE downloads/feeds/{id}", "Delete Download Feed", []),
  35. "Update_a_Download_Feed": _M("PUT downloads/feeds/{id}", "Update a Download Feed", ["PostData"]),
  36. "Refresh_a_Download_Feed": _M("POST downloads/feeds/{id}/fetch", "Refresh a Download Feed", ["PostData"]),
  37. "Refresh_all_Download_Feeds": _M("POST downloads/feeds/fetch", "Refresh all Download Feeds", ["PostData"]),
  38. "Get_the_items_of_a_given_RSS_feed": _M("GET downloads/feeds/{feed_id}/items/", "Get the items of a given RSS feed", []),
  39. "Update_a_feed_item": _M("PUT downloads/feeds/{feed_id}/items/{item_id}", "Update a feed item", ["PostData"]),
  40. "Download_a_feed_item": _M("POST downloads/feeds/{feed_id}/items/{item_id}/download", "Download a feed item", ["PostData"]),
  41. "Mark_all_items_as_read": _M("POST downloads/feeds/{feed_id}/items/mark_all_as_read", "Mark all items as read", ["PostData"]),
  42. },
  43. "Download_Config": {
  44. "Updating_the_download_config": _M("PUT downloads/config/", "Updating the Download Config", ["PostData"]),
  45. "Updating_the_current_Throttling_mode": _M("PUT downloads/throttling", "Updating the current Throttling mode", ["PostData"]),
  46. },
  47. "Fs": {
  48. "List_every_tasks": _M("GET fs/tasks/", "List every tasks", []),
  49. "List_a_task": _M("GET fs/tasks/{id}", "List a task", []),
  50. "Delete_a_task": _M("DELETE fs/tasks/{id}", "Delete a task", []),
  51. "Update_a_task": _M("PUT fs/tasks/{id}", "Update a task", ["PostData"]),
  52. "List_files": _M("GET fs/ls/{path}", "List files", []),
  53. "Get_file_information": _M("GET fs/info/{path}", "Get file information", []),
  54. "Conflict_resolution": _M("POST fs/mv/", "Conflict resolution", ["PostData"]),
  55. "Move_files": _M("POST fs/mv/", "Move files", ["PostData"]),
  56. "Copy_files": _M("POST fs/cp/", "Copy files", ["PostData"]),
  57. "Remove_files": _M("POST fs/rm/", "Remove files", ["PostData"]),
  58. "Cat_files": _M("POST fs/cat/", "Cat files", ["PostData"]),
  59. "Create_an_archive": _M("POST fs/archive/", "Create an archive", ["PostData"]),
  60. "Extract_a_file": _M("POST fs/extract/", "Extract a file", ["PostData"]),
  61. "Repair_a_file": _M("POST fs/repair/", "Repair a file", ["PostData"]),
  62. "Hash_a_file": _M("POST fs/hash/", "Hash a file", ["PostData"]),
  63. "Create_a_directory": _M("POST fs/mkdir/", "Create a directory", ["PostData"]),
  64. "Rename_a_file_folder": _M("POST fs/rename/", "Rename a file/folder", ["PostData"]),
  65. "Download_a_file": _M("GET dl/{path}", "Download a file", []),
  66. },
  67. "Share": {
  68. "Retrieve_a_File_Sharing_link": _M("GET share_link/", "Retrieve a File Sharing link", []),
  69. "Delete_a_File_Sharing_link": _M("DELETE share_link/{token}", "Delete a File Sharing link", []),
  70. "Create_a_File_Sharing_link": _M("POST share_link/", "Create a File Sharing link", ["PostData"]),
  71. },
  72. "Upload": {
  73. "File_Upload_example": _M("GET ws/upload", "File Upload example", []),
  74. "Get_the_list_of_uploads": _M("GET upload/", "Get the list of uploads", []),
  75. "Track_an_upload_status": _M("GET upload/{id}", "Track an upload status", []),
  76. "Cancel_an_upload": _M("DELETE upload/{id}/cancel", "Cancel an upload", []),
  77. "Delete_an_upload": _M("DELETE upload/{id}", "Delete an upload", []),
  78. "Cleanup_all_terminated_uploads": _M("DELETE upload/clean", "Cleanup all terminated uploads", []),
  79. },
  80. "Airmedia": {
  81. "Get_the_current_AirMedia_configuration": _M("GET airmedia/config/", "Get the current AirMedia configuration", []),
  82. "Update_the_current_AirMedia_configuration": _M("PUT airmedia/config/", "Update the current AirMedia configuration", ["PostData"]),
  83. "Get_the_list_of_available_AirMedia_receivers": _M("GET airmedia/receivers/", "Get the list of available AirMedia receivers", []),
  84. },
  85. "Rrd": {
  86. },
  87. "Call": {
  88. "List_every_calls": _M("GET call/log/", "List every calls", []),
  89. "Delete_every_calls": _M("POST call/log/delete_all/", "Delete every calls", ["PostData"]),
  90. "Mark_every_calls_as_read": _M("POST call/log/mark_all_as_read/", "Mark every calls as read", ["PostData"]),
  91. "Access_a_given_call_entry": _M("GET call/log/{id}", "Access a given call entry", []),
  92. "Delete_a_call": _M("DELETE call/log/{id}", "Delete a call", []),
  93. "Update_a_call_entry": _M("PUT call/log/{id}", "Update a call entry", ["PostData"]),
  94. },
  95. "Contacts": {
  96. "Get_a_list_of_contacts": _M("GET contact/", "Get a list of contacts", []),
  97. "Access_a_given_contact_entry": _M("GET contact/{id}", "Access a given contact entry", []),
  98. "Create_a_contact": _M("POST contact/", "Create a contact", ["PostData"]),
  99. "Delete_a_contact": _M("DELETE contact/{id}", "Delete a contact", []),
  100. "Update_a_contact_entry": _M("PUT contact/{id}", "Update a contact entry", ["PostData"]),
  101. "Get_the_list_of_numbers_for_a_given_contact": _M("GET contact/{contact_id}/[numbers|addresses|urls|emails]/", "Get the list of numbers for a given contact", []),
  102. "Access_a_given_contact_number": _M("GET [number,address,url,email]/{id}", "Access a given contact number", []),
  103. "Create_a_contact_number": _M("POST [number,address,url,email]/", "Create a contact number", ["PostData"]),
  104. "Delete_a_contact_number": _M("DELETE [number,address,url,email]/{id}", "Delete a contact number", []),
  105. "Update_a_contact_number": _M("PUT [number,address,url,email]/{id}", "Update a contact number", ["PostData"]),
  106. },
  107. "Connection": {
  108. "Get_the_current_Connection_status": _M("GET connection/", "Get the current Connection status", []),
  109. "Get_the_current_Connection_configuration": _M("GET connection/config/", "Get the current Connection configuration", []),
  110. "Update_the_Connection_configuration": _M("PUT connection/config/", "Update the Connection configuration", ["PostData"]),
  111. "Get_the_current_IPv6_Connection_configuration": _M("GET connection/ipv6/config/", "Get the current IPv6 Connection configuration", []),
  112. "Update_the_IPv6_Connection_configuration": _M("PUT connection/ipv6/config/", "Update the IPv6 Connection configuration", ["PostData"]),
  113. "Get_the_current_xDSL_infos": _M("GET connection/xdsl/", "Get the current xDSL infos", []),
  114. "Get_the_current_FTTH_status": _M("GET connection/ftth/", "Get the current FTTH status", []),
  115. "Get_the_status_of_a_DynDNS_service": _M("GET connection/ddns/{provider}/status/", "Get the status of a DynDNS service", []),
  116. "Get_the_config_of_a_DynDNS_service": _M("GET connection/ddns/{provider}/", "Get the config of a DynDNS service", []),
  117. "Set_the_config_of_a_DynDNS_service": _M("PUT connection/ddns/{provider}/", "Set the config of a DynDNS service", ["PostData"]),
  118. },
  119. "Lan": {
  120. "Get_the_current_Lan_configuration": _M("GET lan/config/", "Get the current Lan configuration", []),
  121. "Update_the_current_Lan_configuration": _M("PUT lan/config/", "Update the current Lan configuration", ["PostData"]),
  122. },
  123. "Freeplug": {
  124. "Get_the_current_Freeplugs_networks": _M("GET freeplug/", "Get the current Freeplugs networks", []),
  125. "Get_a_particular_Freeplug_information": _M("GET freeplug/{id}/", "Get a particular Freeplug information", []),
  126. "Reset_a_Freeplug": _M("POST freeplug/{id}/reset/", "Reset a Freeplug", []),
  127. },
  128. "Dhcp": {
  129. "Get_the_current_DHCP_configuration": _M("GET dhcp/config/", "Get the current DHCP configuration", []),
  130. "Update_the_current_DHCP_configuration": _M("PUT dhcp/config/", "Update the current DHCP configuration", ["PostData"]),
  131. "Get_the_list_of_DHCP_static_leases": _M("GET dhcp/static_lease/", "Get the list of DHCP static leases", []),
  132. "Get_a_given_DHCP_static_lease": _M("GET dhcp/static_lease/{id}", "Get a given DHCP static lease", []),
  133. "Update_DHCP_static_lease": _M("PUT dhcp/static_lease/{id}", "Update DHCP static lease", ["PostData"]),
  134. "Delete_a_DHCP_static_lease": _M("DELETE dhcp/static_lease/{id}", "Delete a DHCP static lease", []),
  135. "Add_a_DHCP_static_lease": _M("POST dhcp/static_lease/", "Add a DHCP static lease", ["PostData"]),
  136. "Get_the_list_of_DHCP_dynamic_leases": _M("GET dhcp/dynamic_lease/", "Get the list of DHCP dynamic leases", []),
  137. },
  138. "Ftp": {
  139. "Get_the_current_Ftp_configuration": _M("GET ftp/config/", "Get the current Ftp configuration", []),
  140. "Update_the_FTP_configuration": _M("PUT ftp/config/", "Update the FTP configuration", ["PostData"]),
  141. },
  142. "Nat": {
  143. "Get_the_current_Dmz_configuration": _M("GET fw/dmz/", "Get the current Dmz configuration", []),
  144. "Update_the_current_Dmz_configuration": _M("PUT fw/dmz/", "Update the current Dmz configuration", ["PostData"]),
  145. },
  146. "Igd": {
  147. "Get_the_current_UPnP_IGD_configuration": _M("GET upnpigd/config/", "Get the current UPnP IGD configuration", []),
  148. "Update_the_UPnP_IGD_configuration": _M("PUT upnpigd/config/", "Update the UPnP IGD configuration", ["PostData"]),
  149. "Get_the_list_of_current_redirection": _M("GET upnpigd/redir/", "Get the list of current redirection", []),
  150. "Delete_a_redirection": _M("DELETE upnpigd/redir/{id}", "Delete a redirection", []),
  151. },
  152. "Lcd": {
  153. "Get_the_current_LCD_configuration": _M("GET lcd/config/", "Get the current LCD configuration", []),
  154. "Update_the_lcd_configuration": _M("PUT lcd/config/", "Update the lcd configuration", ["PostData"]),
  155. },
  156. "Network_Share": {
  157. "Get_the_current_Samba_configuration": _M("GET netshare/samba/", "Get the current Samba configuration", []),
  158. "Update_the_Samba_configuration": _M("PUT netshare/samba/", "Update the Samba configuration", ["PostData"]),
  159. "Get_the_current_Afp_configuration": _M("GET netshare/afp/", "Get the current Afp configuration", []),
  160. "Update_the_Afp_configuration": _M("PUT netshare/afp/", "Update the Afp configuration", ["PostData"]),
  161. },
  162. "Upnpav": {
  163. "Get_the_current_UPnP_AV_configuration": _M("GET upnpav/config/", "Get the current UPnP AV configuration", []),
  164. "Update_the_UPnP_AV_configuration": _M("PUT upnpav/config/", "Update the UPnP AV configuration", ["PostData"]),
  165. },
  166. "Switch": {
  167. "Get_the_current_switch_status": _M("GET switch/status/", "Get the current switch status", []),
  168. "Get_a_port_configuration": _M("GET switch/port/{id}", "Get a port configuration", []),
  169. "Update_a_port_configuration": _M("PUT switch/port/{id}", "Update a port configuration", ["PostData"]),
  170. "Get_a_port_stats": _M("GET switch/port/{id}/stats", "Get a port stats", []),
  171. },
  172. "Wifi": {
  173. "Get_the_current_WiFi_global_configuration": _M("GET wifi/config/", "Get the current Wi-Fi global configuration", []),
  174. "Update_the_WiFi_global_configuration": _M("PUT wifi/config/", "Update the Wi-Fi global configuration", ["PostData"]),
  175. "WiFi_AP_API": _M("GET wifi/ap/", "Wi-Fi AP API", []),
  176. "Get_WiFi_Stations_List": _M("GET wifi/ap/{id}/stations/", "Get Wi-Fi Stations List", []),
  177. "WiFi_BSS_API": _M("GET wifi/bss/", "Wi-Fi BSS API", []),
  178. "List_AP_neighbors": _M("GET wifi/ap/{id}/neighbors/", "List AP neighbors", []),
  179. "List_WiFi_channels_usage": _M("GET wifi/ap/{id}/channel_usage/", "List Wi-Fi channels usage", []),
  180. "Refresh_radar_informations": _M("POST wifi/ap/{id}/neighbors/scan", "Refresh radar informations", ["PostData"]),
  181. "Get_WiFi_Planning": _M("GET wifi/planning/", "Get Wi-Fi Planning", []),
  182. "Update_WiFi_Planning": _M("PUT wifi/planning/", "Update Wi-Fi Planning", ["PostData"]),
  183. "Get_the_MAC_filter_list": _M("GET wifi/mac_filter/", "Get the MAC filter list", []),
  184. "Getting_a_particular_MAC_filter": _M("GET wifi/mac_filter/{filter_id}", "Getting a particular MAC filter", []),
  185. "Updating_a_MAC_filter": _M("PUT wifi/mac_filter/{filter_id}", "Updating a MAC filter", ["PostData"]),
  186. "Delete_a_MAC_filter": _M("DELETE wifi/mac_filter/{filter_id}", "Delete a MAC filter", []),
  187. "Create_a_new_MAC_filter": _M("POST wifi/mac_filter/", "Create a new MAC filter", ["PostData"]),
  188. },
  189. "System": {
  190. "Get_the_current_system_info": _M("GET system/", "Get the current system info [UNSTABLE]", []),
  191. "Reboot_the_system": _M("POST system/reboot/", "Reboot the system", []),
  192. },
  193. "Vpn": {
  194. "VPN_Server_List_API": _M("GET vpn/", "VPN Server List API", []),
  195. "Get_a_VPN_config": _M("GET vpn/{vpn_id}/config/", "Get a VPN config", []),
  196. "Update_the_VPN_configuration": _M("PUT vpn/openvpn_routed/config/", "Update the VPN configuration", ["PostData"]),
  197. "VPN_Server_User_List": _M("GET vpn/user/", "VPN Server User List", []),
  198. "Get_a_VPN_user": _M("GET vpn/user/{login}", "Get a VPN user", []),
  199. "Add_a_VPN_User": _M("POST vpn/user/", "Add a VPN User", ["PostData"]),
  200. "Delete_a_VPN_User": _M("DELETE vpn/user/{login}", "Delete a VPN User", []),
  201. "Update_a_VPN_User": _M("PUT vpn/user/{login}", "Update a VPN User", ["PostData"]),
  202. "Get_the_VPN_server_IP_pool_reservations": _M("GET vpn/ip_pool/", "Get the VPN server IP pool reservations", []),
  203. "Get_the_list_of_connections": _M("GET vpn/connection/", "Get the list of connections", []),
  204. "Close_a_given_connection": _M("DELETE vpn/connection/{id}", "Close a given connection", []),
  205. "Donwload_a_user_configuration_file": _M("GET vpn/download_config/{server_name}/{login}", "Donwload a user configuration file", []),
  206. },
  207. "Vpn_Client": {
  208. "Get_VPN_Client_configuration_list": _M("GET vpn_client/config/", "Get VPN Client configuration list", []),
  209. "Get_a_VPN_client_config": _M("GET vpn_client/config/{id}", "Get a VPN client config", []),
  210. "Add_a_VPN_client_configuration": _M("POST vpn_client/config/", "Add a VPN client configuration", ["PostData"]),
  211. "Delete_a_VPN_client_Configuration": _M("DELETE vpn_client/config/{id}", "Delete a VPN client Configuration", []),
  212. "Update_the_VPN_client_configuration": _M("PUT vpn_client/config/{id}", "Update the VPN client configuration", ["PostData"]),
  213. "Get_the_VPN_client_status": _M("GET vpn_client/status", "Get the VPN client status", []),
  214. "Get_the_VPN_client_logs": _M("GET vpn_client/log", "Get the VPN client logs", []),
  215. },
  216. "Storage": {
  217. "Get_the_list_of_disks": _M("GET storage/disk/", "Get the list of disks", []),
  218. "Get_a_given_disk_info": _M("GET storage/disk/{id}", "Get a given disk info", []),
  219. "Update_a_disk_state": _M("PUT storage/disk/{id}", "Update a disk state", ["PostData"]),
  220. "Format_a_disk": _M("PUT storage/disk/{id}/format/", "Format a disk", ["PostData"]),
  221. "Get_the_list_of_partitions": _M("GET storage/partition/", "Get the list of partitions", []),
  222. "Get_a_given_partition_info": _M("GET storage/partition/{id}", "Get a given partition info", []),
  223. "Update_a_partition_state": _M("PUT storage/partition/{id}", "Update a partition state", ["PostData"]),
  224. "Check_a_partition": _M("PUT storage/partition/{id}/check/", "Check a partition", ["PostData"]),
  225. "Get_the_current_storage_configuration": _M("GET storage/config/", "Get the current storage configuration", []),
  226. "Update_the_External_Storage_configuration": _M("PUT storage/config/", "Update the External Storage configuration", ["PostData"]),
  227. },
  228. "Parental": {
  229. "Get_parental_filter_config": _M("GET parental/config/", "Get parental filter config", []),
  230. "Update_parental_filter_config": _M("PUT parental/config/", "Update parental filter config", ["PostData"]),
  231. "Retrieve_all_Parental_Filter_rules": _M("GET parental/filter/", "Retrieve all Parental Filter rules", []),
  232. "Retrieve_a_Parental_Filter_rule": _M("GET parental/filter/{id}", "Retrieve a Parental Filter rule", []),
  233. "Delete_a_Parental_Filter_rule": _M("DELETE parental/filter/{id}", "Delete a Parental Filter rule", []),
  234. "Update_a_Parental_Filter_rule": _M("PUT parental/filter/{id}", "Update a Parental Filter rule", ["PostData"]),
  235. "Add_a_Parental_Filter_rule": _M("POST parental/filter/", "Add a Parental Filter rule", ["PostData"]),
  236. "Get_a_parental_filter_Planning": _M("GET parental/filter/{id}/planning", "Get a parental filter Planning", []),
  237. "Update_a_parental_filter_Planning": _M("PUT parental/filter/{id}/planning", "Update a parental filter Planning", ["PostData"]),
  238. },
  239. "Pvr": {
  240. "Get_the_current_PVR_configuration": _M("GET pvr/config/", "Get the current PVR configuration", []),
  241. "Update_the_current_PVR_configuration": _M("PUT pvr/config/", "Update the current PVR configuration", ["PostData"]),
  242. "Getting_the_current_quota_info": _M("GET pvr/quota/", "Getting the current quota info", []),
  243. "Request_next_quota_threshold": _M("PUT pvr/quota/", "Request next quota threshold", ["PostData"]),
  244. "Getting_the_list_of_precords": _M("GET pvr/programmed/", "Getting the list of precords", []),
  245. "Getting_a_specific_precord": _M("GET pvr/programmed/{id}", "Getting a specific precord", []),
  246. "Updating_a_precord": _M("PUT pvr/programmed/{id}", "Updating a precord", ["PostData"]),
  247. "Delete_a_precord": _M("DELETE pvr/programmed/{id}", "Delete a precord", []),
  248. "Create_a_precord": _M("POST pvr/programmed/", "Create a precord", ["PostData"]),
  249. "Getting_the_list_of_frecords": _M("GET pvr/finished/", "Getting the list of frecords", []),
  250. "Getting_a_specific_frecord": _M("GET pvr/finished/{id}", "Getting a specific frecord", []),
  251. "Updating_a_frecord": _M("PUT pvr/finished/{id}", "Updating a frecord", ["PostData"]),
  252. "Delete_a_frecord": _M("DELETE pvr/finished/{id}", "Delete a frecord", []),
  253. "Getting_the_list_of_media": _M("GET pvr/media/", "Getting the list of media", []),
  254. },
  255. "Tv": {
  256. "Getting_the_list_of_channels": _M("GET tv/channels/", "Getting the list of channels", [])
  257. }
  258. }