$v) $fields[]=$k.'='.urlencode(stripslashes($v)); return implode('&',$fields); } // creates and executes a cURL session function googleapi($url,$post=null){ global $auth; $ch=curl_init(); curl_setopt($ch,CURLOPT_URL,$url); if(is_array($post)){ curl_setopt($ch,CURLOPT_POST,true); curl_setopt($ch,CURLOPT_POSTFIELDS,query($post)); } if($auth) curl_setopt($ch,CURLOPT_HTTPHEADER,array('Authorization: GoogleLogin auth='.$auth)); curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,2); curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false); $data=curl_exec($ch); curl_close($ch); return $data; } // turns a phone on or off function activate($phoneId,$active=true){ global $rnr; return googleapi('https://www.google.com/voice/settings/editDefaultForwarding/',array( 'phoneId'=>$phoneId, 'enabled'=>$active?1:0, '_rnr_se'=>$rnr )); } if(is_array($_GET['on'])||is_array($_GET['off'])){ // logging in via Google's ClientLogin API $auth=googleapi('https://www.google.com/accounts/ClientLogin',array( 'accountType'=>'GOOGLE', 'Email'=>GOOGLE_ACCOUNT, 'Passwd'=>GOOGLE_PASSWORD, 'service'=>'grandcentral', 'source'=>'chadsmith-googlevoice-locale')); // check for errors if(preg_match('/Error=([A-z]+)/',$auth,$error)) die($error[1]); // read auth tokens if(preg_match('/Auth=([A-z0-9_-]+)/',$auth,$auth)) $auth=$auth[1]; preg_match("/'_rnr_se'\: '([^']+)'/",googleapi('https://www.google.com/voice/'),$rnr); $rnr=$rnr[1]; // read names & ids of phones // remove the next 5 lines and toggle phones using their ID numbers if you don't have PHP5 preg_match("/\\<\!\[CDATA\[(.*)\]\]>\<\/json>/",googleapi('https://www.google.com/voice/settings/tab/phones'),$json); $json=json_decode($json[1]); $phones=array(); foreach($json->phones as $phone) $phones[strtolower($phone->name)]=$phone->id; // turn these phones on if(count($_GET['on'])) foreach($_GET['on'] as $phone) if($phones[$phone]) activate($phones[$phone]); // and these phones off if(count($_GET['off'])) foreach($_GET['off'] as $phone) if($phones[$phone]) activate($phones[$phone],false); // hooray done! } ?>