-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored all HTTP logic (cleaned up debug logic, log body if smalle…
…r than 4096 bytes) Implemented support for Softaculous (for WordPress) Implemented support for PHP version retrieval and modification Implemented support for downloading files Implemented support for creating, retrieving, and restoring backups Implemented support for retrieving messages
- Loading branch information
Showing
26 changed files
with
806 additions
and
278 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
package directadmin | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"net/url" | ||
) | ||
|
||
// CreateBackup (user) creates an account backup for the given domain, and the given items | ||
func (c *UserContext) CreateBackup(domain string, backupItems ...string) error { | ||
var response apiGenericResponse | ||
|
||
body := url.Values{} | ||
body.Set("action", "backup") | ||
body.Set("domain", domain) | ||
body.Set("form_version", "4") | ||
|
||
for index, backupItem := range backupItems { | ||
body.Set(fmt.Sprintf("select%d", index), backupItem) | ||
} | ||
|
||
if _, err := c.makeRequestOld(http.MethodPost, "SITE_BACKUP", body, &response); err != nil { | ||
return err | ||
} | ||
|
||
if response.Success != "Backup creation added to queue" { | ||
return fmt.Errorf("failed to create backup: %v", response.Result) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// CreateBackupAllItems (user) wraps around CreateBackup and provides all available backup items | ||
func (c *UserContext) CreateBackupAllItems(domain string) error { | ||
return c.CreateBackup( | ||
domain, | ||
"domain", | ||
"subdomain", | ||
"email", | ||
"email_data", | ||
"emailsettings", | ||
"forwarder", | ||
"autoresponder", | ||
"vacation", | ||
"list", | ||
"ftp", | ||
"ftpsettings", | ||
"database", | ||
"database_data", | ||
"trash", | ||
) | ||
} | ||
|
||
// GetBackups (user) returns an array of the session user's backups for the given domain | ||
func (c *UserContext) GetBackups(domain string) ([]string, error) { | ||
var backups []string | ||
|
||
if _, err := c.makeRequestOld(http.MethodGet, "SITE_BACKUP?domain="+domain+"&ipp=50", nil, &backups); err != nil { | ||
return nil, err | ||
} | ||
|
||
return backups, nil | ||
} | ||
|
||
// RestoreBackup (user) restores an account backup for the given domain, and the given items | ||
func (c *UserContext) RestoreBackup(domain string, backupFilename string, backupItems ...string) error { | ||
var response apiGenericResponse | ||
|
||
body := url.Values{} | ||
body.Set("action", "restore") | ||
body.Set("domain", domain) | ||
body.Set("file", backupFilename) | ||
body.Set("form_version", "3") | ||
|
||
for index, backupItem := range backupItems { | ||
body.Set(fmt.Sprintf("select%d", index), backupItem) | ||
} | ||
|
||
if _, err := c.makeRequestOld(http.MethodPost, "SITE_BACKUP", body, &response); err != nil { | ||
return err | ||
} | ||
|
||
if response.Success != "Restore will run in the background" { | ||
return fmt.Errorf("failed to restore backup: %v", response.Result) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// RestoreBackupAllItems (user) wraps around RestoreBackup and provides all available backup items | ||
func (c *UserContext) RestoreBackupAllItems(domain string, backupFilename string) error { | ||
return c.RestoreBackup( | ||
domain, | ||
backupFilename, | ||
"domain", | ||
"subdomain", | ||
"email", | ||
"email_data", | ||
"emailsettings", | ||
"forwarder", | ||
"autoresponder", | ||
"vacation", | ||
"list", | ||
"ftp", | ||
"ftpsettings", | ||
"database", | ||
"database_data", | ||
"trash", | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.