Skip to content

Commit

Permalink
Merge pull request #8 from directman66/master
Browse files Browse the repository at this point in the history
Добавлено управление устройством через web из админки модуля
  • Loading branch information
sergejey committed Jul 19, 2019
2 parents a91cd44 + 5a74bdb commit a07836c
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 0 deletions.
121 changes: 121 additions & 0 deletions modules/megad/megad.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,84 @@ function run()
*/
function admin(&$out)
{
if ($_POST['md']=='megad' && $_POST['inst']=='adm' &&$_POST['sourceip'])
{


$par=array();
//debmes($_POST, 'megad');
/*
if ($_POST['eip']<>'') $par['eip']=$_POST['eip'];
if ($_POST['cf']<>'') $par['cf']=$_POST['cf'];
if ($_POST['pwd']<>'') $par['pwd']=$_POST['pwd'];
if ($_POST['gw']<>'') $par['gw']=$_POST['gw'];
if ($_POST['sip']<>'') $par['sip']=$_POST['sip'];
if ($_POST['srvt']<>'') $par['srvt']=$_POST['srvt'];
if ($_POST['sct']<>'') $par['sct']=$_POST['sct'];
if ($_POST['pr']<>'') $par['pr']=$_POST['pr'];
if ($_POST['gsm']<>'') $par['gsm']=$_POST['gsm'];
if ($_POST['gsm_num']<>'') $par['gsm_num']=$_POST['gsm_num'];
if ($_POST['smst']<>'') $par['smst']=$_POST['smst'];
if ($_POST['pty']<>'') $par['pty']=$_POST['pty'];
if ($_POST['pn']<>'') $par['pn']=$_POST['pn'];
if ($_POST['ecmd']<>'') $par['ecmd']=$_POST['ecmd'];
if ($_POST['af']<>'') $par['af']=$_POST['af'];
if ($_POST['gsmf']<>'') $par['gsmf']=$_POST['gsmf'];
if ($_POST['grp']<>'') $par['grp']=$_POST['grp'];
if ($_POST['m']<>'') $par['m']=$_POST['m'];
if ($_POST['d']<>'') $par['d']=$_POST['d'];
if ($_POST['gsmf']<>'') $par['gsmf']=$_POST['gsmf'];
*/
$par= $_POST;
unset($par['sourceurl']);
unset($par['sourceip']);
unset($par['pd']);
unset($par['md']);
unset($par['inst']);


$sourceip=$_POST['sourceip'];
$sourceurl=$_POST['sourceurl'];

$pwd=SQLSelectOne ('select * from megaddevices where IP="'.$sourceip.'"')['PASSWORD'];


//debmes('$sourceip:'. $sourceip.' pwd:'.$pwd, 'megad');
//debmes('$sourceurl:'. $sourceurl, 'megad');
$url2=$_GET['par'];
//debmes($par,'megad');



$cmd='';
foreach ($par as $name=>$value)
{
//debmes( $name.'='.$value, 'megad');
//$cmd.='&'.$name.'='.$value;
$cmd=$cmd.'&'.$name.'='.urlencode(trim($value));
}
//$cmd=urldecode($cmd);

//$ip=$par['eip'];
//if ($ip=='') $id=$this->ip;

//debmes($cmd,'megad');
$newurl='http://'.$sourceip.'/'.$pwd.'/'.$cmd;

//debmes('get message '.$newurl,'megad');
$config=getURL($newurl, 0);
echo $config;
$redirect="?&data_source=&view_mode=edit_megaddevices&id=2&tab=config2&address=".$par['eip'].'&par='.urlencode($sourceurl);
//debmes('redirect '.$redirect,'megad');
$this->redirect($redirect);




}

if (isset($this->data_source) && !$_GET['data_source'] && !$_POST['data_source']) {
$out['SET_DATASOURCE'] = 1;
}
Expand All @@ -151,6 +229,9 @@ function admin(&$out)
}
$out['API_DEBUG'] = $this->config['API_DEBUG'];




if ($this->view_mode == 'update_settings') {
global $api_ip;
$this->config['API_IP'] = $api_ip;
Expand All @@ -173,6 +254,8 @@ function admin(&$out)
$this->redirect("?data_source=megaddevices");
}



if ($this->view_mode == 'scan') {
$this->scan();
$this->redirect("?data_source=megaddevices");
Expand Down Expand Up @@ -263,6 +346,44 @@ function readValues($id, $all = '', $quick = 0)
require(DIR_MODULES . $this->name . '/readvalues.inc.php');
}

