rejetto forum

2.4 template-making guide

rejetto · 67 · 68785

0 Members and 1 Guest are viewing this topic.

Offline danny

  • Tireless poster
  • ****
    • Posts: 281
    • View Profile
How do I alter this form to:  refresh same page if url is not /~login? 

Edit; answer was:
Code: [Select]
location.replace({.if|{.match|*~login|%url%.}|{:document.referrer:}|{:"%encoded-folder%":}.})
« Last Edit: April 15, 2021, 02:18:15 PM by danny »


Offline NaitLee

  • Tireless poster
  • ****
    • Posts: 203
  • Computer-brain boy
    • View Profile
How do I alter this form to:  refresh same page if url is not /~login? 

I think we can pass current page (%encoded-folder%) through urlvar (/~login?redirect=%2Fsome%2Ffolder%2F)
Then redirect in /~login page with javascript etc.
"Computation is not forbidden magic."
Takeback Template | PHFS


Offline danny

  • Tireless poster
  • ****
    • Posts: 281
    • View Profile
new login script
Code: [Select]
[login|public]
{.if|{.match|*.php*;*.js;*.py;*.vbs*;*.exe|%url%.}|{:{.disconnect.}:}.}{.add header|Cache-Control: no-cache, max-age=0.}<!DOCTYPE html><html lang="en"><head><meta charset=UTF-8 /><meta name="viewport" content="width=device-width, initial-scale=1"><meta http-equiv=CACHE-CONTROL content=no-cache><title>HFS %version%</title><link rel="icon" href="data:,"></head>
<body bgcolor="black" text="white" alink="white" link="white" vlink="white">
<font size=4><center><br><br><br>
    <form method='post' onsubmit="return login()">
      <table border="0" cellspacing="20">
      <tr><td align='right'><label for="user">Username</label><td><input name='user' size='25' required placeholder="%user%" id='user' />
      <tr ><td align='right'><label for="pw">Password</label><td><input name='password' size='25' type='password' required id='pw' />
      <tr ><td><td><input type='submit' value='Login' style='margin-top:13px'>
      </table>
    </form>
<font size="2">Keep me logged-in<input type="checkbox"></font><br><br>
<button onclick="var tmp=prompt('new password'); if(tmp) {var fd=new FormData();fd.append('new',tmp);fd.append('token','{.cookie|HFS_SID_.}');fetch('/~ajax.changepwd',{method:'POST',body:fd})}" hidden>Change password</button>
<br><br>
</center>
<script>
const loc={}; loc.Logout='Logout'
var sha256 = function(s) {return SHA256.hash(s)}
function logout() {fetch("/?mode=logout").then(res => location.reload()); return false;}
function login() {
    var sid = "{.cookie|HFS_SID_.}"  //getCookie('HFS_SID');
    if (!sid) return true;  //let the form act normally
    var usr = user.value;
    var pwd = pw.value;
var xhr = new XMLHttpRequest();
xhr.open("POST", "/?mode=login");  // /~login
var formData = new FormData();
formData.append("user",usr)
if (typeof SHA256 != 'undefined') formData.append("passwordSHA256",sha256(sha256(pwd).toLowerCase()+sid).toLowerCase()); else formData.append("password",pwd)
xhr.onload=function(){if(xhr.response=='ok') {
 if(document.querySelector("input[type=checkbox]").checked) localStorage.login=JSON.stringify([usr,pwd]); else localStorage.removeItem('login');
 location.replace({.if|{.match|*~login|%url%.}|{:document.referrer:}|{:"%encoded-folder%":}.})} else {alert("user or password don't match");document.querySelector("form").reset();location.reload(true)}}
xhr.send(formData)
    return false;
}
if(localStorage.login) document.querySelector("input[type=checkbox]").checked=true  //stop keep logged-in: call /~login and disable "Keep me logged-in"
document.querySelector("input[type=checkbox]").onchange=function(){if(!this.checked) localStorage.removeItem('login')}
if('%user%') {document.querySelector("input[type=submit]").value=loc.Logout; document.querySelector("input[type=submit]").onclick=function(){logout(); return false}; document.querySelector('button').hidden=false}
if(!'%user%' && localStorage.login) {
var tmp=JSON.parse(localStorage.login)
user.value=tmp[0]
pw.value=tmp[1]
var myform=document.querySelector("form"); if (myform.requestSubmit) myform.requestSubmit(); else myForm.submit()
} </script> <script src="/~sha256.js" onerror="setTimeout(()=> this.src='/~sha256.js',181)"></script>

[ajax.changepwd|public|no log]
{.check session.}{.break|if={.not|{.can change pwd.}.} |result=Forbidden (0).}{.if|{.length|{.set account||password={.postvar|new.}.}/length.}|OK (1)|Failed (2).}

[unauth]
{.redirect|/~login.}
if you clicked on a login link, then after login it goes back to where you had clicked
if you clicked on a passworded folder, then after login it goes Into the expected folder


Compact version: 
Code: [Select]
[login|public]
{.if|{.match|*.php*;*.js;*.py;*.vbs*;*.exe|%url%.}|{:{.disconnect.}:}.}{.add header|Cache-Control: no-cache, max-age=0.}<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1"><meta http-equiv=CACHE-CONTROL content=no-cache><title>login</title><link rel="icon" href="data:,"></head>
<body bgcolor="black" text="white" alink="white" link="white" vlink="white"><font size=4><center><br><br><br>
<form method='post' onsubmit="return login()">
<table border="0" cellspacing="20">
<tr><td align='right'><label for="user">Username</label><td><input name='user' size='25' required placeholder="%user%" id='user' />
<tr><td align='right'><label for="pw">Password</label><td><input name='password' size='25' type='password' required id='pw' />
<tr><td><td><input type='submit' value='Login' style='margin-top:13px'>
</table></form>
<font size="2">Keep me logged-in<input type="checkbox"></font><br><br>
<button onclick="var tmp=prompt('new password'); if(tmp) {var fd=new FormData();fd.append('new',tmp);fd.append('token','{.cookie|HFS_SID_.}');fetch('/~ajax.changepwd',{method:'POST',body:fd})}" hidden>Change password</button><br><br></center></font>
<script>const loc={Logout:"Logout"};var sha256=function(e){return SHA256.hash(e)};function logout(){return fetch("/?mode=logout").then(e=>location.reload()),!1}function login(){var e="{.cookie|HFS_SID_.}";var o=user.value,r=pw.value,t=new XMLHttpRequest;t.open("POST","/?mode=login");var n=new FormData;return n.append("user",o),"undefined"!=typeof SHA256?n.append("passwordSHA256",sha256(sha256(r).toLowerCase()+e).toLowerCase()):n.append("password",r),t.onload=function(){"ok"==t.response?(document.querySelector("input[type=checkbox]").checked?localStorage.login=JSON.stringify([o,r]):localStorage.removeItem("login"),location.replace({.if|{.match|*~login|%url%.}|{:document.referrer:}|{:"%encoded-folder%":}.})):(alert("user or password don't match"),document.querySelector("form").reset(),location.reload(!0))},t.send(n),!1}
localStorage.login&&(document.querySelector("input[type=checkbox]").checked=!0),document.querySelector("input[type=checkbox]").onchange=function(){this.checked||localStorage.removeItem("login")};
if('%user%') {document.querySelector("input[type=submit]").value=loc.Logout; document.querySelector("input[type=submit]").onclick=function(){logout(); return false}; document.querySelector('button').hidden=false}
if(!'%user%' && localStorage.login) {var tmp=JSON.parse(localStorage.login); user.value=tmp[0]; pw.value=tmp[1]; var myform=document.querySelector("form"); if (myform.requestSubmit) myform.requestSubmit(); else myForm.submit(); }</script>
<script src="/~sha256.js" onerror="setTimeout(()=> this.src='/~sha256.js',181)"></script></body></html>

[ajax.changepwd|public|no log]
{.check session.}{.break|if={.not|{.can change pwd.}.} |result=Forbidden (0).}{.if|{.length|{.set account||password={.postvar|new.}.}/length.}|OK (1)|Failed (2).}

[unauth]
{.redirect|/~login.}
The compact version is caching-compatible so that you can go from/to cached content without confusing the login/logout buttons. 
« Last Edit: April 29, 2021, 06:29:27 PM by danny »


Offline f2065

  • Occasional poster
  • *
    • Posts: 9
    • View Profile
I want to remove the "New folder" button (so that no one can create folders).
In hfs.tpl I found and changed the lines:
Code: [Select]
[+special:strings]
option.newfolder=0
option.move=0
option.comment=0
option.rename=0

But it did not help!
The "New folder" button is there and creates a folder.
I edit the template file correctly - I change/add different elements and they change in the browser.
But for some reason option.newfolder is ignored.

If you remove the entire block {.if|{.can mkdir.}….} - then the button disappears…

But why is option.newfolder=0 not working?

HFS 2.4.0 RC7 build #319


Offline LeoNeeson

  • Tireless poster
  • ****
    • Posts: 859
  • Status: On hiatus       (sporadically here)
    • View Profile
    • twitter.com/LeoNeeson
But why is option.newfolder=0 not working?

HFS 2.4.0 RC7 build #319
The best way to 'catch' where this error was introduced, is to test each build backwards. First, my recommendation is making a backup of your config files .ini and .vfs, and then start testing builds: RC6, RC5, RC4, RC3, etc. until you find the working version. This way it is much easier to find where the bug is.
HFS in Spanish (HFS en Español) / How to compile HFS (Tutorial)
» Currently taking a break, until HFS v2.4 get his stable version.


Offline f2065

  • Occasional poster
  • *
    • Posts: 9
    • View Profile
The best way to 'catch' where this error was introduced, is to test each build backwards.
2.4 beta 2 - The option.newfolder=0 works fine
2.4 beta 3 - The option.newfolder=0 is ignored, "new folder" does not turn off


Offline LeoNeeson

  • Tireless poster
  • ****
    • Posts: 859
  • Status: On hiatus       (sporadically here)
    • View Profile
    • twitter.com/LeoNeeson
2.4 beta 2 - The option.newfolder=0 works fine
2.4 beta 3 - The option.newfolder=0 is ignored, "new folder" does not turn off
Thank you, I will check the source code this weekend, and try to fill a bug report on the next days. My free spare time is limited, so don't expect this to be fixed soon (and also, Rejetto is not actively working on v2.x branch). That said, your report is very appreciated.

» EDIT: I've found the problematic commit where this bug was introduced, HERE. We still need to analyze how to keep the improvements, but fix this issue. Please be patient, until we find a solution.
« Last Edit: December 28, 2022, 10:36:14 PM by LeoNeeson »
HFS in Spanish (HFS en Español) / How to compile HFS (Tutorial)
» Currently taking a break, until HFS v2.4 get his stable version.