Skip to content

Commit

Permalink
Merge pull request #22 from jducoeur/focus_on_one_domain
Browse files Browse the repository at this point in the history
QI.9v5kg2v: Introduce the ability to redirect from a "bad" domain to a "good" one
  • Loading branch information
jducoeur authored Jun 12, 2022
2 parents d03ad6b + 05ebbfb commit cb929fa
Show file tree
Hide file tree
Showing 13 changed files with 80 additions and 31 deletions.
2 changes: 1 addition & 1 deletion querki/scalajvm/app/querki/basic/BasicModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class BasicModule(e: Ecology) extends QuerkiEcot(e) with Basic with WithQL with
Categories(BasicTag),
Summary("A short text that does not contain any QL"),
Details("""Plain Text is a special, restricted sort of Text. It can contains all of the
|formatting described in the [QText Reference](http://www.querki.net/u/systemUser/documentation/QText-Reference),
|formatting described in the [QText Reference](http://querki.net/u/systemUser/documentation/QText-Reference),
|but it can *not* contain any QL expressions. This means that it can not have simply Links to other Things, and can
|not use Properties at all.
|
Expand Down
2 changes: 1 addition & 1 deletion querki/scalajvm/app/querki/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1019,7 +1019,7 @@ trait TypeCreation {
|Large Text Properties are mainly composed of QText -- an easy-to-use "markup" format, that lets you
|describe concepts like boldface, paragraphs, links, bullet lists and so on in fairly intuitive ways, without
|needing to use HTML. For details on all the different things you can do with QText, see
|the [QText Reference](http://www.querki.net/u/systemUser/documentation/QText-Reference).
|the [QText Reference](http://querki.net/u/systemUser/documentation/QText-Reference).
|
|#### QL
|
Expand Down
4 changes: 2 additions & 2 deletions querki/scalajvm/app/querki/email/RealEmailSender.scala
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ private[email] class RealEmailSender(e: Ecology) extends QuerkiEcot(e) with Emai

val body =
Wikitext("""{{maindiv:
|<div class="logocontainer"><img class="logo" alt="Querki Logo" src="http://www.querki.net/assets/images/Logo-green.png"></div>
|<div class="logocontainer"><img class="logo" alt="Querki Logo" src="http://querki.net/assets/images/Logo-green.png"></div>
|
|""".stripMargin) +
bodyWiki +
Expand Down Expand Up @@ -300,7 +300,7 @@ private[email] class RealEmailSender(e: Ecology) extends QuerkiEcot(e) with Emai

val body =
Wikitext("""{{maindiv:
|<div class="logocontainer"><img class="logo" alt="Querki Logo" src="http://www.querki.net/assets/images/Logo-green.png"></div>
|<div class="logocontainer"><img class="logo" alt="Querki Logo" src="http://querki.net/assets/images/Logo-green.png"></div>
|
|""".stripMargin) +
bodyMain +
Expand Down
2 changes: 1 addition & 1 deletion querki/scalajvm/app/querki/identity/IdentityCommands.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class IdentityCommands(e: Ecology) extends QuerkiEcot(e) {
lazy val MakeAllPersonsPublicCommand = Console.defineSpaceCommand(
MakeAllPersonsPublicCommandOID,
"Make All Persons Public",
"This is a one-off command to fix [this bug](https://www.querki.net/u/jducoeur/alpha-issue-tracking/#!.7w4g99b) in your Space",
"This is a one-off command to fix [this bug](https://querki.net/u/jducoeur/alpha-issue-tracking/#!.7w4g99b) in your Space",
Seq(AccessControl.CanEditProp)
) { args =>
val inv = args.inv
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ class InvitationNotifierEcot(e: Ecology) extends QuerkiEcot(e) with Notifier wit
senderOpt.getOrElse(throw new Exception(s"Somehow got Invitation Unsub from unknown sender $senderId!"))
(
Wikitext(s"""**${sender.name}** invited you to join the Querki Space *$spaceName*.
|[Click here for more information about Querki.](https://www.querki.net/help/#!What-is-Querki)
|[Click here for more information about Querki.](https://querki.net/help/#!What-is-Querki)
|
|Use the buttons below to keep ${sender.name} from inviting you to this or any other Space,
|or to suppress Querki invitations entirely.""".stripMargin),
Expand Down
56 changes: 50 additions & 6 deletions querki/scalajvm/app/querki/system/Filters.scala
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
package querki.system

import javax.inject.Inject

import scala.concurrent.{ExecutionContext, Future}

import akka.stream.Materializer

import play.api.mvc._
import play.api.mvc.Results._
import play.api.http.HttpFilters
import play.filters.gzip.GzipFilter

import querki.globals._

class Filters @Inject() (
gzip: GzipFilter,
log: LoggingFilter
log: LoggingFilter,
redirect: RedirectFilter
) extends HttpFilters {
val filters = Seq(log, gzip)
val filters = Seq(redirect, log, gzip)
}

/**
Expand Down Expand Up @@ -82,3 +80,49 @@ class LoggingFilter @Inject() (
}
}
}

class RedirectFilter @Inject() (
implicit
val mat: Materializer,
ec: ExecutionContext,
ecoProv: EcologyProvider
) extends Filter
with EcologyMember {

implicit lazy val ecology = ecoProv.ecology

// Define a "bad" host and a "good" one, so we can redirect www.querki.net to just querki.net.
// TODO: this is all kind of wretchedly typed. Config should return None, not empty String, if it is missing.
// And redirectFrom should, in principle, return a List of Strings, not a single one. (But I don't care much
// about the latter.)
/**
* The domain that we are intercepting and redirecting, eg "www.querki.net".
*/
lazy val redirectFrom = Config.getString("querki.redirect.from", "")

/**
* The full protocol and host we are redirecting to, eg "https://querki.net".
*/
lazy val redirectTo = Config.getString("querki.redirect.to", "")
lazy val redirecting = (redirectTo != "")

def apply(next: (RequestHeader) => Future[Result])(rh: RequestHeader): Future[Result] = {
if (redirecting) {
if (rh.domain == redirectFrom) {
val newUri = rewriteUri(rh)
QLog.info(s"Redirecting ${rh.host}${rh.uri} to ${newUri}")
// Note that this is *extremely* crude -- it only deals with GETs correctly. But that should suffice for the
// realistic use cases we are dealing with, and pushes the user over to the right pathway quickly.
Future.successful(SeeOther(newUri))
} else {
next(rh)
}
} else {
next(rh)
}
}

def rewriteUri(rh: RequestHeader): String = {
s"$redirectTo${rh.uri}"
}
}
4 changes: 2 additions & 2 deletions querki/scalajvm/app/views/index.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ <h3>Please log in</h3>
</div>
</div>

<p>For more information about Querki, see <a href="http://www.querki.net/help/#!Learning-Querki">Learning Querki</a> or
the <a href="http://www.querki.net/help/#!Querki-Quickstart">Querki Quickstart page</a>.</p>
<p>For more information about Querki, see <a href="http://querki.net/help/#!Learning-Querki">Learning Querki</a> or
the <a href="http://querki.net/help/#!Querki-Quickstart">Querki Quickstart page</a>.</p>
}
case Some(u) => {
<a href="/spaces" class="btn btn-primary">Show my Spaces</a>
Expand Down
2 changes: 1 addition & 1 deletion querki/scalajvm/app/views/main.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@
<hr class="_noPrint">

<footer class="_mainFooter _noPrint">
Querki &copy; Querki Inc 2013-2015 | <a href="http://www.querki.net/help/">Help</a> | <a href="/TOS">Terms of Service</a>
Querki &copy; Querki Inc 2013-2022 | <a href="http://querki.net/help/">Help</a> | <a href="/TOS">Terms of Service</a>
</footer>

</div><!--/.fluid-container-->
Expand Down
7 changes: 6 additions & 1 deletion querki/scalajvm/conf/application.conf.template
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ querki {
# semblance of recording of Space ups and downs.
logMonitor : false
}


redirect {
from : "www.querki.net"
to : "https://querki.net"
}

session {
# Time before a UserSpaceSession times out for inactivity
timeout : 5 minutes
Expand Down
2 changes: 1 addition & 1 deletion querki/scalajvm/test/querki/html/UITests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ class UITests extends QuerkiTests {
processQText(commonThingAsContext(_.withUrl), """[[My List of URLs -> _showLink(""hello"")]]""") should
equal("""
|<a href="http://www.google.com/" target="_blank">hello</a>
|<a href="http://www.querki.net/" target="_blank">hello</a>""".stripReturns)
|<a href="http://querki.net/" target="_blank">hello</a>""".stripReturns)
}
"work with a list of Links" in {
class testSpace extends CommonSpace {
Expand Down
24 changes: 12 additions & 12 deletions querki/scalajvm/test/querki/qtext/TransformerTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -413,14 +413,14 @@ And now to something completely different.
}

it should "allow HTTP URLs" in {
apply("[Querki](http://www.querki.net/)") should equal(
"<p><a href=\"http://www.querki.net/\" rel=\"nofollow\" target=\"_blank\">Querki</a></p>\n"
apply("[Querki](http://querki.net/)") should equal(
"<p><a href=\"http://querki.net/\" rel=\"nofollow\" target=\"_blank\">Querki</a></p>\n"
)
}

it should "allow HTTPS URLs" in {
apply("[Querki](https://www.querki.net/)") should equal(
"<p><a href=\"https://www.querki.net/\" rel=\"nofollow\" target=\"_blank\">Querki</a></p>\n"
apply("[Querki](https://querki.net/)") should equal(
"<p><a href=\"https://querki.net/\" rel=\"nofollow\" target=\"_blank\">Querki</a></p>\n"
)
}

Expand All @@ -429,17 +429,17 @@ And now to something completely different.
}

it should "prevent all forms of Javascript injection" in {
apply("[Evil](javascript://www.querki.net/)") should equal(
"<p><a href=\"./javascript://www.querki.net/\" rel=\"nofollow\" target=\"_blank\">Evil</a></p>\n"
apply("[Evil](javascript://querki.net/)") should equal(
"<p><a href=\"./javascript://querki.net/\" rel=\"nofollow\" target=\"_blank\">Evil</a></p>\n"
)
apply("[Evil](javascript+://www.querki.net/)") should equal(
"<p><a href=\"./javascript+://www.querki.net/\" rel=\"nofollow\" target=\"_blank\">Evil</a></p>\n"
apply("[Evil](javascript+://querki.net/)") should equal(
"<p><a href=\"./javascript+://querki.net/\" rel=\"nofollow\" target=\"_blank\">Evil</a></p>\n"
)
apply("[Evil](javascript-://www.querki.net/)") should equal(
"<p><a href=\"./javascript-://www.querki.net/\" rel=\"nofollow\" target=\"_blank\">Evil</a></p>\n"
apply("[Evil](javascript-://querki.net/)") should equal(
"<p><a href=\"./javascript-://querki.net/\" rel=\"nofollow\" target=\"_blank\">Evil</a></p>\n"
)
apply("[Evil](javascript.://www.querki.net/)") should equal(
"<p><a href=\"./javascript.://www.querki.net/\" rel=\"nofollow\" target=\"_blank\">Evil</a></p>\n"
apply("[Evil](javascript.://querki.net/)") should equal(
"<p><a href=\"./javascript.://querki.net/\" rel=\"nofollow\" target=\"_blank\">Evil</a></p>\n"
)
}

Expand Down
2 changes: 1 addition & 1 deletion querki/scalajvm/test/querki/test/CommonSpace.scala
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class CommonSpace(implicit ecologyIn: Ecology) extends TestSpace {
withUrlOID,
"With URL",
optURLProp("http://www.google.com/"),
listURLProp("http://www.google.com/", "http://www.querki.net/")
listURLProp("http://www.google.com/", "http://querki.net/")
)

val withoutUrl = new SimpleTestThing("Without URL", optURLProp())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import querki.test._
* @author jducoeur
*/
class RegressionTests extends QuerkiTests {
// See https://www.querki.net/u/jducoeur/alpha-issue-tracking/#.3y28a3r
// See https://querki.net/u/jducoeur/alpha-issue-tracking/#.3y28a3r
".3y28a3r" should {
"be fixed" in {
class TSpace extends CommonSpace {
Expand Down

0 comments on commit cb929fa

Please sign in to comment.