exit;
}
+function jirafeau_non_fatal_error($errorText)
+{
+ echo '<div class="error"><p>' . $errorText . '</p></div>';
+}
+
function jirafeau_clean_rm_link($link)
{
$p = s2p("$link");
$modifier = substr($value, -1);
$bytes = substr($value, 0, -1);
switch (strtoupper($modifier)) {
- case 'P':
- $bytes *= 1024;
- // no break
- case 'T':
- $bytes *= 1024;
- // no break
- case 'G':
- $bytes *= 1024;
- // no break
- case 'M':
- $bytes *= 1024;
- // no break
- case 'K':
- $bytes *= 1024;
+ default:
+ return intval($value);
+ break;
+ case 'P':
+ $bytes *= 1024;
+ // no break
+ case 'T':
+ $bytes *= 1024;
+ // no break
+ case 'G':
+ $bytes *= 1024;
+ // no break
+ case 'M':
+ $bytes *= 1024;
+ // no break
+ case 'K':
+ $bytes *= 1024;
}
return $bytes;
}
*/
function jirafeau_get_max_upload_chunk_size_bytes($max_upload_chunk_size_bytes = 0)
{
- if ($max_upload_chunk_size_bytes > 0) {
- return min(
- jirafeau_get_max_upload_size_bytes(),
- $max_upload_chunk_size_bytes
- );
+ if ($max_upload_chunk_size_bytes == 0) {
+ $size = jirafeau_get_max_upload_size_bytes();
+ // Jirafeau must choose an arbitrary number as PHP config does not give any limit nor $max_upload_chunk_size_bytes
+ if ($size == 0) {
+ return 10000000; // 10MB
+ }
+ return $size;
}
- return jirafeau_get_max_upload_size_bytes();
+ $size = min(
+ jirafeau_get_max_upload_size_bytes(),
+ $max_upload_chunk_size_bytes
+ );
+ if ($size == 0) {
+ return $max_upload_chunk_size_bytes;
+ }
+ return $size;
}
/**
function jirafeau_upload_errstr($code)
{
switch ($code) {
- case UPLOAD_ERR_INI_SIZE:
- case UPLOAD_ERR_FORM_SIZE:
- return t('Your file exceeds the maximum authorized file size. ');
+ case UPLOAD_ERR_INI_SIZE:
+ case UPLOAD_ERR_FORM_SIZE:
+ return t('Your file exceeds the maximum authorized file size. ');
- case UPLOAD_ERR_PARTIAL:
- case UPLOAD_ERR_NO_FILE:
- return
- t('Your file was not uploaded correctly. You may succeed in retrying. ');
+ case UPLOAD_ERR_PARTIAL:
+ case UPLOAD_ERR_NO_FILE:
+ return
+ t('Your file was not uploaded correctly. You may succeed in retrying. ');
- case UPLOAD_ERR_NO_TMP_DIR:
- case UPLOAD_ERR_CANT_WRITE:
- case UPLOAD_ERR_EXTENSION:
- return t('Internal error. You may not succeed in retrying. ');
+ case UPLOAD_ERR_NO_TMP_DIR:
+ case UPLOAD_ERR_CANT_WRITE:
+ case UPLOAD_ERR_EXTENSION:
+ return t('Internal error. You may not succeed in retrying. ');
}
return t('Unknown error. ');
}
function check_errors($cfg)
{
- if (file_exists(JIRAFEAU_ROOT . 'install.php')
- && !($cfg['installation_done'] === true)) {
- header('Location: install.php');
- exit;
+ if (!($cfg['installation_done'] === true)) {
+ if (file_exists(JIRAFEAU_ROOT . 'install.php')) {
+ header('Location: install.php');
+ exit;
+ } else {
+ add_error(t('INSTALL_FILE_NOT_FOUND_TITLE'), t('INSTALL_FILE_NOT_FOUND_DESC'));
+ }
}
- /* Checking for errors. */
if (!is_writable(VAR_FILES)) {
add_error(t('FILE_DIR_W'), VAR_FILES);
}
if ($cfg['one_time_download'] && $cfg['litespeed_workaround']) {
add_error(t('INCOMPATIBLE_OPTIONS_W'), 'one_time_download=true<br>litespeed_workaround=true');
}
+ if ($cfg['upload_ldap_auth'] === true) {
+ if (sizeof($cfg['upload_password']) > 0) {
+ add_error(t('INCOMPATIBLE_OPTIONS_W'), 'upload_ldap_auth=true<br>sizeof(upload_password) > 0');
+ }
+ if (sizeof($cfg['upload_ip_nopassword']) > 0) {
+ add_error(t('INCOMPATIBLE_OPTIONS_W'), 'upload_ldap_auth=true<br>sizeof(upload_ip_nopassword) > 0');
+ }
+ }
}
/**
$_SESSION['admin_csrf'] = md5(uniqid(mt_rand(), true));
}
-function jirafeau_admin_session_end()
+function jirafeau_session_end()
{
$_SESSION = array();
session_destroy();
return "<input type='hidden' name='admin_csrf' value='". $_SESSION['admin_csrf'] . "'/>";
}
+function jirafeau_user_session_start()
+{
+ $_SESSION['user_auth'] = true;
+}
+
+function jirafeau_user_session_logged()
+{
+ return isset($_SESSION['user_auth']) &&
+ $_SESSION['user_auth'] === true;
+}
+
function jirafeau_dir_size($dir)
{
$size = 0;
function jirafeau_default_web_root()
{
- return $_SERVER['HTTP_HOST'] . str_replace(basename(__FILE__), '', $_SERVER['REQUEST_URI']);
+ return $_SERVER['HTTP_HOST'] . str_replace('install.php', '', $_SERVER['REQUEST_URI']);
+}
+
+function jirafeau_has_ldap_auth($cfg)
+{
+ return $cfg['upload_ldap_auth'] === true;
+}
+
+function jirafeau_challenge_ldap_auth($cfg, $user, $password)
+{
+ if (!jirafeau_has_ldap_auth($cfg)) {
+ return "upload_ldap_auth not set";
+ }
+ if (strlen($cfg['upload_ldap_host']) == 0) {
+ return "upload_ldap_host not set";
+ }
+ if (strlen($cfg['upload_ldap_base_dn']) == 0) {
+ return "upload_ldap_base_dn not set";
+ }
+ $host = $cfg['upload_ldap_host'];
+ $base_dn = $cfg['upload_ldap_base_dn'];
+ $con = ldap_connect("ldap://$host");
+ $ldap_user = "cn=$user,$base_dn";
+ if (!$con) {
+ return "cannot initiate connection to ldap server";
+ }
+ ldap_set_option($con, LDAP_OPT_PROTOCOL_VERSION, 3);
+ ldap_set_option($con, LDAP_OPT_REFERRALS, 0);
+ $bind = ldap_bind_ext($con, $ldap_user, $password, [['oid' => LDAP_CONTROL_PASSWORDPOLICYREQUEST]]);
+ if (!$bind) {
+ ldap_close($con);
+ return "cannot bind to ldap server";
+ }
+ $parsing = ldap_parse_result($con, $bind, $errcode, $matcheddn, $errmsg, $referrals, $ctrls);
+ if (!$parsing) {
+ ldap_close($con);
+ return "cannot parlse ldap results";
+ }
+ if ($errcode == 49) {
+ ldap_close($con);
+ return "bad password";
+ }
+ if ($errcode != 0) {
+ ldap_close($con);
+ return "ldap auth error: $errmsg ($errcode)";
+ }
+ return true;
}