简体   繁体   English

打字错误条件IP / if-if-else

[英]typoscript negate conditions IP / if - if - else

is it possible to negate a condition with typoscript? 是否可以用打字稿否定病情?

We have a page where parts are only seen, if your ip-address is in the range 10.*.*.* : 如果您的ip地址在10.*.*.*范围内,则我们只有一个页面,仅显示部分内容:

[IP=10.*.*.*]
  # show internal content
[global]

This works. 这可行。 But now we have following problem. 但是现在我们有以下问题。 The new loadbalancer (waf) has an iternal address, too (ie 10.1.2.3 ), so the internal content is shown with the above condition! 新的负载均衡器(waf)也具有一个内部地址(即10.1.2.3 ),因此内部内容在上述条件下显示! Unfortunately a negation of the IP-Condition doesn't work. 不幸的是,否定IP条件是行不通的。 I tried: 我试过了:

[IP=10.*.*.*] && [IP!=10.1.2.3]

A working solution for negating a condition is: 否定条件的有效解决方案是:

[IP=10.1.2.3]
  # do nothing
[ELSE]
  # show internal content
[global] 

but I need the condition [IP=10.*.*.*] too! 但我也需要条件[IP=10.*.*.*] I also tried 我也试过

[IP=10.1.2.3]
  # do nothing
[IP=10.*.*.*]
  # show internal content
[global] 

but it doesn't work, too. 但它也不起作用。

Maybe someone has an idea to fix it! 也许有人有解决的办法! Changing the loadbalancer-ip is no option! 更改loadbalancer-ip是没有选择的!

Thanks, mph 谢谢,每小时

What you want to do is not changing your condition but marking this IP as Reverse Proxy like: 您要做的不是更改条件,而是将该IP标记为反向代理,例如:

$GLOBALS['TYPO3_CONF_VARS']['SYS']['reverseProxyIP'] = '10.1.2.3'; $ GLOBALS ['TYPO3_CONF_VARS'] ['SYS'] ['reverseProxyIP'] = '10 .1.2.3'; $GLOBALS['TYPO3_CONF_VARS']['SYS']['reverseProxyHeaderMultiValue'] = 'last'; $ GLOBALS ['TYPO3_CONF_VARS'] ['SYS'] ['reverseProxyHeaderMultiValue'] ='last';

This doesn't use your loadbalancer's IP but the original IP used to connect to it. 这不会使用您的负载均衡器的IP,而是用于连接到它的原始IP。 So your condition will work as it used to (provided your loadbalancer sets a proper X-Forwarded-For header). 因此,您的条件将像往常一样工作(前提是您的负载均衡器设置了正确的X-Forwarded-For标头)。

You want to do this because this fixes your issue not only for these conditions but also for logging (TYPO3 sys_log for login-attempts), for IP-Auth etc. so it's the proper way to solve your issue. 您要这样做,是因为这不仅可以解决这些问题,还可以解决日志记录(用于登录尝试的TYPO3 sys_log),用于IP-Auth等问题,因此这是解决问题的正确方法。

There is a way with pure TypoScript: 纯TypoScript有一种方法:

TS constants: TS常数:

[IP=10.1.2.3]
[else]
  temp.noWaf = 1
[end]

TS setup: TS设定:

[IP = 10.*.*.*] && [globalVar = LIT:1 = {$temp.noWaf}]
  # show internal content
[end]

However splitting the logic into TS constants and setup is IMHO confusing. 但是,将逻辑拆分为TS常数和设置是恕我直言的。 Using globalVar = LIT is hard to read. 使用globalVar = LIT很难阅读。

Finaly, some of my attempts to clean things up failed, eg using LIT:0 or != LIT:1 . 最后,我进行清理工作的某些尝试失败,例如使用LIT:0!= LIT:1

I'd use a userFunc . 我会使用userFunc To retrieve the IP-address you can use GeneralUtility::getIndpEnv('REMOTE_ADDR') and to compare IP addresses there is GeneralUtility::cmpIP() . 要检索IP地址,可以使用GeneralUtility::getIndpEnv('REMOTE_ADDR')并比较IP地址,其中有GeneralUtility::cmpIP()

Basic answer to your question in the topic: Yes, this is possible, and I did it already, here an example: 对该主题中您问题的基本答案:是的,这是可能的,而我已经做到了,这里举一个例子:

[browser = msie] && [version =  <7] && [globalVar = TSFE:id != 100]

(answer friendly taken from pi-phi spicker, http://www.pi-phi.de/19.html ) (答案友好,摘自pi-phi Spicker, http: //www.pi-phi.de/19.html)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM