Basic website

This commit is contained in:
2023-03-21 11:14:25 +01:00
parent 2379383610
commit 623d99adc3
13 changed files with 809 additions and 0 deletions

4
include/bottom.inc.php Normal file
View File

@ -0,0 +1,4 @@
</div>
</div>
</body>
</html>

193
include/function.inc.php Normal file
View File

@ -0,0 +1,193 @@
<?php
// Test si le fichier est appell<6C> "seul"
//if (preg ("function.inc.php", $_SERVER['PHP_SELF']))
//{
// header("Location: /");
// exit;
//}
function printheader($titre){
if(!strlen($titre)) {
$titre = "Homepage";
}
require("header.inc.php");
}
function getimage() {
$curdir=basename(dirname($_SERVER['SCRIPT_NAME']));
if(empty($curdir)) {
return "intro";
} else {
return $curdir;
}
}
// Captcha (cf http://www.webelix.net/trucs_et_astuces-(PHP)_Anti_Robots_Spammeurs.html)
function aff_captcha()
{
// Tableau de valeurs
$input = array(2, 35, 15, 6, 40, 4, 8, 22, 11, 5, 32, 10, 1, 12, 26, 16, 55, 17);
// Extraction al<61>atoire de deux valeurs du tableau
$rand_keys = array_rand($input, 2);
// Creation et calcul de la somme des deux valeurs
$question = 'Quelle est la somme de <strong>'.$input[$rand_keys[0]].' + '.$input[$rand_keys[1]].' = </strong>';
$add = md5($input[$rand_keys[0]] + $input[$rand_keys[1]]);
echo '<table cellspacing="0" cellpadding="6" style="border: 1px solid red">
<tr>
<td><strong>Anti-Spam : </strong>'. $question .'</td>
<td><input name="reponse" type="text" size="3" maxlength="3" value="" style="font-weight: bold" />
<input name="captcha" type="hidden" value="'. $add .'" /></td>
</tr>
</table>';
}
function valid_captcha()
{
// if (md5($_POST['reponse']) == $_POST['captcha'])
if (md5(get_post('reponse')) == get_post('captcha'))
return true;
else
return false;
}
//
// escape_string
// Action: Escape a string
// Call: escape_string (string string)
//
function escape_string ($string)
{
if (get_magic_quotes_gpc () == 0)
{
$search = array ("/'/", "/\"/", "/;/");
$replace = array ("\\\'", "\\\"", "\\;");
$escaped_string = preg_replace ($search, $replace, $string);
}
else
{
$escaped_string = $string;
}
return $escaped_string;
}
//
// get_post
// Action: Get a variable from POST
// Call: get_post('var');
//
function get_post ($string)
{
if (($_SERVER['REQUEST_METHOD'] == "POST") && isset($_POST[$string]))
{
return escape_string($_POST[$string]);
}
else
{
return NULL;
}
}
//
// get_get
// Action: Get a variable from GET
// Call: get_get('var');
//
function get_get ($string)
{
if (($_SERVER['REQUEST_METHOD'] == "GET") && isset($_GET[$string]))
{
return escape_string($_GET[$string]);
}
else
{
return NULL;
}
}
// Pour le menu parse_ini_file();
function searchini() {
return dirname(__FILE__)."/menu.ini";
}
function domenu() {
$menu = parse_ini_file(searchini(),true);
$topmenu = $menu['topmenu'];
$out = ""; // Out text for menu
if (count($topmenu)> 10) {
return "Error Too mutch lines in top menu (max 4)";
}
// Top menu
$out .= "<div class=\"divmenuhaut\">\n";
//$out .= "<p>&nbsp;</p><p>&nbsp;</p>\n";
$out .= "<p>&nbsp;</p>\n";
$out .= "<ul class=\"menu\">\n";
foreach ($topmenu as $line => $val) {
$out .= "<li><a class=\"";
if ($line == getimage()) {
$out .= "menuon";
} else {
$out .= "menuoff";
}
$out .= "\" href=\"/";
if ($line != "intro") {
$out .= $line."/";
}
$out .= "\" >";
if ($line == getimage()) {
$out .= "&gt; ";
}
$out .= $val."</a></li>";
}
$out .= "</ul></div>\n";
// Bottom menu
/*
$out .= "<div class=\"divmenubas\">\n";
$out .= "<ul class=\"menu\">\n";
foreach ($bottommenu as $line => $val) {
$out .= "<li><a class=\"";
if ($line == getimage()) {
$out .= "menuon";
} else {
$out .= "menuoff";
}
$out .= "\" href=\"/";
if ($line != "intro") {
$out .= $line."/";
}
$out .= "\" >";
if ($line == getimage()) {
$out .= "&gt; ";
}
$out .= $val."</a></li>";
}
$out .= "</ul></div>\n";
*/
print $out;
}
// Page
// Do the page with the right title
function page($titre) {
printheader($titre);
domenu();
print "<div class=\"textebox\">\n";
}
function page2($titre) {
printheader2($titre);
domenu();
print "<div class=\"textebox\">\n";
}
// finpage
// ajoute les tags en fin de page
function finpage(){
require("bottom.inc.php");
}
?>

