Tjenester/Hjemmesider: Difference between revisions
m We don't condone jetbrains |
Add section about password protection |
||
| Line 118: | Line 118: | ||
'''MERK''': Blokkeringen gjelder bare nedlasting via vevtjeneren. PHP- og CGI-script kan fortsatt lese blokkerte filer, f.eks. en SQLite-database eller en <code>.env</code>-fil. | '''MERK''': Blokkeringen gjelder bare nedlasting via vevtjeneren. PHP- og CGI-script kan fortsatt lese blokkerte filer, f.eks. en SQLite-database eller en <code>.env</code>-fil. | ||
== Passordbeskyttelse == | |||
Lag en passordfil som heter <code>.htpasswd</code> og gjør den leselig for vevtjeneren: | |||
<pre> | |||
htpasswd -c -B ~/web-docs/.htpasswd gjest | |||
chmod o+r ~/web-docs/.htpasswd | |||
</pre> | |||
(<code>-c</code> er der for å lage en ny fil, så dropp den om du legger til flere brukere) | |||
Legg så en <code>.htaccess</code> i katalogen som skal beskyttes: | |||
<pre><nowiki> | |||
AuthType Basic | |||
AuthName "Hemmelig" | |||
AuthUserFile /home/pvv/d/brukernavn/web-docs/.htpasswd | |||
Require valid-user | |||
</nowiki></pre> | |||
<code>AuthUserFile</code> må være en full filsti. Du kan printe hele filstien med <code>realpath ~/web-docs/.htpasswd</code>. | |||
'''MERK:''' | |||
* Fila er beskyttet mot nedlasting fordi den heter <code>.htpasswd</code>. Om du gir den et annet navn, f.eks. <code>passord.txt</code>, kan hvem som helst laste den ned (se [[#Blokkerte filer og kataloger|Blokkerte filer og kataloger]]) | |||
* Andre PVV-brukere kan lese passord-hashene, så ikke bruk et passord du bruker andre steder. | |||
* Dette beskytter bare mot besøkende på nettet. Andre PVV-brukere kan fortsatt lese filene på disken. | |||
== Visning av PHP-feilmeldinger == | == Visning av PHP-feilmeldinger == | ||
| Line 258: | Line 286: | ||
'''NOTE''': The blocking only applies to downloads through the webserver. PHP and CGI scripts can still read blocked files, e.g. an SQLite database or a <code>.env</code> file. | '''NOTE''': The blocking only applies to downloads through the webserver. PHP and CGI scripts can still read blocked files, e.g. an SQLite database or a <code>.env</code> file. | ||
== Password protection == | |||
Create a password file named <code>.htpasswd</code> and make it readable for the webserver: | |||
<pre> | |||
htpasswd -c -B ~/web-docs/.htpasswd guest | |||
chmod o+r ~/web-docs/.htpasswd | |||
</pre> | |||
(<code>-c</code> is there to create a new file, omit it if you are adding more users) | |||
Then put a <code>.htaccess</code> in the directory you want to protect: | |||
<pre><nowiki> | |||
AuthType Basic | |||
AuthName "Secret" | |||
AuthUserFile /home/pvv/d/username/web-docs/.htpasswd | |||
Require valid-user | |||
</nowiki></pre> | |||
<code>AuthUserFile</code> must be a full file path. You can print the full file path with <code>realpath ~/web-docs/.htpasswd</code>. | |||
'''NOTE:''' | |||
* The file is protected from downloads because it is named <code>.htpasswd</code>. If you give it a different name, e.g. <code>passwords.txt</code>, anyone can download it (see [[#Blocked files and directories|Blocked files and directories]]) | |||
* Other PVV users can read the password hashes, so don't use a password you use anywhere else. | |||
* This only protects against visitors on the web. Other PVV members can still read the files on disk. | |||
== Displaying PHP error messages == | == Displaying PHP error messages == | ||
Revision as of 19:37, 19 November 2026
En hjemmeside er ett eller flere dokument som befinner seg på en brukers hjemmekatalog.
Lage hjemmesidekatalogen
For å lage din egen hjemmeside her på PVV må du gjøre følgende:
- Les Webreglement
- Logg inn på en av loginboksene med SSH.
- Lag katalogen
web-docsi rotnivået av hjemmekatalogen din. Kjør kommandoen:mkdir ~/web-docs. Merk at denne katalogen IKKE heterpublic_html, slik den gjør på studentsalene. - Gi vevtjeneren tilgang:
- Hjemmekatalogen din ha execute-tilgang for gruppa og andre:
chmod g+x,o+x ~ web-docsmå i tillegg være leselig:chmod g+rx,o+rx ~/web-docsls -ld ~ ~/web-docsskal så vise minst:drwx--x--xogdrwxr-xr-x(det kan være at det stårdrwxr-sr-xpå den siste
- Hjemmekatalogen din ha execute-tilgang for gruppa og andre:
- Legg en
index.htmleller lignende iweb-docs.
Flytte filer til hjemmesiden
Du kan kopiere filer til web-docs med scp fra din egen maskin:
# Kopier filene index.html og bilde.png til ~/web-docs/... scp index.html bilde.png brukernavn@login.pvv.ntnu.no:web-docs/ # Kopier katalogen prosjekt til ~/web-docs/prosjekt scp -r prosjekt brukernavn@login.pvv.ntnu.no:web-docs/
Filene får de samme rettighetene som på din maskin. Dersom du får 403 Forbidden etterpå, logg inn på en loginboks og kjør chmod -R a+rX ~/web-docs.
Har du siden i git, kan du også klone repoet rett inn i web-docs og oppdatere med git pull. .git-katalogen blir ikke servert.
Filutvidelser
| Filutvidelse | Behandles som |
|---|---|
.php, .php3, .php4, .php5, .php7, .php8, .pht, .phtml |
PHP |
.cgi, .pl, .py, .sh, .bash |
CGI-script (se under) |
| Alt annet | Vanlig fil |
.pm,.incog.phpsblir ikke servert.- Kopier av script, som
index.php.old,index.php~ogindex.php.bak, blir blokkert, slik at kildekoden ikke kan lastes ned. - PHP- og CGI-script i kataloger som heter
upload,uploadsellersites/*/filesblir ikke kjørt (se Opplasting av filer). - Ved besøk på en katalog ser vevtjeneren etter blant annet
index.htm,index.html,index.php,index.cgi,index.txtogmeg.html, i den rekkefølgen.
Er lista utdatert, er det httpd.nix i NixOS-konfigurasjonen vår som gjelder.
Logger
Dersom du ønsker å motta logger for besøk på hjemmesiden din (for eksempel for å lage statistikk) kan du opprette katalogen ~/nobackup/weblogs. Loggen vil da bli skrevet dit fortløpende, i separate filer for hver dag.
CGI-script
CGI-script er programmer som skriver ut headere og HTML. De er ofte skrevet i Perl, Python eller et tilsvarende språk. For å bruke et cgi-script på PVV holder det å gi det endelsen ".cgi". PHP på PVV kjøres ikke som CGI men som en egen Apache-modul, og du kan derfor bruke PHP direkte uten noe om og men.
Om du av en eller annen grunn ikke vil kalle CGI-scriptene dine noe som ender på .cgi (for eksempel fordi du bruker noe tredjeparts programvare du ikke vil tukle for mye med) kan du lage en egen cgi-katalog på denne måten:
- Opprette en dedikert CGI-katalog (f.eks cgi-bin) i web-docs katalogen din.
- Legg inn filen .htaccess med innholdet:
Options +ExecCGI -Indexes SetHandler cgi-script
- Gjøre katalogen og .htaccess tilgjengelig for andre. (Bruk chmod a+rx katalog og chmod a+r .htaccess.)
- Alle filer du legger i denne katalogen, og i underkataloger, vil bli behandlet som CGI script og kjørt istedenfor å bli vist direkte. En typisk URL til et slikt script blir da http://www.pvv.ntnu.no/~bruker/cgi-bin/script
Blokkerte filer og kataloger
Vevtjeneren nekter å servere filer og kataloger som typisk inneholder hemmeligheter eller ikke er ment for publisering. Slike forespørsler får 403 Forbidden.
Eksempler på blokkerte filer og kataloger:
| Versjonskontroll | .git/, .svn/, .hg/, .gitignore
|
| Nøkler og passord | .env, id_rsa, *.pem, *.key, .htpasswd
|
| Databaser | *.sql, *.sqlite, *.db
|
| Backup og midlertidige filer | *.bak, *.old, *.swp, *~
|
| Logger | *.log, error_log
|
| Konfigurasjon | composer.json, package.json, Dockerfile, .my.cnf
|
| Verktøy og editorer | .ssh/, .vscode/, __pycache__/
|
Hele lista finner du på https://temmie.pvv.ntnu.no/environment/denied-paths.json. files er wildcard-mønstre som sammenlignes mot filnavnet, og directories er regulære uttrykk som kjøres mot hver underkatalog i filstien.
I tillegg gjelder noen regler fra httpd.nix som ikke står i lista:
.phps-filer blir ikke servert.- PHP- og CGI-skript i kataloger som heter
upload,uploadsellersites/*/filesblir ikke kjørt. - PHP- og CGI-skript hvor filutvidelsen følges av en av
.~!_#-vil ikke bli servert.
Vil du likevel publisere en blokkert fil, kan du tillate den i en .htaccess i samme katalog eller en katalog over:
<Files "composer.json">
Require all granted
</Files>
For en blokkert katalog, f.eks. gammel.bak/, legger du en .htaccess i selve katalogen:
<FilesMatch "^(?!\.ht)">
Require all granted
</FilesMatch>
Dette tillater alt unntatt .htaccess-filer. Require all granted alene virker ikke. Ofte er det enklere å gi katalogen et annet navn.
Sjekk at fila ikke inneholder noe hemmelig før du gjør dette.
MERK: Blokkeringen gjelder bare nedlasting via vevtjeneren. PHP- og CGI-script kan fortsatt lese blokkerte filer, f.eks. en SQLite-database eller en .env-fil.
Passordbeskyttelse
Lag en passordfil som heter .htpasswd og gjør den leselig for vevtjeneren:
htpasswd -c -B ~/web-docs/.htpasswd gjest chmod o+r ~/web-docs/.htpasswd
(-c er der for å lage en ny fil, så dropp den om du legger til flere brukere)
Legg så en .htaccess i katalogen som skal beskyttes:
AuthType Basic AuthName "Hemmelig" AuthUserFile /home/pvv/d/brukernavn/web-docs/.htpasswd Require valid-user
AuthUserFile må være en full filsti. Du kan printe hele filstien med realpath ~/web-docs/.htpasswd.
MERK:
- Fila er beskyttet mot nedlasting fordi den heter
.htpasswd. Om du gir den et annet navn, f.eks.passord.txt, kan hvem som helst laste den ned (se Blokkerte filer og kataloger) - Andre PVV-brukere kan lese passord-hashene, så ikke bruk et passord du bruker andre steder.
- Dette beskytter bare mot besøkende på nettet. Andre PVV-brukere kan fortsatt lese filene på disken.
Visning av PHP-feilmeldinger
I utgangspunktet er ikke php-feilmeldinger vist. For at feilmeldinger skal vises, lag filen .htaccess med følgende innhold:
php_flag display_errors on php_value error_reporting E_ALL
Filen lages i katalogen til scriptet som skal kjøres.
Opplastingsgrense for PHP
Maks størrelse på filopplasting i PHP er satt til 40 MB (post_max_size og upload_max_filesize).
Tilgjengelig programvare
CGI- og PHP-script kjører i et sandboksmiljø med et fast sett med programmer og biblioteker. Du kan finne den fullstendige lista med programvare ved https://temmie.pvv.ntnu.no/environment/.
Eget domene o.l.
Det er ikke mulig å ha virtuell server for ditt eget domene på PVV. Du kan ha ikke-kommersielt innhold på PVV, men da må du få ISPen/webhotellet ditt til å sette opp en http-videresending (redirect) til http://www.pvv.ntnu.no/~bruker/
Det er ikke tilstrekkelig å lage en DNS-peker til PVVs vevjener, da dette forutsetter at PVV setter opp en virtuell server eller en redirect til dine sider på serveren.
Grunnene for hvorfor det er sånn er flere, men primært er det fordi PVV som helhet er underlagt NTNUs IT-reglement.
Sikkerhet
Funnet et sikkerhetshull?
Du tror du har funnet et sikkerhetshull i noens hjemmeside? Vennligst ta kontakt med CERT i stedet for å prøve det ut.
Se også
Teknisk informasjon om vevtjener
Homepages
A homepage is one or more documents located in a users home directory.
Creating the homepage directory
To make your own homepage at PVV, you should do the following:
- Read the web rules
- Log onto one of the login boxes with SSH.
- Make a directory
web-docsin your home directory. Run the command:mkdir ~/web-docs. Note that the directory is NOT namedpublic_html, as it is on NTNU's student computer labs. - Give the webserver access:
- Set the correct attributes on your home directory and the web-docs catalog.
- Your home directory should have execute-permissions for its group and others:
chmod g+x,o+x ~ web-docsmust also be readable:chmod g+rx,o+rx ~/web-docsls -ld ~ ~/web-docsshould then show at leastdrwx--x--xanddrwxr-xr-x(the last one might saydrwxr-sr-xinstead)
- Your home directory should have execute-permissions for its group and others:
- Put an
index.htmlor similar inweb-docs.
Copying files to your homepage
You may copy files to web-docs using scp from your own computer:
# Copy the files index.html and picture.png to ~/web-docs/... scp index.html picture.png username@login.pvv.ntnu.no:web-docs/ # Copy the directory project to ~/web-docs/project scp -r project username@login.pvv.ntnu.no:web-docs/
The files keep the permissions they have on your computer. If you get 403 Forbidden afterwards, log onto a login box and run chmod -R a+rX ~/web-docs.
If your keep your site as a git project, you can clone the repository straight into web-docs and update it with git pull. The .git directory will not served.
Logger
If you wish to receive logs on visits to your home page (for an instance to make statistics) you can make the directory ~/nobackup/weblogs. The log with then be written continuously, in separate files each day.
CGI-script
CGI-script are programs that write headers and HTML. They are often written in Perl, Python or a similar language. To use a cgi-script at PVV it is sufficient to give it the file extension .cgi. PHP at PVV is not run as cgi but as a separate Apache module, and you can therefore use PHP directly without having to do any additional work.
If you for some reason don't want to name your CGI-scripts something that ends on ".cgi" (for an instance because you use some third party software that you do not want to fiddle too much with) you can make a cgi catalog in this way:
- Make a dedicated CGI-catalog (for an instance cgi-bin) in your web-docs catalog.
- Add the file .htaccess with the content:
Options +ExecCGI -Indexes SetHandler cgi-script
- Make the catalog and .htaccess available for others. (Use chmod a+rx catalog and chmod a+r .htaccess.)
- All files that yoy put in this catalog, and in sub-catalogs, will be treated as CGI-script and run instead of getting show directly. A typical URL to such a script then becomes: http://www.pvv.ntnu.no/~bruker/cgi-bin/script
Blocked files and directories
The webserver refuses to serve files and directories that typically contain secrets or aren't meant to be published. Such requests get 403 Forbidden.
Examples of blocked files and directories:
| Version control | .git/, .svn/, .hg/, .gitignore
|
| Keys and passwords | .env, id_rsa, *.pem, *.key, .htpasswd
|
| Databases | *.sql, *.sqlite, *.db
|
| Backups and temporary files | *.bak, *.old, *.swp, *~
|
| Logs | *.log, error_log
|
| Configuration | composer.json, package.json, Dockerfile, .my.cnf
|
| Tools and editors | .ssh/, .vscode/, __pycache__/
|
The full list is at https://temmie.pvv.ntnu.no/environment/denied-paths.json. files are wildcard patterns matched against the file name, and directories are regular expressions matched against each directory in the path.
In addition, some rules from httpd.nix apply that aren't in the list:
.phpsfiles are not served.- Copies of scripts are only blocked when the file extension is followed by
.,~,!,_,#or-, e.g.index.php.old,index.php~andindex.php-old. Names likeindex.phpoldorindex.php (1)are served as regular files, with the source code visible to everyone. Delete old copies instead of relying on this rule. - PHP and CGI scripts in directories named
upload,uploadsorsites/*/filesare not run.
To publish a blocked file anyway, allow it in a .htaccess in the same directory or a directory above:
<Files "composer.json">
Require all granted
</Files>
For a blocked directory, e.g. old.bak/, put a .htaccess in the directory itself:
<FilesMatch "^(?!\.ht)">
Require all granted
</FilesMatch>
This allows everything except .htaccess files. Require all granted on its own does not work. Renaming the directory is often easier.
Make sure the file doesn't contain anything secret before doing this.
NOTE: The blocking only applies to downloads through the webserver. PHP and CGI scripts can still read blocked files, e.g. an SQLite database or a .env file.
Password protection
Create a password file named .htpasswd and make it readable for the webserver:
htpasswd -c -B ~/web-docs/.htpasswd guest chmod o+r ~/web-docs/.htpasswd
(-c is there to create a new file, omit it if you are adding more users)
Then put a .htaccess in the directory you want to protect:
AuthType Basic AuthName "Secret" AuthUserFile /home/pvv/d/username/web-docs/.htpasswd Require valid-user
AuthUserFile must be a full file path. You can print the full file path with realpath ~/web-docs/.htpasswd.
NOTE:
- The file is protected from downloads because it is named
.htpasswd. If you give it a different name, e.g.passwords.txt, anyone can download it (see Blocked files and directories) - Other PVV users can read the password hashes, so don't use a password you use anywhere else.
- This only protects against visitors on the web. Other PVV members can still read the files on disk.
Displaying PHP error messages
By default php error messages are not shown. For error messages to be shown, make the file .htaccess with the following content:
php_flag display_errors on php_value error_reporting E_ALL
The file must be made in the directory of the script that is to be run.
Upload limit
The maximum size for PHP file uploads is 40 MB (post_max_size and upload_max_filesize).
Available software
CGI and PHP scripts run in a sandbox with a fixed set of programs and libraries. You may find the full list of software at https://temmie.pvv.ntnu.no/environment/
Your own domain and similar things
It is not possible to have a virtual server for your own domain at PVV. You can have non-commercial content on PVV, but you must then make your ISP/web-hotel set up a HTTP-forwarding (redirect) to http://www.pvv.ntnu.no/~user/
It is not sufficient to make a DNS-pointer to PVVs web-server, because this requires that PVV sets up a virtual server or a redirect to your pages on the server.
There are several reasons for this, but it is primarily because PVV as a whole is subject to NTNUs IT-rules.
Security
Found a security hole?
So you think you have found a security hole in someone's homepage? Please contact CERT instead of letting it rip.
Also See
Technical information about webserver