function gethttpmessage($ip, $cmd)
{

$config=getURL($ip. $cmd, 0);
$new=$config;
//$new=str_replace( 'href=/sec','href=?viewmode=redirect&address='.$ip.'&par='.$cmd, $config);
//$new=str_replace( 'href=/sec','href=?viewmode=redirect&address='.$ip.'&par=', $config);
//$new=preg_replace( '<a href=(.*?)</a\>','<a href=</a\>', $config);
//$new=preg_replace( '<a href=(.*?)</a\>','<a href=</a\>', $config);
//$new=preg_replace("#\<a href=([^\' target='_blank'>]*)\](.*)\</a>#is", "<a href=\"$1\">$2</a>", $config);
//$new=preg_replace("<a href=(.*)</a>", "<a href=\"?viewmode=redirect&address='.$ip.'&par='.$cmd\"</a>", $config);
$new=preg_replace('/<a href=(.+?)>/i', '<a href="?data_source=&view_mode=edit_megaddevices&id='.$this->id.'&tab=config2&address='.$ip.'&par=$1">', $new);

//$new=preg_replace('/<form action=(.+?)>/i', '<form action='.$ip.'$1', $new);
//$new=preg_replace('/<form action=(.+?)>/i', '<form action='.'>', $new);

$new=preg_replace('/<form action=(.+?)>/i', '<form action="?" method="post" enctype="multipart/form-data" name="frmEdit" class="form-horizontal">', $new);

///
//$new=str_replace('<input type="hidden" name="inst" value="adm">', '<input type="hidden" name="inst2" value="adm">', $new);
//$new=str_replace('inst', 'inst2', $new);
$new=str_replace('<input type=submit value=Save>', '<input type=submit value=Save><input type="hidden" name="sourceurl" value="'.$cmd.'"><input type="hidden" name="sourceip" value="'.$ip.'">', $new);



//debmes($new, 'megad');

//$new=str_replace('IP:', 'IP2: ', $new);

//<form action="?" method="post" enctype="multipart/form-data" name="frmEdit" class="form-horizontal">



//$out['TEST']=$new;
return $new;


}


function scan()
Expand Down
22 changes: 22 additions & 0 deletions modules/megad/megaddevices_edit.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,28 @@
}
}
// step: config

if ($this->tab=='config2')
{
//$url='http://' . $rec['IP'] . '/' . $rec['PASSWORD'];
//$url='http://' . $rec['IP'] . '/' . $rec['PASSWORD'] . '/?cf=1';
//$config=getURL($url, 0);

//$new=str_replace( 'href=/','href='.$rec['IP'].'/', $config);

$address = $_GET['address'];
$par = $_GET['par'];

if ($address=='') $address=$rec['IP'];
if ($par=='') $par='/'.$rec['PASSWORD'];

$data=$this->gethttpmessage($address,$par);


//$data=$this->gethttpmessage($rec['IP'], '/'. $rec['PASSWORD']);
$out['TEST']=$data;
}

if ($this->tab == 'config') {

if ($this->mode == 'upgrade_firmware') {
Expand Down
2 changes: 2 additions & 0 deletions modules/megad/megaddevices_search.inc.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php


/*
* @version 0.1 (wizard)
*/
Expand Down
13 changes: 13 additions & 0 deletions templates/megad/action_admin.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
<li[#if TAB="config"#] class="active"[#endif#]>
<a href="?data_source=<#DATA_SOURCE#>&view_mode=<#VIEW_MODE#>&id=<#ID#>&tab=config">Advanced</a>
</li>
<li[#if TAB="config2"#] class="active"[#endif#]>
<a href="?data_source=<#DATA_SOURCE#>&view_mode=<#VIEW_MODE#>&id=<#ID#>&tab=config2">Device config</a>
</li>


</ul>
&nbsp;
[#endif ID#]
Expand All @@ -56,6 +61,14 @@
[#inc megaddevices_edit_config.html#]
[#endif TAB#]
[#endif VIEW_MODE#]


[#endif TAB#]
[#if TAB="config2"#]
[#inc megaddevicesconfig.html#]
[#endif TAB#]


<!-- / table megaddevices edit -->
<!-- table megaddevices view -->
[#if VIEW_MODE="view_megaddevices"#]
Expand Down
3 changes: 3 additions & 0 deletions templates/megad/megaddevicesconfig.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<hr>
[#TEST#]
<hr>

0 comments on commit a07836c

Please sign in to comment.