Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
OpnSense
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
OpnSense
Commits
2ab4d047
Commit
2ab4d047
authored
Mar 18, 2015
by
Ad Schellevis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
work in progress backup
parent
fc568d7c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
9 deletions
+32
-9
config.lib.inc
src/etc/inc/config.lib.inc
+32
-9
No files found.
src/etc/inc/config.lib.inc
View file @
2ab4d047
...
...
@@ -444,14 +444,15 @@ function backup_to_google_drive() {
if
(
$cnf
->
isValid
())
{
$config
=
$cnf
->
object
()
;
if
(
isset
(
$config
->
system
->
remotebackup
)
&&
isset
(
$config
->
system
->
remotebackup
->
GDriveEnabled
)
&&
$config
->
system
->
remotebackup
->
GDriveEnabled
==
"on"
){
$client
->
login
(
$config
->
system
->
remotebackup
->
GDriveEmail
,
$config
->
system
->
remotebackup
->
GDriveP12key
);
// backup
config
$client
->
login
(
$config
->
system
->
remotebackup
->
GDriveEmail
->
__toString
(),
$config
->
system
->
remotebackup
->
GDriveP12key
->
__toString
()
);
// backup
source data and target name
$target_filename
=
"config-"
.
time
()
.
".xml"
;
$confdata
=
encrypt_data
(
file_get_contents
(
'/conf/config.xml'
),
$config
->
system
->
remotebackup
->
GDrivePassword
)
;
$client
->
upload
(
$config
->
system
->
remotebackup
->
GDriveFolderID
,
$target_filename
,
$confdata
);
$confdata
=
file_get_contents
(
'/conf/config.xml'
)
;
$confdata_enc
=
encrypt_data
(
$confdata
,
$config
->
system
->
remotebackup
->
GDrivePassword
->
__toString
())
;
// cleanup old files
$files
=
$client
->
listFiles
(
$config
->
system
->
remotebackup
->
GDriveFolderID
);
$files
=
$client
->
listFiles
(
$config
->
system
->
remotebackup
->
GDriveFolderID
->
__toString
()
);
$configfiles
=
array
();
foreach
(
$files
as
$file
)
{
if
(
fnmatch
(
"config-*.xml"
,
$file
[
'title'
]))
{
...
...
@@ -460,14 +461,36 @@ function backup_to_google_drive() {
}
krsort
(
$configfiles
);
foreach
(
$configfiles
as
$filename
=>
$file
)
{
print
(
$filename
.
"
\n
"
);
if
(
isset
(
$config
->
system
->
remotebackup
->
GDriveBackupCount
)
&&
is_numeric
(
$config
->
system
->
remotebackup
->
GDriveBackupCount
))
{
$fcount
=
0
;
foreach
(
$configfiles
as
$filename
=>
$file
)
{
if
(
$fcount
>
$config
->
system
->
remotebackup
->
GDriveBackupCount
)
{
$client
->
delete
(
$file
);
}
$fcount
++
;
}
}
// print_r($configfiles);
// backup new file if changed (or first)
if
(
count
(
$configfiles
)
>
1
)
{
// compare last backup with current, only save new
$bck_data_enc
=
$client
->
download
(
$configfiles
[
array_keys
(
$configfiles
)[
0
]]);
$bck_data
=
decrypt_data
(
$bck_data_enc
,
$config
->
system
->
remotebackup
->
GDrivePassword
->
__toString
());
if
(
$bck_data
!=
$confdata
)
{
// backup
$configfiles
[
$target_filename
]
=
$client
->
upload
(
$config
->
system
->
remotebackup
->
GDriveFolderID
->
__toString
(),
$target_filename
,
$confdata
);
}
}
else
{
// first file, do backup
$configfiles
[
$target_filename
]
=
$client
->
upload
(
$config
->
system
->
remotebackup
->
GDriveFolderID
->
__toString
(),
$target_filename
,
$confdata
);
}
return
$configfiles
;
}
}
return
array
();
}
register_shutdown_function
(
'pfSense_clear_globals'
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment