예제 #1
0
파일: module.php 프로젝트: Prescia/Prescia
 function get_base_sql($embedWhere = "", $embedOrder = "", $embedLimit = "", $noJoin = false)
 {
     // send $noJoin to get only THIS table, with no auto joining linked tables
     $sql = false;
     if (!$this->parent->debugmode && !$noJoin && is_file(CONS_PATH_CACHE . $_SESSION['CODE'] . "/" . $this->dbname . "_list.cache") && !isset($_REQUEST['nocache'])) {
         $sql = unserialize(cReadFile(CONS_PATH_CACHE . $_SESSION['CODE'] . "/" . $this->dbname . "_list.cache"));
     }
     if (!$sql) {
         $sql = array("SELECT" => array(), "FROM" => array(), "LEFT" => array(), "WHERE" => array(), "GROUP" => array(), "ORDER" => array(), "LIMIT" => array(), "HAVING" => array());
         $sql['FROM'][] = $this->dbname . " as " . $this->name;
         $pos = 0;
         foreach ($this->fields as $nome => $campo) {
             $extrakey = array();
             if ($campo[CONS_XML_TIPO] == CONS_TIPO_LINK && !$noJoin) {
                 // we will add all fields and build the where or left join for this table
                 $linkname = $campo[CONS_XML_MODULE];
                 // remote table name
                 $remodeModule = $this->parent->loaded($linkname);
                 // remote module
                 $tablecast = substr($nome, 3);
                 # id_[name] ... removes id_
                 if (in_array($tablecast, array("group", "from", "to", "as", "having", "order", "by", "join", "left", "right"))) {
                     #reserved words that could cause issues on the SQL
                     $tablecast .= "s";
                 }
                 # keyword, add a "s" to prevent it from causing SQL problems
                 foreach ($remodeModule->fields as $cremote_nome => $remote_campo) {
                     if ($cremote_nome == "password") {
                         continue;
                     }
                     // yeap, never select passwords
                     // for each field on remote table
                     if ($cremote_nome != $remodeModule->keys[0]) {
                         # do not add main key (this module should have it anyway)
                         $rmod_nome = $tablecast;
                         $sql['SELECT'][] = $tablecast . "." . $cremote_nome . " as " . $rmod_nome . "_" . $cremote_nome;
                     }
                     if ($remote_campo[CONS_XML_TIPO] == CONS_TIPO_LINK) {
                         if ($remote_campo[CONS_XML_MODULE] == $this->name && (!isset($remote_campo[CONS_XML_JOIN]) || $remote_campo[CONS_XML_JOIN] == "from")) {
                             # mandatory key to myself (parent)?
                             $extrakey[] = $tablecast . "." . $cremote_nome . "=" . $this->name . "." . $this->keys[0];
                         } else {
                             if (in_array($cremote_nome, $remodeModule->keys) && in_array($cremote_nome, $this->keys)) {
                                 // we are linking the same things oO
                                 $extrakey[] = $tablecast . "." . $cremote_nome . "=" . $this->name . "." . $cremote_nome;
                                 # TODO: is this necessary? who cares we have keys to the same things?
                             }
                         }
                     }
                 }
                 if (isset($campo[CONS_XML_JOIN]) && $campo[CONS_XML_JOIN] == "left") {
                     // left join
                     $linker = array();
                     foreach ($remodeModule->keys as $rkey) {
                         if ($rkey == "id") {
                             $linker[] = $tablecast . ".{$rkey} = " . $this->name . "." . $nome;
                         } else {
                             if ($remodeModule->fields[$rkey][CONS_XML_TIPO] == CONS_TIPO_LINK) {
                                 // not a parent nor main key, is a link to another table
                                 if ($remodeModule->fields[$rkey][CONS_XML_MODULE] == $this->name) {
                                     $linker[] = $tablecast . ".{$rkey} = " . $this->name . "." . $this->keys[0];
                                 } else {
                                     $localField = $this->get_key_from($remodeModule->fields[$rkey][CONS_XML_MODULE]);
                                     $linker[] = $tablecast . ".{$rkey} = " . $this->name . "." . $localField;
                                 }
                             } else {
                                 // not simple id, parent or link. Its a non-standard ID for another table
                                 $linker[] = $tablecast . ".{$rkey} = " . $this->name . "." . ($rkey == $remodeModule->keys[0] ? $nome : $nome . "_" . $rkey);
                                 // first key as is, rest is the original key name + "_" and remote key name
                             }
                         }
                     }
                     $sql['LEFT'][] = $remodeModule->dbname . " as " . $tablecast . " ON " . implode(" AND ", $linker) . (count($extrakey) > 0 && count($linker) > 0 ? " AND " : "") . implode(" AND ", $extrakey);
                 } else {
                     // inner join
                     $sql['FROM'][] = $remodeModule->dbname . " as " . $tablecast;
                     foreach ($remodeModule->keys as $rkey) {
                         if ($rkey == "id") {
                             $sql['WHERE'][] = $tablecast . ".{$rkey} = " . $this->name . "." . $nome;
                         } else {
                             if ($remodeModule->fields[$rkey][CONS_XML_TIPO] == CONS_TIPO_LINK) {
                                 // not a parent nor main key, is a link to another table
                                 if ($remodeModule->fields[$rkey][CONS_XML_MODULE] == $this->name) {
                                     $sql['WHERE'][] = $tablecast . ".{$rkey} = " . $this->name . "." . $this->keys[0];
                                 } else {
                                     $localField = $this->get_key_from($remodeModule->fields[$rkey][CONS_XML_MODULE]);
                                     $sql['WHERE'][] = $tablecast . ".{$rkey} = " . $this->name . "." . $localField;
                                 }
                             } else {
                                 // not simple id, parent or link. Its a non-standard ID for another table
                                 $sql['WHERE'][] = $tablecast . ".{$rkey} = " . $this->name . "." . ($rkey == $remodeModule->keys[0] ? $nome : $nome . "_" . $rkey);
                                 // first key as is, rest is the original key name + "_" and remote key name
                             }
                         }
                     }
                     foreach ($extrakey as $exk) {
                         $sql['WHERE'][] = $exk;
                     }
                 }
                 $pos++;
             }
         }
         array_unshift($sql['SELECT'], $this->name . ".*");
         if (!$noJoin && $this->parent->debugmode && !is_file(CONS_PATH_CACHE . $_SESSION['CODE'] . "/" . $this->dbname . "_list.cache") && !isset($_REQUEST['nocache'])) {
             // save simple cache
             cWriteFile(CONS_PATH_CACHE . $_SESSION['CODE'] . "/" . $this->dbname . "_list.cache", serialize($sql));
         }
     }
     # !$sql
     // embeds:
     if ($embedWhere != "") {
         array_unshift($sql['WHERE'], $embedWhere);
     }
     if ($this->order != "" && $embedOrder == "") {
         $ord = explode(",", $this->order);
         foreach ($ord as $orditem) {
             $orditem = trim($orditem);
             if (strpos($orditem, "+") !== false) {
                 $orditem = str_replace("+", "", $orditem);
                 if (isset($this->fields[$orditem])) {
                     $sql['ORDER'][] = $this->name . "." . $orditem . " ASC";
                 } else {
                     $sql['ORDER'][] = $orditem . " ASC";
                 }
             } else {
                 $orditem = str_replace("-", "", $orditem);
                 if (isset($this->fields[$orditem])) {
                     $sql['ORDER'][] = $this->name . "." . $orditem . " DESC";
                 } else {
                     $sql['ORDER'][] = $orditem . " DESC";
                 }
             }
         }
     }
     if ($embedOrder != "") {
         $sql['ORDER'][] = $embedOrder;
     }
     if ($embedLimit != "") {
         $sql['LIMIT'] = is_array($embedLimit) ? $embedLimit : array($embedLimit);
     }
     // done!
     return $sql;
 }
