Skip to content

Commit

Permalink
Remove hardcoded server name
Browse files Browse the repository at this point in the history
  • Loading branch information
lonemadmax committed Jun 17, 2018
1 parent 9f16f24 commit 512e498
Show file tree
Hide file tree
Showing 20 changed files with 65 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class ResetPassword extends HttpServlet {
private String captchaSecret;
private String emailUsername;
private String emailPassword;
private String fcwHost;

public void init(ServletConfig config) throws ServletException {
super.init(config);
Expand All @@ -55,6 +56,7 @@ public void init(ServletConfig config) throws ServletException {
captchaSecret = prop.getProperty("captcha_secret");
emailUsername = prop.getProperty("email_username");
emailPassword = prop.getProperty("email_password");
fcwHost = prop.getProperty("fcw_host");
} catch (IOException e) {
e.printStackTrace();
}
Expand Down Expand Up @@ -158,7 +160,7 @@ public void doPost(HttpServletRequest request, HttpServletResponse response)
email.setSSLOnConnect(true);
email.setFrom("Freeciv-web <[email protected]>");
email.setSubject("New password for Freeciv-web");
email.setMsg("Your new password for play.freeciv.org has been generated. \n\nUsername: " + username + " \nPassword: " + randomPassword);
email.setMsg("Your new password for " + fcwHost + " has been generated. \n\nUsername: " + username + " \nPassword: " + randomPassword);
email.addTo(email_parameter);
email.send();
} catch (EmailException err) {
Expand Down
3 changes: 3 additions & 0 deletions freeciv-web/src/main/webapp/WEB-INF/config.properties.dist
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ savegame_dir=/var/lib/tomcat8/webapps/data/savegames/
email_username=username
email_password=password
google-signin-client-key=122428231951-2vrvrtd9sc2v9nktemclkvc2t187jkr6.apps.googleusercontent.com
# Used in some messages and to distribute minimized or expanded js files,
# so put the production server even when testing.
fcw_host=example.com
6 changes: 3 additions & 3 deletions freeciv-web/src/main/webapp/WEB-INF/jsp/fragments/header.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<li><a href="https://www.reddit.com/r/freeciv">reddit.com/freeciv</a></li>
</ul>
</li>
<li><a href="https://play.freeciv.org/blog/"><fmt:message key="nav-blog"/></a></li>
<li><a href="/blog/"><fmt:message key="nav-blog"/></a></li>
<li><a href="http://www.freeciv.org/donate.html"><fmt:message key="nav-donate"/></a></li>
<li><a href="https://github.com/freeciv/freeciv-web">Contribute</a></li>
<%--<li class="dropdown">
Expand All @@ -61,7 +61,7 @@
</li>--%>
</ul>
<form class="navbar-form navbar-right hidden-sm hidden-md" action="https://duckduckgo.com/" style="width: 220px;">
<input type="hidden" name="sites" value="www.freeciv.org,forum.freeciv.org,freeciv.wikia.com,play.freeciv.org">
<input type="hidden" name="sites" value="www.freeciv.org,forum.freeciv.org,freeciv.wikia.com">
<div class="form-group">
<div class="input-group">
<input type="text" class="form-control" name="q" placeholder="Search Freeciv...">
Expand All @@ -77,4 +77,4 @@
<script src="/static/javascript/header.min.js"></script>
<!--[if lt IE 8]>
<p class="browserupgrade">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
<![endif]-->
<![endif]-->
4 changes: 2 additions & 2 deletions freeciv-web/src/main/webapp/freeciv-earth/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,12 @@
<li><a id="metalink" href="/meta/metaserver">Online Games</a></li>
<li><a href="http://forum.freeciv.org/f/viewforum.php?f=24">Forum</a></li>
<li><a href="https://github.com/freeciv/freeciv-web">Github</a></li>
<li><a href="http://play.freeciv.org/blog/">Blog</a></li>
<li><a href="/blog/">Blog</a></li>
<li><a href="http://www.freeciv.org/donate.html">Donate</a></li>
<li><a href="http://www.freeciv.org/">Freeciv.org</a></li>
</ul>
<form id="mysearchform" class="navbar-form navbar-right searchbox">
<iframe src="https://duckduckgo.com/search.html?width=170&amp;site=www.freeciv.org,forum.freeciv.org,freeciv.wikia.com,play.freeciv.org&amp;prefill=Search Freeciv.org" style="overflow:hidden;margin:0;padding:0;width:228px;height:40px;" frameborder="0"></iframe>
<iframe src="https://duckduckgo.com/search.html?width=170&amp;site=www.freeciv.org,forum.freeciv.org,freeciv.wikia.com&amp;prefill=Search Freeciv.org" style="overflow:hidden;margin:0;padding:0;width:228px;height:40px;" frameborder="0"></iframe>
</form>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion freeciv-web/src/main/webapp/javascript/client_main.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ function show_new_game_message()
message = "Welcome " + username + "! This is a One Turn per Day game, where you play one " +
"turn every day. Click the Turn Done button when you are done with your turn. To play your next " +
"turn in this One Turn per Day game, you can bookmark this page and use that link to play your next turn. "+
"You can also find this game by going to play.freeciv.org and clicking on the One Turn per Day button. "+
"You can also find this game by going to " + window.location.host + " and clicking on the One Turn per Day button. "+
"Good luck, have fun and see you again tomorrow!";

} else if (is_small_screen()) {
Expand Down
2 changes: 1 addition & 1 deletion freeciv-web/src/main/webapp/javascript/control.js
Original file line number Diff line number Diff line change
Expand Up @@ -2176,7 +2176,7 @@ function send_end_turn()
if (is_longturn()) {
show_dialog_message("Turn done!",
"Your turn in this Freeciv-web: One Turn per Day game is now over. In this game one turn is played every day. " +
"To play your next turn in this game, go to play.freeciv.org and click <b>Games</b> in the menu, then <b>Multiplayer</b> " +
"To play your next turn in this game, go to " + window.location.host + " and click <b>Games</b> in the menu, then <b>Multiplayer</b> " +
"and there you will find this Freeciv-web: One Turn per Day game in the list. You can also bookmark this page.<br>" +
"See you again soon!" );
}
Expand Down
4 changes: 2 additions & 2 deletions freeciv-web/src/main/webapp/javascript/webgl/mapview.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ function webgl_start_renderer()
anaglyph_effect.setSize( new_mapview_width, new_mapview_height );
}

if (location.hostname != "play.freeciv.org" && Detector.webgl) {
if (location.host != fcw_host && Detector.webgl) {
stats = new Stats();
container.appendChild( stats.dom );
console.log("MAX_FRAGMENT_UNIFORM_VECTORS:" + maprenderer.context.getParameter(maprenderer.context.MAX_FRAGMENT_UNIFORM_VECTORS));
Expand Down Expand Up @@ -299,4 +299,4 @@ function animate() {

if (renderer == RENDERER_WEBGL) requestAnimationFrame(animate);

}
}
4 changes: 2 additions & 2 deletions freeciv-web/src/main/webapp/javascript/webgl/renderer_main.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function init_webgl_renderer()

$.ajax({
async: false,
url: (location.hostname == "play.freeciv.org") ? "/javascript/webgl/libs/webgl-client.min.js" : "/javascript/webgl/libs/webgl-client.js",
url: (location.host == fcw_host) ? "/javascript/webgl/libs/webgl-client.min.js" : "/javascript/webgl/libs/webgl-client.js",
dataType: "script"
});

Expand Down Expand Up @@ -133,4 +133,4 @@ function webgl_preload_complete()
username = "autostart";
network_init();
}
}
}
33 changes: 22 additions & 11 deletions freeciv-web/src/main/webapp/webclient/index.jsp
Original file line number Diff line number Diff line change
@@ -1,25 +1,44 @@
<%@ page import="java.util.Properties" %>
<%@ page import="java.io.IOException" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
String googleSigninClientKey = null;
String fcwHost = null;
try {
Properties prop = new Properties();
prop.load(getServletContext().getResourceAsStream("/WEB-INF/config.properties"));
googleSigninClientKey = prop.getProperty("google-signin-client-key");
fcwHost = prop.getProperty("fcw_host");
} catch (IOException e) {
e.printStackTrace();
}
if (googleSigninClientKey == null) {
googleSigninClientKey = "";
}
if (fcwHost == null || fcwHost.isEmpty()) {
fcwHost = request.getServerName();
}
%>
<!DOCTYPE html>
<html>
<head>
<title>Freeciv-web</title>
<link rel="stylesheet" href="/css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="/css/webclient.min.css?ts=${initParam.buildTimeStamp}" />
<meta name="description" content="Freeciv-Web is a Free and Open Source empire-building strategy game inspired by the history of human civilization.">
<% if (!request.getServerName().equals("localhost")) { %>
<% if (request.getServerName().equals(fcwHost)) { %>
<script type="text/javascript">window._trackJs = { token: 'ee5dba6fe2e048f79b422157b450947b' };</script>
<script type="text/javascript" src="https://cdn.trackjs.com/releases/current/tracker.js"></script>
<% } %>
<script type="text/javascript">
var ts="${initParam.buildTimeStamp}";
var fcw_host="<%= fcwHost %>";
</script>
<script type="text/javascript" src="/javascript/libs/jquery.min.js?ts=${initParam.buildTimeStamp}"></script>

<script src="https://apis.google.com/js/platform.js"></script>

<% if (request.getServerName().equals("play.freeciv.org")) { %>
<% if (request.getServerName().equals(fcwHost)) { %>
<script type="text/javascript" src="/javascript/webclient.min.js?ts=${initParam.buildTimeStamp}"></script>
<% } else { %>
<script type="text/javascript" src="/javascript/webclient.js?ts=${initParam.buildTimeStamp}"></script>
Expand All @@ -38,15 +57,7 @@ var ts="${initParam.buildTimeStamp}";
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />

<meta name="google-signin-client_id" content="<%
try {
Properties prop = new Properties();
prop.load(getServletContext().getResourceAsStream("/WEB-INF/config.properties"));
out.print(prop.getProperty("google-signin-client-key"));
} catch (IOException e) {
e.printStackTrace();
}
%>">
<meta name="google-signin-client_id" content="<%= googleSigninClientKey %>">
<link rel="manifest" href="/static/manifest.json">

<script src="https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit"
Expand Down
2 changes: 1 addition & 1 deletion nginx/sites-available/freeciv-web
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
}


# proxy for resin app-server on port 8080 at play.freeciv.org
# proxy for app-server on port 8080
location ~ / {
rewrite ^(.*)$ /freeciv-web/$1 break;
proxy_pass http://localhost:8080;
Expand Down
6 changes: 2 additions & 4 deletions pbem/email_template_generic.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,18 @@

<div style="width: 650px; border: 1px solid black; background-color: white;">
<div style="background-color: #003876; min-height: 20px; padding: 3px; margin: 0px;">
<span style="font-size: 200%;"><a href="https://play.freeciv.org" style="color: white;">Freeciv-web</a></>
<span style="font-size: 200%;"><a href="https://{host}" style="color: white;">Freeciv-web</a></span>
</div>
<div>

{message}

<br><br>

<a href="https://play.freeciv.org">Freeciv-web</a> is a free and open source empire-building strategy game
<a href="https://{host}">Freeciv-web</a> is a free and open source empire-building strategy game
inspired by the history of human civilization. Please report feedback on the <a href="http://forum.freeciv.org/f/viewforum.php?f=24">forum</a>.
<br><br>

The Freeciv-web project - <a href="https://play.freeciv.org">play.freeciv.org</a><br><br>

</div>
</div>
</body>
Expand Down
8 changes: 3 additions & 5 deletions pbem/email_template_invitation.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<div style="width: 650px; border: 1px solid black; background-color: white;">
<div style="background-color: #003876; min-height: 20px; padding: 3px; margin: 0px;">
<span style="font-size: 200%;"><a href="https://play.freeciv.org" style="color: white;">Freeciv-web</a></>
<span style="font-size: 200%;"><a href="https://{host}" style="color: white;">Freeciv-web</a></span>
</div>
<div>
Hello!<br>
Expand All @@ -12,20 +12,18 @@


<br><br>
<a href="https://play.freeciv.org/pbem?u={sender}" style="color: white; background-color: #3c98ff; padding: 10px; font-size: 160%;">Please click here to play your first turn!</a>
<a href="https://{host}/pbem?u={sender}" style="color: white; background-color: #3c98ff; padding: 10px; font-size: 160%;">Please click here to play your first turn!</a>

<br><br>

Please complete your turn within 7 days, the other player will be waiting for you.

<br><br>

<a href="https://play.freeciv.org">Freeciv-web</a> is a free and open source empire-building strategy game
<a href="https://{host}">Freeciv-web</a> is a free and open source empire-building strategy game
inspired by the history of human civilization. Please report feedback on the <a href="http://forum.freeciv.org/f/viewforum.php?f=24">forum</a>.
<br><br>

The Freeciv-web project - <a href="https://play.freeciv.org">play.freeciv.org</a><br><br>

</div>
</div>
</body>
Expand Down
8 changes: 3 additions & 5 deletions pbem/email_template_next_turn.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<div style="width: 650px; border: 1px solid black; background-color: white;">
<div style="background-color: #003876; min-height: 20px; padding: 3px; margin: 0px;">
<span style="font-size: 200%;"><a href="https://play.freeciv.org" style="color: white;">Freeciv-web</a></>
<span style="font-size: 200%;"><a href="https://{host}" style="color: white;">Freeciv-web</a></span>
</div>
<div>
To {player_name}
Expand All @@ -19,16 +19,14 @@
<br><br>

Please complete your turn within 7 days, the other player will be waiting for you. A friendly reminder will be sent when there is 1 day until the game expires.
You can always check the game status on the <a href="https://play.freeciv.org/meta/metaserver">metaserver</a>.
You can always check the game status on the <a href="https://{host}/meta/metaserver">metaserver</a>.

<br><br>

<a href="https://play.freeciv.org">Freeciv-web</a> is a free and open source empire-building strategy game
<a href="https://{host}">Freeciv-web</a> is a free and open source empire-building strategy game
inspired by the history of human civilization. Please report feedback on the <a href="http://forum.freeciv.org/f/viewforum.php?f=24">forum</a>.
<br><br>

The Freeciv-web project - <a href="https://play.freeciv.org">play.freeciv.org</a><br><br>

</div>
</div>
</body>
Expand Down
7 changes: 7 additions & 0 deletions pbem/mailsender.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class MailSender():
smtp_port=settings.get("Config", "smtp_port")
smtp_sender=settings.get("Config", "smtp_sender")

host = settings.get("Config", "host")

template_next_turn = "";
with open('email_template_next_turn.html', 'r') as content_file:
template_next_turn = content_file.read();
Expand Down Expand Up @@ -76,6 +78,7 @@ def send_email_next_turn(self, player_name, players, email_address, game_url, tu
for p in players:
plrs_txt += p + ", ";
msg = msg.replace("{players}", plrs_txt);
msg = msg.replace("{host}", self.host);

self.send_mailgun_message(email_address, "Freeciv-Web: It's your turn to play! Turn: " \
+ str(turn), msg);
Expand All @@ -84,6 +87,7 @@ def send_invitation(self, invitation_from, invitation_to):
sender = re.sub(r'\W+', '', invitation_from);
msg = self.template_invitation;
msg = msg.replace("{sender}", sender);
msg = msg.replace("{host}", self.host);

self.send_mailgun_message(invitation_to, "Freeciv-Web: Join my game!" , msg);

Expand All @@ -95,12 +99,14 @@ def send_game_result_mail(self, winner, winner_score, winner_email, losers, lose
msg_winner += "Winner score: " + winner_score + "<br>"
msg_winner += "Loser score: " + losers_score + "<br>"
msg = self.template_generic.replace("{message}", msg_winner);
msg = msg.replace("{host}", self.host);
self.send_mailgun_message(winner_email, "Freeciv-Web: You won!", msg);

msg_loser = "To " + losers + "<br>You have lost the game of Freeciv-web against " + winner + ".<br>";
msg_loser += "Winner score: " + winner_score + "<br>"
msg_loser += "Loser score: " + losers_score + "<br>"
msg = self.template_generic.replace("{message}", msg_loser);
msg = msg.replace("{host}", self.host);
self.send_mailgun_message(losers_email, "Freeciv-Web: You lost!", msg);

# send email with reminder that game is about to expire
Expand All @@ -110,5 +116,6 @@ def send_game_reminder(self, email, game_url):
msg += "<a href='" + game_url + "'>Click here to play your turn now</a> <br><br>";
msg += "Your game will expire in 24 hours.<br>"
msg = self.template_generic.replace("{message}", msg);
msg = msg.replace("{host}", self.host);
self.send_mailgun_message(email, "Freeciv-Web: Remember to play your turn!", msg);

2 changes: 1 addition & 1 deletion pbem/mailstatus.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def initialize(self, mailchecker):

def get(self):
self.write("<html><head><title>Mail status for Freeciv-web</title>" +
"<link href='//play.freeciv.org/css/bootstrap.min.css' rel='stylesheet'>" +
"<link href='/css/bootstrap.min.css' rel='stylesheet'>" +
"<meta http-equiv=\"refresh\" content=\"20\"><style>td { padding: 2px;}</style></head><body>");
self.write("<div class='container'><h2>Freeciv-web PBEM status</h2>" +
"<table><tr><td>PBEM E-mails sent:</td><td>" + str(self.mailchecker.emails_sent) + "</td></tr>" +
Expand Down
3 changes: 2 additions & 1 deletion pbem/pbem.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
savedir = settings.get("Config", "savegame_directory");
rankdir = settings.get("Config", "ranklog_directory");

host = settings.get("Config", "host");

# load game status from file.
loaded_games = {};
Expand Down Expand Up @@ -119,7 +120,7 @@ def handle_savegame(root, file):
active_player = players[phase];
print("active_player=" + active_player);
active_email = find_email_address(active_player);
game_url = "https://play.freeciv.org/webclient/?action=pbem&savegame=" + new_filename.replace(".xz", "");
game_url = "https://" + host + "/webclient/?action=pbem&savegame=" + new_filename.replace(".xz", "");
if (active_email != None):
status.games[game_id] = {'turn' : turn, 'phase': phase, 'players' : players, 'time_str' : time.ctime(),
'time_int' : int(time.time()), 'state' : state, 'url' : game_url,
Expand Down
2 changes: 2 additions & 0 deletions pbem/settings.ini.dist
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ mysql_password = #DB_PASSWORD#

savegame_directory = /var/lib/tomcat8/webapps/data/savegames/pbem/
ranklog_directory = /var/lib/tomcat8/webapps/data/ranklogs/

host = #FCW_HOST#
2 changes: 1 addition & 1 deletion publite2/pubstatus.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def get(self):
if (game_count > 0): error_rate = (error_count * 100) / game_count;

self.write("<html><head><title>Publite2 status for Freeciv-web</title>" +
"<link href='//play.freeciv.org/css/bootstrap.min.css' rel='stylesheet'>" +
"<link href='/css/bootstrap.min.css' rel='stylesheet'>" +
"<meta http-equiv=\"refresh\" content=\"20\"><style>td { padding: 2px;}</style></head><body>");
self.write("<div class='container'><h2>Freeciv-web Publite2 status</h2>" +
"<table><tr><td>Number of Freeciv-web games run:</td><td>" + str(game_count) + "</td></tr>" +
Expand Down
3 changes: 3 additions & 0 deletions scripts/configuration.sh.dist
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ DB_ROOT_PASSWORD=${RANDOM}${RANDOM}${RANDOM}
# script is run.
# TOMCATMANAGER_USER=tomcat-user
# TOMCATMANAGER_PASSWORD=

# Freeciv-web externally accessible host
FCW_HOST=example.com
2 changes: 1 addition & 1 deletion scripts/freeciv-img-extract/img-extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def increment_tileset_image(tileset_name):
global tileset_inc;

draw = ImageDraw.Draw(tileset)
draw.text((130, 0), "Freeciv-web - http://play.freeciv.org/ GPL Licensed - Copyright 2007-2015 Andreas Rosdal", fill="rgb(0,0,0)")
draw.text((130, 0), "Freeciv-web - https://github.com/freeciv/freeciv-web GPL Licensed - Copyright 2007-2015 Andreas Rosdal", fill="rgb(0,0,0)")

tileset.save("freeciv-web-tileset-" + tileset_name + "-" + str(tileset_inc) + ".png");
tileset_inc += 1;
Expand Down

0 comments on commit 512e498

Please sign in to comment.