Browse Source

Added dialogue box for Steam Guard code

Added dialogue box for Steam Guard code that shows up in the update process if the last part of the log matches "Two-factor code:".
DieFeM 8 năm trước cách đây
mục cha
commit
c4a5817ef0

+ 21 - 0
css/global.css

@@ -85,3 +85,24 @@ table.hundred{
 	margin-top: 1em;
 	margin-bottom: 1em;
 }
+
+.loader{
+	border: 6px solid #f3f3f3;
+	border-radius: 50%;
+	border-top: 6px solid #3498db;
+	width: 12px;
+	height: 12px;
+	-webkit-animation: spin 2s linear infinite; /* Safari */
+	animation: spin 2s linear infinite;
+}
+
+/* Safari */
+@-webkit-keyframes spin {
+	0% { -webkit-transform: rotate(0deg); }
+	100% { -webkit-transform: rotate(360deg); }
+}
+
+@keyframes spin {
+	0% { transform: rotate(0deg); }
+	100% { transform: rotate(360deg); }
+}

+ 19 - 0
includes/lib_remote.php

@@ -1105,5 +1105,24 @@ class OGPRemoteLibrary
 			return NULL;
 		return base64_decode($response);
 	}
+	
+	public function send_steam_guard_code($home_id, $sgc)
+	{
+		$params_array = $this->encrypt_params($home_id, $sgc);
+		$this->add_enc_chk($params_array);
+		$request = xmlrpc_encode_request("send_steam_guard_code", $params_array);
+		$response = $this->sendRequest($request);
+		
+		if ($response === NULL)
+			return -1;
+		
+		if (is_array($response) && xmlrpc_is_fault($response))
+			return -1;
+		
+		if ($response === 1)
+			return -1;
+		
+		return 1;
+	}
 }
 ?>

+ 50 - 0
js/modules/gamemanager_update.js

@@ -0,0 +1,50 @@
+function GetURLParameter(sParam)
+{
+	var sPageURL = window.location.search.substring(1);
+	var sURLVariables = sPageURL.split('&');
+	for (var i = 0; i < sURLVariables.length; i++)
+	{
+		var sParameterName = sURLVariables[i].split('=');
+		if (sParameterName[0] == sParam)
+		{
+			return sParameterName[1];
+		}
+	}
+}
+
+$(document).ready(function(){
+	if( GetURLParameter('get_sgc') == 'show' )
+	{
+		var home_id = GetURLParameter('home_id');
+		var mod_id = GetURLParameter('mod_id');
+		var returnUrl = "home.php?m=gamemanager&p=update&update=refresh&home_id="+home_id+"&mod_id="+mod_id
+		var addpost = {};
+		addpost.sgc = '';
+		$('#dialog').html("<label for='SteamGuardCode'>Steam Guard:</label>\n"+
+						  "<input class='SteamGuardCode' type=text style='width:99%;' name='sgc'>");
+		$('#dialog').dialog({
+			autoOpen: true,
+			width: 450,
+			modal: true,
+			buttons: [{ text: "Send Code", click: function(){
+					addpost.sgc = $('input[class="SteamGuardCode"]').val();
+					$.ajax({
+						type: "POST",
+						url: returnUrl,
+						data: addpost,
+						async: false,
+						success: function(data){
+							$('#dialog').html("<div class=\"loader\"></div>");
+							setTimeout(function(){
+								window.location.href = returnUrl;
+							}, 10000);
+						}
+					});
+				}
+			}],
+			close: function() {
+				$( this ).dialog( "close" );
+			}
+		});
+	}
+});

+ 14 - 3
modules/gamemanager/update_server.php

@@ -182,6 +182,11 @@ function exec_ogp_module() {
 		// Refresh update page.
 		else
 		{
+			if(isset($_POST['sgc']))
+			{
+				$remote->send_steam_guard_code($home_id, $_POST['sgc']);
+				return;
+			}
 			if ( isset( $_POST['stop_update_x'] ) )
 			{
 				$remote->stop_update($home_id);
@@ -204,9 +209,15 @@ function exec_ogp_module() {
 			}
 			if (empty($log_txt))
 				$log_txt = get_lang("not_available");
-
-			echo "<pre>".$log_txt."</pre>\n";
-
+								
+			echo "<pre>".$log_txt."</pre>\n<script type=\"text/javascript\" src=\"js/modules/gamemanager_update.js\"></script>\n<div id='dialog' ></div>\n";
+			if(preg_match('/Two-factor code:$/m', $log_txt) and !isset($_GET['get_sgc']))
+			{
+				$view->refresh("?m=gamemanager&amp;p=update&amp;update=refresh&amp;home_id=$home_id&amp;mod_id=$mod_id&amp;get_sgc=show", 0);
+				return;
+			}
+			if(isset($_GET['get_sgc']) && $_GET['get_sgc'] == 'show')
+				return;
 			if ( $update_complete )
 				return;
 		}