예제 #2
0
파일: module.php 프로젝트: Prescia/Prescia
 function importer()
 {
     $htmlIMG = $_REQUEST['imgpath'];
     $cssIMG = $_REQUEST['cssimgpath'];
     // improves/fix css, in and out
     $cssFiles = listFiles(CONS_PATH_PAGES . $_SESSION["CODE"] . "/files/", '/^.*\\.css$/i');
     foreach ($cssFiles as $cF) {
         $css = cReadFile(CONS_PATH_PAGES . $_SESSION["CODE"] . "/files/" . $cF);
         $css = str_replace($cssIMG, "", $css);
         $css = str_replace("    ", "\t", $css);
         cWriteFile(CONS_PATH_PAGES . $_SESSION["CODE"] . "/files/" . $cF, $css);
     }
     // improves/fix html, in
     $htmlFiles = listFiles(CONS_PATH_PAGES . $_SESSION["CODE"] . "/template/", '/^([^_]).*\\.html$/i');
     $htmlSTR = array();
     $cut = array();
     foreach ($htmlFiles as $hF) {
         $htmlSTR[$hF] = cReadFile(CONS_PATH_PAGES . $_SESSION["CODE"] . "/template/" . $hF);
         $htmlSTR[$hF] = str_replace($htmlIMG, "{IMG_PATH}", $htmlSTR[$hF]);
         $htmlSTR[$hF] = str_replace("    ", "\t", $htmlSTR[$hF]);
         $bodyPos = strpos($htmlSTR[$hF], "<body>");
         if ($bodyPos !== false) {
             $htmlSTR[$hF] = substr($htmlSTR[$hF], $bodyPos + 6);
             $htmlSTR[$hF] = str_replace("</body>", "", $htmlSTR[$hF]);
         } else {
             $bodyPos = strpos($htmlSTR[$hF], "<body");
             if ($bodyPos !== false && $bodyPos != 0) {
                 $htmlSTR[$hF] = substr($htmlSTR[$hF], $bodyPos - 1);
             }
         }
         $htmlSTR[$hF] = str_replace("</html>", "", $htmlSTR[$hF]);
         cWriteFile(CONS_PATH_PAGES . $_SESSION["CODE"] . "/template/" . $hF . ".out", $htmlSTR[$hF]);
     }
     // locate patterns within the files, using index.html
     //{CORE_DEBUG} {FRAME_CONTENT}
     echo "css replaced, html outputed as .out, frame breaking not implemented";
     #TODO:
     die;
 }
