mirror of
				https://github.com/taigrr/godns
				synced 2025-01-18 04:03:25 -08:00 
			
		
		
		
	Merge pull request #51 from TimothyYe/cf
add API token support for Cloudflare
This commit is contained in:
		
						commit
						14bce004f6
					
				
							
								
								
									
										24
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										24
									
								
								README.md
									
									
									
									
									
								
							@ -112,7 +112,9 @@ Usage of ./godns:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
### Config example for Cloudflare
 | 
					### Config example for Cloudflare
 | 
				
			||||||
 | 
					
 | 
				
			||||||
For Cloudflare, you need to provide email & Global API Key as password, and config all the domains & subdomains.
 | 
					For Cloudflare, you need to provide the email & Global API Key as password (or to use the API token) and config all the domains & subdomains.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					* Using email & Global API Key
 | 
				
			||||||
 | 
					
 | 
				
			||||||
```json
 | 
					```json
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@ -133,6 +135,26 @@ For Cloudflare, you need to provide email & Global API Key as password, and conf
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					* Using the API Token
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```json
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  "provider": "Cloudflare",
 | 
				
			||||||
 | 
					  "login_token": "API Token",
 | 
				
			||||||
 | 
					  "domains": [{
 | 
				
			||||||
 | 
					      "domain_name": "example.com",
 | 
				
			||||||
 | 
					      "sub_domains": ["www","test"]
 | 
				
			||||||
 | 
					    },{
 | 
				
			||||||
 | 
					      "domain_name": "example2.com",
 | 
				
			||||||
 | 
					      "sub_domains": ["www","test"]
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  ],
 | 
				
			||||||
 | 
					  "ip_url": "https://myip.biturl.top",
 | 
				
			||||||
 | 
					  "interval": 300,
 | 
				
			||||||
 | 
					  "socks5_proxy": ""
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### Config example for DNSPod
 | 
					### Config example for DNSPod
 | 
				
			||||||
 | 
					
 | 
				
			||||||
For DNSPod, you need to provide your API Token(you can create it [here](https://www.dnspod.cn/console/user/security)), and config all the domains & subdomains.
 | 
					For DNSPod, you need to provide your API Token(you can create it [here](https://www.dnspod.cn/console/user/security)), and config all the domains & subdomains.
 | 
				
			||||||
 | 
				
			|||||||
@ -146,8 +146,14 @@ func (handler *Handler) newRequest(method, url string, body io.Reader) (*http.Re
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	req, _ := http.NewRequest(method, handler.API+url, body)
 | 
						req, _ := http.NewRequest(method, handler.API+url, body)
 | 
				
			||||||
	req.Header.Set("Content-Type", "application/json")
 | 
						req.Header.Set("Content-Type", "application/json")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if handler.Configuration.Email != "" && handler.Configuration.Password != "" {
 | 
				
			||||||
		req.Header.Set("X-Auth-Email", handler.Configuration.Email)
 | 
							req.Header.Set("X-Auth-Email", handler.Configuration.Email)
 | 
				
			||||||
		req.Header.Set("X-Auth-Key", handler.Configuration.Password)
 | 
							req.Header.Set("X-Auth-Key", handler.Configuration.Password)
 | 
				
			||||||
 | 
						} else if handler.Configuration.LoginToken != "" {
 | 
				
			||||||
 | 
							req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", handler.Configuration.LoginToken))
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return req, client
 | 
						return req, client
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										2
									
								
								utils.go
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								utils.go
									
									
									
									
									
								
							@ -196,12 +196,14 @@ func CheckSettings(config *Settings) error {
 | 
				
			|||||||
			return errors.New("password cannot be empty")
 | 
								return errors.New("password cannot be empty")
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	} else if config.Provider == CLOUDFLARE {
 | 
						} else if config.Provider == CLOUDFLARE {
 | 
				
			||||||
 | 
							if config.LoginToken == "" {
 | 
				
			||||||
			if config.Email == "" {
 | 
								if config.Email == "" {
 | 
				
			||||||
				return errors.New("email cannot be empty")
 | 
									return errors.New("email cannot be empty")
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			if config.Password == "" {
 | 
								if config.Password == "" {
 | 
				
			||||||
				return errors.New("password cannot be empty")
 | 
									return errors.New("password cannot be empty")
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	} else if config.Provider == ALIDNS {
 | 
						} else if config.Provider == ALIDNS {
 | 
				
			||||||
		if config.Email == "" {
 | 
							if config.Email == "" {
 | 
				
			||||||
			return errors.New("email cannot be empty")
 | 
								return errors.New("email cannot be empty")
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user