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.

594 lines
19 KiB

7 years ago
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3. /*
  4. |--------------------------------------------------------------------------
  5. | HTTP protocol
  6. |--------------------------------------------------------------------------
  7. |
  8. | Set to force the use of HTTPS for REST API calls
  9. |
  10. */
  11. $config['force_https'] = FALSE;
  12. /*
  13. |--------------------------------------------------------------------------
  14. | REST Output Format
  15. |--------------------------------------------------------------------------
  16. |
  17. | The default format of the response
  18. |
  19. | 'array': Array data structure
  20. | 'csv': Comma separated file
  21. | 'json': Uses json_encode(). Note: If a GET query string
  22. | called 'callback' is passed, then jsonp will be returned
  23. | 'html' HTML using the table library in CodeIgniter
  24. | 'php': Uses var_export()
  25. | 'serialized': Uses serialize()
  26. | 'xml': Uses simplexml_load_string()
  27. |
  28. */
  29. $config['rest_default_format'] = 'json';
  30. /*
  31. |--------------------------------------------------------------------------
  32. | REST Supported Output Formats
  33. |--------------------------------------------------------------------------
  34. |
  35. | The following setting contains a list of the supported/allowed formats.
  36. | You may remove those formats that you don't want to use.
  37. | If the default format $config['rest_default_format'] is missing within
  38. | $config['rest_supported_formats'], it will be added silently during
  39. | REST_Controller initialization.
  40. |
  41. */
  42. $config['rest_supported_formats'] = [
  43. 'json',
  44. 'array',
  45. 'csv',
  46. 'html',
  47. 'jsonp',
  48. 'php',
  49. 'serialized',
  50. 'xml',
  51. ];
  52. /*
  53. |--------------------------------------------------------------------------
  54. | REST Status Field Name
  55. |--------------------------------------------------------------------------
  56. |
  57. | The field name for the status inside the response
  58. |
  59. */
  60. $config['rest_status_field_name'] = 'status';
  61. /*
  62. |--------------------------------------------------------------------------
  63. | REST Message Field Name
  64. |--------------------------------------------------------------------------
  65. |
  66. | The field name for the message inside the response
  67. |
  68. */
  69. $config['rest_message_field_name'] = 'error';
  70. /*
  71. |--------------------------------------------------------------------------
  72. | Enable Emulate Request
  73. |--------------------------------------------------------------------------
  74. |
  75. | Should we enable emulation of the request (e.g. used in Mootools request)
  76. |
  77. */
  78. $config['enable_emulate_request'] = TRUE;
  79. /*
  80. |--------------------------------------------------------------------------
  81. | REST Realm
  82. |--------------------------------------------------------------------------
  83. |
  84. | Name of the password protected REST API displayed on login dialogs
  85. |
  86. | e.g: My Secret REST API
  87. |
  88. */
  89. $config['rest_realm'] = 'REST API';
  90. /*
  91. |--------------------------------------------------------------------------
  92. | REST Login
  93. |--------------------------------------------------------------------------
  94. |
  95. | Set to specify the REST API requires to be logged in
  96. |
  97. | FALSE No login required
  98. | 'basic' Unsecure login
  99. | 'digest' More secure login
  100. | 'session' Check for a PHP session variable. See 'auth_source' to set the
  101. | authorization key
  102. |
  103. */
  104. $config['rest_auth'] = FALSE;
  105. /*
  106. |--------------------------------------------------------------------------
  107. | REST Login Source
  108. |--------------------------------------------------------------------------
  109. |
  110. | Is login required and if so, the user store to use
  111. |
  112. | '' Use config based users or wildcard testing
  113. | 'ldap' Use LDAP authentication
  114. | 'library' Use a authentication library
  115. |
  116. | Note: If 'rest_auth' is set to 'session' then change 'auth_source' to the name of the session variable
  117. |
  118. */
  119. $config['auth_source'] = 'ldap';
  120. /*
  121. |--------------------------------------------------------------------------
  122. | Allow Authentication and API Keys
  123. |--------------------------------------------------------------------------
  124. |
  125. | Where you wish to have Basic, Digest or Session login, but also want to use API Keys (for limiting
  126. | requests etc), set to TRUE;
  127. |
  128. */
  129. $config['allow_auth_and_keys'] = TRUE;
  130. /*
  131. |--------------------------------------------------------------------------
  132. | REST Login Class and Function
  133. |--------------------------------------------------------------------------
  134. |
  135. | If library authentication is used define the class and function name
  136. |
  137. | The function should accept two parameters: class->function($username, $password)
  138. | In other cases override the function _perform_library_auth in your controller
  139. |
  140. | For digest authentication the library function should return already a stored
  141. | md5(username:restrealm:password) for that username
  142. |
  143. | e.g: md5('admin:REST API:1234') = '1e957ebc35631ab22d5bd6526bd14ea2'
  144. |
  145. */
  146. $config['auth_library_class'] = '';
  147. $config['auth_library_function'] = '';
  148. /*
  149. |--------------------------------------------------------------------------
  150. | Override auth types for specific class/method
  151. |--------------------------------------------------------------------------
  152. |
  153. | Set specific authentication types for methods within a class (controller)
  154. |
  155. | Set as many config entries as needed. Any methods not set will use the default 'rest_auth' config value.
  156. |
  157. | e.g:
  158. |
  159. | $config['auth_override_class_method']['deals']['view'] = 'none';
  160. | $config['auth_override_class_method']['deals']['insert'] = 'digest';
  161. | $config['auth_override_class_method']['accounts']['user'] = 'basic';
  162. | $config['auth_override_class_method']['dashboard']['*'] = 'none|digest|basic';
  163. |
  164. | Here 'deals', 'accounts' and 'dashboard' are controller names, 'view', 'insert' and 'user' are methods within. An asterisk may also be used to specify an authentication method for an entire classes methods. Ex: $config['auth_override_class_method']['dashboard']['*'] = 'basic'; (NOTE: leave off the '_get' or '_post' from the end of the method name)
  165. | Acceptable values are; 'none', 'digest' and 'basic'.
  166. |
  167. */
  168. // $config['auth_override_class_method']['deals']['view'] = 'none';
  169. // $config['auth_override_class_method']['deals']['insert'] = 'digest';
  170. // $config['auth_override_class_method']['accounts']['user'] = 'basic';
  171. // $config['auth_override_class_method']['dashboard']['*'] = 'basic';
  172. // ---Uncomment list line for the wildard unit test
  173. // $config['auth_override_class_method']['wildcard_test_cases']['*'] = 'basic';
  174. /*
  175. |--------------------------------------------------------------------------
  176. | Override auth types for specfic 'class/method/HTTP method'
  177. |--------------------------------------------------------------------------
  178. |
  179. | example:
  180. |
  181. | $config['auth_override_class_method_http']['deals']['view']['get'] = 'none';
  182. | $config['auth_override_class_method_http']['deals']['insert']['post'] = 'none';
  183. | $config['auth_override_class_method_http']['deals']['*']['options'] = 'none';
  184. */
  185. // ---Uncomment list line for the wildard unit test
  186. // $config['auth_override_class_method_http']['wildcard_test_cases']['*']['options'] = 'basic';
  187. /*
  188. |--------------------------------------------------------------------------
  189. | REST Login Usernames
  190. |--------------------------------------------------------------------------
  191. |
  192. | Array of usernames and passwords for login, if ldap is configured this is ignored
  193. |
  194. */
  195. $config['rest_valid_logins'] = ['admin' => '1234'];
  196. /*
  197. |--------------------------------------------------------------------------
  198. | Global IP Whitelisting
  199. |--------------------------------------------------------------------------
  200. |
  201. | Limit connections to your REST server to whitelisted IP addresses
  202. |
  203. | Usage:
  204. | 1. Set to TRUE and select an auth option for extreme security (client's IP
  205. | address must be in whitelist and they must also log in)
  206. | 2. Set to TRUE with auth set to FALSE to allow whitelisted IPs access with no login
  207. | 3. Set to FALSE but set 'auth_override_class_method' to 'whitelist' to
  208. | restrict certain methods to IPs in your whitelist
  209. |
  210. */
  211. $config['rest_ip_whitelist_enabled'] = FALSE;
  212. /*
  213. |--------------------------------------------------------------------------
  214. | REST IP Whitelist
  215. |--------------------------------------------------------------------------
  216. |
  217. | Limit connections to your REST server with a comma separated
  218. | list of IP addresses
  219. |
  220. | e.g: '123.456.789.0, 987.654.32.1'
  221. |
  222. | 127.0.0.1 and 0.0.0.0 are allowed by default
  223. |
  224. */
  225. $config['rest_ip_whitelist'] = '';
  226. /*
  227. |--------------------------------------------------------------------------
  228. | Global IP Blacklisting
  229. |--------------------------------------------------------------------------
  230. |
  231. | Prevent connections to the REST server from blacklisted IP addresses
  232. |
  233. | Usage:
  234. | 1. Set to TRUE and add any IP address to 'rest_ip_blacklist'
  235. |
  236. */
  237. $config['rest_ip_blacklist_enabled'] = FALSE;
  238. /*
  239. |--------------------------------------------------------------------------
  240. | REST IP Blacklist
  241. |--------------------------------------------------------------------------
  242. |
  243. | Prevent connections from the following IP addresses
  244. |
  245. | e.g: '123.456.789.0, 987.654.32.1'
  246. |
  247. */
  248. $config['rest_ip_blacklist'] = '';
  249. /*
  250. |--------------------------------------------------------------------------
  251. | REST Database Group
  252. |--------------------------------------------------------------------------
  253. |
  254. | Connect to a database group for keys, logging, etc. It will only connect
  255. | if you have any of these features enabled
  256. |
  257. */
  258. $config['rest_database_group'] = 'default';
  259. /*
  260. |--------------------------------------------------------------------------
  261. | REST API Keys Table Name
  262. |--------------------------------------------------------------------------
  263. |
  264. | The table name in your database that stores API keys
  265. |
  266. */
  267. $config['rest_keys_table'] = 'keys';
  268. /*
  269. |--------------------------------------------------------------------------
  270. | REST Enable Keys
  271. |--------------------------------------------------------------------------
  272. |
  273. | When set to TRUE, the REST API will look for a column name called 'key'.
  274. | If no key is provided, the request will result in an error. To override the
  275. | column name see 'rest_key_column'
  276. |
  277. | Default table schema:
  278. | CREATE TABLE `keys` (
  279. | `id` INT(11) NOT NULL AUTO_INCREMENT,
  280. | `user_id` INT(11) NOT NULL,
  281. | `key` VARCHAR(40) NOT NULL,
  282. | `level` INT(2) NOT NULL,
  283. | `ignore_limits` TINYINT(1) NOT NULL DEFAULT '0',
  284. | `is_private_key` TINYINT(1) NOT NULL DEFAULT '0',
  285. | `ip_addresses` TEXT NULL DEFAULT NULL,
  286. | `date_created` INT(11) NOT NULL,
  287. | PRIMARY KEY (`id`)
  288. | ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  289. |
  290. */
  291. $config['rest_enable_keys'] = FALSE;
  292. /*
  293. |--------------------------------------------------------------------------
  294. | REST Table Key Column Name
  295. |--------------------------------------------------------------------------
  296. |
  297. | If not using the default table schema in 'rest_enable_keys', specify the
  298. | column name to match e.g. my_key
  299. |
  300. */
  301. $config['rest_key_column'] = 'key';
  302. /*
  303. |--------------------------------------------------------------------------
  304. | REST API Limits method
  305. |--------------------------------------------------------------------------
  306. |
  307. | Specify the method used to limit the API calls
  308. |
  309. | Available methods are :
  310. | $config['rest_limits_method'] = 'IP_ADDRESS'; // Put a limit per ip address
  311. | $config['rest_limits_method'] = 'API_KEY'; // Put a limit per api key
  312. | $config['rest_limits_method'] = 'METHOD_NAME'; // Put a limit on method calls
  313. | $config['rest_limits_method'] = 'ROUTED_URL'; // Put a limit on the routed URL
  314. |
  315. */
  316. $config['rest_limits_method'] = 'ROUTED_URL';
  317. /*
  318. |--------------------------------------------------------------------------
  319. | REST Key Length
  320. |--------------------------------------------------------------------------
  321. |
  322. | Length of the created keys. Check your default database schema on the
  323. | maximum length allowed
  324. |
  325. | Note: The maximum length is 40
  326. |
  327. */
  328. $config['rest_key_length'] = 40;
  329. /*
  330. |--------------------------------------------------------------------------
  331. | REST API Key Variable
  332. |--------------------------------------------------------------------------
  333. |
  334. | Custom header to specify the API key
  335. | Note: Custom headers with the X- prefix are deprecated as of
  336. | 2012/06/12. See RFC 6648 specification for more details
  337. |
  338. */
  339. $config['rest_key_name'] = 'X-API-KEY';
  340. /*
  341. |--------------------------------------------------------------------------
  342. | REST Enable Logging
  343. |--------------------------------------------------------------------------
  344. |
  345. | When set to TRUE, the REST API will log actions based on the column names 'key', 'date',
  346. | 'time' and 'ip_address'. This is a general rule that can be overridden in the
  347. | $this->method array for each controller
  348. |
  349. | Default table schema:
  350. | CREATE TABLE `logs` (
  351. | `id` INT(11) NOT NULL AUTO_INCREMENT,
  352. | `uri` VARCHAR(255) NOT NULL,
  353. | `method` VARCHAR(6) NOT NULL,
  354. | `params` TEXT DEFAULT NULL,
  355. | `api_key` VARCHAR(40) NOT NULL,
  356. | `ip_address` VARCHAR(45) NOT NULL,
  357. | `time` INT(11) NOT NULL,
  358. | `rtime` FLOAT DEFAULT NULL,
  359. | `authorized` VARCHAR(1) NOT NULL,
  360. | `response_code` smallint(3) DEFAULT '0',
  361. | PRIMARY KEY (`id`)
  362. | ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  363. |
  364. */
  365. $config['rest_enable_logging'] = FALSE;
  366. /*
  367. |--------------------------------------------------------------------------
  368. | REST API Logs Table Name
  369. |--------------------------------------------------------------------------
  370. |
  371. | If not using the default table schema in 'rest_enable_logging', specify the
  372. | table name to match e.g. my_logs
  373. |
  374. */
  375. $config['rest_logs_table'] = 'logs';
  376. /*
  377. |--------------------------------------------------------------------------
  378. | REST Method Access Control
  379. |--------------------------------------------------------------------------
  380. | When set to TRUE, the REST API will check the access table to see if
  381. | the API key can access that controller. 'rest_enable_keys' must be enabled
  382. | to use this
  383. |
  384. | Default table schema:
  385. | CREATE TABLE `access` (
  386. | `id` INT(11) unsigned NOT NULL AUTO_INCREMENT,
  387. | `key` VARCHAR(40) NOT NULL DEFAULT '',
  388. | `all_access` TINYINT(1) NOT NULL DEFAULT '0',
  389. | `controller` VARCHAR(50) NOT NULL DEFAULT '',
  390. | `date_created` DATETIME DEFAULT NULL,
  391. | `date_modified` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  392. | PRIMARY KEY (`id`)
  393. | ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  394. |
  395. */
  396. $config['rest_enable_access'] = FALSE;
  397. /*
  398. |--------------------------------------------------------------------------
  399. | REST API Access Table Name
  400. |--------------------------------------------------------------------------
  401. |
  402. | If not using the default table schema in 'rest_enable_access', specify the
  403. | table name to match e.g. my_access
  404. |
  405. */
  406. $config['rest_access_table'] = 'access';
  407. /*
  408. |--------------------------------------------------------------------------
  409. | REST API Param Log Format
  410. |--------------------------------------------------------------------------
  411. |
  412. | When set to TRUE, the REST API log parameters will be stored in the database as JSON
  413. | Set to FALSE to log as serialized PHP
  414. |
  415. */
  416. $config['rest_logs_json_params'] = FALSE;
  417. /*
  418. |--------------------------------------------------------------------------
  419. | REST Enable Limits
  420. |--------------------------------------------------------------------------
  421. |
  422. | When set to TRUE, the REST API will count the number of uses of each method
  423. | by an API key each hour. This is a general rule that can be overridden in the
  424. | $this->method array in each controller
  425. |
  426. | Default table schema:
  427. | CREATE TABLE `limits` (
  428. | `id` INT(11) NOT NULL AUTO_INCREMENT,
  429. | `uri` VARCHAR(255) NOT NULL,
  430. | `count` INT(10) NOT NULL,
  431. | `hour_started` INT(11) NOT NULL,
  432. | `api_key` VARCHAR(40) NOT NULL,
  433. | PRIMARY KEY (`id`)
  434. | ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  435. |
  436. | To specify the limits within the controller's __construct() method, add per-method
  437. | limits with:
  438. |
  439. | $this->method['METHOD_NAME']['limit'] = [NUM_REQUESTS_PER_HOUR];
  440. |
  441. | See application/controllers/api/example.php for examples
  442. */
  443. $config['rest_enable_limits'] = FALSE;
  444. /*
  445. |--------------------------------------------------------------------------
  446. | REST API Limits Table Name
  447. |--------------------------------------------------------------------------
  448. |
  449. | If not using the default table schema in 'rest_enable_limits', specify the
  450. | table name to match e.g. my_limits
  451. |
  452. */
  453. $config['rest_limits_table'] = 'limits';
  454. /*
  455. |--------------------------------------------------------------------------
  456. | REST Ignore HTTP Accept
  457. |--------------------------------------------------------------------------
  458. |
  459. | Set to TRUE to ignore the HTTP Accept and speed up each request a little.
  460. | Only do this if you are using the $this->rest_format or /format/xml in URLs
  461. |
  462. */
  463. $config['rest_ignore_http_accept'] = FALSE;
  464. /*
  465. |--------------------------------------------------------------------------
  466. | REST AJAX Only
  467. |--------------------------------------------------------------------------
  468. |
  469. | Set to TRUE to allow AJAX requests only. Set to FALSE to accept HTTP requests
  470. |
  471. | Note: If set to TRUE and the request is not AJAX, a 505 response with the
  472. | error message 'Only AJAX requests are accepted.' will be returned.
  473. |
  474. | Hint: This is good for production environments
  475. |
  476. */
  477. $config['rest_ajax_only'] = FALSE;
  478. /*
  479. |--------------------------------------------------------------------------
  480. | REST Language File
  481. |--------------------------------------------------------------------------
  482. |
  483. | Language file to load from the language directory
  484. |
  485. */
  486. $config['rest_language'] = 'korean';
  487. /*
  488. |--------------------------------------------------------------------------
  489. | CORS Check
  490. |--------------------------------------------------------------------------
  491. |
  492. | Set to TRUE to enable Cross-Origin Resource Sharing (CORS). Useful if you
  493. | are hosting your API on a different domain from the application that
  494. | will access it through a browser
  495. |
  496. */
  497. $config['check_cors'] = FALSE;
  498. /*
  499. |--------------------------------------------------------------------------
  500. | CORS Allowable Headers
  501. |--------------------------------------------------------------------------
  502. |
  503. | If using CORS checks, set the allowable headers here
  504. |
  505. */
  506. $config['allowed_cors_headers'] = [
  507. 'Origin',
  508. 'X-Requested-With',
  509. 'Content-Type',
  510. 'Accept',
  511. 'Access-Control-Request-Method'
  512. ];
  513. /*
  514. |--------------------------------------------------------------------------
  515. | CORS Allowable Methods
  516. |--------------------------------------------------------------------------
  517. |
  518. | If using CORS checks, you can set the methods you want to be allowed
  519. |
  520. */
  521. $config['allowed_cors_methods'] = [
  522. 'GET',
  523. 'POST',
  524. 'OPTIONS',
  525. 'PUT',
  526. 'PATCH',
  527. 'DELETE'
  528. ];
  529. /*
  530. |--------------------------------------------------------------------------
  531. | CORS Allow Any Domain
  532. |--------------------------------------------------------------------------
  533. |
  534. | Set to TRUE to enable Cross-Origin Resource Sharing (CORS) from any
  535. | source domain
  536. |
  537. */
  538. $config['allow_any_cors_domain'] = FALSE;
  539. /*
  540. |--------------------------------------------------------------------------
  541. | CORS Allowable Domains
  542. |--------------------------------------------------------------------------
  543. |
  544. | Used if $config['check_cors'] is set to TRUE and $config['allow_any_cors_domain']
  545. | is set to FALSE. Set all the allowable domains within the array
  546. |
  547. | e.g. $config['allowed_origins'] = ['http://www.example.com', 'https://spa.example.com']
  548. |
  549. */
  550. $config['allowed_cors_origins'] = [];