[CGI] Output van LINUX program.

Pagina: 1
Acties:

  • aKra
  • Registratie: Mei 2000
  • Laatst online: 23:35

aKra

Intentionally left blank.

Topicstarter
Omdat ze blijkbaar het verkeerd hebben opgevat:

Ik zoek de regel waarmee je de output van het linux programma 'ipac' met spaties uitgespuugd wordt.

Dus niet dat je krijgt:

IP accounting summaryHost: montu / Time created: 2002/04/29 09:02:14 CESTData from 2002/04/28 01:05:14 CEST to 2002/04/29 09:02:14 CEST

Maar:

IP accounting summary
Host: montu / Time created: 2002/04/29 09:02:14 CEST
Data from 2002/04/28 01:05:14 CEST to 2002/04/29 09:02:14 CEST

Het scriptje hangt al in elkaar, maar ik ben kwijt hoe dat commando heette.

Dit is het script tot nu toe:
code:
1
2
3
4
5
6
7
#!/usr/bin/perl

$ipacsum = `ipacsum`;

print "Content-type: text/html\n\n";

print "$ipacsum\n";

(Het is op het moment zelfs zo erg dat het helemaal geen output geeft!)

http://montu.getfragged.nl/cgi-bin/ipacsum.pl

Intentionally left blank.


  • muba
  • Registratie: April 2002
  • Laatst online: 19-10-2013

muba

Prince of Persia!

Goed, waarom het geen output geeft is mij ook onduidelijk.
Wat ik echter wel weet, is dat je een belangrijk basisbeginsel van HTML vergeet: de <BR> tag!
Een nieuwe regel,
zoals
wat ik hier
steeds doe,
levert in normaal HTML niet per definitie een nieuwe regel op.<BR>
Daarvoor moet je de <BR> tag gebruiken.<BR>
Snap je?<BR>

Dus goed, wat doen we?
code:
1
2
3
4
5
6
7
8
#!/usr/bin/perl

$ipacsum = `ipacsum`;
$ipacsum = s/\n/<BR>/gi;

print "Content-type: text/html\n\n";

print "$ipacsum\n";

Of tewel vervang elke \n teken voor de <BR> tag. Verder zou ik ook gewoon wat HTML rommel outputten, ik weet niet of het wat uitmaakt, maar het is wel netter:
code:
1
2
3
4
5
6
7
8
9
10
11
#!/usr/bin/perl

$ipacsum = `ipacsum`;
$ipacsum = s/\n/<BR>/gi;

print "Content-type: text/html\n\n";

print "<HTML><HEAD><TITLE>Euh, yeah right</TITLE></HEAD>";
print "<BODY>";
print "$ipacsum\n";
print "</BODY></HTML>";

Succes ermee!

Reporter: Mister Gandhi, what do you think of western civilisation?
Gandhi: I think it would be a good idea


Verwijderd

gewoon met een regexpje

  • muba
  • Registratie: April 2002
  • Laatst online: 19-10-2013

muba

Prince of Persia!

Haha ik was lekker eerder, terwijl mijn bericht toch langer was!

Reporter: Mister Gandhi, what do you think of western civilisation?
Gandhi: I think it would be a good idea


  • aKra
  • Registratie: Mei 2000
  • Laatst online: 23:35

aKra

Intentionally left blank.

Topicstarter
Geen van bijde geven ook enige output...

Zelfde als eerst, ik draai gewoon Apache met PHP & MySQL.

En natuurlijk de perl module.

Intentionally left blank.


  • muba
  • Registratie: April 2002
  • Laatst online: 19-10-2013

muba

Prince of Persia!

Goed het is een linux programma. Ik weet niet of je zelf op die Linux bak werkt ook nog? Nouja wat ik je in ieder geval aanraadt, is inloggen op die machine (dan wel gewoon op de computer zelf, dan wel via SSH of Telnet), en dan voer je je Perl script gewoon uit, kijken of je dan output krijgt. Zo niet, dan is er iets fout met je perms waarschijnlijk ofzo.

Reporter: Mister Gandhi, what do you think of western civilisation?
Gandhi: I think it would be a good idea


  • aKra
  • Registratie: Mei 2000
  • Laatst online: 23:35

aKra

Intentionally left blank.

Topicstarter
chmod = 755
uitvoeren = Hoe doe je dat dan? Met pipes ofsow? En dan elke enter vervangen voor een pipe?

Intentionally left blank.


  • muba
  • Registratie: April 2002
  • Laatst online: 19-10-2013

muba

Prince of Persia!

Pipes? Neej joh.
Inloggen op die bak, change-dirren naar de dir waar je script staat, iets van [cd cgi-bin] ofzo dus, dan:
./ipacsum.pl

Of:
perl ipacsum.pl

Euh 755, -rwxr-xr-x dus... dat zou goed moeten zijn.

Reporter: Mister Gandhi, what do you think of western civilisation?
Gandhi: I think it would be a good idea


  • Jelmer
  • Registratie: Maart 2000
  • Laatst online: 22:27
Als je nou de uitvoer eens tussen de <pre> tag's zet, maak je het jezelf lekker makkelijk.. En om stderr af te vangen zet je achter je commando (zonder quotes) " 2>&1". (kun je eenvoudig zien, ook als je het script via het www aanroept of er iets mis gaat)

  • aKra
  • Registratie: Mei 2000
  • Laatst online: 23:35

aKra

Intentionally left blank.

Topicstarter
Euhhhh??? Dat begrijp ik ook echt :)

root@montu:/www/montu/cgi-bin# perl ipacsum.pl
Content-type: text/html

<HTML><HEAD><TITLE>Euh, yeah right</TITLE></HEAD><BODY>
</BODY></HTML>root@montu:/www/montu/cgi-bin#

Intentionally left blank.


Verwijderd

-ipacsum wordt uit gevoerd door je apache ik neem niet aan dat die onder root daait dus heb je wel voldoende rechten.

-Altijd volledige paden opgeven (ik gok er zomaar op dat ipacsumin /sbin staat en die niet in de path van je apache user staat?)

-Wat doet het script als je het handmatig afschiet op je shell?

  • muba
  • Registratie: April 2002
  • Laatst online: 19-10-2013

muba

Prince of Persia!

2>&1?

Hieruit kan ik afleiden dat 2=STDERR en 1=STDOUT?
Waar moet je dat neerzetten dan? Dit vind ik namelijk zelf ook wel handig om te weten.

./ipacsum.pl 2>&1
?

Maar als je gewoon met commandline aan het linuxxen bent, verschijnt STDERR toch gewoon op je scherm?

Reporter: Mister Gandhi, what do you think of western civilisation?
Gandhi: I think it would be a good idea


  • zeroxcool
  • Registratie: Januari 2001
  • Laatst online: 04-09 13:39
code:
1
2
3
4
5
6
7
#!/usr/bin/perl
my $ipacsum;
$ipacsum = "ipacsum";

print "Content-type: text/html\n\n";

print "$ipacsum\n";

zeroxcool.net - curity.eu


  • muba
  • Registratie: April 2002
  • Laatst online: 19-10-2013

muba

Prince of Persia!

Jaa! Output!
DWZ, de HTML rommel wordt geprint, het programma zelf geeft geen output... hrrmz probeer es dit:

$ipacsum = `ipacsum` or "(programma niet gevonden)";

Als je dat krijgt, dan is het wat iemand dus al zei iets fout met je paden idd.

Reporter: Mister Gandhi, what do you think of western civilisation?
Gandhi: I think it would be a good idea


  • muba
  • Registratie: April 2002
  • Laatst online: 19-10-2013

muba

Prince of Persia!

Op maandag 29 april 2002 10:23 schreef ZeRoXcOoL het volgende:
code:
1
2
3
4
5
6
7
#!/usr/bin/perl
my $ipacsum;
$ipacsum = "ipacsum";

print "Content-type: text/html\n\n";

print "$ipacsum\n";
Ok en wat wil je nou bereiken?
Dit is natuurlijk niet waar het om gaat he, een beetje "ipacsum" op het scherm zetten... Daar heb je geen Perl voor nodig. D'oh.

Reporter: Mister Gandhi, what do you think of western civilisation?
Gandhi: I think it would be a good idea


  • aKra
  • Registratie: Mei 2000
  • Laatst online: 23:35

aKra

Intentionally left blank.

Topicstarter
Vervangen door /usr/local/bin/ipacsum...

En nog geen output...

Apache heeft ook recht om dat programma te draaien.

Intentionally left blank.


  • aKra
  • Registratie: Mei 2000
  • Laatst online: 23:35

aKra

Intentionally left blank.

Topicstarter
Op maandag 29 april 2002 10:22 schreef MUBA het volgende:
2>&1?

Hieruit kan ik afleiden dat 2=STDERR en 1=STDOUT?
Waar moet je dat neerzetten dan? Dit vind ik namelijk zelf ook wel handig om te weten.

./ipacsum.pl 2>&1
?

