Created
May 7, 2011 17:47
-
-
Save paulbarbu/960680 to your computer and use it in GitHub Desktop.
soluţiile mele pentru yap-phpro-book (paullik)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
background no | |
use_xft yes | |
xftfont Bitstream Vera Sans:Bold:size=10 | |
xftalpha 0.9 | |
update_interval 3.0 | |
total_run_times 0 | |
own_window yes | |
own_window_type desktop | |
own_window_transparent yes | |
own_window_hints undecorated,sticky,skip_taskbar,skip_pager | |
double_buffer yes | |
minimum_size 300 400 | |
maximum_width 300 | |
draw_shades no | |
draw_outline no | |
draw_borders no | |
draw_graph_borders yes | |
default_color 616263 | |
default_shade_color 101319 | |
default_outline_color green | |
alignment top_left | |
gap_x 100 | |
gap_y 100 | |
color1 424e66 | |
no_buffers yes | |
uppercase no | |
cpu_avg_samples 2 | |
override_utf8_locale no | |
TEXT | |
${nodename}(${color1}${exec echo $USER}${color}) | |
${color1}| | |
${color1}|--${color}time | |
${color1}| |--${color}now - ${color1}${time %d %b %Y} @${time %l:%M} | |
${color1}| '--${color}uptime - ${color1}${uptime} | |
${color1}| | |
${color1}|--${color}system | |
${color1}| |--${color}cpu | |
${color1}| | |--${color}used - ${color1}${cpu}% | |
${color1}| | '--${color}load - ${color1}${loadavg} | |
${color1}| |--${color}memory | |
${color1}| | |--${color}ram - ${color1}${memperc}% | |
${color1}| | '--${color}swap - ${color1}${swapperc}% | |
${color1}| '--${color}processes | |
${color1}| |--${color}total - ${color1}${processes} | |
${color1}| '--${color}active - ${color1}${running_processes} | |
${color1}| | |
${color1}'--${color}network | |
${color1} |--${color}up - ${color1}${upspeed wlan0} | |
${color1} '--${color}down - ${color1}${downspeed wlan0} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*.swp | |
*~ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# {{{ Environment settings | |
errorlog="${HOME}/.xerrors" | |
# }}} | |
# {{{ Log settings | |
# | |
# Always start X11 with a clean log file | |
if (cp /dev/null "${errorlog}"); then | |
chmod 600 "${errorlog}" | |
exec >"${errorlog}" 2>&1 | |
break | |
fi | |
# }}} | |
# {{{ Resource and keymap settings | |
usermodmap="${HOME}/.Xmodmap" | |
userresources="${HOME}/.Xresources" | |
sysmodmap="/etc/X11/xinit/.Xmodmap" | |
sysresources="/etc/X11/xinit/.Xresources" | |
# Merge system and user resources and keymaps | |
[[ -r "${sysresources}" ]] && xrdb -merge "${sysresources}" | |
[[ -r "${sysmodmap}" ]] && xmodmap "${sysmodmap}" | |
[[ -r "${userresources}" ]] && xrdb -merge "${userresources}" | |
[[ -r "${usermodmap}" ]] && xmodmap "${usermodmap}" | |
# }}} | |
# Xwrits reminds you to take wrist breaks and avoid RSI | |
#xwrits typetime=45 clock breakclock top ready-picture="${HOME}/.xwrits/ready.gif" \ | |
# rest-picture="${HOME}/.xwrits/rest.gif" warning-picture="${HOME}/.xwrits/warning.gif" & | |
#autostart | |
xset b off | |
archassistant & | |
xfce4-clipman & | |
yapan & | |
#xwrits typetime=45 breakclock top after 15 clock multiply=5:1.4 & | |
gnote & | |
case $1 in | |
awesome) | |
exec ck-launch-session awesome | |
;; | |
gnome) | |
exec ck-launch-session gnome-session | |
;; | |
*) | |
exec ck-launch-session awesome | |
;; | |
esac | |
#exec ck-launch-session gnome-session |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Decide if the custom page should be showed or not | |
*/ | |
if(!(isset($modules[$module]['VL']['custom']) && $modules[$module]['VL']['custom'])){ | |
header("HTTP/1.1 404 Not Found"); | |
exit(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
f the file ab.txt |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
djal;lsal | |
sdadsadasdadasadsa |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<p>This page should say things about me, but it's unfinished, sorry!</p> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1234 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dfghjklalina! | |
d ada s | |
dadassda |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
aaaaaaaaaaaaaaaaaaaaaaaa | |
dasdasd | |
asdas | |
d | |
asd | |
as | |
d |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$prev = NULL; | |
if(isset($_COOKIE[session_name()])){ | |
session_set_cookie_params(0, app_path()); | |
session_start(); | |
} | |
if(!isset($_SESSION['admin']) && isset($_COOKIE[session_name()]) && is_numeric($_COOKIE[session_name()])){ | |
$_SESSION = $_COOKIE[session_name()]; | |
} | |
elseif(isset($modules[$module]['VL']['login_need']) && $modules[$module]['VL']['login_need'] && !isset($_SESSION['admin'])){ | |
if($module != 'login_admin'){ | |
$prev = $module; | |
} | |
$module = 'login_admin'; | |
} | |
return $prev; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$prev = NULL; | |
if(isset($_COOKIE[session_name()])){ | |
session_set_cookie_params(0, app_path()); | |
session_start(); | |
} | |
if(!isset($_SESSION['uID']) && isset($_COOKIE[session_name()]) && is_numeric($_COOKIE[session_name()])){ | |
$_SESSION = $_COOKIE[session_name()]; | |
} | |
elseif(isset($modules[$module]['VL']['login_need']) && $modules[$module]['VL']['login_need'] && !isset($_SESSION['uID'])){ | |
if($module != 'login_admin'){ | |
$prev = $module; | |
} | |
$module = 'login_user'; | |
} | |
return $prev; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Captcha code | |
*/ | |
$chars = '0123456789qwertyuioplkjhgfdsazxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM'; | |
$used = '!'; | |
$chars_array = array(); | |
$captcha = NULL; | |
for($i=0;$i<strlen($chars);$i++){ | |
$chars_array[$i] = $chars[$i]; | |
} | |
shuffle($chars_array); | |
$i=0; | |
while($i<5){ | |
$pos = rand(0, count($chars_array) - 1); | |
if($used != $chars_array[$pos]){ | |
$captcha .= $chars_array[$pos]; | |
$chars_array[$pos] = $used; | |
$i++; | |
} | |
} | |
$_SESSION['captcha'] = $captcha; | |
if(-1 != $_SESSION['captcha']){ | |
$code = $_SESSION['captcha']; | |
//create image | |
$im = imagecreatetruecolor(141, 50); | |
if(FALSE != $im){ | |
$bg = imagecolorallocate($im, 251, 249, 226); | |
$black = imagecolorallocate($im, 0, 0, 0); | |
//set bg color | |
if(FALSE !== $bg){ | |
imagefill($im, 0, 0, $bg); | |
//write chars in random positions | |
for($i=0;$i<5;$i++){ | |
$x = rand(1 + (27 * $i), 27 + (27 * $i)); //every char in its part of the image | |
$y = rand(1, 36); | |
imagechar($im, 5, $x, $y, $code[$i], $black); | |
} | |
$style = array($bg, $bg, $bg, $bg, $bg, $bg, $bg, | |
$black, $black, $black, $black, $black, $black); | |
imagesetstyle($im, $style); | |
$y_line_top = rand(0, 12); | |
$y_line_bot = rand(38, 50); | |
imageline($im, 0, $y_line_top, 140, $y_line_bot, IMG_COLOR_STYLED); | |
$y_line_top = rand(0, 12); | |
$y_line_bot = rand(38, 50); | |
imageline($im, 0, $y_line_bot, 140, $y_line_top, IMG_COLOR_STYLED); | |
header('Content-Type: image/png'); | |
imagepng($im); | |
imagedestroy($im); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Defined constants for the gallery script | |
*/ | |
const G_OK = 0; | |
const G_ERR_IS_DIR = 1; | |
const G_ERR_NO_DIR = 2; | |
const G_ERR_OPEN_DIR = 3; | |
const G_ERR_NO_IMAGES = 4; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Constants for GB script | |
*/ | |
define('PATH_MSG_FILE', DATA_ROOT . DIRECTORY_SEPARATOR . 'gbook' | |
. DIRECTORY_SEPARATOR . 'msg.json'); | |
define('PATH_BAN_FILE', DATA_ROOT . DIRECTORY_SEPARATOR . 'gbook' | |
. DIRECTORY_SEPARATOR . 'bans'); | |
const GB_OK = 0; | |
const GB_ERR_NO_NICK = 1; | |
const GB_ERR_NO_MSG = 2; | |
const GB_ERR_OPEN_MSG_FILE = 3; | |
const GB_ERR_WRITE_POST = 4; | |
const GB_POST_SUCCESS = 5; | |
const GB_ERR_NO_SELECTED = 6; | |
const GB_DEL_SUCCESS = 7; | |
const GB_ERR_NO_MSG_FILE = 8; | |
const GB_ERR_CANNOT_READ = 9; | |
const GB_ERR_READONLY = 10; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Constants for Admin panel | |
*/ | |
define('PATH_MSG_FILE', DATA_ROOT . DIRECTORY_SEPARATOR . 'gbook' | |
. DIRECTORY_SEPARATOR . 'msg.json'); | |
define('PATH_BAN_FILE', DATA_ROOT . DIRECTORY_SEPARATOR . 'gbook' | |
. DIRECTORY_SEPARATOR . 'bans'); | |
const GP_ERR_NO_IP = 7; | |
const GP_ERR_FOPEN_BAN_FILE = 8; | |
const GP_BANNED = 9; | |
const GP_UNBANNED = 10; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Constants for Login module | |
*/ | |
const LA_ERR_PASS = 1; | |
const LA_ERR_READING = 2; | |
const LA_ERR_FOPEN_ADMIN = 3; | |
const LA_ERR_DIR = 4; | |
const LA_ERR_NO_PASS = 5; | |
const LA_ERR_COOKIE = 6; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Defined constants for the login script | |
*/ | |
const LU_ERR_USER = 1; | |
const LU_ERR_FOPEN_USER = 2; | |
const LU_ERR_PASS = 3; | |
const LU_ERR_NO_USER = 4; | |
const LU_ERR_NO_PASS = 5; | |
const LU_ERR_SESS = 6; | |
const LU_ERR_COOKIE = 7; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Constants for the "Edit text on-site" script | |
*/ | |
const TXT_ERR_PASS = 1; | |
const TXT_ERR_READ = 2; | |
const TXT_ERR_WRITE = 3; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* in this file are stored constants related to the upload.php script | |
* for details go to: | |
* http://www.php.net/manual/en/features.file-upload.errors.php | |
*/ | |
const UP_ERR_SIZE = 1; | |
const UP_ERR_PARTiAL = 2; | |
const UP_ERR_NO_FILE = 3; | |
const UP_ERR_NO_TMP = 4; | |
const UP_ERR_NO_WRITE = 5; | |
const UP_ERR_EXT = 6; | |
const UP_ERR_SECRET = 7; | |
const UP_ERR_NOT_UPLOADED = 8; | |
const UP_ERR_CREATE_DIR = 9; | |
const UP_ERR_MOVE = 10; | |
const UP_SUCCESS = 11; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<p>Ooops, nothing to see here, this page is inexistent!</p> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if(isset($feedback['gallery']) && is_array($feedback['gallery'])){ | |
echo '<p>'; | |
foreach($feedback['gallery'] as $img){ | |
echo '<img src="' . strip_tags($img) . '" /> '; | |
} | |
echo '</p>'; | |
} | |
else{ | |
?> | |
<form method="post" action="?show=gallery" > | |
<label for="id-dir">Directory containing images</label> | |
<input type="text" name="dir" id="id-dir" /> | |
<br /> | |
<input type="submit" name="submit" value="Display" /> | |
</form> | |
<?php | |
} | |
if(isset($feedback['gallery']) && NULL != $feedback['gallery'] && is_numeric($feedback['gallery'])){ | |
echo '<h3>'; | |
switch($feedback['gallery']){ | |
case G_ERR_IS_DIR: echo 'Invalid directory name! - ', G_ERR_IS_DIR; | |
break; | |
case G_ERR_NO_DIR: echo 'Please provide a directory name! - ', G_ERR_NO_DIR; | |
break; | |
case G_ERR_OPEN_DIR: echo 'Failed to open directory! - ', G_ERR_OPEN_DIR; | |
break; | |
case G_ERR_NO_IMAGES: echo 'The directory does not contain images! - ', | |
G_ERR_NO_IMAGES; | |
break; | |
default; | |
} | |
echo '</h3>'; | |
} | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$status = check_ip($_SERVER['REMOTE_ADDR']); | |
if(is_numeric($status)){ | |
echo '<h3>'; | |
switch($status){ | |
case GB_ERR_IP_STRING: echo 'Invalid supplied IP! - ' , GB_ERR_IP_STRING; | |
break; | |
case GB_ERR_FOPEN_BAN_FILE: echo 'Error opening DB! - ' , GB_ERR_FOPEN_BAN_FILE; | |
break; | |
default; | |
} | |
echo '</h3>'; | |
} | |
elseif(TRUE == $status){ | |
echo '<h3>This IP is banned, <u>' , $_SERVER['REMOTE_ADDR'] , '</u>!</h3>'; | |
} | |
else{ | |
?> | |
<span id="adminlogin"> | |
<a href="index.php?show=gbook_panel">Admin panel</a> | |
</span> | |
<br /> | |
<form action="" method="post" > | |
<label for="id-n">Name: </label> | |
<input type="text" name="nick" id="id-n" /> | |
<br /> | |
<label for="id-m">Mail: </label> | |
<input type="text" name="mail" id="id-m" /> | |
<br /> | |
<label for="id-u">Web - site: </label> | |
<input type="text" name="url" id="id-u" /> | |
<br /> | |
<label for="id-msg">Message: </label> | |
<br /> | |
<textarea name="message" id="id-msg" cols="60" rows="5"> | |
Your message here... | |
</textarea> | |
<br /> | |
<input type="submit" name="post" value="Post" /> | |
<?php | |
if(isset($_SESSION['admin'])){ | |
echo '<br/> <input type="submit" name="del" value="Delete selected" />'; | |
} | |
if(is_numeric($feedback['gbook'])){ | |
echo '<h3>'; | |
switch($feedback['gbook']){ | |
case GB_ERR_NO_NICK: echo 'Please provide a nickname! - ', GB_ERR_NO_NICK; | |
break; | |
case GB_ERR_NO_MSG: echo 'Please write a message! - ', GB_ERR_NO_MSG; | |
break; | |
case GB_ERR_OPEN_MSG_FILE: echo 'Could not open file for writing! - ', GB_ERR_OPEN_MSG_FILE; | |
break; | |
case GB_ERR_WRITE_POST: echo 'Could not write your message! - ', GB_ERR_WRITE_POST; | |
break; | |
case GB_POST_SUCCESS: echo 'Posted!'; | |
break; | |
case GB_DEL_SUCCESS: echo 'Deleted!'; | |
break; | |
case GB_ERR_NO_SELECTED: echo 'No posts selected! - ', GB_ERR_NO_SELECTED; | |
break; | |
case GB_ERR_NO_MSG_FILE: echo 'Database does not exists! - ', GB_ERR_NO_MSG_FILE; | |
break; | |
case GB_ERR_READONLY: echo 'Database is readonly! - ', GB_ERR_READONLY; | |
break; | |
case GB_ERR_CANNOT_READ: echo 'Cannot read from database! - ', GB_ERR_CANNOT_READ; | |
break; | |
default; | |
} | |
echo '</h3>'; | |
} | |
if(isset($_SESSION['admin']) && $_SESSION['admin']){ | |
$messages = post_to_div(PATH_MSG_FILE, TRUE); | |
} | |
else{ | |
$messages = post_to_div(); | |
} | |
if(is_numeric($messages)){ | |
echo '<h3>'; | |
switch($messages){ | |
case GB_ERR_OPEN: echo 'Error opening file! - ', GB_ERR_OPEN; | |
break; | |
case GB_ERR_DECODE: echo 'Message cannot be decoded! - ', GB_ERR_DECODE; | |
break; | |
case GB_ERR_EMPTY: echo 'No posts! - ', GB_ERR_EMPTY; | |
break; | |
default; | |
} | |
echo '</h3>'; | |
} | |
else{ | |
for($i=count($messages) - 1;$i>=0;$i--){ | |
echo $messages[$i]; | |
} | |
} | |
} | |
?> | |
</form> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<span id="adminlogin"><a href="index.php?show=logout_admin">Log out</a></span> | |
<h3>Ban IPs:</h3> | |
<form action="?show=gbook_panel" method="post"> | |
<?php | |
$ips = get_ips_ban(); | |
if(is_numeric($ips)){ | |
echo '<h3>'; | |
switch($ips){ | |
case GP_ERR_OPEN: echo 'Error opening file! - ', GP_ERR_OPEN; | |
break; | |
case GP_ERR_DECODE: echo 'Message cannot be decoded! - ', GP_ERR_DECODE; | |
break; | |
case GP_ERR_EMPTY: echo 'No posts! - ', GP_ERR_EMPTY; | |
break; | |
default; | |
} | |
echo '</h3>'; | |
} | |
else{ | |
foreach($ips as $ip){ | |
echo $ip; | |
} | |
} | |
?> | |
<input type="submit" name="ban_ip" value="Ban selected IPs" /> | |
<br /> | |
<h3>Unban IPs:</h3> | |
<?php | |
$ips = get_ips_unban(); | |
if(is_numeric($ips)){ | |
echo '<h3>'; | |
switch($ips){ | |
case GP_ERR_OPEN: echo 'Error opening file! - ', GP_ERR_OPEN; | |
break; | |
case GP_ERR_EMPTY: echo 'No bans! - ', GP_ERR_EMPTY; | |
break; | |
default; | |
} | |
echo '</h3>'; | |
} | |
else{ | |
foreach($ips as $ip){ | |
echo $ip; | |
} | |
} | |
?> | |
<input type="submit" name="unban_ip" value="Unban selected IPs" /> | |
</form> | |
<?php | |
if(is_numeric($feedback['panel'])){ | |
echo '<h3>'; | |
switch($feedback['panel']){ | |
case GP_ERR_NO_IP: echo 'Please select an IP! - ', GP_ERR_NO_IP; | |
break; | |
case GP_ERR_FOPEN_BAN_FILE: echo 'Could not access ban DB! - ' , GP_ERR_FOPEN_BAN_FILE; | |
break; | |
case GP_UNBANNED: echo 'Selected IPs successfully unbanned!'; | |
break; | |
case GP_ERR_INVALID_ARRAY: echo 'Invalid IP list! - ' , GP_ERR_INVALID_ARRAY; | |
break; | |
case GP_BANNED: echo 'Selected IPs successfully banned!'; | |
default; | |
} | |
echo '</h3>'; | |
} | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- TODO say about yap and this site --> | |
<p>Hello site!</p> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form action="index.php?show=login_admin | |
<?php | |
if(!empty($feedback_pre['autologin'])){ | |
?> | |
&action= | |
<?php | |
echo $feedback_pre['autologin']; | |
} | |
?> | |
" method="post"> | |
<label for="id-p">Password:</label> | |
<input type="password" name="pass" id="id-p" /> | |
<br /> | |
<input type="checkbox" name="r_me" id="id-r_me" /> | |
<label for="id-r_me"> Remember me</label> | |
<br /> | |
<input type="submit" name="adminlogin" value="Log in"/> | |
</form> | |
<?php | |
echo '<h3>'; | |
if(is_numeric($feedback['login'])){ | |
switch($feedback['login']){ | |
case LA_ERR_PASS: echo 'Invalid password! - ' , LA_ERR_PASS; | |
break; | |
case LA_ERR_READING: echo 'Could not read from DB! - ' , LA_ERR_READING; | |
break; | |
case LA_ERR_FOPEN_ADMIN: echo 'Could not open DB! - ' , LA_ERR_FOPEN_ADMIN; | |
break; | |
case LA_ERR_DIR: echo 'Invalid directory! - ', LA_ERR_DIR; | |
break; | |
case LA_ERR_NO_PASS: echo 'Plase fill in a password! - ' , LA_ERR_NO_PASS; | |
break; | |
case LA_ERR_COOKIE: echo 'Error setting cookie! - ' , LA_ERR_COOKIE; | |
break; | |
default; | |
} | |
} | |
elseif($feedback['login']){ | |
echo 'Authentified!'; | |
} | |
echo '</h3>'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form action="index.php?show=login_user | |
<?php | |
if(!empty($feedback_pre['autologin'])){ | |
?> | |
&action= | |
<?php | |
echo $feedback_pre['autologin']; | |
} | |
?> | |
" method="post"> | |
<label for="id-u">User name:</label><input type="text" id="id-u" name="user" /> | |
<br /><label for="id-p">Password:</label> | |
<input type="password" id="id-p" name="pass" /> | |
<br /><input type="checkbox" name="r_me" id="id-r" /> | |
<label for="id-r">Remember me</label> | |
<br /> | |
<br /><input type="submit" name="go" value="Log In" /> | |
</form> | |
<?php | |
echo '<h3>'; | |
if(is_numeric($feedback['login'])){ | |
switch($feedback['login']){ | |
case LU_ERR_USER: echo 'Inexistent user! - ', LU_ERR_USER; | |
break; | |
case LU_ERR_FOPEN_USER: echo 'Error opening users.csv! - ', LU_ERR_FOPEN_USER; | |
break; | |
case LU_ERR_PASS: echo 'Incorrect password! - ', LU_ERR_PASS; | |
break; | |
case LU_ERR_NO_USER: echo 'Please fill in a user name! - ', LU_ERR_NO_USER; | |
break; | |
case LU_ERR_NO_PASS: echo 'Please provide a password! - ', LU_ERR_NO_PASS; | |
break; | |
case LU_ERR_SESS: echo 'Error starting session! - ', LU_ERR_SESS; | |
break; | |
case LU_ERR_COOKIE: echo 'Cannot set cookie! - ', LU_ERR_COOKIE; | |
break; | |
default; | |
} | |
} | |
elseif($feedback['login']){ | |
echo 'Authentified!'; | |
} | |
echo '</h3>'; | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
echo '<h3>'; | |
if($feedback['logout']){ | |
echo 'You\'ve been successfully logged out!'; | |
} | |
else{ | |
echo 'An error occured during log out!'; | |
} | |
echo '</h3>'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
echo '<h3>'; | |
if($feedback['logout']){ | |
echo 'You\'ve been successfully logged out!'; | |
} | |
else{ | |
echo 'An error occured during log out!'; | |
} | |
echo '</h3>'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form action="" method="post" > | |
<?php | |
if(is_numeric($feedback['text'])){ | |
echo '<h3>'; | |
switch($feedback['text']){ | |
case TXT_ERR_PASS: echo 'Incorrect passphrase! - ', TXT_ERR_PASS; | |
break; | |
case TXT_ERR_READ: echo 'Error on reading the file! - ', TXT_ERR_READ; | |
break; | |
case TXT_ERR_WRITE: echo 'Error on writing to file! - ', TXT_ERR_WRITE; | |
default; | |
} | |
echo '</h3>'; | |
} | |
elseif(NULL != $feedback['text']['contents']){ | |
echo '<label for="id-c">Edit here:</label><br /><textarea name="contents" | |
id="id-c" rows="15" cols="100">' , $feedback['text']['contents'] | |
, '</textarea><br />' , PHP_EOL; | |
echo '<input type="hidden" name="file" value="' | |
, $feedback['text']['msg'] , '" />'; | |
} | |
elseif(NULL != $feedback['text']['files']){ | |
foreach($feedback['text']['files'] as $file){ | |
echo '<input type="radio" name="filelist" id="id-' , $file , | |
'" value="' , $file , '" /><label for="id-' , $file , '">' | |
, $file , '</label><br />' , PHP_EOL; | |
} | |
echo '<input type="hidden" name="sec" value="' , $feedback['text']['msg'] , | |
'" />'; | |
} | |
elseif(NULL != $feedback['text']['msg']){ | |
echo '<h3><i>' , $feedback['text']['msg'] , '</i> successfully updated! | |
</h3>'; | |
} | |
else{ //the user must specify the 'secret' | |
echo '<label for="id-s">Passphrase</label><input type="password" | |
name="secret" id="id-s" />'; | |
} | |
?> | |
<input type="submit" value="Continue" name="edit" /> | |
</form> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form enctype="multipart/form-data" action="" method="post" > | |
<input type="hidden" name="MAX_FILE_SIZE" value=" | |
<?php echo $size = return_bytes(ini_get('upload_max_filesize')); ?>" /> | |
<label for="id-secret">Secret dir. name: </label> | |
<input type="text" name="secret" id="id-secret" /><br /> | |
<label for="up">Your file(max <?php echo ($size/1024)/1024 ?> mB): </label> | |
<input type="file" id="up" name="file" /><br /> | |
<input type="submit" name="upload" value="Upload" /> | |
</form> | |
<?php | |
if(is_numeric($feedback['upload'])){ | |
echo '<h3>' ; | |
switch($feedback['upload']){ | |
case UP_ERR_SIZE: echo 'The input file exceeded the size limit! - ' , UP_ERR_SIZE; | |
break; | |
case UP_ERR_PARTiAL: echo 'The uploaded file was only partially uploaded! - ' , UP_ERR_PARTiAL; | |
break; | |
case UP_ERR_NO_FILE: echo 'You must select a file for uploading! - ' , UP_ERR_NO_FILE; | |
break; | |
case UP_ERR_NO_TMP: echo 'The temporary directory is missing! - ' , UP_ERR_NO_TMP; | |
break; | |
case UP_ERR_NO_WRITE: echo 'Directory permissions problems! - ' , UP_ERR_NO_WRITE; | |
break; | |
case UP_ERR_EXT: echo 'Upload stopped by extension! - ' , UP_ERR_EXT; | |
break; | |
case UP_ERR_SECRET: echo 'Please specify a directory name to upload to! - ' , UP_ERR_SECRET; | |
break; | |
case UP_ERR_NOT_UPLOADED: echo 'The file you are trying to submit is not a valid uploaded file! - ' , UP_ERR_NOT_UPLOADED; | |
break; | |
case UP_ERR_CREATE_DIR: echo 'Error creating directory! - ' , UP_ERR_CREATE_DIR; | |
break; | |
case UP_ERR_MOVE: echo 'An unexpected error occured while moving the file to destination! - ' , UP_ERR_MOVE; | |
break; | |
case UP_SUCCESS: echo 'File uploaded successfully! - ' , UP_SUCCESS; | |
break; | |
default; | |
} | |
echo '</h3>'; | |
} | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Foo{ | |
public $foo = TRUE; | |
} | |
class Factory{ | |
public static function create($Product){ | |
return new $Product; | |
} | |
} | |
var_dump(Factory::create('Foo')); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a file full of | |
Text and with MANY | |
spaces and \n's |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
const RENDER_OK = 0; | |
const RENDER_ERR_NO_FILE = 1; | |
const RENDER_ERR_FILE = 2; | |
/** | |
* int return_bytes(string $val) | |
* | |
* this function is used to convert a shorthand notation like 2M in bytes | |
* please visit: http://www.php.net/manual/en/function.ini-get.php | |
* | |
* @param string $val shotrnotation (e.g. "2M") | |
* | |
* @return int bytes representation of the shorthand notation | |
*/ | |
function return_bytes($val) { | |
$val = trim($val); | |
$last = $val[strlen($val)-1]; | |
switch($last) { | |
case 'g': | |
case 'G': | |
$val *= 1024; | |
case 'm': | |
case 'M': | |
$val *= 1024; | |
case 'k': | |
case 'K': | |
$val *= 1024; | |
} | |
return $val; | |
} | |
/** | |
* int render($template, $vars = NULL) | |
* | |
* creates variables that are necessary for including the file specified by | |
* $template and includes it | |
* | |
* @param string $template path to the file to be required | |
* @param array $vars associative array containing variable names needed by | |
* $template, default NULL(none) | |
* | |
* @return int returns an status code, if it's the case that status coude is an | |
* error | |
* | |
*/ | |
function render($template, $vars = NULL){ | |
if($vars){ | |
extract($vars); | |
} | |
if(!file_exists($template)){ | |
return RENDER_ERR_NO_FILE; | |
} | |
if(!is_readable($template)){ | |
return RENDER_ERR_FILE; | |
} | |
require $template; | |
return RENDER_OK; | |
} | |
/** | |
* string build_menu_from_modules($modules, $currentModule) | |
* | |
* this function will build an HTML menu based on the array received as | |
* parameter and will return it as a string | |
* | |
* @param array $modules array to get menu entries from | |
* @param string $currentModule name of the module not to wrap in <a> tags | |
* | |
* @return string string representing the menu's HTML code | |
*/ | |
function build_menu_from_modules($modules, $currentModule){ | |
$menu = '<ul>' .PHP_EOL; | |
foreach($modules as $moduleName => $metaData){ | |
if(!isset($modules[$moduleName]['VL']['show_in_menu']) || | |
FALSE != $modules[$moduleName]['VL']['show_in_menu']){ | |
if($moduleName == $currentModule){ | |
$menu .= '<li>' .$metaData['VL']['title']. '</li>' .PHP_EOL; | |
} | |
else{ | |
$menu .= '<li><a href="?show=' . $moduleName . '">' | |
. $metaData['VL']['title'] . '</a></li>' . PHP_EOL; | |
} | |
} | |
} | |
$menu .= '</ul>' .PHP_EOL; | |
return $menu; | |
} | |
/** | |
* find_files_by_mime($path, $mime) | |
* | |
* searches recursively in the path provided by $path the files which have the | |
* MIME type set to $mime | |
* | |
* @param string $path path to a directory | |
* @param string $mime MIME type to be matched | |
* @param bool $recursive search recursively or not in the provided directory | |
* (default: TRUE) | |
* | |
* @return array $files containing the the directory name as key and the | |
* path to the file as the value | |
*/ | |
function find_files_by_mime($path, $mime, $recursive = TRUE){ | |
$files = array(); | |
$finfo = finfo_open(FILEINFO_MIME_TYPE); | |
if(DIRECTORY_SEPARATOR == substr($path, -1)){ | |
$path = substr($path, 0, strlen(path)-2); | |
} | |
if(is_dir($path)){ | |
$d = opendir($path); | |
while($entry = readdir($d)){ | |
$mime_type = finfo_file($finfo, $path . DIRECTORY_SEPARATOR . $entry); | |
if("." != $entry && ".." != $entry){ | |
if(is_dir($path . DIRECTORY_SEPARATOR . $entry) && $recursive){ | |
$files = array_unique(array_merge(find_files_by_mime( | |
$path . DIRECTORY_SEPARATOR . $entry, $mime), $files)); | |
} | |
elseif(FALSE !== stristr($mime_type, $mime)){ | |
$files[] = $path . DIRECTORY_SEPARATOR . $entry; | |
} | |
} | |
} | |
closedir($d); | |
} | |
return $files; | |
} | |
/** | |
* csv_search($fh, $column, $criteria) | |
* | |
* Read line by line the file stored in $file_handle and search on the $column | |
* the $criteria. | |
* The $column is the number of CSV separator + 1, example: | |
* john|31 | |
* Here the CSV separator is | and "31" is on the second column, because it is | |
* found after the first separator | |
* | |
* @param resource $fh file stream for reading the comma separated values | |
* @param int $column colum to read the data from | |
* | |
* @return FALSE|array on success returns the line containing the $criteria as array if $criteria was found otherwise | |
* FALSE | |
*/ | |
function csv_search($fh, $column, $criteria){ | |
$line = array(); | |
while(FALSE !== ($line = fgetcsv($fh, 1000))){ | |
if($criteria == $line[$column]){ | |
return $line; | |
} | |
} | |
return FALSE; | |
} | |
/** | |
* app_path() | |
* | |
* Get the application's directory on the server | |
* | |
* @return string $path the path the the directory where the application runs | |
*/ | |
function app_path(){ | |
$pos = strrpos($_SERVER['REQUEST_URI'], DIRECTORY_SEPARATOR); | |
$path = substr($_SERVER['REQUEST_URI'], 0, $pos); | |
return $path; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Functions for the guest Book | |
*/ | |
const GB_ERR_OPEN = 1; | |
const GB_ERR_DECODE = 2; | |
const GB_ERR_EMPTY = 3; | |
const GB_ERR_IP_STRING = 4; | |
const GB_ERR_FOPEN_BAN_FILE = 5; | |
/** | |
* post_to_div() - Helper function, echoes div's as posts from a file passed as parameter | |
* | |
* @param string $path path to file containing posts formatted as JSON, | |
* default: PATH_MSG_FILE constant | |
* @return int|array an int is returned in case that the file canot be opened(1), | |
* 2 if the messages cannot be decoded(from JSON format) or 3 if the file does | |
* not exists or it's empty, on success it returns an array of strings | |
*/ | |
function post_to_div($path = PATH_MSG_FILE, $admin = FALSE){ | |
if(is_file($path) && 0 != filesize($path)){ | |
$posts = array(); | |
$nr_posts = 0; | |
$fh = fopen(PATH_MSG_FILE, "r"); | |
if(FALSE != $fh){ | |
while(!feof($fh)){ | |
$post = fgets($fh); | |
if(FALSE == $post){ | |
return $posts; | |
} | |
$result = json_decode($post, TRUE); | |
if(NULL == $result){ | |
fclose($fh); | |
return GB_ERR_DECODE; | |
} | |
$result['msg'] = wordwrap($result['msg'], 100, "\n", TRUE); | |
$result['msg'] = nl2br($result['msg']); | |
$posts[$nr_posts] = NULL; | |
$posts[$nr_posts] .= '<div id="post"><div id="headpost">' . PHP_EOL; | |
if(FALSE != $admin){ | |
$unique_id = $result['time'] . '!' . $result['ip']; | |
$posts[$nr_posts] .= '<input type="checkbox" name="manage_posts[]" value="' . $unique_id . '" />'; | |
} | |
$posts[$nr_posts] .= $result['nick']; | |
if(NULL != $result['mail']){ | |
$posts[$nr_posts] .= ' <a href="mailto:' . $result['mail'] . '">' | |
. $result['mail'] . '<a/>'; | |
} | |
if(NULL != $result['url']){ | |
$posts[$nr_posts] .= ' <a href="' . $result['url'] . '">' | |
. $result['url'] . '</a>'; | |
} | |
if(FALSE != $admin){ | |
$posts[$nr_posts] .= ' ' . $result['ip']; | |
} | |
$posts[$nr_posts] .= '<span id="date">' . $result['time'] | |
. '</span></div><br />' . $result['msg'] . '</div>' . PHP_EOL; | |
$nr_posts++; | |
} | |
fclose($fh); | |
} | |
else{ | |
return GB_ERR_OPEN; | |
} | |
return $posts; | |
} | |
else{ | |
return GB_ERR_EMPTY; | |
} | |
} | |
/** | |
* check_ip() - Helper function that checks if an IP is banned or not | |
* | |
* @param string $ip user's IP | |
* @param string $path_to_bans path to the ban list(database), default: | |
* PATH_BAN_FILE | |
* | |
* @return int|BOOL returns TRUE if the verified IP is banned, else FALSE, on | |
* error returns the error's code | |
*/ | |
function check_ip($ip, $path = PATH_BAN_FILE){ | |
if(!is_string($ip)){ | |
return GB_ERR_IP_STRING; | |
} | |
if(is_file($path) && 0 != filesize($path)){ | |
$fh = fopen($path, "r"); | |
if(FALSE == $fh){ | |
return GB_ERR_FOPEN_BAN_FILE; | |
} | |
while(!feof($fh)){ | |
$currentIP = fgets($fh); | |
if(trim($currentIP) == trim($ip)){ | |
fclose($fh); | |
return TRUE; | |
} | |
} | |
fclose($fh); | |
} | |
return FALSE; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Functions for Admin panel | |
*/ | |
const GP_ERR_OPEN = 1; | |
const GP_ERR_DECODE = 2; | |
const GP_ERR_EMPTY = 3; | |
const GP_ERR_INVALID_ARRAY = 4; | |
/** | |
* get_ips_ban() - Helper function that displays checkboxes with IP's | |
* susceptible to ban | |
* | |
* @param string $path path to file containing posts formatted as JSON, | |
* default: PATH_MSG_FILE constant | |
* | |
* @return int|array an int is returned in case that the file canot be opened(1), | |
* 2 if the messages cannot be decoded(from JSON format) or 3 if the file does | |
* not exists or it's empty, on success it returns an array of strings containing | |
* the IPs | |
*/ | |
function get_ips_ban($path = PATH_MSG_FILE){ | |
if(is_file($path) && 0 != filesize($path)){ | |
$ips = array(); | |
$nr_ips = 0; | |
$fh = fopen($path, "r"); | |
if(FALSE != $fh){ | |
while(!feof($fh)){ | |
$post = fgets($fh); | |
if(FALSE == $post){ | |
fclose($fh); | |
return $ips; | |
} | |
$result = json_decode($post, true); | |
if(NULL == $result){ | |
fclose($fh); | |
return GP_ERR_DECODE; | |
} | |
$ips[$nr_ips] = NULL; | |
$ips[$nr_ips] .= '<input type="checkbox" name="ips[]" value="' | |
. $result['ip'] . '" id="id-' . $result['ip'] . '" /><label | |
for="id-' . $result['ip'] . '">' . $result['ip'] . '</label> | |
<br />'; | |
$ips = array_unique($ips); | |
$nr_ips++; | |
} | |
fclose($fh); | |
} | |
else{ | |
return GP_ERR_OPEN; | |
} | |
return $ips; | |
} | |
else{ | |
return GP_ERR_EMPTY; | |
} | |
} | |
/** | |
* ban_ip() - writes array entries on a new line | |
* | |
* @param resource $fh resource to opened file with flag "a" | |
* @param array $ips array containing the IP's to be banned | |
* | |
* @return int|TRUE on success returns TRUE, else return the error | |
* code | |
*/ | |
function ban_ip($fh, $ips){ | |
if(is_array($ips)){ | |
foreach($ips as $ip){ | |
fwrite($fh, $ip . "\n"); | |
} | |
} | |
else{ | |
return GP_ERR_INVALID_ARRAY; | |
} | |
return TRUE; | |
} | |
/** | |
* get_ips_unban() Helper function that displays IPs for unban | |
* | |
* @param string $path path to ban file containing IPs | |
* | |
* @return int|array return and array containing the IPs or an error code | |
*/ | |
function get_ips_unban($path = PATH_BAN_FILE){ | |
if(is_file($path) && 0 != filesize($path)){ | |
$ips = array(); | |
$nr_ips = 0; | |
$currentIP = NULL; | |
$fh = fopen($path, "r"); | |
if(FALSE != $fh){ | |
while(!feof($fh)){ | |
$currentIP = trim(fgets($fh)); | |
if(FALSE == $currentIP){ | |
fclose($fh); | |
return $ips; | |
} | |
$ips[$nr_ips] = NULL; | |
$ips[$nr_ips] .= '<input type="checkbox" name="unban_ips[]" value="' | |
. $currentIP . '" id="idu-' . $currentIP . '" /><label | |
for="idu-' . $currentIP . '">' . $currentIP . '</label> | |
<br />'; | |
$ips = array_unique($ips); | |
$nr_ips++; | |
} | |
fclose($fh); | |
} | |
else{ | |
return GP_ERR_OPEN; | |
} | |
return $ips; | |
} | |
else{ | |
return GP_ERR_EMPTY; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* void render(string $template, array $vars = NULL) | |
* | |
* this function will take a path as first parameter and | |
* an associative array as second, from the array the function will create | |
* variables that are necessary for includeing the file specified by $template | |
*/ | |
function render($template, $vars = NULL){ | |
if($vars){ | |
extract($vars); | |
} | |
require $template; | |
} | |
/** | |
* string build_menu_from_pages(array $pages) | |
* | |
* this function will build an HTMl menu based on the array received as | |
* parameter and will return it as a string | |
*/ | |
function build_menu_from_pages($pages, $currentPage){ | |
$menu = '<ul>' .PHP_EOL; | |
foreach($pages as $pageName => $metaData){ | |
if($pageName != 'notfound'){ | |
if($pageName == $currentPage){ | |
$menu .= '<li>' .$metaData['title']. '</li>' .PHP_EOL; | |
} | |
else{ | |
$menu .= '<li><a href="?show=' .$pageName. '">' .$metaData['title']. '</a></li>' .PHP_EOL; | |
} | |
} | |
} | |
$menu .= '</ul>' .PHP_EOL; | |
return $menu; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* int return_bytes( string $val) | |
* | |
* this function is used to converd a shorthand notation like 2M in bytes | |
* please visit: http://www.php.net/manual/en/function.ini-get.php | |
*/ | |
function return_bytes($val) { | |
$val = trim($val); | |
$last = $val[strlen($val)-1]; | |
switch($last) { | |
case 'g': | |
case 'G': | |
$val *= 1024; | |
case 'm': | |
case 'M': | |
$val *= 1024; | |
case 'k': | |
case 'K': | |
$val *= 1024; | |
} | |
return $val; | |
} | |
/** | |
* void render(string $template, array $vars = NULL) | |
* | |
* this function will take a path as first parameter and | |
* an associative array as second, from the array the function will create | |
* variables that are necessary for including the file specified by $template | |
*/ | |
function render($template, $vars = NULL){ | |
if($vars){ | |
extract($vars); | |
} | |
require $template; | |
} | |
/** | |
* string build_menu_from_pages(array $pages, string $currentPage) | |
* | |
* this function will build an HTMl menu based on the array received as | |
* parameter and will return it as a string | |
*/ | |
function build_menu_from_pages($pages, $currentPage){ | |
$menu = '<ul>' .PHP_EOL; | |
foreach($pages as $pageName => $metaData){ | |
if('notfound' != $pageName && 'login' != $pageName | |
&& 'logout' != $pageName && 'captcha' != $pageName){ | |
if($pageName == $currentPage){ | |
$menu .= '<li>' .$metaData['title']. '</li>' .PHP_EOL; | |
} | |
else{ | |
$menu .= '<li><a href="?show=' . $pageName . '">' | |
. $metaData['title'] . '</a></li>' . PHP_EOL; | |
} | |
} | |
} | |
$menu .= '</ul>' .PHP_EOL; | |
return $menu; | |
} | |
/** | |
* array list_text_files($path) | |
* | |
* searches recursively in the path provided by the only parameter the files | |
* which have the MIME type set to 'text/plain' | |
* | |
* returns an array containing the secret name of the directory as key and the | |
* path to the file as the value | |
*/ | |
function list_text_files($path){ | |
$files = array(); | |
if(is_dir($path)){ | |
$d = opendir($path); | |
while($entry = readdir($d)){ | |
if("." != $entry && ".." != $entry){ | |
if(is_dir($path . DIRECTORY_SEPARATOR . $entry)) { | |
$files = array_unique(array_merge(list_text_files( | |
$path . DIRECTORY_SEPARATOR . $entry), $files)); | |
} | |
elseif('text/plain' == mime_content_type( | |
$path . DIRECTORY_SEPARATOR . $entry)){ | |
$files[] = $entry; | |
} | |
} | |
} | |
closedir($d); | |
} | |
return $files; | |
} | |
/** | |
* array csv_search(resource $file_handle, int $column, string $criteria) | |
* | |
* Read line by line the file stored in $file_handle and search on the $column | |
* the $criteria. | |
* The $column is the number of CSV separator + 1, example: | |
* john|31 | |
* Here the CSV separator is | and "31" is on the second column, because it is | |
* found after the first separator | |
* | |
* $line represents one line from the CSV file to be checked against $criteria | |
* | |
* Returns the line containing the $criteria as array if $criteria was found otherwise | |
* FALSE | |
*/ | |
function csv_search($fh, $column, $criteria){ | |
$line = array(); | |
while(FALSE !== ($line = fgetcsv($fh, 1000))){ | |
if($criteria == $line[$column]){ | |
return $line; | |
} | |
} | |
return FALSE; | |
} | |
/** | |
* dir_type_check() checks if a directory is full of $type files or not | |
* | |
* @param resource $dir directory handle(created by opendir) you want to check | |
* @param string $type file type to search into the mime type of the file | |
* (default: image) | |
* @param string $path path to directory opened in $dir_h | |
* @return array|NULL array of strings containing the image names, | |
* if the directory does not contain ONLY images then NULL is returned | |
*/ | |
function dir_type_check($dir_h, $dir_name, $type = 'image'){ | |
$finfo = finfo_open(FILEINFO_MIME_TYPE); | |
$images = array(); | |
$num_files = 0; | |
while($entry = readdir($dir_h)){ | |
if('.' != $entry && ".." != $entry && "users.csv" != $entry){ | |
$entry = '.' . DIRECTORY_SEPARATOR . 'uploads' | |
. DIRECTORY_SEPARATOR . $dir_name . DIRECTORY_SEPARATOR . $entry; | |
$mime_type = finfo_file($finfo, $entry); | |
$num_files++; | |
if(FALSE !== stristr($mime_type, $type)){ | |
$images[] = $entry; | |
} | |
else{ | |
return NULL; | |
} | |
} | |
} | |
finfo_close($finfo); | |
return $num_files ? $images : NULL; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* BL for the gallery script | |
*/ | |
$result = NULL; | |
if(isset($_POST['submit'])){ | |
if(isset($_POST['dir']) && !empty($_POST['dir'])){ | |
$dir_name = $_POST['dir']; | |
$dir = UPLOADS_ROOT . $dir_name; | |
if(is_dir($dir)){ | |
$result = find_files_by_mime($dir, 'image', FALSE); | |
if(!empty($result)){ | |
return $result; | |
} | |
else{ | |
return G_ERR_NO_IMAGES; | |
} | |
} | |
else{ | |
return G_ERR_IS_DIR; | |
} | |
} | |
else{ | |
return G_ERR_NO_DIR; | |
} | |
} | |
return G_OK; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* BL for the gallery script | |
*/ | |
$result = NULL; | |
if(isset($_POST['submit'])){ | |
if(isset($_POST['dir']) && !empty($_POST['dir'])){ | |
$dir_name = $_POST['dir']; | |
$dir = PATH . $dir_name; | |
if(is_dir($dir)){ | |
$dir_h = opendir($dir); | |
if(FALSE != $dir_h){ | |
rewinddir($dir_h); | |
$result = dir_type_check($dir_h, $dir_name); | |
closedir($dir_h); | |
if(NULL !== $result){ | |
return $result; | |
} | |
else{ | |
return ERR_ONLY_IMAGES; | |
} | |
} | |
else{ | |
return ERR_OPEN_DIR; | |
} | |
} | |
else{ | |
return ERR_IS_DIR; | |
} | |
} | |
else{ | |
return ERR_NO_DIR; | |
} | |
} | |
return OK; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Defined constants for the gallery script | |
*/ | |
const OK = 0; | |
const ERR_IS_DIR = 1; | |
const ERR_NO_DIR = 2; | |
const ERR_OPEN_DIR = 3; | |
const ERR_ONLY_IMAGES = 4; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if(is_array($feedback['gallery'])){ | |
echo '<p>'; | |
foreach($feedback['gallery'] as $img){ | |
//XSS here :) | |
echo '<img src="' . $img . '" /> '; | |
} | |
echo '</p>'; | |
} | |
else{ | |
?> | |
<form method="post" action="" > | |
<label for="id-dir">Directory containing images</label> | |
<input type="text" name="dir" id="id-dir" /> | |
<br /> | |
<input type="submit" name="submit" value="Display" /> | |
</form> | |
<?php | |
} | |
if(NULL != $feedback['gallery'] && is_numeric($feedback['gallery'])){ | |
switch($feedback['gallery']){ | |
case ERR_IS_DIR: echo 'Invalid directory name! - ', ERR_IS_DIR; | |
break; | |
case ERR_NO_DIR: echo 'Please provide a directory name! - ', ERR_NO_DIR; | |
break; | |
case ERR_OPEN_DIR: echo 'Failed to open directory! - ', ERR_OPEN_DIR; | |
break; | |
case ERR_ONLY_IMAGES: echo 'The directory does not contain only images! - ', | |
ERR_ONLY_IMAGES; | |
break; | |
default; | |
} | |
} | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* BL for Guest Book script | |
*/ | |
$result = array( | |
'nick' => NULL, | |
'msg' => NULL, | |
'mail' => NULL, | |
'url' => NULL, | |
'time' => NULL, | |
'ip' => NULL, | |
); | |
if(isset($_POST['post'])){ | |
if(isset($_POST['nick']) && NULL != $_POST['nick']){ | |
$result['nick'] = strip_tags($_POST['nick']); | |
if(isset($_POST['message']) && NULL != $_POST['message']){ | |
$result['msg'] = $_POST['message']; | |
$result['msg'] = strip_tags($result['msg'], '<p><i><b>'); | |
if(isset($_POST['mail']) && NULL != $_POST['mail']){ | |
$result['mail'] = strip_tags($_POST['mail']); | |
} | |
if(isset($_POST['url']) && NULL != $_POST['url']){ | |
$result['url'] = strip_tags($_POST['url']); | |
} | |
$result['time'] = date("F j, Y, g:i a"); | |
$result['ip'] = $_SERVER['REMOTE_ADDR']; | |
if(file_exists(PATH_MSG_FILE)){ | |
if(is_writeable(PATH_MSG_FILE)){ | |
$fh = fopen(PATH_MSG_FILE, "a"); | |
if(FALSE != $fh){ | |
$post = json_encode($result); | |
$post .= PHP_EOL; | |
$write_success = fwrite($fh, $post); | |
fclose($fh); | |
if(FALSE != $write_success){ | |
return GB_POST_SUCCESS; | |
} | |
else{ | |
return GB_ERR_WRITE_POST; | |
} | |
} | |
else{ | |
return GB_ERR_OPEN_MSG_FILE; | |
} | |
} | |
else{ | |
return GB_ERR_READONLY; | |
} | |
} | |
else{ | |
return GB_ERR_NO_MSG_FILE; | |
} | |
} | |
else{ | |
return GB_ERR_NO_MSG; | |
} | |
} | |
else{ | |
return GB_ERR_NO_NICK; | |
} | |
} | |
if(isset($_POST['del'])){ | |
if(isset($_SESSION['admin']) && $_SESSION['admin']){ | |
if(isset($_POST['manage_posts']) && !empty($_POST['manage_posts'])){ | |
$manage_posts = $_POST['manage_posts']; | |
$posts_info = array(); | |
$remaining_posts = array(); | |
foreach($manage_posts as $post){ | |
$post = explode('!', $post); | |
$posts_info[] = $post; | |
} | |
if(file_exists(PATH_MSG_FILE)){ | |
if(is_readable(PATH_MSG_FILE)){ | |
$fh = fopen(PATH_MSG_FILE, "r"); | |
if(FALSE != $fh){ | |
while(!feof($fh)){ | |
$post = fgets($fh); | |
if(FALSE != $post){ | |
$result = json_decode($post, TRUE); | |
foreach($posts_info as $info){ | |
if($info[0] != $result['time'] || $info[1] != $result['ip']){ | |
$remaining_posts[] = $post; | |
} | |
} | |
} | |
else{ | |
fclose($fh); | |
if(is_writeable(PATH_MSG_FILE)){ | |
$fh = fopen(PATH_MSG_FILE, "w"); | |
if(FALSE != $fh){ | |
foreach($remaining_posts as $post){ | |
fwrite($fh, $post); | |
} | |
fclose($fh); | |
} | |
else{ | |
return GB_ERR_OPEN_MSG_FILE; | |
} | |
return GB_DEL_SUCCESS; | |
} | |
else{ | |
return GB_ERR_READONLY; | |
} | |
} | |
} | |
fclose($fh); | |
} | |
else{ | |
return GB_ERR_OPEN_MSG_FILE; | |
} | |
} | |
else{ | |
return GB_ERR_CANNOT_READ; | |
} | |
} | |
else{ | |
return GB_ERR_NO_MSG_FILE; | |
} | |
} | |
else{ | |
return GB_ERR_NO_SELECTED; | |
} | |
} | |
} | |
return GB_OK; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Global constants for Remote File Storage | |
*/ | |
define('MODULES_ROOT', BASE_DIR . 'modules' . DIRECTORY_SEPARATOR); | |
define('DATA_ROOT', BASE_DIR . 'data' . DIRECTORY_SEPARATOR); | |
define('UPLOADS_ROOT', 'uploads' . DIRECTORY_SEPARATOR); | |
const ERR_LOAD_FILE = 'Cannot use current file, it does not exists or it\'s not | |
readable, check your modules! <br /> <a href="javascript:history.go(-1)"> | |
Go back!</a>'; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Global constants for Remote File Storage | |
*/ | |
define('PATH', BASE_DIR . DIRECTORY_SEPARATOR . 'uploads' | |
. DIRECTORY_SEPARATOR); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<p>Hello site!</p> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<p>Hello site!</p> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>STPg - STrong Password generator</title> | |
</head> | |
<body> | |
<center> | |
<p><h3>STPg</h3></p> | |
<form action="fstp.php" method="post"> | |
<h5>Pt. a genera o parola va rugam introduceti lungimea dorita: </h5> | |
<p> | |
<input type="text" name="lung" size="40" maxlength="2" value="Lungime" | |
onfocus="this.value='';" onblur="if(this.value == '') this.value='Lungime';"/> | |
</p> | |
<input type="submit" name="trimite" value="Genereaza cu ajutorul STPg"/> | |
<input type='reset' value="Reseteaza campurile"/> | |
<div align="left"> | |
<h5>© PauLLiK - Toate drepturile rezervate asupra scriptului PHP.</h5> | |
</div> | |
</form> | |
</center> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
define('BASE_DIR', __DIR__ . DIRECTORY_SEPARATOR); | |
require_once BASE_DIR . 'functions.php'; | |
require_once BASE_DIR . 'global_const.php'; | |
$modules = require_once BASE_DIR . 'modules.php'; | |
$feedback = array(); | |
$feedback_pre = array(); | |
$reload = FALSE; | |
$rendered = NULL; | |
if(isset($_GET['show'])){ | |
if(array_key_exists($_GET['show'], $modules)){ | |
$module = $_GET['show']; | |
} | |
else{ | |
$module = '404'; | |
} | |
} | |
else{ | |
foreach($modules as $candidate => $candidate_content){ | |
if(!isset($candidate_content['VL']['show_in_menu'])){ | |
$module = $candidate; | |
break; | |
} | |
elseif(TRUE == $candidate_content['VL']['show_in_menu']){ | |
$module = $candidate; | |
break; | |
} | |
} | |
} | |
load_module: | |
if(isset($modules[$module]['pre-process']) && !empty($modules[$module]['pre-process'])){ | |
foreach($modules[$module]['pre-process'] as $pre_key => $pre){ | |
if(FALSE != stristr($pre, '.php')){ | |
if(file_exists(MODULES_ROOT . $module . DIRECTORY_SEPARATOR . $pre) && | |
is_readable(MODULES_ROOT . $module . DIRECTORY_SEPARATOR . $pre)){ | |
$feedback_pre[$pre_key] = require_once MODULES_ROOT . $module . DIRECTORY_SEPARATOR . $pre; | |
} | |
else{ | |
echo ERR_LOAD_FILE; | |
exit(); | |
} | |
} | |
else{//our module has another module as pre-dependency | |
foreach($modules[$pre]['pre-process'] as $dep_pre_key => $dep_pre){ | |
$feedback_pre[$dep_pre_key] = require_once MODULES_ROOT . $pre . DIRECTORY_SEPARATOR . $dep_pre; | |
} | |
} | |
} | |
} | |
/** | |
* Load BL | |
*/ | |
if(isset($modules[$module]['BL'])){ | |
foreach($modules[$module]['BL'] as $blName => $blFile){ | |
if(file_exists(MODULES_ROOT . $module . DIRECTORY_SEPARATOR . $blFile) && | |
is_readable(MODULES_ROOT . $module . DIRECTORY_SEPARATOR . $blFile)){ | |
$feedback[$blName] = require_once MODULES_ROOT . $module . DIRECTORY_SEPARATOR . $blFile; | |
} | |
else{ | |
echo ERR_LOAD_FILE; | |
exit(); | |
} | |
} | |
} | |
if($reload){ | |
$reload = FALSE; | |
goto load_module; | |
} | |
$rendered = render('layout.php', compact('module', 'feedback', 'modules', 'feedback_pre')); | |
switch($rendered){ | |
case RENDER_ERR_NO_FILE: echo 'No page to display! - ' , RENDER_ERR_NO_FILE; | |
break; | |
case RENDER_ERR_FILE: echo 'Cound not read the file! - ' , RENDER_ERR_FILE; | |
break; | |
default; | |
} | |
if(isset($modules[$module]['post-process']) && !empty($modules[$module]['post-process'])){ | |
foreach($modules[$module]['post-process'] as $post){ | |
if(FALSE != stristr($post, '.php')){ | |
if(file_exists(MODULES_ROOT . $module . DIRECTORY_SEPARATOR . $post) && | |
is_readable(MODULES_ROOT . $module . DIRECTORY_SEPARATOR . $post)){ | |
require_once MODULES_ROOT . $module . DIRECTORY_SEPARATOR . $post; | |
} | |
else{ | |
echo ERR_LOAD_FILE; | |
exit(); | |
} | |
} | |
else{//our module has another module as post-dependency | |
foreach($modules[$post]['post-process'] as $dep_post){ | |
require_once MODULES_ROOT . $post . DIRECTORY_SEPARATOR . $dep_post; | |
} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once 'functions.php'; | |
$pages = require_once 'pages.php'; | |
if(isset($_GET['show'])){ | |
if(array_key_exists($_GET['show'], $pages)){ | |
$page = $_GET['show']; | |
} | |
else{ | |
$page = 'notfound'; | |
} | |
} | |
else{ | |
$page = 'home'; | |
} | |
render('layout.php', compact('page', 'pages')); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
const BASE_DIR = __DIR__; | |
require_once '.' . DIRECTORY_SEPARATOR . 'functions.php'; | |
require_once '.' . DIRECTORY_SEPARATOR . 'global_const.php'; | |
$pages = require_once '.' . DIRECTORY_SEPARATOR . 'pages.php'; | |
$feedback = array(); | |
if(isset($_GET['show'])){ | |
if(array_key_exists($_GET['show'], $pages)){ | |
$page = $_GET['show']; | |
} | |
else{ | |
$page = 'notfound'; | |
} | |
} | |
else{ | |
$page = 'home'; | |
} | |
session_start(); | |
if(!isset($_SESSION['uID']) && isset($_COOKIE[session_name()]) && is_numeric($_COOKIE[session_name()])){ | |
$_SESSION['uID'] = $_COOKIE[session_name()]; | |
} | |
elseif(isset($pages[$page]['login']) && !isset($_SESSION['uID'])){ | |
/** | |
* if no session is registered and 'remember me' was not checked | |
* and still the page needs authentication | |
*/ | |
$page = 'login'; | |
} | |
if(isset($pages[$page]['preprocess'])){ | |
foreach($pages[$page]['preprocess'] as $preprocessName => $preprocessFile){ | |
$feedback[$preprocessName] = require BASE_DIR . DIRECTORY_SEPARATOR . 'pages' . DIRECTORY_SEPARATOR . $preprocessFile; | |
} | |
} | |
render('layout.php', compact('page', 'feedback', 'pages')); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" | |
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
<html> | |
<head> | |
<link rel="stylesheet" type="text/css" href="css/style.css" /> | |
<title><?php echo $modules[$module]['VL']['title'];?></title> | |
</head> | |
<body> | |
<div id="header"> | |
<div id="login"> | |
<?php | |
if(isset($_SESSION['uID'])){ | |
echo '<a href="?show=logout_user">Log out</a>'; | |
} | |
else{ | |
echo '<a href="?show=login_user">Log in</a>'; | |
} | |
?> | |
</div> | |
</div> | |
<div id="menu"> | |
<h3>Menu here</h3> | |
<?php echo build_menu_from_modules($modules, $module)?> | |
</div> | |
<div id="content"> | |
<h3><?php echo $modules[$module]['VL']['title'];?></h3> | |
<?php | |
if(file_exists(MODULES_ROOT . $module . DIRECTORY_SEPARATOR | |
. $modules[$module]['VL']['content']) && | |
is_readable(MODULES_ROOT . $module . DIRECTORY_SEPARATOR | |
. $modules[$module]['VL']['content'])){ | |
?> | |
<p> | |
<?php | |
include MODULES_ROOT . $module . DIRECTORY_SEPARATOR | |
. $modules[$module]['VL']['content']; | |
} | |
else{ | |
echo '<h3>' , ERR_LOAD_FILE , '</h3>'; | |
} | |
?> | |
</p> | |
</div> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<link rel="stylesheet" type="text/css" href="css/style.css" /> | |
<title><?php echo $pages[$page]['title'];?></title> | |
</head> | |
<body> | |
<div id="menu"> | |
<h3>Menu here</h3> | |
<?php echo build_menu_from_pages($pages, $page)?> | |
</div> | |
<div id="content"> | |
<h3>Content here</h3> | |
<p><?php include __DIR__ . '/pages/' . $pages[$page]['content'];?></p> | |
</div> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<link rel="stylesheet" type="text/css" href="css/style.css" /> | |
<title><?php echo $pages[$page]['title'];?></title> | |
</head> | |
<body> | |
<div id="header"> | |
<div id="login"> | |
<?php | |
if(isset($_SESSION['uID'])){ | |
echo '<a href="?show=logout">Log out</a>'; | |
} | |
else{ | |
echo '<a href="?show=login">Log in</a>'; | |
} | |
?> | |
</div> | |
</div> | |
<div id="menu"> | |
<h3>Menu here</h3> | |
<?php echo build_menu_from_pages($pages, $page)?> | |
</div> | |
<div id="content"> | |
<h3><?php echo $pages[$page]['title'];?></h3> | |
<p><?php include BASE_DIR . '/pages/' . $pages[$page]['content'];?></p> | |
</div> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Login BL | |
* This script the verifies the admin's credentials and logs him in(starts a | |
* session registering his ID) or rejects him | |
* | |
* The password must match the one in DATA_ROOT/gbook/admin_pass | |
* | |
* $auth - stores a boolean, if the user is authentified or not | |
*/ | |
$currentPass = NULL; | |
$auth = FALSE; | |
if(isset($_POST['adminlogin'])){ | |
if(isset($_POST['pass']) && !empty($_POST['pass'])){ | |
$pass = $_POST['pass']; | |
if(is_dir(DATA_ROOT . 'gbook')){ | |
if(($f = fopen(DATA_ROOT . 'gbook' . DIRECTORY_SEPARATOR . 'admin_pass', "r")) !== FALSE){ | |
$currentPass = fgets($f); | |
fclose($f); | |
if(FALSE !== $currentPass){ | |
if(trim($currentPass) == trim($pass)){ | |
$auth = TRUE; | |
if(!isset($_SESSION)){ | |
session_set_cookie_params(0, app_path()); | |
session_start(); | |
} | |
$_SESSION['admin'] = TRUE; | |
if(isset($_GET['action']) && is_string($_GET['action'])){ | |
$module = $_GET['action']; | |
$reload = TRUE; | |
} | |
} | |
else{ | |
return LA_ERR_PASS; | |
} | |
} | |
else{ | |
return LA_ERR_READING; | |
} | |
} | |
else{ //error opening admin_pass | |
return LA_ERR_FOPEN_ADMIN; | |
} | |
} | |
else{ | |
return LA_ERR_DIR; | |
} | |
} | |
else{ //empty password field | |
return LA_ERR_NO_PASS; | |
} | |
if(isset($_POST['r_me']) && $auth){ //create cookie for remembering the session | |
$cookie = setcookie(session_name(), session_id(), time()+60*60*24*30, app_path()); | |
if(!$cookie){ | |
return LA_ERR_COOKIE; | |
} | |
} | |
} | |
return $auth; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Login BL | |
* This script the verifies the user's credentials and logs him in(starts a | |
* session registering his uID) or rejects him | |
* | |
* The password must be a directory in uploads/ and the user must be found in | |
* 'users.csv' file into uploads/password_dir | |
* | |
* $currentUser - array of two strings containing the credentials(username and | |
* the ID) of the logged in user | |
* $auth - stores a boolean, if the user is authentified or not | |
*/ | |
$currentUser = array(); | |
$auth = FALSE; | |
if(isset($_POST['go'])){ | |
if(isset($_POST['pass']) && !empty($_POST['pass'])){ | |
$pass = $_POST['pass']; | |
if(is_dir(UPLOADS_ROOT . $pass)){ | |
if(($f = fopen(UPLOADS_ROOT . $pass . DIRECTORY_SEPARATOR . 'users.csv', | |
"r")) !== FALSE){ | |
if(isset($_POST['user']) && !empty($_POST['user'])){ | |
$user = $_POST['user']; | |
$currentUser = csv_search($f, 0, $user); | |
fclose($f); | |
if(FALSE !== $currentUser){ | |
$auth = TRUE; | |
if(!isset($_SESSION)){ | |
session_set_cookie_params(0, app_path()); | |
session_start(); | |
} | |
$_SESSION['uID'] = $currentUser[1]; | |
if(isset($_GET['action']) && is_string($_GET['action'])){ | |
$module = $_GET['action']; | |
$reload = TRUE; | |
} | |
} | |
else{ //inexistent username | |
return LU_ERR_USER; | |
} | |
} | |
else{ //empty user field | |
return LU_ERR_NO_USER; | |
} | |
} | |
else{ //error opening users.csv | |
return LU_ERR_FOPEN_USER; | |
} | |
} | |
else{ //incorrect password | |
return LU_ERR_PASS; | |
} | |
} | |
else{ //empty password field | |
return LU_ERR_NO_PASS; | |
} | |
if(isset($_POST['r_me']) && $auth){ //create cookie for remembering the session | |
$pos = strrpos($_SERVER['REQUEST_URI'], DIRECTORY_SEPARATOR); | |
$cookie_path = substr($_SERVER['REQUEST_URI'], 0, $pos); | |
$cookie = setcookie(session_name(), session_id(), time()+60*60*24*30, app_path()); | |
if(!$cookie){ | |
return LU_ERR_COOKIE; | |
} | |
} | |
} | |
return $auth; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Login BL | |
* This script the verifies the user's credentials and logs him in(starts a | |
* session registering his uID) or rejects him | |
* | |
* The password must be a directory in uploads/ and the user must be found in | |
* 'users.csv' file into uploads/password_dir | |
* | |
* $currentUser - array of two strings containing the credentials(username and | |
* the ID) of the logged in user | |
* $auth - stores a boolean, if the user is authentified or not | |
*/ | |
$currentUser = array(); | |
$auth = FALSE; | |
if(!isset($_SESSION['captcha']) || -1 == $_SESSION['captcha']){ | |
return ERR_CAPTCHA; | |
} | |
if(isset($_POST['go'])){ | |
if(isset($_POST['code']) && NULL != $_POST['code']){ | |
if($_POST['code'] != $_SESSION['captcha']){ | |
return ERR_W_CODE; | |
} | |
} | |
else{ | |
return ERR_NO_CODE; | |
} | |
if(isset($_POST['pass']) && !empty($_POST['pass'])){ | |
$pass = $_POST['pass']; | |
if(is_dir(PATH . $pass)){ | |
if(($f = fopen(PATH . $pass . DIRECTORY_SEPARATOR . 'users.csv', | |
"r")) !== FALSE){ | |
if(isset($_POST['user']) && !empty($_POST['user'])){ | |
$user = $_POST['user']; | |
$currentUser = csv_search($f, 0, $user); | |
fclose($f); | |
if(FALSE !== $currentUser){ | |
$auth = TRUE; | |
$_SESSION = array(); | |
$_SESSION['uID'] = $currentUser[1]; | |
} | |
else{ //inexistent username | |
return ERR_USER; | |
} | |
} | |
else{ //empty user field | |
return ERR_NO_USER; | |
} | |
} | |
else{ //error opening users.csv | |
return ERR_FOPEN_USER; | |
} | |
} | |
else{ //incorrect password | |
return ERR_PASS; | |
} | |
} | |
else{ //empty password field | |
return ERR_NO_PASS; | |
} | |
if(isset($_POST['r_me']) && $auth){ //create cookie for remembering the session | |
$cookie = setcookie(session_name(), $currentUser[1], time()+60*60*24*30, '/'); | |
if(!$cookie){ | |
return ERR_COOKIE; | |
} | |
} | |
} | |
return $auth; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Defined constants for the login script | |
*/ | |
const ERR_USER = 1; | |
const ERR_FOPEN_USER = 2; | |
const ERR_PASS = 3; | |
const ERR_NO_USER = 4; | |
const ERR_NO_PASS = 5; | |
const ERR_SESS = 6; | |
const ERR_COOKIE = 7; | |
const ERR_CAPTCHA = 8; | |
const ERR_NO_CODE = 9; | |
const ERR_W_CODE = 10; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form action="" method="post"> | |
<label for="id-u">User name:</label><input type="text" id="id-u" name="user" /> | |
<br /><label for="id-p">Password:</label> | |
<input type="password" id="id-p" name="pass" /> | |
<br /><input type="checkbox" name="r_me" id="id-r" /> | |
<label for="id-r">Remember me</label> | |
<br /> | |
<br /> | |
<img src="index.php?show=captcha"> | |
<br /> | |
<br /> | |
<label for="id-code">Code here:</label> | |
<input type="text" name="code" id="id-code" /> | |
<br /><input type="submit" name="go" value="Log In" /> | |
</form> | |
<?php | |
if(is_numeric($feedback['login'])){ | |
echo '<h3>'; | |
switch($feedback['login']){ | |
case ERR_USER: echo 'Inexistent user! - ', ERR_USER; | |
break; | |
case ERR_FOPEN_USER: echo 'Error opening users.csv! - ', ERR_FOPEN_USER; | |
break; | |
case ERR_PASS: echo 'Incorrect password! - ', ERR_PASS; | |
break; | |
case ERR_NO_USER: echo 'Please fill in a user name! - ', ERR_NO_USER; | |
break; | |
case ERR_NO_PASS: echo 'Please provide a password! - ', ERR_NO_PASS; | |
break; | |
case ERR_SESS: echo 'Error starting session! - ', ERR_SESS; | |
break; | |
case ERR_COOKIE: echo 'Cannot set cookie! - ', ERR_COOKIE; | |
break; | |
case ERR_CAPTCHA: echo 'Captcha error! - ', ERR_CAPTCHA; | |
break; | |
case ERR_NO_CODE: echo 'Please type the captcha code! - ', ERR_NO_CODE; | |
break; | |
case ERR_W_CODE: echo 'Wrong captcha code! - ', ERR_W_CODE; | |
break; | |
default; | |
} | |
echo '</h3>'; | |
} | |
elseif($feedback['login']){ | |
echo '<h3>You\'ve been successfully authentified</h3>'; | |
} | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Log out script | |
* | |
* At first we need to unset the $_SESSION, then to delete the session cookie | |
* if it's set and finally to destroy the session itself | |
*/ | |
$del_cookie = FALSE; | |
$destroy_session = FALSE; | |
$_SESSION = array(); | |
if(ini_get("session.use_cookies")){ | |
$params = session_get_cookie_params(); | |
$del_sCookie = setcookie(session_name(), '', time() - 42000, $params['path'], | |
$params['domain'], $params['secure'], $params['httponly'] | |
); | |
} | |
$destroy_session = session_destroy(); | |
return $destroy_session & $del_sCookie; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Log out script | |
* | |
* At first we need to unset the $_SESSION, then to delete the session cookie | |
* if it's set and finally to destroy the session itself | |
*/ | |
$del_cookie = FALSE; | |
$destroy_session = FALSE; | |
$_SESSION = array(); | |
if(ini_get("session.use_cookies")){ | |
$params = session_get_cookie_params(); | |
$del_sCookie = setcookie(session_name(), '', time() - 42000, $params['path'], | |
$params['domain'], $params['secure'], $params['httponly'] | |
); | |
} | |
$destroy_session = session_destroy(); | |
return $destroy_session & $del_sCookie; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Log out script | |
* | |
* At first we need to unset the $_SESSION, then to delete the session cookie | |
* if it's set and finally to destroy the session itself | |
*/ | |
$del_cookie = FALSE; | |
$destroy_session = FALSE; | |
$_SESSION = array(); | |
if(ini_get("session.use_cookies")){ | |
$params = session_get_cookie_params(); | |
$del_sCookie = setcookie(session_name(), '', time() - 42000, $params['path'], | |
$params['domain'], $params['secure'], $params['httponly'] | |
); | |
} | |
$destroy_session = session_destroy(); | |
return $destroy_session & $del_sCookie; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
echo '<h3>'; | |
if($feedback['logout']){ | |
echo 'You\'ve been successfully logged out!'; | |
} | |
else{ | |
echo 'An error occured during log out!'; | |
} | |
echo '</h3>'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Module list | |
* | |
* A configuration file to hold all available modules | |
* From this file a menu is build and pages are loaded | |
* | |
* Every module's structure must be compilant with the following example: | |
* | |
* 'module_name' => array( | |
* 'pre-process' => array( | |
* 'script_meta_info' => 'script_name.php', | |
* 'module_meta_info' => 'module_name', | |
* 'more_meta_info_here' => 'more_modules_to_load', | |
* ), | |
* 'VL' => array( | |
* 'title' => 'Module Title', | |
* 'content' => 'VL_script_name', | |
* 'show_in_menu' => <bool value>, | |
* 'login_need' => <bool value>, | |
* ), | |
* 'BL' => array( | |
* 'script_meta_name' => 'name.php', | |
* 'script_meta_name2' => 'name_other.php', | |
* 'more_script_meta_here' => 'more_BL_scripts_to_load', | |
* ), | |
* 'post-process' => array( | |
* 'script_meta_info' => 'script_name.php', | |
* 'module_meta_info' => 'module_name', | |
* 'more_meta_info_here' => 'more_modules_to_load', | |
* ), | |
* ), | |
* | |
* So every module is a dictionary of MAXIMUM four dictionaries. | |
* The example shown above is a MAXIMUM of what a module can contain, except for | |
* the pre-preprocess, BL, and post-process, these parts can contain a | |
* never-ending set of scripts, more on this later. | |
* | |
* 'module_name' -> | |
* Represents the name which will be shown in the URL '?show=' | |
* part and the name by which it will be recognizable by other modules | |
* | |
* 'pre-process' -> | |
* This part of the module is optional, it's required when the module needs | |
* some pre-processing(e.g.: logging in a user), here simple scripts can be | |
* loaded(if the *.php extension is set on the name part) or whole modules | |
* if there is no extension set, of course the module needed is searched in | |
* this file, if it's found it's 'pre-process' part is loaded before the | |
* callee is loaded. | |
* If a single script is to be pre-loaded then it is searched in the | |
* current module's directory, if a module is to be loaded then it's loaded | |
* from MODULES_ROOT | |
* An undetermined number of modules/scripts can be loaded. | |
* | |
* Example: | |
* 'pre-process' => array( | |
* 'foo_script' => 'foo.php', | |
* 'login' => 'login_user', | |
* ), | |
* | |
* In this example 2 things are pre-loaded, the 'foo.php' script(from the | |
* current module's directory) and the pre-process part of the 'login_user' | |
* module | |
* | |
* 'post-process' -> | |
* Acts the same as 'pre-process', the only differece being that the | |
* scripts/modules are post-loaded, so they are loaded after the callee has | |
* made his job. For post-loading modules the same rule applies: only the | |
* post-process part of the module is loaded after the callee | |
* | |
* 'VL' -> | |
* Here you can set a predefined number of characteristics | |
* Entries available at the moment: | |
* | |
* 'title' -> the user will see this text as title | |
* | |
* 'content' -> the VL script of the module found int he modeule's | |
* directory | |
* | |
* 'show_in_menu' -> OPTIONAL - if it's not set the user will see this | |
* module in the menu, if it's set to FALSE the user will not be able to | |
* see it in the menu, else it will be shown | |
* | |
* 'login_need' -> OPTIONAL - if it's not set and a login module is | |
* pre-loaded then it's optional to log in to use this module, if it's | |
* set to TRUE then the login is mandatory | |
* | |
* Example: | |
* 'VL' => array( | |
* 'title' => 'BAR', | |
* 'content' => 'vl_script.php', | |
* ), | |
* | |
* In this example the user will see the page's title as 'BAR' and when | |
* accessing the module the file 'vl_script.php' will be loaded, in this | |
* case loggin in to use the module is optional and the module will be | |
* visible in the menu | |
* | |
* 'VL' => array( | |
* 'title' => 'foo', | |
* 'content' => 'content.php', | |
* 'login_need' => TRUE, | |
* ), | |
* | |
* Here the title will be 'foo', the file 'content.php' will be loaded and | |
* the login is mandatory so this module must have a login module as | |
* 'pre-process' | |
* | |
* 'BL' -> | |
* This part of a module holds the "brain", the business logic scripts. | |
* An undefined number of *.php scripts can be loaded, all files are loaded | |
* from the module's directory. | |
* The key from the array is the name under which the VL part of the | |
* module receives feedback after the script finished processing(giving | |
* feedback is not mandatory e.g. constants or functions files) | |
* | |
* Example: | |
* 'BL' => array( | |
* 'constants' => 'constants.php', | |
* 'func' => 'functions.php', | |
* 'brain' => 'baz.php', | |
* ), | |
* | |
* Here three files are loaded, the VL receives feedback from 'baz.php' | |
* under this form: $feedback['brain'] | |
*/ | |
return array( | |
'home' => array( | |
'pre-process' => array( | |
'autologin' => 'login_user', | |
), | |
'VL' => array( | |
'title' => 'Home', | |
'content' => 'content.php', | |
), | |
), | |
'gbook' => array( | |
'pre-process' => array( | |
'autologin' => 'login_admin', | |
), | |
'VL' => array( | |
'title' => 'G - book', | |
'content' => 'content.php', | |
), | |
'BL' => array( | |
'gbook_const' => 'constants.php', | |
'gbook_func' => 'functions.php', | |
'gbook' => 'gbook.php', | |
), | |
), | |
'gbook_panel' => array( | |
'pre-process' => array( | |
'autologin' => 'login_admin' | |
), | |
'VL' => array( | |
'title' => 'Admin panel', | |
'content' => 'content.php', | |
'show_in_menu' => FALSE, | |
'login_need' => TRUE, | |
), | |
'BL' => array( | |
'const' => 'constants.php', | |
'func' => 'functions.php', | |
'panel' => 'panel.php', | |
), | |
), | |
'login_admin' => array( | |
'pre-process' => array( | |
'autologin' => 'autologin.php', | |
), | |
'VL' => array( | |
'title' => 'Admin Log In', | |
'content' => 'content.php', | |
'show_in_menu' => FALSE, | |
), | |
'BL' => array( | |
'login_const' => 'constants.php', | |
'login' => 'login.php', | |
), | |
), | |
'logout_admin' => array( | |
'pre-process' => array( | |
'autologin_admin' => 'login_admin', | |
), | |
'VL' => array( | |
'title' => 'Admin logged out', | |
'content' => 'content.php', | |
'show_in_menu' => FALSE, | |
), | |
'BL' => array( | |
'logout' => 'logout.php' | |
), | |
), | |
'404' => array( | |
'VL' => array( | |
'title' => 'Inexistent page', | |
'content' => 'content.php', | |
'show_in_menu' => FALSE, | |
'custom' => TRUE, | |
), | |
'BL' => array( | |
'notfound' => '404.php', | |
), | |
), | |
'login_user' => array( | |
'pre-process' => array( | |
'autologin' => 'autologin.php', | |
), | |
'VL' => array( | |
'title' => 'User Log in', | |
'content' => 'content.php', | |
'show_in_menu' => FALSE, | |
), | |
'BL' => array( | |
'login_const' => 'constants.php', | |
'login' => 'login.php', | |
), | |
), | |
'logout_user' => array( | |
'pre-process' => array( | |
'autologin_user' => 'login_user', | |
), | |
'VL' => array( | |
'title' => 'User logged out', | |
'content' => 'content.php', | |
'show_in_menu' => FALSE, | |
), | |
'BL' => array( | |
'logout' => 'logout.php' | |
), | |
), | |
'gallery' => array( | |
'pre-process' => array( | |
'autologin_user' => 'login_user', | |
), | |
'VL' => array( | |
'title' => 'Gallery', | |
'content' => 'content.php', | |
'login_need' => TRUE, | |
), | |
'BL' => array( | |
'const' => 'constants.php', | |
'gallery' => 'gallery.php', | |
), | |
), | |
'text' => array( | |
'pre-process' => array( | |
'autologin' => 'login_user', | |
), | |
'VL' => array( | |
'title' => 'Text edit', | |
'content' => 'content.php', | |
'login_need' => TRUE, | |
), | |
'BL' => array( | |
'const' => 'constants.php', | |
'text' => 'text.php', | |
), | |
), | |
'upload' => array( | |
'pre-process' => array( | |
'autologin' => 'login_user', | |
), | |
'VL' => array( | |
'title' => 'Upload', | |
'content' => 'content.php', | |
'login_need' => TRUE, | |
), | |
'BL' => array( | |
'const' => 'constants.php', | |
'upload' => 'upload.php' | |
), | |
), | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"nick":"a","msg":"Your message here...\r\n","mail":null,"url":null,"time":"June 19, 2011, 7:18 pm","ip":"::1"} | |
{"nick":"paul","msg":"Your message here...\r\n","mail":"mail","url":"web","time":"June 19, 2011, 7:55 pm","ip":"::1"} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<p>Ooops, nothing to see here, this page is inexistent!</p> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<p>Ooops, nothing to see here, this page is inexistent!</p> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
return array( | |
'home' => array( | |
'title' => 'Home', | |
'content' => 'home.php' | |
), | |
'about' => array( | |
'title' => 'About me', | |
'content' => 'about.php' | |
), | |
'notfound' => array( | |
'title' => 'Inexistent page', | |
'content' => 'notfound.php' | |
), | |
'user' => array( | |
'title' => 'About you', | |
'content' => 'user.php' | |
) | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
return array( | |
'home' => array( | |
'title' => 'Home', | |
'content' => 'home.php', | |
), | |
'upload' => array( | |
'title' => 'Upload', | |
'content' => 'upload_content.php', | |
'login' => TRUE, | |
'preprocess' => array( | |
'upload_const' => 'upload_const.php', | |
'upload' => 'upload.php', | |
), | |
), | |
'notfound' => array( | |
'title' => 'Inexistent page', | |
'content' => 'notfound.php', | |
), | |
'text' => array( | |
'title' => 'Edit your text', | |
'content' => 'text_content.php', | |
'login' => TRUE, | |
'preprocess' => array( | |
'text_const' => 'text_const.php', | |
'text' => 'text.php', | |
), | |
), | |
'login' => array( | |
'title' => 'Log In', | |
'content' => 'login_content.php', | |
'preprocess' => array( | |
'login_const' => 'login_const.php', | |
'login' => 'login.php', | |
), | |
), | |
'logout' => array( | |
'title' => 'Log out', | |
'content' => 'logout_content.php', | |
'preprocess' => array( | |
'logout' => 'logout.php' | |
), | |
), | |
'captcha' => array( | |
'preprocess' => array( | |
'captcha_img' => 'captcha_img.php', | |
), | |
), | |
'gallery' => array( | |
'title'=> 'Gallery', | |
'content' => 'gallery_content.php', | |
'login' => TRUE, | |
'preprocess' => array( | |
'gallery_const' => 'gallery_const.php', | |
'gallery' => 'gallery.php', | |
), | |
), | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Controls for Admin panel | |
*/ | |
//BAN | |
if(isset($_POST['ban_ip'])){ | |
if(isset($_POST['ips'])){ | |
$ips = $_POST['ips']; | |
$fh = fopen(PATH_BAN_FILE, "a"); | |
if(FALSE == $fh){ | |
return GP_ERR_FOPEN_BAN_FILE; | |
} | |
$ban = ban_ip($fh, $ips); | |
fclose($fh); | |
if(TRUE != $ban){ | |
return $ban; | |
} | |
else{ | |
return GP_BANNED; | |
} | |
} | |
else{ | |
return GP_ERR_NO_IP; | |
} | |
} | |
//UNBAN | |
if(isset($_POST['unban_ip'])){ | |
if(isset($_POST['unban_ips'])){ | |
$ips = $_POST['unban_ips']; | |
$bans = file(PATH_BAN_FILE); | |
if(FALSE == $bans){ | |
return GP_ERR_FOPEN_BAN_FILE; | |
} | |
for($i=0;$i<count($bans);$i++){ | |
$bans[$i] = trim($bans[$i]); | |
} | |
$ips = array_unique(array_diff($bans, $ips)); //remove the IPs that match | |
$fh = fopen(PATH_BAN_FILE, "w"); | |
if(FALSE == $fh){ | |
return GP_ERR_FOPEN_BAN_FILE; | |
} | |
$unban = ban_ip($fh, $ips); //write the remaining IPs | |
fclose($fh); | |
if(TRUE != $unban){ | |
return $unban; | |
} | |
else{ | |
return GP_UNBANNED; | |
} | |
} | |
else{ | |
return GP_ERR_NO_IP; | |
} | |
} | |
return TRUE; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> | |
<FileZilla3> | |
<Queue /> | |
</FileZilla3> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$path = __DIR__ . DIRECTORY_SEPARATOR . 'file.txt'; | |
if(is_readable($path)){ | |
if(filesize($path)){ | |
$file = fopen($path, "rb"); | |
while(!feof($file)){ | |
$bytes = rand(1, 32); | |
$content = fread($file, $bytes); | |
echo '<pre>' , $content , '</pre>'; | |
} | |
} | |
else{ | |
echo 'Ooops, your file is empty!'; | |
} | |
} | |
else{ | |
echo 'Sorry, file busy!'; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
aaaaaa |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Singleton{ | |
private static $instance; | |
private $var = 0; | |
private function __construct(){ | |
} | |
public function __clone(){ | |
trigger_error('Cloning of singletons is not allowed!', E_USER_ERROR); | |
} | |
public function __wakeup(){ | |
trigger_error('Singletons cannot be unserialized!', E_USER_ERROR); | |
} | |
public static function getInstance(){ | |
if(!isset(self::$instance)){ | |
self::$instance = new Singleton(); | |
} | |
return self::$instance; | |
} | |
public function process(){ | |
return $this->var++; | |
} | |
} | |
$bar = Singleton::getInstance(); | |
$bar->process(); | |
$baz = Singleton::getInstance(); | |
$baz->process(); | |
$foo = serialize($baz); | |
var_dump($bar, $baz, $foo); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
interface Strategy{ | |
public function compute(); | |
} | |
class FooAlgorithm implements Strategy{ | |
public function compute(){ | |
return 42; | |
} | |
} | |
class BarAlgorithm implements Strategy{ | |
public function compute(){ | |
return 42+42; | |
} | |
} | |
class Consumer{ | |
public $algo; | |
public function __construct(Strategy $strategy){ | |
$this->algo = $strategy; | |
} | |
public function doJob(){ | |
return $this->algo->compute(); | |
} | |
} | |
if(!TRUE){ | |
$a = new Consumer(new BarAlgorithm); | |
} | |
else{ | |
$a = new Consumer(new FooAlgorithm); | |
} | |
var_dump($a->doJob()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#content{ | |
text-align: left; | |
width: 90%; | |
position: relative; | |
left:10.1%; | |
border: #FBF9E2; | |
border-style: solid; | |
border-width: 1px; | |
background-color: #FBF9E2; | |
} | |
#menu{ | |
width: 10%; | |
float: left; | |
border: #E6E6FA; | |
border-style: solid; | |
border-width: 1px; | |
background-color: #E6E6FA; | |
} | |
#login{ | |
width: 99%; | |
float: right; | |
} | |
#post{ | |
margin-top: 5px; | |
border: #E6E6FA; | |
border-style: solid; | |
border-width: 1px; | |
} | |
#headpost{ | |
background-color: #E6E6FA; | |
} | |
#date{ | |
position: relative; | |
float:right; | |
text-align: right; | |
} | |
#adminlogin{ | |
position: relative; | |
float:right; | |
text-align: right; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#content{ | |
text-align: left; | |
width: 90%; | |
position: relative; | |
left:10.1%; | |
border: #FBF9E2; | |
border-style: solid; | |
border-width: 1px; | |
background-color: #FBF9E2; | |
} | |
#menu{ | |
width: 10%; | |
float: left; | |
border: #E6E6FA; | |
border-style: solid; | |
border-width: 1px; | |
background-color: #E6E6FA; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#content{ | |
text-align: left; | |
width: 90%; | |
position: relative; | |
left:10.1%; | |
border: #FBF9E2; | |
border-style: solid; | |
border-width: 1px; | |
background-color: #FBF9E2; | |
} | |
#menu{ | |
width: 10%; | |
float: left; | |
border: #E6E6FA; | |
border-style: solid; | |
border-width: 1px; | |
background-color: #E6E6FA; | |
} | |
#login{ | |
width: 99%; | |
float: right; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
adasdad | |
aaaaaaasdasdada |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Business Logic of "Edit text on-site" | |
* | |
* This script will return an array with available text files in the | |
* 'uploads' folder, or a string the will be laoded in a textbox from VL or a | |
* message confirming the file's change or the error that occured. | |
* | |
* $file - the file selected to be edited | |
* $result['files'] - an array containing all the text files from the 'secret' | |
* folder | |
* $result['content'] - string that holds the content of the chosen file | |
* $result['msg'] - string that holds metadatas about the secret folder, the | |
* file or the upload itself | |
* TXT_ERR_PASS - will be returned when passphrase(secret) is incorrect | |
* TXT_ERR_READ - returned when file_get_contents() fails | |
* TXT_ERR_WRITE - returned if there is an error on writing the new contents to the | |
* file | |
*/ | |
$result = array( | |
'files' => NULL, | |
'contents' => NULL, | |
'msg' => NULL, | |
); | |
if(isset($_POST['edit'])){ | |
if(isset($_POST['secret']) && !empty($_POST['secret'])){ | |
$secret = strip_tags($_POST['secret']); | |
if(is_dir(UPLOADS_ROOT . $secret)){ | |
$result['files'] = find_files_by_mime(UPLOADS_ROOT . $secret, 'text', FALSE); | |
foreach($result['files'] as $key => $file){ | |
$result['files'][$key] = strip_tags(substr($file, strrpos($file, '/')+1)); | |
} | |
$result['msg'] = $secret; | |
} | |
else{ //passphrase incorrect(inexistent directory) | |
return TXT_ERR_PASS; | |
} | |
} | |
elseif(isset($_POST['filelist'])){ | |
$file = UPLOADS_ROOT . $_POST['sec'] . DIRECTORY_SEPARATOR . $_POST['filelist']; | |
$result['contents'] = file_get_contents($file); | |
if(FALSE == $result['contents']){ | |
return TXT_ERR_READ; | |
} | |
$result['msg'] = DIRECTORY_SEPARATOR . $_POST['sec'] | |
. DIRECTORY_SEPARATOR . $_POST['filelist']; | |
} | |
elseif(isset($_POST['contents'])){ | |
$file = UPLOADS_ROOT . $_POST['file']; | |
$check = file_put_contents($file, $_POST['contents']); | |
if(FALSE === $check){ | |
return TXT_ERR_WRITE; | |
} | |
$name = substr(strrchr($file, DIRECTORY_SEPARATOR), 1); | |
$result['msg'] = $name; | |
} | |
} | |
return $result; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Business Logic of "Edit text on-site" | |
* | |
* This script will return an array with available text files in the | |
* 'uploads' folder, or a string the will be laoded in a textbox from VL or a | |
* message confirming the file's change or the error that occured. | |
* | |
* PATH - string containing the path for list_text_files() to look in | |
* $file - the file selected to be edited | |
* $result['files'] - an array containing all the text files from the 'secret' | |
* folder | |
* $result['content'] - string that holds the content of the chosen file | |
* $result['msg'] - string that holds metadatas about the secret folder, the | |
* file or the upload itself | |
* ERR_PASS - will be returned when passphrase(secret) is incorrect | |
* ERR_READ - returned when file_get_contents() fails | |
* ERR_WRITE - returned if there is an error on writing the new contents to the | |
* file | |
*/ | |
$result = array( | |
'files' => NULL, | |
'contents' => NULL, | |
'msg' => NULL, | |
); | |
if(isset($_POST['edit'])){ | |
if(isset($_POST['secret']) && !empty($_POST['secret'])){ | |
$secret = $_POST['secret']; | |
if(is_dir(PATH . $secret)){ | |
$result['files'] = list_text_files(PATH . $secret); | |
$result['msg'] = $secret; | |
} | |
else{ //passphrase incorrect(inexistent directory) | |
return ERR_PASS; | |
} | |
} | |
elseif(isset($_POST['filelist'])){ | |
$file = PATH . $_POST['sec'] . DIRECTORY_SEPARATOR . $_POST['filelist']; | |
$result['contents'] = file_get_contents($file); | |
if(FALSE == $result['contents']){ | |
return ERR_READ; | |
} | |
$result['msg'] = DIRECTORY_SEPARATOR . $_POST['sec'] | |
. DIRECTORY_SEPARATOR . $_POST['filelist']; | |
} | |
elseif(isset($_POST['contents'])){ | |
$file = PATH . $_POST['file']; | |
$check = file_put_contents($file, $_POST['contents']); | |
if(FALSE === $check){ | |
return ERR_WRITE; | |
} | |
$name = substr(strrchr($file, DIRECTORY_SEPARATOR), 1); | |
$result['msg'] = $name; | |
} | |
} | |
return $result; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Constants for the "Edit text on-site" script | |
*/ | |
const ERR_PASS = 1; | |
const ERR_READ = 2; | |
const ERR_WRITE = 3; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form action="" method="post" > | |
<?php | |
if(is_numeric($feedback['text'])){ | |
echo '<h3>'; | |
switch($feedback['text']){ | |
case ERR_PASS: echo 'Incorrect passphrase! - ', ERR_PASS; | |
break; | |
case ERR_READ: echo 'Error on reading the file! - ', ERR_READ; | |
break; | |
case ERR_WRITE: echo 'Error on writing to file! - ', ERR_WRITE; | |
default; | |
} | |
echo '</h3>'; | |
} | |
elseif(NULL != $feedback['text']['contents']){ | |
echo '<label for="id-c">Edit here:</label><br /><textarea name="contents" | |
id="id-c" rows="15" cols="100">' , $feedback['text']['contents'] | |
, '</textarea><br />' , PHP_EOL; | |
echo '<input type="hidden" name="file" value="' | |
, $feedback['text']['msg'] , '" />'; | |
} | |
elseif(NULL != $feedback['text']['files']){ | |
foreach($feedback['text']['files'] as $file){ | |
echo '<input type="radio" name="filelist" id="id-' , $file , | |
'" value="' , $file , '" /><label for="id-' , $file , '">' | |
, $file , '</label><br />' , PHP_EOL; | |
} | |
echo '<input type="hidden" name="sec" value="' , $feedback['text']['msg'] , | |
'" />'; | |
} | |
elseif(NULL != $feedback['text']['msg']){ | |
echo '<h3><i>' , $feedback['text']['msg'] , '</i> successfully updated! | |
</h3>'; | |
} | |
else{ //the user must specify the 'secret' | |
echo '<label for="id-s">Passphrase</label><input type="password" | |
name="secret" id="id-s" />'; | |
} | |
?> | |
<input type="submit" value="Edit" name="edit" /> | |
</form> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Business logic of "Remote file upload" | |
* | |
* $_POST['secret'] - string that will represent the directory name to upload to | |
* $file - "abbreviation" from $FILES['file'] | |
* $uploadDir - string that will represent the path for the user's directory | |
* specified by $_POST['secret'] | |
* $created - check-variable to verify if the directory was created successfully | |
* $moved - check-variable to verify if the intendet file was moved in unser's | |
* directory | |
*/ | |
//create short variables | |
$uploadDir = UPLOADS_ROOT; | |
$result = NULL; | |
if(isset($_POST['upload'])){ | |
$file = $_FILES['file']; | |
if($file['error'] == UPLOAD_ERR_OK){ // if the upload went ok | |
if(is_uploaded_file($file['tmp_name'])){ // if the file is legitim(uploaded by POST method) | |
if(isset($_POST['secret']) && !empty($_POST['secret'])){ //the directory is a "must" | |
$uploadDir .= DIRECTORY_SEPARATOR . $_POST['secret']; | |
if(!is_dir($uploadDir)){ // create the directory if its inexistent | |
$created = mkdir($uploadDir); | |
if(!$created){ | |
return UP_ERR_CREATE_DIR; | |
} | |
} | |
$moved = move_uploaded_file($file['tmp_name'], $uploadDir . DIRECTORY_SEPARATOR . $file['name']); | |
if(!$moved){ | |
return UP_ERR_MOVE; | |
} | |
else{ | |
$result = UP_SUCCESS; | |
} | |
} | |
else{ | |
return UP_ERR_SECRET; | |
} | |
} | |
else{ | |
return UP_ERR_NOT_UPLOADED; | |
} | |
} | |
else{ //if something went wrong | |
switch($file['error']){ | |
case UPLOAD_ERR_INI_SIZE: //break omitted intentionally | |
case UPLOAD_ERR_FORM_SIZE: | |
return UP_ERR_SIZE; | |
break; | |
case UPLOAD_ERR_PARTIAL: | |
return UP_ERR_PARTIAL; | |
break; | |
case UPLOAD_ERR_NO_FILE: | |
return UP_ERR_NO_FILE; | |
break; | |
case UPLOAD_ERR_NO_TMP_DIR: | |
return UP_ERR_NO_TMP; | |
break; | |
case UPLOAD_ERR_CANT_WRITE: | |
return UP_ERR_NO_WRITE; | |
break; | |
case UPLOAD_ERR_EXTENSION: | |
return UP_ERR_EXT; | |
break; | |
default: | |
} | |
} | |
} | |
return $result; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Business logic of "Remote file upload" | |
* | |
* $_POST['secret'] - string that will represent the directory name to upload to | |
* $file - "abbreviation" from $FILES['file'] | |
* $uploadDir - string that will represent the path for the user's directory | |
* specified by $_POST['secret'] | |
* $created - check-variable to verify if the directory was created successfully | |
* $moved - check-variable to verify if the intendet file was moved in unser's | |
* directory | |
*/ | |
//create short variables | |
$uploadDir = BASE_DIR . DIRECTORY_SEPARATOR . 'uploads'; | |
$result = NULL; | |
if(isset($_POST['upload'])){ | |
$file = $_FILES['file']; | |
if($file['error'] == UPLOAD_ERR_OK){ // if the upload went ok | |
if(is_uploaded_file($file['tmp_name'])){ // if the file is legitim(uploaded by POST method) | |
if(isset($_POST['secret']) && !empty($_POST['secret'])){ //the directory is a "must" | |
$uploadDir .= DIRECTORY_SEPARATOR . $_POST['secret']; | |
if(!is_dir($uploadDir)){ // create the directory if its inexistent | |
$created = mkdir($uploadDir); | |
if(!$created){ | |
return ERR_CREATE_DIR . $_POST['secret']; | |
} | |
} | |
$moved = move_uploaded_file($file['tmp_name'], $uploadDir . DIRECTORY_SEPARATOR . $file['name']); | |
if(!$moved){ | |
return ERR_MOVE; | |
} | |
else{ | |
$result = SUCCESS; | |
} | |
} | |
else{ | |
return ERR_SECRET; | |
} | |
} | |
else{ | |
return ERR_NOT_UPLOADED; | |
} | |
} | |
else{ //if something went wrong | |
switch($file['error']){ | |
case UPLOAD_ERR_INI_SIZE: //break omitted intentionally | |
case UPLOAD_ERR_FORM_SIZE: | |
return ERR_SIZE; | |
break; | |
case UPLOAD_ERR_PARTIAL: | |
return ERR_PARTIAL; | |
break; | |
case UPLOAD_ERR_NO_FILE: | |
return ERR_NO_FILE; | |
break; | |
case UPLOAD_ERR_NO_TMP_DIR: | |
return ERR_NO_TMP; | |
break; | |
case UPLOAD_ERR_CANT_WRITE: | |
return ERR_NO_WRITE; | |
break; | |
case UPLOAD_ERR_EXTENSION: | |
return ERR_EXT; | |
break; | |
default: | |
} | |
} | |
} | |
return $result; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* in this file are stored constants related to the upload.php script | |
* for details go to: | |
* http://www.php.net/manual/en/features.file-upload.errors.php | |
*/ | |
const ERR_SIZE = 'The input file exceeded the size limit!'; | |
const ERR_PARTIAL = 'The uploaded file was only partially uploaded!'; | |
const ERR_NO_FILE = 'You must select a file for uploading!'; | |
const ERR_NO_TMP = 'Please contact our staff: the temporary directory is missing!'; | |
const ERR_NO_WRITE = 'Please contact our staff: directory permissions problems!'; | |
const ERR_EXT = 'Please contact our staff: upload stopped by extension!'; | |
const ERR_SECRET = 'Please specify a directory name to upload to!'; | |
const ERR_NOT_UPLOADED = 'The file you are trying to submit is not a valid uploaded file!'; | |
const ERR_CREATE_DIR = 'Error creating: '; | |
const ERR_MOVE = 'An unexpected error occured while moving the file to destination!'; | |
const SUCCESS = 'File uploaded successfully!'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form enctype="multipart/form-data" action="" method="post" > | |
<input type="hidden" name="MAX_FILE_SIZE" value=" | |
<?php echo $size = return_bytes(ini_get('upload_max_filesize')); ?>" /> | |
<label for="id-secret">Secret dir. name: </label> | |
<input type="text" name="secret" id="id-secret" /><br /> | |
<label for="up">Your file(max <?php echo ($size/1024)/1024 ?> mB): </label> | |
<input type="file" id="up" name="file" /><br /> | |
<input type="submit" name="upload" value="Upload" /> | |
</form> | |
<?php | |
if($feedback['upload'] != NULL){ | |
echo '<h3>' , $feedback['upload'] , '</h3>'; | |
} | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<p> | |
<ul> | |
<?php | |
echo '<li> You are currently on: ' ,$_SERVER['SERVER_NAME'], '</li>' ,PHP_EOL, | |
'<li> Your IP:PORT: ' ,$_SERVER['REMOTE_ADDR'], '</li>' ,PHP_EOL, | |
'<li> Port on wich the connection was established: ' ,$_SERVER['REMOTE_PORT'], '</li>' ,PHP_EOL; | |
?> | |
</ul> | |
</p> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
paullik | 12345 | |
---|---|---|
ion | 4567 | |
adina | 8 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ion | 4567 | |
---|---|---|
adina | 8 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment