Example #1
0
/**
 * Convert XMLTree to Array
 * @param mixed $data Data
 * @return array
 */
function XMLTreeToArray($data)
{
    $res = array();
    $total = count($data);
    for ($i = 0; $i < $total; $i++) {
        if (!isset($res[$data[$i]['tag']])) {
            $res[$data[$i]['tag']] = array();
            $elem =& $res[$data[$i]['tag']];
        } elseif (!is_array($res[$data[$i]['tag']][0])) {
            $tmp = $res[$data[$i]['tag']];
            $res[$data[$i]['tag']] = array();
            $res[$data[$i]['tag']][0] = $tmp;
            $res[$data[$i]['tag']][] = array();
            $elem =& $res[$data[$i]['tag']][count($res[$data[$i]['tag']]) - 1];
        } else {
            $elem = array();
            $res[$data[$i]['tag']][] =& $elem;
        }
        if (is_array($data[$i]['attributes'])) {
            foreach ($data[$i]['attributes'] as $k => $v) {
                $elem[$k] = $v;
            }
        }
        if ($data[$i]['value']) {
            $elem['textvalue'] = $data[$i]['value'];
        }
        if (is_array($data[$i]['children'])) {
            $children = XMLTreeToArray($data[$i]['children']);
            foreach ($children as $k => $v) {
                $elem[$k] = $v;
            }
        }
        unset($elem);
    }
    return $res;
}
Example #2
0
 /**
 * BackEnd
 *
 * Module backend
 *
 * @access public
 */
 function admin(&$out)
 {
     global $err_msg;
     if ($err_msg) {
         $out['ERR_MSG'] = $err_msg;
     }
     global $ok_msg;
     if ($ok_msg) {
         $out['OK_MSG'] = $ok_msg;
     }
     $this->getConfig();
     if (is_dir(ROOT . 'saverestore/temp')) {
         $out['CLEAR_FIRST'] = 1;
     }
     $this->getConfig();
     $github_feed = getURL('https://github.com/sergejey/majordomo/commits/master.atom', 30 * 60);
     if ($github_feed != '') {
         @($tmp = GetXMLTree($github_feed));
         @($data = XMLTreeToArray($tmp));
         @($items = $data['feed']['entry']);
         if (is_array($items)) {
             $total = count($items);
             if ($total) {
                 if ($total > 5) {
                     $total = 5;
                 }
                 //print_r($items);exit;
                 for ($i = 0; $i < $total; $i++) {
                     $itm = array();
                     $itm['ID'] = trim($items[$i]['id']['textvalue']);
                     $itm['ID'] = preg_replace('/.+Commit\\//is', '', $itm['ID']);
                     $itm['TITLE'] = trim($items[$i]['title']['textvalue']);
                     $itm['AUTHOR'] = $items[$i]['author']['name']['textvalue'];
                     $itm['LINK'] = $items[$i]['link']['href'];
                     $itm['UPDATED'] = strtotime($items[$i]['updated']['textvalue']);
                     $itm['UPDATE_TEXT'] = date('m/d/Y H:i', $itm['UPDATED']);
                     $out['UPDATES'][] = $itm;
                 }
                 $out['LATEST_ID'] = $out['UPDATES'][0]['ID'];
                 if ($out['LATEST_ID'] != '' && $out['LATEST_ID'] == $this->config['LATEST_UPDATED_ID']) {
                     $out['NO_NEED_TO_UPDATE'] = 1;
                 }
                 //print_r($out['UPDATES']);
                 //exit;
             }
         }
     }
     if ($this->mode == 'savedetails') {
         global $ftp_host;
         global $ftp_username;
         global $ftp_password;
         global $ftp_folder;
         global $ftp_clear;
         if ($ftp_clear) {
             $this->config['FTP_USERNAME'] = '';
             $this->config['FTP_PASSWORD'] = '';
             $this->saveConfig();
             $this->redirect("?");
         }
         $out['FTP_HOST'] = $ftp_host;
         $out['FTP_USERNAME'] = $ftp_username;
         $out['FTP_PASSWORD'] = $ftp_password;
         $out['FTP_FOLDER'] = $ftp_folder;
         $conn_id = @ftp_connect($ftp_host);
         if ($conn_id) {
             $login_result = @ftp_login($conn_id, $ftp_username, $ftp_password);
             if ($login_result) {
                 $systyp = ftp_systype($conn_id);
                 if (!preg_match('/\\/$/', $ftp_folder)) {
                     $ftp_folder .= '/';
                 }
                 if (@ftp_chdir($conn_id, $ftp_folder . 'saverestore')) {
                     $this->config['FTP_HOST'] = $ftp_host;
                     $this->config['FTP_USERNAME'] = $ftp_username;
                     $this->config['FTP_PASSWORD'] = $ftp_password;
                     $this->config['FTP_FOLDER'] = $ftp_folder;
                     $this->saveConfig();
                     $this->redirect("?");
                 } else {
                     $out['FTP_ERR'] = 'Incorrect folder (' . $ftp_folder . ')';
                 }
             } else {
                 $out['FTP_ERR'] = 'Incorrect username/password';
             }
             ftp_close($conn_id);
         } else {
             $out['FTP_ERR'] = 'Cannot connect to host (' . $ftp_host . ')';
         }
     }
     if ($this->mode != 'savedetails') {
         $out['FTP_HOST'] = $this->config['FTP_HOST'];
         $out['FTP_USERNAME'] = $this->config['FTP_USERNAME'];
         $out['FTP_PASSWORD'] = $this->config['FTP_PASSWORD'];
         $out['FTP_FOLDER'] = $this->config['FTP_FOLDER'];
     }
     // if ($this->mode=='' || $this->mode=='upload' || $this->mode=='savedetails') {
     $method = 'ftp';
     if (function_exists('getmyuid') && function_exists('fileowner')) {
         $temp_file = tempnam("./saverestore/", "FOO");
         if (file_exists($temp_file)) {
             $method = 'direct';
             unlink($temp_file);
         }
     }
     $out['METHOD'] = $method;
     $this->method = $method;
     // }
     if ($this->mode == 'clear') {
         $this->removeTree(ROOT . 'saverestore/temp');
         $this->redirect("?err_msg=" . urlencode($err_msg) . "&ok_msg=" . urlencode($ok_msg));
     }
     if ($this->mode == 'checksubmit') {
         $this->checkSubmit($out);
     }
     if ($this->mode == 'uploadupdates') {
         $this->uploadUpdates($out);
     }
     if ($this->mode == 'checkupdates') {
         $this->checkupdatesSVN($out);
     }
     if ($this->mode == 'downloadupdates') {
         $this->downloadupdatesSVN($out);
     }
     if ($this->mode == 'checkapps') {
         $this->checkApps($out);
     }
     if ($this->mode == 'downloadapps') {
         $this->downloadApps($out);
     }
     if ($this->mode == 'upload') {
         $this->upload($out);
         //$this->redirect("?mode=clear");
     }
     if ($this->mode == 'dump') {
         $this->dump($out);
         $this->redirect("?mode=clear");
         //$this->redirect("?");
     }
     if ($this->mode == 'delete') {
         global $file;
         @unlink(ROOT . 'saverestore/' . $file);
         $this->redirect("?");
     }
     if ($this->mode == 'getlatest') {
         $this->getLatest($out);
     }
     $source = ROOT . 'saverestore';
     $currentdir = getcwd();
     chdir($source);
     array_multisort(array_map('filemtime', $files = glob("*.*")), SORT_DESC, $files);
     chdir($currentdir);
     foreach ($files as $file) {
         $tmp = array();
         $tmp['FILENAME'] = $file;
         $tmp['FILESIZE'] = number_format(filesize($source . "/" . $file) / 1024 / 1024, 2);
         $out['FILES'][] = $tmp;
     }
 }
Example #3
0
 /**
 * BackEnd
 *
 * Module backend
 *
 * @access public
 */
 function admin(&$out)
 {
     global $name;
     $data_url = 'http://connect.smartliving.ru/market/?lang=' . SETTINGS_SITE_LANGUAGE;
     global $err_msg;
     if ($err_msg) {
         $out['ERR_MSG'] = $err_msg;
     }
     global $ok_msg;
     if ($ok_msg) {
         $out['OK_MSG'] = $ok_msg;
     }
     if (is_dir(ROOT . 'saverestore/temp')) {
         $out['CLEAR_FIRST'] = 1;
     }
     $result = getURL($data_url, 120);
     $data = json_decode($result);
     if (!$data->PLUGINS) {
         $out['ERR'] = 1;
         return;
     }
     $total = count($data->PLUGINS);
     $old_category = '';
     $can_be_updated = array();
     for ($i = 0; $i < $total; $i++) {
         $rec = (array) $data->PLUGINS[$i];
         if (is_dir(ROOT . 'modules/' . $rec['MODULE_NAME'])) {
             $rec['EXISTS'] = 1;
             $plugin_rec = SQLSelectOne("SELECT * FROM plugins WHERE MODULE_NAME LIKE '" . DBSafe($rec['MODULE_NAME']) . "'");
             if ($plugin_rec['ID']) {
                 $rec['INSTALLED_VERSION'] = $plugin_rec['CURRENT_VERSION'];
             }
         }
         if ($rec['CATEGORY'] != $old_category) {
             $rec['NEW_CATEGORY'] = 1;
             $old_category = $rec['CATEGORY'];
         }
         //if ($rec['MODULE_NAME']==$name) {
         unset($rec['LATEST_VERSION']);
         if (preg_match('/github\\.com/is', $rec['REPOSITORY_URL']) && ($rec['EXISTS'] || $rec['MODULE_NAME'] == $name)) {
             $git_url = str_replace('archive/master.tar.gz', 'commits/master.atom', $rec['REPOSITORY_URL']);
             $github_feed = getURL($git_url, 5 * 60);
             @($tmp = GetXMLTree($github_feed));
             @($items_data = XMLTreeToArray($tmp));
             @($items = $items_data['feed']['entry']);
             if (is_array($items)) {
                 $latest_item = $items[0];
                 //print_r($latest_item);exit;
                 $updated = strtotime($latest_item['updated']['textvalue']);
                 $rec['LATEST_VERSION'] = date('Y-m-d H:i:s', $updated);
                 $rec['LATEST_VERSION_COMMENT'] = $latest_item['title']['textvalue'];
                 $rec['LATEST_VERSION_URL'] = $latest_item['link']['href'];
             }
         }
         if ($rec['MODULE_NAME'] == $name) {
             $url = $rec['REPOSITORY_URL'];
             $version = $rec['LATEST_VERSION'];
         }
         //}
         if ($rec['EXISTS']) {
             $can_be_updated[] = array('NAME' => $rec['MODULE_NAME'], 'URL' => $rec['REPOSITORY_URL'], 'VERSION' => $rec['LATEST_VERSION']);
             //$can_be_updated[]=$rec['MODULE_NAME'];
         }
         $out['PLUGINS'][] = $rec;
     }
     if ($this->mode == 'update_all') {
         $this->updateAll($can_be_updated);
     }
     if ($this->mode == 'install' && $url) {
         $this->getLatest($out, $url, $name, $version);
     }
     if ($this->mode == 'upload') {
         $this->upload($out);
     }
     if ($this->mode == 'uninstall' && $name) {
         $this->uninstallPlugin($name);
     }
     if ($this->mode == 'clear') {
         $this->removeTree(ROOT . 'saverestore/temp');
         @SaveFile(ROOT . 'reboot', 'updated');
         $this->redirect("?err_msg=" . urlencode($err_msg) . "&ok_msg=" . urlencode($ok_msg));
     }
 }