Maar als je gewoon met commandline aan het linuxxen bent, verschijnt STDERR toch gewoon op je scherm?
root@montu:/www/montu/cgi-bin# ./ipacsum.pl 2>&1
Content-type: text/html

<HTML><HEAD><TITLE>Euh, yeah right</TITLE></HEAD><BODY>
</BODY></HTML>root@montu:/www/montu/cgi-bin#

Intentionally left blank.


  • muba
  • Registratie: April 2002
  • Laatst online: 19-10-2013

muba

Prince of Persia!

Hrrmz, voer ipacsum (met volledige pad) dan eens gewoon uit vanuit Linux dus, maar niet als root maar als gewone user.

Reporter: Mister Gandhi, what do you think of western civilisation?
Gandhi: I think it would be a good idea


  • aKra
  • Registratie: Mei 2000
  • Laatst online: 23:35

aKra

Intentionally left blank.

Topicstarter
Dit is het script nu:
code:
1
2
3
4
5
6
7
8
9
10
#!/usr/bin/perl
$ipacsum = `ipacsum` or "(programma niet gevonden)";
$ipacsum = s/\n/<BR>/gi;

print "Content-type: text/html\n\n";

print "<HTML><HEAD><TITLE>Euh, yeah right</TITLE></HEAD>";
print "<BODY>";
print "$ipacsum\n";
print "</BODY></HTML>";

Intentionally left blank.


  • Jelmer
  • Registratie: Maart 2000
  • Laatst online: 22:27
Op maandag 29 april 2002 10:22 schreef MUBA het volgende:
2>&1?

Hieruit kan ik afleiden dat 2=STDERR en 1=STDOUT?
Waar moet je dat neerzetten dan? Dit vind ik namelijk zelf ook wel handig om te weten.

./ipacsum.pl 2>&1
?

Maar als je gewoon met commandline aan het linuxxen bent, verschijnt STDERR toch gewoon op je scherm?
Klopt helemaal. Wat je doet is dus de output stream stderr (2) aan die van stdout (1) knopen. Op de console/via een ssh sessie krijg je dit gewoon te zien omdat beide dan aan de tty worden gehangen. Maar zodra je een programma als less gaat gebruiken en er uitvoer op stderr komt, kun je daar niet door scrollen. Om die uitvoer dan wel te krijgen moet je dit doen: (squidclient is zo'n proggie, zullen er vast wel meer zijn)

squidclient 2>&1 | less

Nu kun je mooi door de help van squidclient bladeren :)


Voor topicstarter, jij moet dit dus in je script zetten:
code:
1
2
3
4
5
6
#!/usr/bin/perl
$ipacsum = `ipacsum 2>&1`;

print "Content-type: text/html\n\n";

print "<pre>$ipacsum\n</pre>";

  • aKra
  • Registratie: Mei 2000
  • Laatst online: 23:35

aKra

Intentionally left blank.

Topicstarter
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
root@montu:~# ipacsum
IP accounting summary
Host: montu / Time created: 2002/04/29 10:30:48 CEST
Data from 2002/04/28 01:05:14 CEST to 2002/04/29 10:30:48 CEST
* incoming59ssh                      :         0
* incoming59www                      :         0
* outgoing59ssh                      :         0
* outgoing59www                      :         0
* eth0-in                            :       32G
* eth0-out                          :        59G
* rsa-in                            :        13G
* rsa-out                            :       25G
* dw-in                          :      814M
* dw-out                            :        3656M
* usp-in                            :        3695M
* usp-out                            :       7353M
* ee-in                          :       10G
* ee-out                            :        16G
* u!-in                          :       2430M
* u!-out                            :        5567M
* = data incomplete, rule was not there all the time
root@montu:~#

nander@montu:~$ ipacsum
IP accounting summary
Host: montu / Time created: 2002/04/29 10:31:10 CEST
Data from 2002/04/28 01:05:14 CEST to 2002/04/29 10:31:10 CEST
* incoming59ssh                      :         0
* incoming59www                      :         0
* outgoing59ssh                      :         0
* outgoing59www                      :         0
* eth0-in                            :       32G
* eth0-out                          :        59G
* rsa-in                            :        13G
* rsa-out                            :       25G
* dw-in                          :      814M
* dw-out                            :        3656M
* usp-in                            :        3695M
* usp-out                            :       7353M
* ee-in                          :       10G
* ee-out                            :        16G
* u!-in                          :       2430M
* u!-out                            :        5567M
* = data incomplete, rule was not there all the time
nander@montu:~$

Ik ga even eten... Na al dat gezoek :Y)

Intentionally left blank.


  • aKra
  • Registratie: Mei 2000
  • Laatst online: 23:35

