| Server IP : 202.155.9.250 / Your IP : 216.73.216.236 Web Server : LiteSpeed System : Linux srv339029361 5.15.0-177-generic #187-Ubuntu SMP Sat Apr 11 22:54:33 UTC 2026 x86_64 User : lucky4072 ( 1024) PHP Version : 8.0.30 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /usr/local/CyberPanel/lib/python3.10/site-packages/examples/ |
Upload File : |
#!/usr/bin/env python
"""Cloudflare API code - example"""
import os
import sys
import time
# sys.path.insert(0, os.path.abspath('..'))
import CloudFlare
def main():
# Code up ...
# cli4 /accounts/::00000000000000000000000000000000/rules/lists/::00000000000000000000000000000000/items
try:
account_id = sys.argv[1]
list_id = sys.argv[2]
except IndexError:
exit('usage: example_account_rules_lists_items.py account_id list_id')
with CloudFlare.CloudFlare() as cf:
#
# Print existing list - showing GET function
#
print('EXISTING LIST LOOKS LIKE:')
items = cf.accounts.rules.lists.items(account_id, list_id)
for item in items:
print('%s %s %s %-30s ; %s' % (item['id'], item['created_on'], item['modified_on'], item['ip'], item['comment']))
print('')
#
# Add an element to list - showing POST function
#
new_ip_address = '4.4.4.4'
new_ip_comment = 'all the fours!'
new_ip_id = None
print('ADD TO LIST:')
new_r = cf.accounts.rules.lists.items.post(account_id, list_id, data=[{'ip':new_ip_address,'comment':new_ip_comment}])
print('new_r = %s' % (new_r))
print('')
#
# So it seems that it takes a while for the database to update; this is delay is a hack
#
time.sleep(1)
#
# Print the full list again - to show POST worked
#
print('NEW LIST LOOKS LIKE:')
items = cf.accounts.rules.lists.items(account_id, list_id)
for item in items:
print('%s %s %s %-30s ; %s' % (item['id'], item['created_on'], item['modified_on'], item['ip'], item['comment']))
if item['ip'] == new_ip_address:
new_ip_id = item['id']
print('')
#
# Now remove that element - to show DELETE function (note the use of new_ip_id value
#
print('DELETE FROM LIST:')
if new_ip_id is None:
exit(' --- NOTHING TO DELETE')
del_r = cf.accounts.rules.lists.items.delete(account_id, list_id, data={'items':[{'id':new_ip_id}]})
print('del_r = %s' % (del_r))
print('')
#
# So it seems that it takes a while for the database to update; this is delay is a hack
#
time.sleep(1)
#
# Print the full list again - to show DELETE worked
#
print('FINAL LIST LOOKS LIKE:')
items = cf.accounts.rules.lists.items(account_id, list_id)
for item in items:
print('%s %s %s %-30s ; %s' % (item['id'], item['created_on'], item['modified_on'], item['ip'], item['comment']))
print('')
exit(0)
if __name__ == '__main__':
main()