17
include/header.inc.php Normal file
View File

@ -0,0 +1,17 @@
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"
<meta name="ROBOTS" content="ALL">
<meta name="REVISIT-AFTER" content="15 DAYS">
<meta name="RATING" content="Internet">
<meta name="AUTHOR" content="Xavier Beaudouin">
<meta name="SUBJECT" content="RIS LSI Consulting SASU">
<meta name="keywords" content="Consulting, FreeLance, Smart Contracts, C, BSD, FreeBSD, NetBSD, UNIX, Cloud Computing, Linux, git, Linux, DevOps, NetOps, Python, Cisco, Networking, Juniper, Mikrotik, RIPE, IPv4, IPv6, Routing, ZFS, Storage, Victron Energy">
<meta name="robots" content="index, follow">
<title>RIS LSI Consulting - <?php print "$titre"; ?></title>
<link rel=stylesheet type="text/css" href="/css/base.css">
</head>
<body class="lapage">
<div style="position:relative; min-height:100%">

15
include/menu.ini Normal file
View File

@ -0,0 +1,15 @@
; menu file
;
[topmenu]
; / = intro
intro=RIS LSI
bsd=BSD Unix
linux=GNU/Linux
network=Networking
energy=Energy Storage
[bottommenu]
faq=FAQ

390
include/send_mail.inc.php Normal file
View File