aKra

Intentionally left blank.

Topicstarter
Op maandag 29 april 2002 10:31 schreef Jelmer Barhorst het volgende:

[..]

Klopt helemaal. Wat je doet is dus de output stream stderr (2) aan die van stdout (1) knopen. Op de console/via een ssh sessie krijg je dit gewoon te zien omdat beide dan aan de tty worden gehangen. Maar zodra je een programma als less gaat gebruiken en er uitvoer op stderr komt, kun je daar niet door scrollen. Om die uitvoer dan wel te krijgen moet je dit doen: (squidclient is zo'n proggie, zullen er vast wel meer zijn)

squidclient 2>&1 | less

Nu kun je mooi door de help van squidclient bladeren :)


Voor topicstarter, jij moet dit dus in je script zetten:
code:
1
2
3
4
5
6
#!/usr/bin/perl
$ipacsum = `ipacsum 2>&1`;

print "Content-type: text/html\n\n";

print "<pre>$ipacsum\n</pre>";
Jouw lines/script:

http://montu.getfragged.nl/cgi-bin/ipacsum3.pl

Nope, dus niet de oplossing :D

Intentionally left blank.


  • muba
  • Registratie: April 2002
  • Laatst online: 19-10-2013

muba

Prince of Persia!

Nou wordt het echt vervelend.

$ipacsum = (`/usr/local/bin/ipacsum 2>&1` or "(programma niet gevonden)");

Nouja het is gewoon een enorm slappe debug regel maar als het nou nog niet werkt... dan wordt het eng!

Reporter: Mister Gandhi, what do you think of western civilisation?
Gandhi: I think it would be a good idea


  • Jelmer
  • Registratie: Maart 2000
  • Laatst online: 22:27
Je regexp is niet goed. Die gooit alle content weg. Zet hem maar eens uit:
code:
1
2
3
4
5
6
7
8
9
#!/usr/bin/perl
$ipacsum = `ls` or "(programma niet gevonden)";
#$ipacsum = s/\n/<BR>/gi;
print "Content-type: text/html\n\n";

print "<HTML><HEAD><TITLE>Euh, yeah right</TITLE></HEAD>";
print "<BODY><PRE>";
print "$ipacsum\n";
print "</PRE></BODY></HTML>";

  • muba
  • Registratie: April 2002
  • Laatst online: 19-10-2013

muba

Prince of Persia!

Wat is er fout met mijn regexp?

"\n" -> "<BR>"

daarvan gaat toch niet alle context weg?
Wacht ik heb het...
Het is niet $ipacsum = s/\n/<BR>/gi; maar
$ipacsum =~ s/\n/<BR>/gi;

=~!
Ik had =...

Stohhhhhhhhm! |:(

Reporter: Mister Gandhi, what do you think of western civilisation?
Gandhi: I think it would be a good idea


  • muba
  • Registratie: April 2002
  • Laatst online: 19-10-2013

muba

Prince of Persia!

Hrrmz... :Z Aan de lange tijd dat het hier nu al rustig is maak ik op dat het nu werkt?
Neej, zo te zien dus niet.

Reporter: Mister Gandhi, what do you think of western civilisation?
Gandhi: I think it would be a good idea


  • aKra
  • Registratie: Mei 2000
  • Laatst online: 23:35

aKra

Intentionally left blank.

Topicstarter
http://montu.getfragged.nl/cgi-bin/ipacsum4.pl

Het werkt nu eindelijk!

Allemaal bedankt voor jullie hulp!

Intentionally left blank.


  • muba
  • Registratie: April 2002
  • Laatst online: 19-10-2013

muba

Prince of Persia!

* muba zucht: "Finally!".

$mubaWilWeten = Akra->getCode();

om het zo maar even uit te drukken

Reporter: Mister Gandhi, what do you think of western civilisation?
Gandhi: I think it would be a good idea


  • aKra
  • Registratie: Mei 2000
  • Laatst online: 23:35

aKra

Intentionally left blank.

Topicstarter
if MUBA == aardig then
aKra geef code!
else aKra geef ook code
fi
code:
1
2
3
4
5
6
7
8
#!/usr/bin/perl
$ipacsum = `/usr/local/bin/ipacsum` or "(programma niet gevonden)";
#$ipacsum = s/\n/<BR>/gi;
print "Content-type: text/html\n\n";
print "<HTML><HEAD><TITLE>Euh, yeah right</TITLE></HEAD>";
print "<BODY><PRE>";
print "$ipacsum\n";
print "</PRE></BODY></HTML>";

Intentionally left blank.

Pagina: 1