mirror of
				https://github.com/billz/raspap-webgui.git
				synced 2025-03-01 10:31:47 +00:00 
			
		
		
		
	Merge pull request #1334 from RaspAP/feat/resetbtn
Feature: Restore settings
This commit is contained in:
		
							
								
								
									
										35
									
								
								ajax/networking/do_sys_reset.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								ajax/networking/do_sys_reset.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,35 @@ | ||||
| <?php | ||||
|  | ||||
| require_once '../../includes/config.php'; | ||||
| require_once '../../includes/session.php'; | ||||
| require_once '../../includes/functions.php'; | ||||
|  | ||||
| if (isset($_POST['csrf_token'])) { | ||||
|     if (csrfValidateRequest() && !CSRFValidate()) { | ||||
|         handleInvalidCSRFToken(); | ||||
|     } | ||||
|     $return = 0; | ||||
|     $path = "../../config"; | ||||
|     $configs = array( | ||||
|         array("src" => $path .'/hostapd.conf', "tmp" => "/tmp/hostapddata", "dest" => RASPI_HOSTAPD_CONFIG), | ||||
|         array("src" => $path .'/dhcpcd.conf', "tmp" => "/tmp/dhcpddata", "dest" => RASPI_DHCPCD_CONFIG), | ||||
|         array("src" => $path .'/090_wlan0.conf', "tmp" => "/tmp/dnsmasqdata", "dest" => RASPI_DNSMASQ_PREFIX.'wlan0.conf'), | ||||
|         array("src" => $path .'/090_raspap.conf', "tmp" => "/tmp/dnsmasqdata", "dest" => RASPI_DNSMASQ_PREFIX.'raspap.conf'), | ||||
|     ); | ||||
|      | ||||
|     foreach ($configs as $config) { | ||||
|         try { | ||||
|             $tmp = file_get_contents($config["src"]); | ||||
|             file_put_contents($config["tmp"], $tmp); | ||||
|             system("sudo cp ".$config["tmp"]. " ".$config["dest"]); | ||||
|         } catch (Exception $e) { | ||||
|             $return = $e->getCode(); | ||||
|         } | ||||
|     } | ||||
|     $jsonData = ['return'=>$return]; | ||||
|     echo json_encode($jsonData); | ||||
|  | ||||
| } else { | ||||
|     handleInvalidCSRFToken(); | ||||
| } | ||||
|  | ||||
| @@ -20,7 +20,6 @@ function createNetmaskAddr(bitCount) { | ||||
| function loadSummary(strInterface) { | ||||
|     $.post('ajax/networking/get_ip_summary.php',{interface:strInterface},function(data){ | ||||
|         jsonData = JSON.parse(data); | ||||
|         console.log(jsonData); | ||||
|         if(jsonData['return'] == 0) { | ||||
|             $('#'+strInterface+'-summary').html(jsonData['output'].join('<br />')); | ||||
|         } else if(jsonData['return'] == 2) { | ||||
| @@ -322,6 +321,27 @@ $('#ovpn-userpw,#ovpn-certs').on('click', function (e) { | ||||
|     } | ||||
| }); | ||||
|  | ||||
| $('#js-system-reset-confirm').on('click', function (e) { | ||||
|     var progressText = $('#js-system-reset-confirm').attr('data-message'); | ||||
|     var successHtml = $('#system-reset-message').attr('data-message'); | ||||
|     var closeHtml = $('#js-system-reset-cancel').attr('data-message'); | ||||
|     var csrfToken = $('meta[name=csrf_token]').attr('content'); | ||||
|     var progressHtml = $('<div>').text(progressText).html() + '<i class="fas fa-cog fa-spin ml-2"></i>'; | ||||
|     $('#system-reset-message').html(progressHtml); | ||||
|     $.post('ajax/networking/do_sys_reset.php?',{'csrf_token':csrfToken},function(data){ | ||||
|         setTimeout(function(){ | ||||
|             jsonData = JSON.parse(data); | ||||
|             if(jsonData['return'] == 0) { | ||||
|                 $('#system-reset-message').text(successHtml); | ||||
|             } else { | ||||
|                 $('#system-reset-message').text('Error occured: '+ jsonData['return']); | ||||
|             } | ||||
|             $("#js-system-reset-confirm").hide(); | ||||
|             $("#js-system-reset-cancel").text(closeHtml); | ||||
|         },750); | ||||
|     }); | ||||
| }); | ||||
|  | ||||
| $(document).ready(function(){ | ||||
|   $("#PanelManual").hide(); | ||||
| }); | ||||
| @@ -464,7 +484,6 @@ window.addEventListener('load', function() { | ||||
|     // Loop over them and prevent submission | ||||
|     var validation = Array.prototype.filter.call(forms, function(form) { | ||||
|         form.addEventListener('submit', function(event) { | ||||
|           //console.log(event.submitter); | ||||
|           if (form.checkValidity() === false) { | ||||
|             event.preventDefault(); | ||||
|             event.stopPropagation(); | ||||
|   | ||||
										
											Binary file not shown.
										
									
								
							| @@ -758,7 +758,36 @@ msgstr "OS" | ||||
| msgid "Kernel" | ||||
| msgstr "Kernel" | ||||
|  | ||||
| #: includes/themes.php | ||||
| msgid "System reset" | ||||
| msgstr "System reset" | ||||
|  | ||||
| msgid "Reset RaspAP to its initial configuration? This action cannot be undone." | ||||
| msgstr "Reset RaspAP to its initial configuration? This action cannot be undone." | ||||
|  | ||||
| msgid "Reset complete. Restart the hotspot for the changes to take effect." | ||||
| msgstr "Reset complete. Restart the hotspot for the changes to take effect." | ||||
|  | ||||
| msgid "System reset in progress..." | ||||
| msgstr "System reset in progress..." | ||||
|  | ||||
| msgid "Reset" | ||||
| msgstr "Reset" | ||||
|  | ||||
| msgid "Restore settings" | ||||
| msgstr "Restore settings" | ||||
|  | ||||
| msgid "To reset RaspAP to its <a href=\"%s\">initial configuration</a>, click or tap the button below." | ||||
| msgstr "To reset RaspAP to its <a href=\"%s\">initial configuration</a>, click or tap the button below." | ||||
|  | ||||
| msgid "Custom files for optional components such as Ad Blocking, WireGuard or OpenVPN will remain on the system." | ||||
| msgstr "Custom files for optional components such as Ad Blocking, WireGuard or OpenVPN will remain on the system." | ||||
|  | ||||
| msgid "Perform reset" | ||||
| msgstr "Perform reset" | ||||
|  | ||||
| msgid "Restores all access point (AP) service settings to their default values. This applies to hostapd, dhcpcd and dnsmasq." | ||||
| msgstr "Restores all access point (AP) service settings to their default values. This applies to hostapd, dhcpcd and dnsmasq." | ||||
|  | ||||
| msgid "Theme settings" | ||||
| msgstr "Theme settings" | ||||
|  | ||||
|   | ||||
| @@ -17,6 +17,7 @@ | ||||
|           <li role="presentation" class="nav-item"><a class="nav-link" id="languagetab" href="#language" aria-controls="language" role="tab" data-toggle="tab"><?php echo _("Language"); ?></a></li> | ||||
|           <li role="presentation" class="nav-item"><a class="nav-link" id="themetab" href="#theme" aria-controls="theme" role="tab" data-toggle="tab"><?php echo _("Theme"); ?></a></li> | ||||
|           <li role="presentation" class="nav-item"><a class="nav-link" id="advancedtab" href="#advanced" aria-controls="advanced" role="tab" data-toggle="tab"><?php echo _("Advanced"); ?></a></li> | ||||
|           <li role="presentation" class="nav-item"><a class="nav-link" id="resettab" href="#reset" aria-controls="reset" role="tab" data-toggle="tab"><?php echo _("Reset"); ?></a></li> | ||||
|         </ul> | ||||
|           <!-- Tab panes --> | ||||
|           <div class="tab-content"> | ||||
| @@ -24,6 +25,7 @@ | ||||
|             <?php echo renderTemplate("system/language", $__template_data) ?> | ||||
|             <?php echo renderTemplate("system/theme", $__template_data) ?> | ||||
|             <?php echo renderTemplate("system/advanced", $__template_data) ?> | ||||
|             <?php echo renderTemplate("system/reset", $__template_data) ?> | ||||
|           </div><!-- /.tab-content --> | ||||
|         </form> | ||||
|       </div><!-- /.card-body --> | ||||
| @@ -31,3 +33,22 @@ | ||||
|     </div><!-- /.card --> | ||||
|   </div><!-- /.col-lg-12 --> | ||||
| </div><!-- /.row --> | ||||
|  | ||||
| <!-- modal confirm-reset--> | ||||
| <div class="modal fade" id="system-confirm-reset" tabindex="-1" role="dialog" aria-labelledby="ModalLabel" aria-hidden="true"> | ||||
|   <div class="modal-dialog" role="document"> | ||||
|     <div class="modal-content"> | ||||
|       <div class="modal-header"> | ||||
|       <div class="modal-title" id="ModalLabel"><i class="fas fa-history mr-2"></i><?php echo _("System reset"); ?></div> | ||||
|       </div> | ||||
|       <div class="modal-body"> | ||||
|         <div class="col-md-12 mb-3 mt-1" data-message="<?php echo _("Reset complete. Restart the hotspot for the changes to take effect."); ?>" id="system-reset-message"><?php echo _("Reset RaspAP to its initial configuration? This action cannot be undone."); ?></div> | ||||
|       </div> | ||||
|       <div class="modal-footer"> | ||||
|       <button type="button" id="js-system-reset-cancel" data-message="<?php echo _("Close"); ?>" class="btn btn-outline-secondary" data-dismiss="modal"><?php echo _("Cancel"); ?></button> | ||||
|       <button type="button" id="js-system-reset-confirm" data-message="<?php echo _("System reset in progress..."); ?>" class="btn btn-outline-danger btn-delete"><?php echo _("Reset"); ?></button> | ||||
|       </div> | ||||
|     </div> | ||||
|   </div> | ||||
| </div> | ||||
|  | ||||
|   | ||||
							
								
								
									
										21
									
								
								templates/system/reset.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								templates/system/reset.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,21 @@ | ||||
| <!-- reset tab --> | ||||
| <div role="tabpanel" class="tab-pane" id="reset"> | ||||
|   <h4 class="mt-3"><?php echo _("Restore settings") ;?></h4> | ||||
|     <?php if (!RASPI_MONITOR_ENABLED) : ?> | ||||
|     <?php echo CSRFTokenFieldTag() ?> | ||||
|       <div class="row"> | ||||
|         <div class="form-group col-lg-8 col-md-8"> | ||||
|           <label for="cbxhwmode"> | ||||
|             <?php echo sprintf(_("To reset RaspAP to its <a href=\"%s\">initial configuration</a>, click or tap the button below."), "https://docs.raspap.com/defaults/"); ;?> | ||||
|           </label> | ||||
|           <?php getTooltip('Restores all access point (AP) service settings to their default values. This applies to hostapd, dhcpcd and dnsmasq.', 'tiphwmode', true); ?> | ||||
|           <div class="small">  | ||||
|           <?php echo _("Custom files for optional components such as Ad Blocking, WireGuard or OpenVPN will remain on the system."); ?> | ||||
|           </div> | ||||
|         </div> | ||||
|       </div> | ||||
|       <button type="button" class="btn btn-danger" name="system-reset" data-toggle="modal" data-target="#system-confirm-reset" /><?php echo _("Perform reset"); ?></button> | ||||
|     <?php endif ?> | ||||
| </div> | ||||
|  | ||||
|  | ||||
		Reference in New Issue
	
	Block a user