@ -0,0 +1,390 @@
<?php
// send_mail
// Action: send a mail
// Return if mail has been sent
// Call: send_mail(string from, string to, string subject, string message, string cc, string bcc)
// Details of calls :
// $from = mail from
// $to = recipient for the mail
// $subject = subject of the mail
// $message = message body
// $cc = Carbon Copy
function send_mail($from, $to, $subject="", $message="(empty message)", $cc="",$format="text")
{
$smail = new SMTP("mail.oav.net"); //Initiate class into object.
if ($smail->errno)
die ($smail->errmsg());
if (!$smail->SetFrom("$from"))
die ($smail->errmsg());
if (!$smail->SetToTitle("$to"))
die ($smail->errmsg());
if (!$smail->SetTo("$to"))
die ($smail->errmsg());
// if (!$smail->SetTo('somebody@somewhere.com')) die ($smail->errmsg());
if ($cc) {
if (!$smail->SetCC("$cc"))
die ($smail->errmsg());
// if (!$smail->SetCC('somebody@something.com')) die ($smail->errmsg());
}
if (!$smail->SetSubject("$subject"))
die ($smail->errmsg());
if (!$smail->SetText("$message"))
die ($smail->errmsg());
if (!$smail->sendmail($format))
die ($smail->errmsg());
if (!$smail->end())
die ($smail->errmsg());
}
Class SMTP {
// global variables
Var $errno = 0;
Var $errmsg = '';
Var $errors=Array(
1 => 'Invalid Input',
2 => 'Unable to establish connection',
3 => 'Connection timed out',
4 => 'SMTP Error returned',
);
Var $server = "";
Var $user = "";
Var $sock = false;
Var $readlength = 1024;
Var $mailto = array();
Var $mailcc = array();
Var $mailfrom = "";
Var $mailfromtitle = '';
Var $mailsubject = "";
Var $mailtext = "";
Var $attachments = array();
Var $deadmsg = "";
Var $verbose = "0";
//Modify this for verbose output of the transaction..
//1 for verbose
//0 for silent
Function SMTP($server, $smtpport=25, $timeout=10)
{
// Return false if we can't get an SMTP connection...
if (strlen($server)<=0)
return $this->error(1, 'server');
else $this->server=$server;
if (!$this->sock = fsockopen($server, $smtpport, &$errno, &$errstr, $timeout))
return $this->error(2);
if (!socket_set_blocking($this->sock, true))
return $this->error(4, 'set blocking');
if (!$this->GetFeedback())
return $this->error(2, 'during onset');
return true;
}
Function Error($errno, $message)
{
$this->errno=$errno;
$this->errmsg.=$message;
return false;
}
Function ErrMsg($error=false)
{
if (false===$error)
{
$errno=$this->errno;
return $this->$errors[$errno].' '.$this->errmsg;
}
else return $this->$errors[$error];
}
Function ErrNo()
{
return $this->errno;
}
Function SetSubject($subject)
{
if (strlen($subject)<=0)
return $this->Error(1, 'subject');
$this->mailsubject = ereg_replace("\n"," ",$subject);
return true;
}
Function setText($text)
{
if (strlen($text)<=0)
return $this->Error(1, 'message body');
$text = ereg_replace("\n.\n", "\n. \n", $text);
$text = ereg_replace("\n.\r", "\n. \r", $text);
$this->mailtext = $text;
return true;
}
Function SetTo($to)
{
// THIS CAN BE USED TO SET AS MANY "BCC" RECIPIENTS AS YOU LIKE.
if (strlen($to)<=0)
return $this->Error(1, '"to" too short');
if (strlen($to)>=129)
return $this->Error(1, '"to" too long');
$this->mailto[]=$to;
return true;
}
Function SetToTitle($title)
{
if (strlen($title)<=0)
return $this->Error(1, 'totitle too short');
if (strlen($title)>=128)
return $this->Error(1, 'totitle too long');
$this->mailtotitle="<$title>";
return true;
}
function SetCC($to)
{
// THIS WORKS LIKE "SETTO" ABOVE, BUT TELLS EVERYBODY WHO'S INVOLVED.
// This is a potential privacy issue...
if (!$this->setto($to))
return false;
$this->mailcc[]=$to;
return true;
}
Function SetFrom($from)
{
if (strlen($from)<=0)
return $this->Error(1, 'from too short');
if (strlen($from)>=128)
return $this->Error(1, 'from too long');
$this->mailfrom=$from;
return true;
}
Function SetFromTitle($title)
{
if (strlen($title)<=0)
return $this->Error(1, 'fromtitle too short');
if (strlen($title)>=128)
return $this->Error(1, 'fromtitle too long');
$this->mailfromtitle=$title;
return true;
}
function AddAttachment($type, $data, $name)
{
// THIS WILL TAKE ATTACHMENTS, BUT WON'T YET MAIL THEM.
$insert=sizeof($this->attachements);
$this->attachements[$insert][data]=$data;
$this->attachements[$insert][type]=$type;
$this->attachements[$insert][name]=$name;
return false;
}
Function BuildBody($MIMEType)
{
$return = "";
// Take the text, add any attachements, doc type, etc.
// attachments currently don't work.
// SET MIME TYPE
if ($MIMEType=='text')
$return.="Content-Type: text/plain; charset=iso-8859-1\r\n";
elseif($MIMEType=='html')
$return.="Content-Type: text/html; charset=iso-8859-1\r\n";
else
$return.="Content-Type: text/plain; charset=iso-8859-1\r\n";
// SET TO HEADER
if (strlen($this->mailtotitle)>=1)
$return.="To: ".$this->mailtotitle."\r\n";
// SET FROM HEADER
if (strlen($this->mailfromtitle)>=1)
$return.="From: ".$this->mailfromtitle." <".$this->mailfrom.">\r\n";
else $return.="From: ".$this->mailfrom."\r\n";
if (sizeof($this->mailcc)>=1)
{
$return.="Cc:";
for ($i=0; $i<sizeof($this->mailcc); $i++)
{
if ($i)
$return.=", ";
$return.=$this->mailcc[$i];
}
$return.="\r\n";
}
if (strlen($this->mailsubject)>=1)
$return.="Subject: ".$this->mailsubject."\r\n";
$return .="X-Priority: 3\r\n";
$return .= "\r\n" . $this->mailtext;
return $return;
}
Function sendmail($text_type='html')
{
if (!$this->sock)
return $this->error(2);
else {
if (!$body=$this->BuildBody($text_type))
return $this->Error(1, 'BuildBody Failed');
$head[]="HELO ".$this->server;
$head[]="MAIL FROM:<".$this->mailfrom.">";
while (list($key, $value)= each($this->mailto))
{
$head[]="RCPT TO:<$value>";
}
$head[]='DATA';
reset ($head);
while (list($key, $value)=each ($head))
{
fputs($this->sock, $value."\r\n");
if (!$this->GetFeedback())
return $this->error($this->errno(), "($value)");
}
fputs($this->sock, "$body\r\n.\r\n");
if (!$this->GetFeedback())
return false;
}
$this->ResetData();
return true;
}
function ResetData()
{
$mailto = array();
$mailfrom = "";
$mailfromtitle = '';
$mailsubject = "";
$mailtext = "";
$attachments = array();
return true;
}
Function GetFeedback()
{
if (!$response=fgets($this->sock, $this->readlength))
return false;
if ($this->IsOK($response))
return true;
else return false;
}
Function IsOK ($input)
{
// Extract the return code from the SMTP server, and make sure it's a
// 'yahoo' instead of a 'shucks'.
if (!ereg("((^[0-9])([0-9]*))", $input, $regs))
return $this->error(1, 'input');
$code=$regs[1];
switch ($code)
{
case '220':
case '221':
case '250':
case '251':
case '354':
return true;
break;
default:
return $this->error(4, $input);
break;
}
}
Function end()
{
if (!$this->sock)
return $this->error(3, 'function end');
fputs($this->sock, "QUIT\r\n");
if ($this->GetFeedback())
{
fclose($this->sock);
return true;
}
else {
return false;
}
}
} // END OF CLASS...
/*
I wanted a class that could be easily stretched into doing attachements
(intelligently!) wasn't cumbersome, and verified that stuff being flung
at the SMTP server made it.
Something that would allow for intelligent error reporting and would
reliably fail
if something goes wrong, and do so w/o waiting for the PHP timeout...
This has:
- Bcc: support - now send the same mail to 100 people w/o sending
100 emails! (repeatedly use function SetTo())
- Error code control - If the SMTP server complains, we trap that
and report the error - so the application can act on it properly.
- MIME Support is but a small breath away - need to update only the
BuildBody() function as soon as an effective algorithm is figured out...
- Broke out alot of the settings functions because I could never remember
what went where... feel free to create "wrapper" functions to set a bunch
all at once.
- Greatly improved header support - though still not fully complete. (MIME
only partially supported)
- block read support - to trap the SMTP server replies.
- connection timeout() should be implemented - but I don't have a slow or
unreliable mailserver to test it on...
- We can now send multiple e-mails with a single connection... when a mail
is sent, you can simply set the fields and send another! This **SHOULD** result
in better performance when sending alot of emails. This functionality should
mirror the "reset" SMTP command...
- Lots of incrememental improvements - loops and functions used to turn
recycled code into reused code, etc.
- CC: Support - works just like SetTo() but also writes the header(s)
in the e-mail body.
CHANGES:
v1.3.1 16 Sep 01 James McGlinn <james@mcglinn.org>
Fixed bug in routine setting mail from title
v1.3.2 16 Sep 01 James McGlinn <james@mcglinn.org>
Added new blank line between headers and message text to
prevent remote
server from inserting headers into middle of message
*/
?>