Jelajahi Sumber

Added Web API Integration to Load Panel Settings

own3mall 6 tahun lalu
induk
melakukan
69ba3757a4
2 mengubah file dengan 23 tambahan dan 1 penghapusan
  1. 2 0
      agent_conf.sh
  2. 21 1
      ogp_agent.pl

+ 2 - 0
agent_conf.sh

@@ -202,6 +202,8 @@ then
 	key => '${key}',
 	steam_license => '${steam_license}',
 	sudo_password => '${sudo_password}',
+	web_admin_api_key => '{your_admin_ogp_web_api_key_here}',
+	web_api_url => '{your_url_to_ogp_api.php}',
 	);" > $cfgfile
 	
 	if [ $? != 0 ]

+ 21 - 1
ogp_agent.pl

@@ -59,6 +59,8 @@ use constant AGENT_IP	   => $Cfg::Config{listen_ip};
 use constant AGENT_LOG_FILE => $Cfg::Config{logfile};
 use constant AGENT_PORT	 => $Cfg::Config{listen_port};
 use constant AGENT_VERSION  => $Cfg::Config{version};
+use constant WEB_ADMIN_API_KEY  => $Cfg::Config{web_admin_api_key};
+use constant WEB_API_URL => $Cfg::Config{web_api_url};
 use constant SCREEN_LOG_LOCAL  => $Cfg::Preferences{screen_log_local};
 use constant DELETE_LOGS_AFTER  => $Cfg::Preferences{delete_logs_after};
 use constant AGENT_PID_FILE =>
@@ -362,7 +364,7 @@ my $d = Frontier::Daemon::OGP::Forking->new(
 				 remote_query					=> \&remote_query,
 				 send_steam_guard_code  		=> \&send_steam_guard_code,
 				 steam_workshop					=> \&steam_workshop,
-				 get_workshop_mods_info			=> \&get_workshop_mods_info
+				 get_workshop_mods_info			=> \&get_workshop_mods_info,
 			 },
 			 debug	 => 4,
 			 LocalPort => AGENT_PORT,
@@ -4365,3 +4367,21 @@ sub get_workshop_mods_info()
 	
 	return -1;
 }
+
+sub get_setting_using_api
+{
+	my ($setting_name) = @_;
+	
+	if(defined WEB_API_URL && WEB_API_URL ne "" && defined WEB_ADMIN_API_KEY && WEB_ADMIN_API_KEY ne ""){
+		my $url = WEB_API_URL . "?setting/get&setting_name=" . $setting_name . "&token=" . WEB_ADMIN_API_KEY;
+		logger "URL is " . $url;
+		my $ua = LWP::UserAgent->new;
+		$ua->agent('Mozilla/5.0');
+		$ua->timeout(5);
+		$ua->ssl_opts( verify_hostname => 0 ,SSL_verify_mode => 0x00);
+		my $response = $ua->get($url);
+		return $response->decoded_content();
+	}
+	
+	return -1;
+}