예제 #3
0
파일: edit.php 프로젝트: Prescia/Prescia
         if (!makeDirs($destination)) {
             $ok = 9;
             $core->errorControl->raise(804, $core->langOut("mpu_error_mkdir"));
         }
     }
 }
 if ($ok == 0) {
     // no error in preparing /mpu
     $zHn = zip_open($zipFile);
     if (is_resource($zHn)) {
         $core->errorControl->raise('300', "Unzipping file...");
         $hadFolders = false;
         while ($zHn_file = zip_read($zHn)) {
             $zip_name = zip_entry_name($zHn_file);
             if (strpos($zip_name, '.') !== false) {
                 cWriteFile($destination . $zip_name, zip_entry_read($zHn_file, zip_entry_filesize($zHn_file)), false, true);
             } else {
                 $hadFolders = true;
             }
         }
         // unzip complete
         @unlink($zipFile);
         // process files
         $listFiles = listFiles($destination, '/^.*$/');
         $core->errorControl->raise('300', "Files to unzip: " . count($listFiles));
         if ($hadFolders) {
             $core->log[] = $core->langOut('mup_hadfolders');
         }
         if (count($listFiles) > CONS_MAX_MUP) {
             $core->log[] = str_replace("#", CONS_MAX_MUP, $core->langOut("mup_toomany"));
         }
예제 #4
0
파일: core.php 프로젝트: Prescia/Prescia
 function saveConfig($NO_RAISE = false)
 {
     #saves the dimconfig and/or the statsConfig
     unset($this->dimconfig['_forced']);
     $this->dimconfig['_debugmode'] = CONS_DEVELOPER || $this->debugmode ? 1 : 0;
     if (isset($this->loadedPlugins['bi_dev'])) {
         $this->dimconfig['_debugmode']++;
     }
     if (count($this->dimconfig) == 0 || !isset($this->dimconfig['adminmail'])) {
         if (!$NO_RAISE) {
             $this->errorControl->raise(164, 'dimconfig');
         }
         return;
     }
     $oFile = CONS_PATH_DINCONFIG . $_SESSION['CODE'] . "/din.dat";
     if (!cWriteFile($oFile, serialize($this->dimconfig))) {
         sleep(1);
         if (!cWriteFile($oFile, serialize($this->dimconfig))) {
             if (!$NO_RAISE) {
                 $this->errorControl->raise(165, 'dimconfig');
             }
         }
     } else {
         $_SESSION[CONS_SESSION_CONFIG] = array($this->dimconfig, date("i"));
         // lasts tops 1 min
         $this->dimconfig['_forced'] = true;
     }
 }
예제 #5
0
    // add new hit
    $thd['hits'][] = $now;
    if (isset($_POST['login'])) {
        $thd['hits'][] = $now;
    }
    // ya, we count twice the fault if you are trying to login
    if (count($thd['hits']) >= CONS_BOTPROTECT_MAXHITS) {
        // sorry guy, you are banned
        $_SESSION['BOTPROTECT_BANNED'] = $now;
        $thd['banned'] = $now;
        $banned = true;
        // prescia log
        $this->errorControl->raise(171, CONS_IP . " made " . count($thd['hits']) . " in 60 seconds", "IP BANNED");
    } else {
        if (count($thd['hits']) > CONS_BOTPROTECT_MAXHITS / 2) {
            // throttle requests (guy going too fast)
            sleep(1);
        }
    }
    // save throttle
    cWriteFile($filename, serialize($thd));
    if ($banned) {
        header($_SERVER["SERVER_PROTOCOL"] . " 403 Forbidden");
        echo str_replace("{MORE}", CONS_BOTPROTECT_BANTIME * 60, str_replace("{TS}", $now, $throttle));
        die;
    }
    unset($banned);
    unset($thd);
    unset($now);
    unset($throttle);
}
예제 #6
0
 function logCacheThrottle()
 {
     // saves a log of the last hour of cachecontrol in the log folder, it can be accessed or viewed by the console. This is not used other than logging
     if (!isset($this->parent->storage['CORE_CACHECONTROL'])) {
         $this->startCaches();
     }
     $average = $this->parent->storage['CORE_CACHECONTROL'][0];
     $cmod = $this->parent->storage['CORE_CACHECONTROL'][1];
     $cc = array();
     if (is_file(CONS_PATH_LOGS . "cachecontrol.dat")) {
         $cc = unserialize(cReadFile(CONS_PATH_LOGS . "cachecontrol.dat"));
         if (!is_array($cc)) {
             $cc = array();
         }
     }
     $thisEntry = array(date("Y-m-d H:i:s"), $average, $cmod);
     $cc[] = $thisEntry;
     // cleanup to show only the whole last week (24*7=168)
     while (count($cc) > 168) {
         array_shift($cc);
     }
     cWriteFile(CONS_PATH_LOGS . "cachecontrol.dat", serialize($cc));
 }
예제 #7
0
파일: cron.php 프로젝트: Prescia/Prescia
     // if botprotect, reset bans
     if (CONS_BOTPROTECT) {
         foreach (glob(CONS_PATH_TEMP . "*.dat") as $file) {
             if (!is_dir($file)) {
                 @unlink($file);
             }
         }
     }
 }
 // reset 404 caches
 $core->dimconfig['_404cache'] = array();
 // backup main files
 $this->loadDimconfig(true);
 if ($this->dimconfig !== false) {
     $oFile = CONS_PATH_DINCONFIG . $_SESSION['CODE'] . "/din.bck";
     cWriteFile($oFile, serialize($this->dimconfig), false, true);
 }
 # delete performance log (it should only keep latest files anyway)
 if (is_file(CONS_PATH_LOGS . $_SESSION['CODE'] . "/pm.log")) {
     @unlink(CONS_PATH_LOGS . $_SESSION['CODE'] . "/pm.log");
 }
 # Check absurd amount of errors?
 if (CONS_HTTPD_ERRFILE != '') {
     $httpderrlog = str_replace("{Y}", date("Y"), CONS_HTTPD_ERRFILE);
     $httpderrlog = str_replace("{m}", date("m"), $httpderrlog);
     $httpderrlog = str_replace("{d}", date("d"), $httpderrlog);
     if (is_file(CONS_HTTPD_ERRDIR . $httpderrlog) && filesize(CONS_HTTPD_ERRDIR . $httpderrlog) > 1048576) {
         # php log has more than 1Mb, come on!
         $this->raise(604, "size=" . filesize(CONS_HTTPD_ERRDIR . $httpderrlog), "PHP error log too big");
     }
 } else {
예제 #8
0
-*/
$domains = cReadFile(CONS_PATH_SETTINGS . "domains");
if (!$domains) {
    $this->errorControl->raise(100);
}
$domains = explode("\n", str_replace("\r", "", preg_replace("/(\t| ){1,}/", " ", $domains)));
$domainList = array();
$gotdomain = false;
foreach ($domains as $dline) {
    if (strlen($dline) > 0 && $dline[0] != "#") {
        $dline = explode(" ", $dline);
        if (count($dline) == 2) {
            $thisdomains = explode(",", $dline[1]);
            foreach ($thisdomains as $td) {
                $td = trim($td);
                if ($td != "") {
                    $domainList[$td] = $dline[0];
                    if (!$gotdomain && ($td == $this->domain || $td == "*")) {
                        $_SESSION["CODE"] = $dline[0];
                        $gotdomain = true;
                    }
                }
            }
        }
    }
}
if (!is_dir(CONS_PATH_CACHE)) {
    makeDirs(CONS_PATH_CACHE);
}
cWriteFile(CONS_PATH_CACHE . "domains.dat", serialize($domainList));
return $domainList;
예제 #9
0
 function loadLangFile($file, $standard = true, $plugin = '')
 {
     # loads a templating language file to the template, checks if cache is present
     # called by /index.php
     $file .= ".php";
     $strippedFile = str_replace("/", "_", $file);
     if ($standard) {
         if ($plugin == "") {
             $file = CONS_PATH_SETTINGS . "locale/" . $file;
         } else {
             $file = CONS_PATH_SYSTEM . "plugins/{$plugin}/locale/{$file}";
         }
     } else {
         $file = CONS_PATH_PAGES . $_SESSION['CODE'] . "/_config/locale/{$file}";
     }
     if (!is_file($file)) {
         return false;
     }
     if (!isset($_REQUEST['nocache'])) {
         # if nocache is specified, ignore caches ... not the case
         if ($standard) {
             if ($plugin != '') {
                 $plugin .= '/';
             }
             if (!is_dir(CONS_PATH_CACHE . "locale/{$plugin}")) {
                 safe_mkdir(CONS_PATH_CACHE . "locale/{$plugin}");
             }
             $cacheFile = CONS_PATH_CACHE . "locale/{$plugin}" . $strippedFile . ".cache";
             $cacheMTFile = CONS_PATH_CACHE . "locale/{$plugin}" . $strippedFile . ".cachemd";
         } else {
             if (!is_dir(CONS_PATH_CACHE . $_SESSION['CODE'] . "/meta/locale/")) {
                 safe_mkdir(CONS_PATH_CACHE . $_SESSION['CODE'] . "/meta/locale/");
             }
             $cacheFile = CONS_PATH_CACHE . $_SESSION['CODE'] . "/meta/locale/" . $strippedFile . ".cache";
             $cacheMTFile = CONS_PATH_CACHE . $_SESSION['CODE'] . "/meta/locale/" . $strippedFile . ".cachemd";
         }
         if (is_file($cacheFile) && is_file($cacheMTFile)) {
             $ofMD = filemtime($file);
             # modify date of ORIGINAL file
             $cMD = cReadFile($cacheMTFile);
             # modify date of ORIGINAL file when CACHE file was created
             if ($cMD == $ofMD) {
                 # valid cache file (it was created from the current original file)
                 $newData = @unserialize(cReadFile($cacheFile));
                 if (is_array($newData)) {
                     $this->parent->template->lang_replacer = array_merge($this->parent->template->lang_replacer, $newData);
                     return true;
                 } else {
                     $this->parent->errorControl->raise(6, $_SESSION[CONS_SESSION_LANG], $plugin, $standard ? "standard" : "non-standard");
                 }
             } else {
                 if ($this->parent->debugmode && CONS_CACHE) {
                     # Warning: if the lang file was replaced, template caches might be invalid
                     # So we must delete ALL TEMPLATE CACHES!
                     $this->parent->cacheControl->dumpTemplateCaches();
                 }
             }
         }
     }
     # no cache available or no cache specified
     $data = (include $file);
     if ($data === false || !is_array($data)) {
         $this->parent->errorControl->raise(7, $_SESSION[CONS_SESSION_LANG], $plugin, $standard ? "standard" : "non-standard");
         return false;
     }
     if (!isset($_REQUEST['nocache'])) {
         $ofMD = filemtime($file);
         cWriteFile($cacheMTFile, $ofMD);
         cWriteFile($cacheFile, serialize($data));
     }
     foreach ($data as $term => $trans) {
         $this->parent->template->lang_replacer[$term] = $trans;
         // array_merge has issues
     }
     return true;
 }
예제 #10
0
파일: module.php 프로젝트: Prescia/Prescia
 function resetSTdata($data)
 {
     // fulls hit data on scripttime
     /* data stored:
     		   0 = Hour of latest stats
     		   1 = Max time (in this hour) w/o cache
     		   2 = Max time (in this hour) w/ cache
     		   3 = Bot hits TODAY (or yesterday if no hit so far)
     		   4 = Normal hits TODAY
     		   5 = Last week data (array with 4 hit counter)
     		   6 = Browser data for last MONTH (array with all browsers)
     		*/
     $file = CONS_PATH_LOGS . $_SESSION['CODE'] . "/scripttime.dat";
     $sb = $this->parent->loaded('statsbots');
     $data[3] = $this->parent->dbo->fetch("SELECT hits FROM " . $sb->dbname . " WHERE data='" . date("Y-m-d") . "'");
     if ($data[3] === false) {
         $data[3] = 0;
     }
     // bots
     $data[4] = $this->getHits(1);
     if (count($data[4]) == 0) {
         $data[4] = 0;
     } else {
         $data[4] = $data[4][0][0];
     }
     $data[5] = $this->getHits(7);
     if (count($data[5]) == 0) {
         $data[5] = array(0, 0, 0, 0);
     }
     // sums
     // 6 is browser stats on last week
     $data[6] = array();
     // browser
     $sb = $this->parent->loaded('statsbrowser');
     $this->parent->dbo->query("SELECT sum(hits), browser FROM " . $sb->dbname . " WHERE data>NOW() - INTERVAL 1 MONTH GROUP BY browser", $r, $n);
     for ($c = 0; $c < $n; $c++) {
         list($count, $browser) = $this->parent->dbo->fetch_row($r);
         $data[6][$browser] = $count;
     }
     cWriteFile($file, serialize($data));
     if ($data[3] > $data[4] * 3 && $data[4] > 0 && $data[3] > $data[5][0]) {
         $this->parent->errorControl->raise(525, $data[3], 'bi_stats');
     }
 }
예제 #11
0
파일: module.php 프로젝트: Prescia/Prescia
 function buildAdminMenu()
 {
     // this function builds the Ttree object for the menu, but does not handle the HTML. The menu stays in the private var $this->menudata
     if (!isset($_SESSION[CONS_SESSION_ACCESS_USER]['id_group'])) {
         return;
     }
     $file = CONS_PATH_CACHE . $_SESSION['CODE'] . "/admin" . $_SESSION[CONS_SESSION_ACCESS_USER]['id_group'] . ".cache";
     // HTML output with normal menu
     if (!is_file($file) || $this->parent->debugmode || isset($_REQUEST['nocache'])) {
         if (is_file($file)) {
             unlink($file);
         }
         if (!is_file(CONS_PATH_PAGES . $_SESSION['CODE'] . "/_config/admin.xml")) {
             $this->parent->errorControl->raise(517, "buildAdminMenu", "admin");
         }
         if (!defined('C_XHTML_AUTOTAB')) {
             include CONS_PATH_INCLUDE . "xmlHandler.php";
         }
         $xml = new xmlHandler();
         $menuXML = $xml->cReadXML(CONS_PATH_PAGES . $_SESSION['CODE'] . "/_config/admin.xml", array('C_XML_autoparse' => true, 'C_XML_lax' => true), false);
         $menu = array();
         $this->parent->lockPermissions();
         // guarantee permissions are loaded
         $this->addMenuItens($menuXML->getbranch(0), $menu, 0, $this->parent);
         if (!function_exists("mysort")) {
             function mysort($a, $b)
             {
                 if ($a['id_parent'] == $b['id_parent']) {
                     return $a['id'] <= $b['id'] ? -1 : 1;
                     // itens on the same level sorted by id
                 } else {
                     return $a['id_parent'] <= $b['id_parent'] ? -1 : 1;
                 }
                 // menus sorted by ID
             }
         }
         usort($menu, 'mysort');
         $this->menudata = new TTree();
         $this->menudata->arrayToTree($menu, '\\', 'id_parent', 'title');
         // save caches
         cWriteFile($file, serialize($this->menudata));
         // <- ttree object
     } else {
         @($this->menudata = unserialize(cReadFile($file)));
         if ($this->menudata === false || !is_object($this->menudata)) {
             $this->parent->log[] = "Error loading admin menu";
             $this->parent->setLog(CONS_LOGGING_ERROR);
         }
     }
 }
예제 #12
0
function resizeImage($original, $miniatura, $desiredW = 100, $desiredH = 100, $quality = 0, $watermarkArray = array(), $bgcolor = "FFFFFF", $forceJPG = false)
{
    $thumbext = explode(".", $miniatura);
    $thumbext = array_pop($thumbext);
    if ($thumbext == 'jpg' || $thumbext == 'png' || $thumbext == 'gif' || $thumbext == 'bmp') {
        // removes extension
        $miniatura = explode(".", $miniatura);
        array_pop($minuatura);
        $miniatura = implode(".", $miniatura);
    }
    // miniatura have no extension from here on
    if ($quality == 0) {
        $quality = CONS_JPGQUALITY;
    }
    $acceptable = false;
    $ih = @getimagesize($original);
    if ($ih) {
        $acceptable = $ih[2] == IMAGETYPE_BMP || $ih[2] == IMAGETYPE_JPEG || $ih[2] == IMAGETYPE_PNG || $ih[2] == IMAGETYPE_GIF;
        if (!$acceptable) {
            return false;
            // unknown format, abort
        }
        $cropMe = count($watermarkArray) > 0 && !is_array($watermarkArray[0]) && $watermarkArray[0][0] == "C";
        $oW = $ih[0];
        # original
        $oH = $ih[1];
        $tW = $oW;
        # thumb
        $tH = $oH;
        if ($desiredW > 0) {
            // limits width
            if ($tW > $desiredW) {
                # reduces proportionally to fit
                $tW = $desiredW;
                $tH = floor($oH / $oW * $tW);
            }
        }
        if ($desiredH > 0) {
            // limits height (if by width was not enough)
            if ($tH > $desiredH) {
                # reduces further proportionally
                $tH = $desiredH;
                $tW = floor($oW / $oH * $tH);
            }
        }
        $willCrop = false;
        # at this point, the image has been reduced to fit inside desired dimensions, but it ignored CropMe
        if ($cropMe) {
            if ($tW < $desiredW) {
                # enlarges proportionally to MATCH
                $tW = $desiredW;
                $tH = floor($oH / $oW * $tW);
                $willCrop = true;
            }
            if ($tH < $desiredH) {
                # enlarges further proportionally to MATCH
                $tH = $desiredH;
                $tW = floor($oW / $oH * $tH);
                $willCrop = true;
            }
            # at this point, the image is probably larger than the container, so the offset system will cut it
        }
        # else the image is smaller or equal to container
    } else {
        return false;
        // unable to open as image with GD
    }
    if ($ih[2] == IMAGETYPE_PNG) {
        // png
        $miniatura_id = imagecreatefrompng($original);
    } else {
        if ($ih[2] == IMAGETYPE_GIF) {
            // gif
            $miniatura_id = imagecreatefromgif($original);
        } else {
            if ($ih[2] == IMAGETYPE_BMP) {
                // bmp
                $miniatura_id = imagecreatefromwbmp($original);
            } else {
                // jpg
                $miniatura_id = imagecreatefromjpeg($original);
            }
        }
    }
    if ($willCrop) {
        # needs to crop a part of the image, regardless if the image will be reduced or enlarged
        $reductionFactor = $oW / $tW;
        if (strpos($watermarkArray[0], 'left') !== false) {
            $offset_x = 0;
        } else {
            if (strpos($watermarkArray[0], 'right') !== false) {
                $offset_x = $tW > $desiredW ? $oW - $reductionFactor * $desiredW : 0;
            } else {
                $offset_x = $tW > $desiredW ? floor($oW / 2) - floor($reductionFactor * $desiredW / 2) : 0;
            }
        }
        if (strpos($watermarkArray[0], 'top') !== false) {
            $offset_y = 0;
        } else {
            if (strpos($watermarkArray[0], 'bottom') !== false) {
                $offset_y = $tH > $desiredH ? $oH - $reductionFactor * $desiredH : 0;
            } else {
                $offset_y = $tH > $desiredH ? floor($oH / 2) - floor($reductionFactor * $desiredH / 2) : 0;
            }
        }
        $im_dest = imagecreatetruecolor($desiredW, $desiredH);
        array_shift($watermarkArray);
        // consumes the crop
    } else {
        # either crop don't neet to cut a part of the image, or crop not applied
        $offset_x = 0;
        $offset_y = 0;
        $im_dest = imagecreatetruecolor($tW, $tH);
        if ($cropMe) {
            array_shift($watermarkArray);
        }
        // consumes the crop
    }
    /*
    	    echo "Original: $oW x $oH <br/>";
    	    echo "Desired: $desiredW x $desiredH ".($cropMe?"CROP":"normal")."<br/>";
    	    echo "Output: $tW x $tH offset $offset_x x $offset_y <br/>";
    	    //*/
    if ($ih[2] != IMAGETYPE_PNG || $forceJPG) {
        $Hbgcolor = imagecolorallocate($im_dest, hexdec(substr($bgcolor, 0, 2)), hexdec(substr($bgcolor, 2, 2)), hexdec(substr($bgcolor, 4, 2)));
        // forces a white bg on thumbs
        imagefilledrectangle($im_dest, 0, 0, $tW, $tH, $Hbgcolor);
    } else {
        //imagecolortransparent($im_dest, imagecolorallocatealpha($im_dest, 0, 0, 0, 127)); // <-- if it where a .gif
        imagealphablending($im_dest, false);
        imagesavealpha($im_dest, true);
    }
    imagecopyresampled($im_dest, $miniatura_id, 0, 0, $offset_x, $offset_y, $tW, $tH, $oW, $oH);
    imagedestroy($miniatura_id);
    $miniatura_id = $im_dest;
    if ($cropMe) {
        array_shift($watermarkArray);
    }
    if ($miniatura_id != "") {
        // might fail on reduction
        if ($ih[2] == IMAGETYPE_PNG) {
            // managed to create a png thumbnail
            $miniatura .= ".png";
            @imagepng($miniatura_id, $miniatura);
            if (!is_file($miniatura)) {
                // unknown error while creating temporary PNG
                return false;
            }
            @imagedestroy($miniatura_id);
            if (count($watermarkArray) > 0) {
                $ok = watermark($miniatura, $watermarkArray, $miniatura, $quality, $bgcolor, false);
            } else {
                $ok = true;
            }
        } else {
            // jpg
            $miniatura .= ".jpg";
            imagejpeg($miniatura_id, $miniatura, $quality);
            if (!is_file($miniatura)) {
                // unknown error while creating thumb, try lame style (note: if $quality is not a number, weird things WILL happen)
                ob_start();
                imagejpeg($miniatura_id, NULL, $quality);
                $i = ob_get_clean();
                if (!cWriteFile($miniatura, $i) || filesize($miniatura) == 0) {
                    // no way to save the file ... bummer
                    @unlink($miniatura);
                    return false;
                }
            }
            @imagedestroy($miniatura_id);
            if (count($watermarkArray) > 0) {
                $ok = watermark($miniatura, $watermarkArray, $miniatura, $quality, $bgcolor, true);
            } else {
                $ok = true;
            }
        }
        if ($ok) {
            $temp = umask(0);
            chmod($miniatura, 0775);
            umask($temp);
        }
        return $ok;
    } else {
        @imagedestroy($miniatura_id);
        @imagedestroy($im_dest);
        return false;
    }
}
예제 #13
0
<?php

$admmural = $_POST['admmural'];
cWriteFile(CONS_PATH_DINCONFIG . $_SESSION['CODE'] . "/mural.txt", $admmural);
$core->close();
예제 #14
0
파일: console.php 프로젝트: Prescia/Prescia
function console($core, $command)
{
    if (defined('CONS_AUTH_USERMODULE') && $_SESSION[CONS_SESSION_ACCESS_LEVEL] < 100) {
        echo 'access denied';
        $core->close();
    }
    $words = explode(" ", trim($command));
    if ($words[0] == "help" || $words[0] == "?") {
        echo "clear - clears the console screen<br/>";
        // implemented on the HTML/js
        echo "delete [key] - deletes a key off dimconfig<br/>";
        echo "dev [on|off] - enable/disable developer assistent plugin (affbi_dev)<br/>";
        echo "test - returns a bi_dev fulltest<br/>";
        echo "dump [dimconfig|session|constants|config] - displays the contents of the dimconfig, session or constant variables<br/>";
        //echo "compileaff - compiles aff distribution into new/ folder<br/>";
        echo "dbfill - adds up to 10 random items on EVERY database of the site<br/>";
        echo "set [variable] [value] - sets a dimconfig variable<br/>";
        echo "cache - displays the full cacheThrottle log, as well current values<br/>";
        echo "purge [log|cache|bans|all] - purches all server-side log, cache, ip bans or all these options<br/>";
        echo "ip - Shows local/server IP's";
        $core->close();
    }
    if ($words[0] == "set" && isset($words[1]) && isset($words[2])) {
        $core->dimconfig[$words[1]] = $words[2];
        echo $words[1] . " set to '" . $words[2] . "'";
        $core->saveConfig(true);
        $core->close();
    }
    if ($words[0] == "ip") {
        echo "SERVER IP: " . GetIP(false) . "<br/>";
        echo "ON SERVER: " . (CONS_ONSERVER ? "true" : "false") . "<br/>";
        echo "REMOTE IP: " . CONS_IP;
        $core->close();
    }
    if ($words[0] == "delete") {
        if (isset($core->dimconfig[$words[1]])) {
            unset($core->dimconfig[$words[1]]);
            $core->saveConfig(true);
            echo "dimconfig keyword deleted";
        } else {
            echo "dimconfig keyword not found";
        }
        $core->close();
    }
    if ($words[0] == "dev") {
        if ($words[1] == "on" || $words[1] == '1') {
            if (isset($core->loadedPlugins['bi_dev'])) {
                echo "dev already on";
                $core->close();
            } else {
                $filenm = CONS_PATH_PAGES . $_SESSION['CODE'] . "/_config/config.php";
                $file = cReadFile($filenm);
                cWriteFile($filenm . ".bak", $file);
                $file .= "\n\$dev = \$this->addPlugin('bi_dev');\n\$dev->administrativePage = \"/adm/\";";
                cWriteFile($filenm, $file);
                echo "dev added to config.php";
                $core->close();
            }
        } else {
            if (!isset($core->loadedPlugins['bi_dev'])) {
                echo "dev already off";
                $core->close();
            } else {
                $filenm = CONS_PATH_PAGES . $_SESSION['CODE'] . "/_config/config.php";
                $file = cReadFile($filenm);
                cWriteFile($filenm . ".bak", $file);
                $file = str_replace("\$dev = \$this->addPlugin('bi_dev');", "", $file);
                $file = str_replace("\$dev->administrativePage = \"/adm/\";", "", $file);
                cWriteFile($filenm, $file);
                echo "dev removed from config.php";
                $core->close();
            }
        }
    }
    if ($words[0] == "test") {
        if (isset($core->loadedPlugins['bi_dev'])) {
            $ok = $core->loadedPlugins['bi_dev']->fulltest(true);
            echo "DEV-Fulltest: " . ($ok ? "ERRORS!" : "OK!");
        } else {
            echo "dev is off";
        }
        $core->close();
    }
    if ($words[0] == "dump") {
        $out = "";
        if ($words[1] == "dimconfig") {
            foreach ($core->dimconfig as $name => $content) {
                $out .= $name . " : " . vardump($content) . "<br/>";
            }
            echo $out;
            $core->close();
        } else {
            if ($words[1] == "session") {
                foreach ($_SESSION as $name => $content) {
                    $out .= $name . " : " . (is_array($content) ? implode(", ", $content) : $content) . "<br/>";
                }
                echo $out;
                $core->close();
            } else {
                if ($words[1] == "constants") {
                    foreach ($core->template->constants as $name => $content) {
                        $out .= $name . " : " . (is_array($content) ? implode(", ", $content) : $content) . "<br/>";
                    }
                    echo $out;
                    $core->close();
                } else {
                    if ($words[1] == "config") {
                        echo "CONS_AFF_DATABASECONNECTOR: " . CONS_AFF_DATABASECONNECTOR . "<br/>";
                        echo "CONS_AFF_ERRORHANDLER: " . (CONS_AFF_ERRORHANDLER ? "true" : "false") . "<br/>";
                        echo "CONS_AFF_ERRORHANDLER_NOWARNING: " . (CONS_AFF_ERRORHANDLER_NOWARNING ? "true" : "false") . "<br/>";
                        echo "CONS_AJAXRUNSSCRIPTS: " . (CONS_AJAXRUNSSCRIPTS ? "true" : "false") . "<br/>";
                        echo "CONS_SINGLEDOMAIN: " . CONS_SINGLEDOMAIN . "<br/>";
                        echo "CONS_DEFAULT_IPP: " . CONS_DEFAULT_IPP . "<br/>";
                        echo "CONS_FLATTENURL: " . CONS_FLATTENURL . "<br/>";
                        echo "CONS_AUTOREMOVEWWW: " . CONS_AUTOREMOVEWWW . "<br/>";
                        echo "CONS_DEFAULT_MIN_OBJECTCACHETIME: " . CONS_DEFAULT_MIN_OBJECTCACHETIME . "<br/>";
                        echo "CONS_DEFAULT_MAX_OBJECTCACHETIME: " . CONS_DEFAULT_MAX_OBJECTCACHETIME . "<br/>";
                        echo "CONS_DEFAULT_MIN_BROWSERCACHETIME: " . CONS_DEFAULT_MIN_BROWSERCACHETIME . "<br/>";
                        echo "CONS_DEFAULT_MAX_BROWSERCACHETIME: " . CONS_DEFAULT_MAX_BROWSERCACHETIME . "<br/>";
                        echo "CONS_PM_MINTIME: " . CONS_PM_MINTIME . "<br/>";
                        echo "CONS_PM_TIME: " . CONS_PM_TIME . "<br/>";
                        echo "CONS_FREECPU: " . (CONS_FREECPU ? "true" : "false") . "<br/>";
                        echo "CONS_MONITORMAILSOURCE: " . CONS_MONITORMAILSOURCE . "<br/>";
                        echo "CONS_MONITORMAIL: " . CONS_MONITORMAIL . "<br/>";
                        echo "CONS_HTTPD_ERRDIR: " . CONS_HTTPD_ERRDIR . "<br/>";
                        echo "CONS_HTTPD_ERRFILE: " . CONS_HTTPD_ERRFILE . "<br/>";
                        echo "CONS_MASTERMAIL: " . CONS_MASTERMAIL . "<br/>";
                        echo "CONS_ECONOMICMODE: " . (CONS_ECONOMICMODE ? 'true' : 'false') . "<br/>";
                        echo "CONS_ACCEPT_DIRECTLINK: " . (CONS_ACCEPT_DIRECTLINK ? "true" : "false") . "<br/>";
                        echo "CONS_SITESELECTOR: " . (CONS_SITESELECTOR ? "true" : "false") . "<br/>";
                        echo "CONS_NOROBOTDOMAINS: " . CONS_NOROBOTDOMAINS . "<br/>";
                        echo "CONS_FILESEARCH_EXTENSIONS: " . CONS_FILESEARCH_EXTENSIONS . "<br/>";
                        echo "CONS_TOOLS_DEFAULTPERM: " . CONS_TOOLS_DEFAULTPERM . "<br/>";
                        echo "CONS_GZIP_MINSIZE: " . CONS_GZIP_MINSIZE . "<br/>";
                        echo "CONS_CRAWLER_WHITELIST_ENABLE: " . (CONS_CRAWLER_WHITELIST_ENABLE ? "true" : "false") . "<br/>";
                        echo "CONS_CRAWLER_WHITELIST: " . CONS_GZIP_MINSIZE . "<br/>";
                        echo "CONS_HONEYPOT: " . (CONS_HONEYPOT ? "true" : "false") . "<br/>";
                        echo "CONS_HONEYPOTURL: " . CONS_GZIP_MINSIZE . "<br/>";
                        echo "------ site config (" . $_SESSION['CODE'] . ") ------<br/>";
                        echo "CONS_USE_I18N: " . (CONS_USE_I18N ? "true" : "false") . "<br/>";
                        echo "CONS_DEFAULT_LANG: " . CONS_DEFAULT_LANG . "<br/>";
                        echo "CONS_DEFAULT_FAVICON: " . (CONS_DEFAULT_FAVICON ? "true" : "false") . "<br/>";
                        echo "CONS_INSTALL_ROOT: " . CONS_INSTALL_ROOT . "<br/>";
                        echo "CONS_DB_HOST: " . CONS_DB_HOST . "<br/>";
                        echo "CONS_DB_BASE: " . CONS_DB_BASE . "<br/>";
                        echo "CONS_SITE_ENTRYPOINT: " . CONS_SITE_ENTRYPOINT . "<br/>";
                        echo "languagetl: " . vardump($core->languageTL) . "<br/>";
                        echo "forceLang: " . $core->forceLang . "<br/>";
                        echo "------ modules loaded ----------<br/>";
                        foreach ($core->modules as $mname => &$m) {
                            echo "{$mname}<br/>";
                        }
                        $core->close();
                    }
                }
            }
        }
        echo "add 'dimconfig', 'session', 'constants', 'config'<br/>";
    }
    if ($words[0] == "dbfill") {
        if (isset($core->loadedPlugins['bi_dev'])) {
            $ok = $core->loadedPlugins['bi_dev']->fill();
            echo "DEV-Fill: " . ($ok == false ? "ERROR!" : "Ok, {$ok} items included");
        } else {
            echo "dev is off, turn dev on to use dbfill";
        }
        $core->close();
    }
    if ($words[0] == 'cache') {
        if (CONS_ECONOMICMODE) {
            echo "Economic mode on, cache control disabled";
        } else {
            if (is_file(CONS_PATH_LOGS . "cachecontrol.dat")) {
                $cc = unserialize(cReadFile(CONS_PATH_LOGS . "cachecontrol.dat"));
                if ($cc !== false) {
                    echo "Date, Page average loadtime, Cache throttle %\n<br/>";
                    foreach ($cc as $ccitem) {
                        echo $ccitem[0] . ", " . number_format($ccitem[1]) . "ms, " . floor(100 * $ccitem[2]) . "%\n<br/>";
                    }
                    $cc = unserialize(cReadFile(CONS_PATH_CACHE . "cachecontrol.dat"));
                    if ($cc !== false) {
                        echo "CURRENT: " . number_format($cc[0]) . "ms, " . floor(100 * $cc[1]) . "%";
                    } else {
                        echo "CURRENT: unable to load cachecontrol.dat in cache";
                    }
                } else {
                    echo "cachecontrol.dat corrupt";
                }
            } else {
                echo "cachecontrol.dat not found in logs";
            }
        }
        $core->close();
    }
    if ($words[0] == "purge") {
        $purgeThis = array(!isset($words[1]) || $words[1] == "log" || $words[1] == "all", !isset($words[1]) || $words[1] == "cache" || $words[1] == "all", !isset($words[1]) || $words[1] == "bans" || $words[1] == "all");
        if ($purgeThis[1]) {
            $core->cacheControl->dumpTemplateCaches($purgeThis[0], true);
            $core->dimconfig['_404cache'] = array();
            $core->saveConfig(true);
        }
        if ($purgeThis[0]) {
            $listFiles = listFiles(CONS_PATH_LOGS, "/^([^a]).*(\\.log)\$/i", false, false, true);
            foreach ($listFiles as $file) {
                @unlink(CONS_PATH_LOGS . $file);
            }
        }
        if ($purgeThis[2]) {
            foreach (glob(CONS_PATH_TEMP . "*.dat") as $file) {
                if (!is_dir($file)) {
                    @unlink($file);
                }
            }
        }
        echo "Ok! (flags=" . ($purgeThis[0] ? "L" : "l") . ($purgeThis[1] ? "C" : "c") . ($purgeThis[2] ? "B" : "b") . ")";
        $core->close();
    }
    if ($words[0] == "phpinfo") {
        phpinfo();
        $core->close();
    }
    if (is_file(CONS_PATH_PAGES . $_SESSION['CODE'] . "/_config/_console.php")) {
        include CONS_PATH_PAGES . $_SESSION['CODE'] . "/_config/_console.php";
    }
    echo "command not understood";
    $core->close();
}
예제 #15
0
 function addPlugin($script, $relateToModule = "", $renamePluginTo = "", $noRaise = false)
 {
     $r = parent::addPlugin($script, $relateToModule, $renamePluginTo, $noRaise);
     if (!isset($this->dimconfig['_pluginStarter' . $script]) || $this->dimconfig['_pluginStarter' . $script] != true) {
         // ad monitors form this script to the list
         $fileP = CONS_PATH_SYSTEM . "plugins/{$script}/monitor.xml";
         $fileS = CONS_PATH_PAGES . $_SESSION['CODE'] . "/_config/monitor.xml";
         if (is_file($fileP)) {
             // plugin has a monitor
             if (is_file($fileS)) {
                 // site has a monitor
                 $contentP = cReadFile($fileP);
                 if (preg_match("@[^<]*(<[^>]*>).*@", $contentP, $e)) {
                     // get first tag ($e[1])
                     // check if site's monitor has this tag
                     $contentS = cReadFile($fileS);
                     if (strpos($contentS, $e[1]) === false) {
                         // it doesn't have, add
                         $contentS .= "\n" . $contentP;
                     }
                     cWriteFile($fileS, $contentS);
                 }
             } else {
                 copy($fileP, $fileS);
             }
         }
         $this->dimconfig['_pluginStarter' . $script] = true;
     }
     return $r;
 }
예제 #16
0
if ($_SESSION[CONS_SESSION_ACCESS_LEVEL] < 100 || strpos(CONS_MASTERDOMAINS, $_SESSION['DOMAIN']) === false) {
    $core->fastClose(403);
}
if (isset($_REQUEST['haveinfo'])) {
    $domains = cReadFile(CONS_PATH_SETTINGS . "domains");
    $domains = explode("\n", str_replace("\r", "", preg_replace("/(\t| ){1,}/", " ", $domains)));
    $output = "";
    $added = false;
    foreach ($domains as $dline) {
        if (strlen($dline) == 0 || $dline[0] == "#") {
            $output .= $dline . "\n";
        } else {
            $dline = explode(" ", $dline);
            if ($dline[0] == $_REQUEST['prevcode']) {
                // it's the line we where editing
                $output .= trim($_REQUEST['code']) . "\t" . trim($_REQUEST['domains']) . "\n";
                $added = true;
            } else {
                $output .= implode(" ", $dline) . "\n";
            }
        }
    }
    if (!$added) {
        $output .= trim($_REQUEST['code']) . "\t" . trim($_REQUEST['domains']) . "\n";
    }
    cWriteFile(CONS_PATH_SETTINGS . "domains", $output);
    @unlink(CONS_PATH_CACHE . "domains.dat");
    $core->close(false);
    header("location: master.php?debugmode=true&nocache=true");
    $core->action = "master";
}